Using the __builtins__ module to assign new global variables

Discussion in 'Python' started by Opinder, Mar 1, 2004.

  1. Opinder

    Opinder Guest

    Hi,

    For the Python experts out there:

    Are there any side effects in assigning new variables to the
    __builtins__ module for the purpose of exposing variables to imported
    modules.

    For example.

    #/ main file

    class Test: pass

    mytest = Test() #/ instance of a class
    __builtins__.mytest = mytest

    import abc


    #/ -----------------------
    #/ This is the abc.py module file
    #/ This should work because of the __builtins__ above
    print mytest

    Thanks.
     
    Opinder, Mar 1, 2004
    #1
    1. Advertisements

  2. Opinder wrote:

    > Are there any side effects in assigning new variables to the
    > __builtins__ module for the purpose of exposing variables to imported
    > modules.


    Generally, Guido frowns at you very sternly. Also, you could
    cause a disaster if there is a conflict between your idea of what
    should be a global and some other module's idea. You will be in
    big trouble if a builtin is added that you over-write (actually
    a form of the same problem).

    --
    -Scott David Daniels
     
    Scott David Daniels, Mar 2, 2004
    #2
    1. Advertisements

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. Wayne
    Replies:
    2
    Views:
    647
    Wayne
    Nov 11, 2003
  2. Zunbeltz Izaola

    global variables in module

    Zunbeltz Izaola, Feb 4, 2004, in forum: Python
    Replies:
    2
    Views:
    351
    Zunbeltz Izaola
    Feb 5, 2004
  3. Adam Hupp
    Replies:
    1
    Views:
    325
    Marc Christiansen
    Jun 22, 2007
  4. jubelbrus
    Replies:
    5
    Views:
    816
    JohnQ
    Jul 20, 2007
  5. mark4asp
    Replies:
    1
    Views:
    340
  6. Tony Archer

    Global Variables? Multi-Application Variables?

    Tony Archer, Nov 24, 2003, in forum: ASP General
    Replies:
    5
    Views:
    392
    Tony Archer
    Nov 25, 2003
  7. king
    Replies:
    2
    Views:
    330
    Tad McClellan
    Jun 27, 2006
  8. Replies:
    2
    Views:
    779
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...