Alot of questions about Python: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Alot of questions about Python:

1: How can I get the hour, minutes and second? 2: If other languages has system("cls") How can I do that in Python (Clearing screens in Python) 3: GetASyncKeyState in Python?

12th Apr 2017, 1:02 PM
MrCoder
MrCoder - avatar
13 Answers
+ 18
#1: from datetime import datetime now = datetime.now() print(now.hour,now.minute,now.second) #2: import os print("stuff") os.system('cls') #only works on windows I think. also won't work on Sololearn. there are other commands for other OS #3: import msvcrt while True: #loop if msvcrt.kbhit() == True: #if key is being pressed keypress=str(msvcrt.getch()) #get key if keypress == "b'c'": print("sup bruhh") #wont work on Sololearn. Might also be only Windows, but I'm not sure #Another Question: print(chr(87))
12th Apr 2017, 1:10 PM
Ahri Fox
Ahri Fox - avatar
+ 14
updated my answer. check it out!
12th Apr 2017, 1:49 PM
Ahri Fox
Ahri Fox - avatar
14th Apr 2017, 12:00 AM
Gami
Gami - avatar
+ 8
Terminals either need ANSI Escape Sequences* (as visph describes in @Supersebi3's linked answer) or--if not in ANSI mode--a 'form feed', which is in the 'ASCII control characters': chr(12) Manually, you can test your terminal by pressing Ctrl+L (the 12th letter). Ctrl+A through Z map to control characters 1-26. On Windows you may need to use echo (^ is Ctrl, echo is like print): C:\>echo ^L * ANSI escape codes start with chr(27), aka: Escape, aka: Ctrl+[ ... or the same code as the PC 'Esc key'.
13th Apr 2017, 1:25 AM
Kirk Schafer
Kirk Schafer - avatar
+ 8
@Gami Thanks :D
14th Apr 2017, 12:01 AM
MrCoder
MrCoder - avatar
+ 6
chr() makes numbers into ASCII
12th Apr 2017, 1:13 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
print(chr(219))
12th Apr 2017, 1:16 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
If you make a console application, you can use ANSI escape codes to clear the screen For more info, read this: https://www.sololearn.com/discuss/303028/?ref=app
12th Apr 2017, 2:33 PM
Supersebi3
Supersebi3 - avatar
+ 4
@Kuba Siekierzynski Oh yeah totally forgot I'm not on Ruby, thank you very much :D
12th Apr 2017, 1:17 PM
MrCoder
MrCoder - avatar
+ 4
@Ahri Fox Thanks alot :D
12th Apr 2017, 1:50 PM
MrCoder
MrCoder - avatar
+ 3
And Another Question: How can I make numbers into ASCII ? Please answer ASAP, thanks :D
12th Apr 2017, 1:08 PM
MrCoder
MrCoder - avatar
+ 3
Thanks, what I meant about GetASyncKeyState is, it isa function which gets what you typed. for example you wrote a code where when you hit letter 'C' it will output "What bruh"
12th Apr 2017, 1:11 PM
MrCoder
MrCoder - avatar
+ 3
@Kuba Siekierzynski Oh thank you :D so it is like: print(219).chr() ?
12th Apr 2017, 1:14 PM
MrCoder
MrCoder - avatar