Consola de impresión#
Print Console commands are only available when using VEXcode EXP. If you are coding in VS Code, you will need to print to the V5’s Brain Screen using brain.screen commands.
Todos los proyectos nuevos comienzan con el cursor en la fila 1 de la Consola de impresión.
Comandos#
Print to the Print Console#
The print(text, end) method prints text on the screen using the current cursor position.
Parámetros |
Descripción |
|---|---|
|
La cadena para imprimir en la consola de impresión. |
|
Si se pasa o no a la siguiente línea de la consola de impresión. Por defecto, está vacío. |
Formato#
Values being printed to the Print Console can use the Python format method.
Algunos tipos de formato comúnmente utilizados son:
d - Entero decimal
f - Número de punto flotante
o - Entero octal
s - Cadena
In order to use a formatting type, put the desired formatting type in curly brackets ({}), starting with a colon (:) followed by .format.
Este ejemplo imprimirá el número 3.140000.
print("{:f}".format(3.14))
You can also include a number to specify how many decimal places you want to be printed. Do so by including a . and the number of decimal places before your formatting type.
Este ejemplo imprimirá el número 3.14.
print("{:.2f}".format(3.14))
You can also include sensors with the format method to change how many decimals are returned when the sensor’s value is reported.
print("{:.2f}".format(brain.timer.time(SECONDS)))
Nuevas líneas#
By default, Python will add a new line after each print command. To print multiple values to the same line, use the end parameter.
In this example, the text from both print commands will be printed on the same line.
print("This text will be ", end="")
print("printed on the same line")
Diferentes colores#
Puede cambiar el color del texto al imprimir en la Consola de impresión utilizando los siguientes códigos de color:
[31m- Red[32m- Green[34m- Blue[30m- Black[37m- White[33m- Yellow[91m- Orange[35m- Purple[36m- Cyan[97m- Transparent
All color codes need to follow an escape sequence = \033 in order to function.
You can either use this directly in a print command with a string.
# Print VEXcode in Red to the Print Console.
print("\033[31mVEXcode")
Or, you can use it on its own to set all print commands afterwards to the set color.
# Set the Print Console text color to Red before printing VEXcode.
print("\033[31m")
print("VEXcode")
Devoluciones: Ninguna.
Clear the Print Console#
By using \033[2J inside of the print command, you can clear the entire Print Console. This will also set the cursor back to row 1.
El siguiente ejemplo imprimirá “VEXcode” y luego borrará la consola de impresión después de 2 segundos.
print("VEXcode")
wait(2, SECONDS)
print("\033[2J")