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?
#1
When writing some applications (e.g., games), one ends up having perhaps dozens or even hundreds of "global" values, of several types:

1. Predefined static values one wishes to use as "named constants"
Example: Index numbers for standard items stored in arrays or lists, or names for color values

2. Values that are static after initialization, perhaps dependent on argument or configuration file or environment variable values
Example: Terminal LINES and COLS values in a console application or a boolean variable for a debug switch argument to optionally generate debugging output

3. Values that are not static for the whole program but which need to be used at many different scoping levels
Example: The current position of a player or other object(s) in a game map

Is it better to use actual python "global" (module-level) variables, or set up a "static_vars" class to initialize and hold them (all or only some?), or some other design pattern that works better?

Thanks in advance for your advice and references.

Peter
Reply


Messages In This Thread
Best way(s) to organize and use "global" values? - by pjfarley3 - Sep-02-2020, 05:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I organize my simple ftp modules? blobdx7 3 538 Jan-05-2024, 01:23 PM
Last Post: Gribouillis
  How can I organize my code according to output that I want ilknurg 1 1,183 Mar-11-2022, 09:24 AM
Last Post: perfringo
Star Split and organize my Pandas Dataframe brunolelli 4 2,723 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,684 Feb-05-2021, 03:49 PM
Last Post: perfringo
  Global variable does not seem to be global. Columbo 6 3,717 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