Hi all,

How can I declare a global variable inside a module and use it across other modules for throughout the lifecycle of the program?

Regards,
Dinil

Recommended Answers

All 3 Replies

So i take it your making you own module and importing it right? Well if you import a module you can access its variables by going

module.variable

If you have imported the module then the module is global and therefore there is global access to the variable.

If that isnt it, would you mind clearing it up a bit, in more detail.

Hi ...
Thanks for the suggestions. I will have to check my code again if this really works out. Any way will get back if I am stuck somewhere!!!..

Regards,
Dinil

+1 for you!

#here are global values
import wx
import random
#here are global values

class MyFrame(wx.Frame):
    #here are only class methods
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(180, 380))

#Global to the rest of the code but not the first class MyFrame
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.