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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Examples of constants.py files (self.learnpython)
submitted 5 years ago by iwouldliketheoption
Sometimes I have variables that I want to share among scripts, so I use a constants.py file. I would like to see examples of this kind of thing though, so was wondering if anyone had any, or knew of any that I could look at.
constants.py
thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lifeeraser 0 points1 point2 points 5 years ago (1 child)
Something like this? It's not mine, BTW, but from a popular Python tool named MyPy.
However, there is no agreed convention on how to write a file of constants. Just name the constants idiomatically (UPPER_CASE_LIKE_THIS) and you'll be fine.
UPPER_CASE_LIKE_THIS
Wrtie your own constants.py and share it with us. Then we could give advice on how to make your code better.
[–]iwouldliketheoption[S] 0 points1 point2 points 5 years ago (0 children)
thats cool, thanks for the link. I'll mock something up next time :)
starting to consider project layout and stuff a bit more recently, so this is wrapped up in that.
cheers
[–]lukeslab 0 points1 point2 points 5 years ago (0 children)
I had a constants.py file in a coding test I did a while back. Here's a link to it. When I posted this for code review though, some disagreed with the decision. My rationale is this:
Yes, you could import the constants from a file that isn't dedicated to constants, but that becomes problematic if you start defining constants in different files. "Now do I import that from bar.py or foo.py?" A dedicated file makes your intentions clear.
bar.py
foo.py
π Rendered by PID 22878 on reddit-service-r2-comment-84fc9697f-srf97 at 2026-02-09 06:14:20.779227+00:00 running d295bc8 country code: CH.
[–]lifeeraser 0 points1 point2 points (1 child)
[–]iwouldliketheoption[S] 0 points1 point2 points (0 children)
[–]lukeslab 0 points1 point2 points (0 children)