Fredrik Lundh wrote:
> no, the "bar.py" *file* gets loaded twice, first as the "foo.bar"
> module, and then as the "bar" module.
True and I agree with your email, but suppose there is bar1.py and bar2.py
in foo, then they can refer to each other by importing bar2 and bar1,
respectively. These mod
Jeremy Sanders wrote:
>> if you got some other result, you didn't just import the same thing
>> twice...
>
> I think you may be incorrect, or I have misinterpreted you.
you've misinterpreted what Python means by "a module".
> Try this:
> import foo.bar
here you import the module named "foo.ba
Fredrik Lundh wrote:
> if you got some other result, you didn't just import the same thing
> twice...
I think you may be incorrect, or I have misinterpreted you.
Try this:
** In test.py
import sys
import foo.bar
print foo.bar.myvar
foo.bar.myvar = 42
print foo.bar.myvar
Got crystal clear. Thanks a lot to all for the elaborated replies.
Sanjay
--
http://mail.python.org/mailman/listinfo/python-list
Jeremy Sanders wrote:
>> "import" doesn't create new objects, so that's not very likely. can you
>> post some code so we don't have to guess what you've tried and not ?
>
> It does if you mess around with sys.path between doing two imports of the
> same thing (at least I found out the hard way o
Fredrik Lundh wrote:
> "Sanjay" wrote:
>
>> Trying hard, I am not even being able to figure out how to create an
>> object in one module and refer the same in another one. "import"
>> created a new object, as I tried.
>
> "import" doesn't create new objects, so that's not very likely. can you
>
Sanjay wrote:
> Hi Bruno,
>
> Thanks a lot for the reply. In order to post here, I wrote a very
> simple program now, and it seems working! I can diagnose the original
> problem now.
Fine.
> There might be some other problem.
This, we can't tell, since you didn't post the code !-)
> Pardon me
Sanjay wrote:
> Probably a newcomer question, but I could not find a solution.
>
> I am trying to have some singleton global objects like "database
> connection" or "session" shared application wide.
>
> Trying hard, I am not even being able to figure out how to create an
> object in one module and
Hi Bruno,
Thanks a lot for the reply. In order to post here, I wrote a very
simple program now, and it seems working! I can diagnose the original
problem now. There might be some other problem.
Pardon me if I am too novice but I could not make out the meaning of
this phrase from your reply:
"(at
"Sanjay" wrote:
> Trying hard, I am not even being able to figure out how to create an
> object in one module and refer the same in another one. "import"
> created a new object, as I tried.
"import" doesn't create new objects, so that's not very likely. can you post
some code so we don't have to
Sanjay wrote:
> Probably a newcomer question, but I could not find a solution.
>
> I am trying to have some singleton global objects like "database
> connection" or "session" shared application wide.
Whenever possible, dont. If you really have no other way out, create the
'singleton' in it's modu
Probably a newcomer question, but I could not find a solution.
I am trying to have some singleton global objects like "database
connection" or "session" shared application wide.
Trying hard, I am not even being able to figure out how to create an
object in one module and refer the same in another
12 matches
Mail list logo