How can i use python to control my computer ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i use python to control my computer ?

I mean , if i want to shut down my computer it will show the notepad to save the time in a text

5th Sep 2020, 6:28 PM
S E N I O R
S E N I O R - avatar
5 Answers
+ 2
I am not sure I understand the request completely, you want to shutdown your computer and you want to save the date and timestamp of the shutdown to a notepad or some other text editor? If that is the case, you really don't need Python to do that, you can create a batch file, if you're on Windows, that can perform those two tasks. If you're on Linux or Mac a BASh script would work too.
5th Sep 2020, 6:33 PM
Steven M
Steven M - avatar
+ 2
If you really wanna use python then I think system function from OS library would be helpful: import os command = # something to execute in CMD os.system(command) And you can use time/datetime library for time
5th Sep 2020, 6:50 PM
Bagon
Bagon - avatar
+ 2
Ok, I would l use the OS library https://docs.python.org/3/library/os.html it will allow you to shutdown the machine. I would also use the Logging library https://docs.python.org/3/howto/logging.html because it has more control, it is better than just writing to a file. However, if you want to write directly to a file, then print('YOUR MESSAGE HERE', file='YOUR LOCATION HERE') should work just fine
5th Sep 2020, 6:51 PM
Steven M
Steven M - avatar
+ 1
Thousand thanks😍😍
5th Sep 2020, 7:05 PM
S E N I O R
S E N I O R - avatar
0
Yeah i mean that ,but i want to chose only python
5th Sep 2020, 6:41 PM
S E N I O R
S E N I O R - avatar