(no subject)

MARGINEAN TITUS m-titus at usa.net
Mon Dec 13 15:22:36 EST 1999


I created a class to help me to debug an communication protocol.
It work really fine, but I got a problem about some kind of share of global
variables between interpreter and module.
Please reply directly to me, because I'm not in the list.


In module FibSel.py I have the FMServer class definition folowed by the next
piece of code:


##############################################
#
# Estabilish the default connection when module is imported
#
##############################################


fm=None

def ReConnect():
	global fm
    	if not fm:
		print 'Try to estabilish the default conexion on the object called fm'
	fm=FMServer()
	fm.Connect()
	fm.Login('python'+`time.time()`)
	print fm	

ReConnect()  # connect when module is imported 

# End of FibSel.py module

From command line:


Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from FibSel import *
Try to estabilish the default conexion on the object called fm
connected with  wl01191.corning.com  on port  3490
<FibSel.FMServer instance at 857860>
>>> # Was called ReConnect so I have in fm an FMServer object
>>> print fm
<FibSel.FMServer instance at 857860>
>>> # Is OK
>>> fm.Disconnect()
>>> # now distroy the fm object
>>> fm=None
>>> # Then reconnect
>>> ReConnect()
connected with  wl01191.corning.com  on port  3490
<FibSel.FMServer instance at 882970>
>>> # I expect to have in fm an FMServer object
>>> print fm
None
>>> # ?????????????????????????????????????????????????????

As you seen,  in ReConect function object was right ( print fm gave:
"<FibSel.FMServer instance at 882970>") 
but from command line I got None. 
Why first time ( when reconnect was called during module import) I got the
global fm object and when I try calling by hand reconnect
it goes wrong?

TIA



____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1




More information about the Python-list mailing list