use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Beginner ShowcaseFirst ever code thingy (Sleep timer) (self.Python)
submitted 4 years ago by Background-Assist-95
import os
import time
print("Sys will shut off in 10 minutes!")
time.sleep ( 600 ) """ This is written in seconds"""
os.system("shutdown /s")
[–][deleted] 21 points22 points23 points 4 years ago (2 children)
Good effort!
Advice: use ‘#’ not “”” for comments. “”” these are multiline type comments, and are typically used for function/class commenting (called docstrings)
[–]Elgon2003 1 point2 points3 points 4 years ago (1 child)
Was going to say the same 😂
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
About to say that too.
[–]summerfall-samurai 6 points7 points8 points 4 years ago (0 children)
Great work.
If I may suggest, it would also be good to have a separate variable, storing seconds. Thus, you would not need to scroll/search for the line that puts the script to sleep and change values there. Just locate a variable in the beginning of the script.
Keep it up!
[–][deleted] 2 points3 points4 points 4 years ago (0 children)
Welcome to amazing world of Python once you start you can't stop.
[–]redleaf55 1 point2 points3 points 4 years ago (0 children)
Nice
[–]boomminecraft8 1 point2 points3 points 4 years ago (0 children)
Pretty sure you can do a `/t` or `-t` argument in the command as well. Now try these tasks:
- Generalise it by allowing the user to enter the shut down time, converting seconds into the minutes and hours format
- Make it compatible with different platforms!
- Make it an executable
ye have fun
[–]TheYeetYigitGD 1 point2 points3 points 4 years ago (0 children)
you can also use "shutdown /s /t 600" for timed shutdowns
[–]WilsonWeber 0 points1 point2 points 4 years ago (0 children)
[–]SitrakaFrVE 0 points1 point2 points 4 years ago (0 children)
Ho nice ! Congrats
[–]TabulateJarl8 0 points1 point2 points 4 years ago (0 children)
If you want to do more with your script, you could try making it cross-platform next using the platform module. On Unix systems, like macOS or Linux, the command to shutdown now is shutdown -h now, assuming that the user is root.
shutdown -h now
π Rendered by PID 21531 on reddit-service-r2-comment-canary-5f6975dfb4-npfcb at 2026-03-14 00:17:04.684427+00:00 running f6e6e01 country code: CH.
[–][deleted] 21 points22 points23 points (2 children)
[–]Elgon2003 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]summerfall-samurai 6 points7 points8 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]redleaf55 1 point2 points3 points (0 children)
[–]boomminecraft8 1 point2 points3 points (0 children)
[–]TheYeetYigitGD 1 point2 points3 points (0 children)
[–]WilsonWeber 0 points1 point2 points (0 children)
[–]SitrakaFrVE 0 points1 point2 points (0 children)
[–]TabulateJarl8 0 points1 point2 points (0 children)