Learning variable visibility

  • Thread starter Niklasro(.appspot)
  • Start date
N

Niklasro(.appspot)

Hi
How do I declare a variable visibility across files? Will import name
where name is name of the file do?
Thanks for instructing
Niklas Rosencrantz
 
D

Dennis Lee Bieber

Hi
How do I declare a variable visibility across files? Will import name
where name is name of the file do?
Thanks for instructing
Niklas Rosencrantz

-=-=-=-=- shareddata.py
me = "What"
you = "Why"
us = 3

-=-=-=-=- main.py
import shareddata
import othercode

print shareddata.me #Python 2.x
shareddata.us = 3.1415926
othercode.something("Wow")
print shareddata.you, shareddata.us

-=-=-=-=- othercode.py
import shareddata

def something(x):
print "Othercode", shareddata.us
shareddata.you = x
shareddata.us = 2.718
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top