×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    help accesing info from dict/db

    Hi Guys,

    I can populate my dictionary with the following code..
    This is fine and the code goes to the database.

    Code:
    import e32dbm
    
    # Open the dictionary
    d = e32dbm.open(u"c:\\python\\People.dict", "c")
    
    # Add the default entries into the dictionary
    People = {  'John'                 : {"Age": "20",
    				       "Address"    : "blah"}, 
    	    'Jim'                  : {"Age": "31",
    				       "Address"    : "blah2"},
    	    'Paul'                 : {"Age": "42",
    				       "Address"    : "blah3"},
                'Peter'                 : {"Age": "23",
    				       "Address"    : "blah4"}}
    
    # Close the db
    d.close()
    But i cannot retrieve this information i want when running my other script..

    i reopen the db and attempt to print something and i get errors.

    heres my code to try fetch some dictionary entry in my other script
    Code:
    import e32dbm
    
    # Open it again , in write mode
    dd = e32dbm.open(u'c:\\python\\People.dict')
    
    for k in dd.keys():
       print k 
       print dd[k]
    
    dd.close()
    Any help on how i can just do this simple task!!

    Thanks you

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: help accesing info from dict/db

    EDIT: Are you sure the information gets written to the file People.dict? It looks to me like you just assign the dictionary to the variable People, but don't write it to the file.

    I've tried your scripts. I don't get any errors on the second one, but nothing happens. I just don't know why, the code looks fine.
    Anyway, I have an alternative:

    Script 1:
    Code:
    import e32, appuifw, codecs
    
    def quit():app_lock.signal()
    appuifw.app.exit_key_handler=quit
    
    # Open the dictionary in write mode
    d = codecs.open(u"c:\\python\\People.dict", "w", "utf_8")
    
    # Add the default entries into the dictionary
    People = {'John' : {"Age": "20", "Address" : "blah"}, 
              'Jim' : {"Age": "31", "Address" : "blah2"},
              'Paul' : {"Age": "42", "Address" : "blah3"},
              'Peter' : {"Age": "23", "Address" : "blah4"}}
    
    People="People="+str(People)
    
    d.write(People)
    
    # Close the db
    d.close()
    
    app_lock=e32.Ao_lock()
    app_lock.wait()
    Script 2:
    Code:
    import e32, appuifw, codecs
    
    def quit():app_lock.signal()
    appuifw.app.exit_key_handler=quit
    
    # Open it again , in read mode
    dd = codecs.open(u"c:\\python\\People.dict", "r", "utf8")
    
    t=dd.read()
    exec(t)
    
    for k in People.keys():
       print k 
       print People[k]
    
    dd.close()
    
    app_lock=e32.Ao_lock()
    app_lock.wait()
    Basically all I did was put the dictionary assignment in a text file as a string and then execute it in the second script.
    Sorry this is not the answer you were looking for, but I can't figure out why your code doesn't work.
    Last edited by bogdan.galiceanu; 2008-03-08 at 06:46.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    Re: help accesing info from dict/db

    Hi Bogdan,

    Thank you for all your help.

    I will try your approach in future..
    Seems to be good enough for what i need.

    Thank you

Similar Threads

  1. JSR 179 - format of NMEA extra info field on the real N95
    By bt049088 in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2007-10-18, 08:27
  2. Replies: 20
    Last Post: 2007-10-09, 09:19
  3. SIP INFO suppport in stack
    By raj_rr7 in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-09-10, 07:24
  4. Problem executing Maze Racer
    By IFtechsupport in forum Mobile Java Games
    Replies: 1
    Last Post: 2006-09-22, 17:18
  5. Accessing network info from Java and location based info in Australia
    By T-Funk in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2002-12-09, 09:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •