Learning variable visibility

Discussion in 'Python' started by Niklasro(.appspot), Sep 6, 2010.

  1. 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
     
    Niklasro(.appspot), Sep 6, 2010
    #1
    1. Advertising

  2. eOn Mon, 6 Sep 2010 00:52:12 -0700 (PDT), "Niklasro(.appspot)"
    <> declaimed the following in
    gmane.comp.python.general:

    > 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

    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Sep 6, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Wark
    Replies:
    1
    Views:
    610
    Brock Allen
    May 23, 2005
  2. Steve Wark

    Variable Scope / Visibility

    Steve Wark, May 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    476
    Steve Wark
    May 23, 2005
  3. COHENMARVIN
    Replies:
    2
    Views:
    649
    Lucas Tam
    Sep 12, 2005
  4. Hal Vaughan
    Replies:
    7
    Views:
    509
  5. Andrey Popp

    [I'm learning C]: Learning to use ucontext

    Andrey Popp, Jan 29, 2012, in forum: C Programming
    Replies:
    5
    Views:
    784
    Keith Thompson
    Jan 31, 2012
Loading...

Share This Page