global variables 03-28-2013, 12:31 AM
#1
hey, not sure if this will be of any use but it took me a while to find out how to do make global variables in python and i think this is the easiest way.
First off make a config.py file this will hold all of your global variables so you can use them later in your other modules.
Config
then all you need to do is import this file at the start of any modules you will be using these global variables in.
So basically after you have imported the config module you can use the variables from it as you would normally, as long as you remember to put the config. in front of the variable name.
p.s. the module can be called anything just make sure that you keep the name same throughout. e.g. if your config file was called global.py you would
import global and use the global.(your variable)
First off make a config.py file this will hold all of your global variables so you can use them later in your other modules.
Config
Code:
name = ' '
age = 0
# you can add what ever variables you need to herethen all you need to do is import this file at the start of any modules you will be using these global variables in.
Code:
import config # loads all variables from the config module
print (config.name) # will print the variable from config
config.name = input('what is your name') # this will edit the variable in the config moduleSo basically after you have imported the config module you can use the variables from it as you would normally, as long as you remember to put the config. in front of the variable name.
p.s. the module can be called anything just make sure that you keep the name same throughout. e.g. if your config file was called global.py you would
import global and use the global.(your variable)
there are 10 types of people in this world,
those who understand binary and those who don't.
skype name: J4W3S.23
those who understand binary and those who don't.
skype name: J4W3S.23


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)


![[Image: Signature.png]](https://dl.dropbox.com/u/81692631/Signature.png)