Python Forum
Global accessing of parameter to class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global accessing of parameter to class
#4
If you use the if __name__ == "__main__": check, you should be able to just import it.

# eggs.py

frame_data = 42

if __name__ == "__main__":
    import spam
    print(spam.other_data)
    print(frame_data) # what will this be?
# spam.py

import eggs
other_data = eggs.frame_data * 2
eggs.frame_data = 1
Output:
> python eggs.py 84 42
It's not a great way to do it, since each module would then have it's own concept of what the values are, so a change in one file won't be reflected in the other (as demonstrated).  It works for basic cases, but you're better off restructuring if you want something that works better.
Reply


Messages In This Thread
RE: Global accessing of parameter to class - by nilamo - Aug-23-2017, 07:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,103 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  accessing value in dict_values class CompleteNewb 14 5,216 Mar-31-2022, 04:02 AM
Last Post: deanhystad
  read a parameter after updating it in another class MKS2020 3 2,280 Jul-25-2020, 08:27 AM
Last Post: MKS2020
  accessing local variable outside class priyanka08 3 2,189 Sep-24-2019, 10:00 AM
Last Post: buran
  Global variable does not seem to be global. Columbo 6 3,718 Jul-15-2019, 11:00 PM
Last Post: Columbo
  The derivate class dosn't behave like the base when i pass parameter to them drudox 4 3,189 Aug-05-2018, 06:42 PM
Last Post: drudox
  How to print a global dictionary class properly 3dimensions 2 3,236 Apr-18-2018, 05:45 PM
Last Post: nilamo
  [Python Class] save method output to global file/list Vijay 3 5,074 Dec-23-2017, 03:20 AM
Last Post: Vijay

Forum Jump:

User Panel Messages

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