python - Libraries act differently depending on if they are installed or not -


I have a Python Library which I have written which is working on me I have a set of variables Changes the way It is all right to test, but when I use the python lib.py install variable does not affect the library. I probably broke it down for the easiest example:

Library:

  ## lib.py config = "original" def run (): print config   

script:

  import lib libconfig = "new" lib.run () print lib.config   

if Place the library in the same directory as a script and output it to:

  New new   

But if you install the library and try again Use of Library from Display Package The script output is:

  original new   

Can someone tell what is happening? I am a little confused and I am very interested in events and reasons. Is the programmatic configuration completely wrong?

Edit

It shows that the problem is the init .py file. It's basically like importing a library which only imports another library when you import an installed module, then the folder lib and init .py file Looks at init .py is only one liner liberalization import * . This is only the appearance of the actual library, but if you use a global variable it causes a strange problem. A simulated example of what's actually going on:

  script ## init.py lib import * from   

script:

 < Code> import init init.config = 'new' init.run () print init.config   

Output:

  original new   

Function run () appears in lib.py for config , but print init.config looks for init.py. Thanks for the help everyone. The way to fix the fix module is to change (no init .py). After all, I hope to remove all the global variables, but for the time everything is correct.

Do you describe how Python works with incompatible (Read, if you wish , "I do not believe you did well and got the exact same result").

If you can lib from different places or in different ways, however, you can finish it with two copies, either copies of two modules or current Getting a "basic" / "new" behavior from directory- lib and one of the other lib if you are Seems possible reason.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -