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. Advertising

  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. 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. Remy Blank
    Replies:
    3
    Views:
    887
    Lothar Scholz
    Mar 6, 2004
  2. Jacek Generowicz
    Replies:
    1
    Views:
    390
    Daniel Dittmar
    Apr 8, 2004
  3. Adam Hupp
    Replies:
    1
    Views:
    277
    Marc Christiansen
    Jun 22, 2007
  4. Chris Angelico
    Replies:
    0
    Views:
    155
    Chris Angelico
    Oct 11, 2012
  5. Chris Angelico
    Replies:
    0
    Views:
    152
    Chris Angelico
    Oct 14, 2012
Loading...

Share This Page