[Tutor] return a dictionary?

Bill Gibson wbgibson2 at yahoo.com
Thu Oct 9 20:42:21 CEST 2008


Can I ‘return’ a dictionary from an imported Python script?
I have a utility module (NameAddress.py)  done using Tkinter. (For example, Name/Address City,State,Zip,Email, Phone) that I want to use as imported module. I wanted to return the values as a dictionary to the module that imported but this does not seem to work.
This is the dictionary as printed out from the NameAddress.py by print theDict shows what I want:
{'City': 'San Francisco', 'Name': 'Sam Spade', 'Zip': '98765', 'Address1': 'Apt. #87', 'Address2': '2345 Union Street', 'Phone': '1-415-896-9876', 'State': 'Ca.', 'Email': 'samspade at yahoo.com'}
However the code for return in NameAddress.py  , I.E.     return theDict
gives this error when called from a testing module (Inter_module.py)  whose code looks like this:
                import NameAddress
                y = NameAddress.getName()  
                print y
Traceback (most recent call last):
  File "C:\Python24\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\B\Desktop\Inter_module.py", line 6, in ?
    y = NameAddress.getName()
  File "C:\Users\B\Desktop\NameAddress.py", line 22, in getName
    theDict={'Name': w2.get(), 'Address1': w4.get(), 'Address2': w6.get(),'City':w8.get()}
  File "C:\Python24\Lib\lib-tk\Tkinter.py", line 2303, in get
    return self.tk.call(self._w, 'get')
TclError: invalid command name ".43065216"


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081009/560e79ae/attachment-0001.htm>


More information about the Tutor mailing list