Python Forum
Best way(s) to organize and use "global" values?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way(s) to organize and use "global" values?
#6
@jefsummers - there is no need of line 4 in this example
IF it is really waranted to have a constant, as per PEP8 recommendation, it should be ALL_CAPS:
Quote:Constants

Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL.

@pjfarley3, some of your your "examples" under 1 and 2 MAY be a case to use a constant or enumeration. Some of the examples in 1 and 2 are definitely NOT such case - e.g. index numbers for elements in a list (i.e. if you want meaningful names, not int index, work with dict or named tuple). item 3 in the list is exactly why using globals should be avoided - changing variable at different scope levels is recipe for disaster and will cost you a lot of debugging time sooner than later. If we take the example you give - current position of a player, most probably you will have a Player class and it will have current_position attribute if needed, but definitely not a global variable.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Best way(s) to organize and use "global" values? - by buran - Sep-02-2020, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I organize my simple ftp modules? blobdx7 3 586 Jan-05-2024, 01:23 PM
Last Post: Gribouillis
  How can I organize my code according to output that I want ilknurg 1 1,205 Mar-11-2022, 09:24 AM
Last Post: perfringo
Star Split and organize my Pandas Dataframe brunolelli 4 2,763 Apr-18-2021, 03:00 AM
Last Post: brunolelli
  Counting number of words and organize for the bigger frequencies to the small ones. valeriorsneto 1 1,707 Feb-05-2021, 03:49 PM
Last Post: perfringo
  Global variable does not seem to be global. Columbo 6 3,760 Jul-15-2019, 11:00 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020