[prev in list] [next in list] [prev in thread] [next in thread] 

List:       zodb-dev
Subject:    [ZODB-Dev] import problem ? (code snippet inside)
From:       db () zetamonks ! com
Date:       2004-03-30 16:56:54
Message-ID: 20040330165654.GA707 () ellroy ! zetamonks ! com
[Download RAW message or body]

Hi,

I am a newbie with python and ZODB.  I have a problem with
importing a module, I can't understand why the following code
is not working.  (code is very ugly ;)

Using ZODB 3.2.1c + Python 2.3.2 on a redhat 9.0 and freebsd 4.9

See interactive session capture below the following code snippet
for problem details.

Thanks for your help,

--
Daniel


[dbl@euler]$ cat user.py 
#!/usr/bin/env python2.3

from ZODB import FileStorage, DB
from Persistence import Persistent

def connect():    
    storage = FileStorage.FileStorage('/tmp/datas.fs')
    db = DB(storage)
    conn = db.open()
    dbroot = conn.root()
    if not dbroot.has_key('users'):
        from BTrees.OOBTree import OOBTree
        dbroot['users'] = OOBTree()
        db = dbroot['users']
    return conn

def get_user(name):
    "retourne un objet user ou None si inexistant."
    conn = connect()
    r = conn.root()
    u = None
    if r['users'].has_key(name):
        u = r['users'][name]
    return u

class User(Persistent):
    def __init__(self, name = None, passwd = None):
        self.name = name
        self.passwd = passwd

    def check_passwd(self, passwd):
        return self.passwd == passwd

if __name__ == "__main__":
    n = raw_input("name: ")
    p = raw_input("passwd: ")
    q = raw_input("create y/n? ")
    if q=="y":
        print "creating..."
        u = User(n, p)
        dbroot = connect().root()
        dbroot["users"][u.name]=u
        get_transaction().commit()
    else:
        print "aborted!"

# set vim: syn=python ts=4 sw=4 et ai hls tw=79:

[dbl@euler]$ ./user.py 
name: db
passwd: mypass
create y/n? y
creating...
[dbl@euler]$ python2.3
Python 2.3.2 (#1, Oct  6 2003, 10:07:16) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> > > import user
> > > u=user.get_user('db')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "user.py", line 22, in get_user
    if r['users'].has_key(name):
  File "/home/db/src/zodb/ZODB3-3.2c1/build/lib.linux-i686-2.3/ZODB/Connection.py", \
line 564, in setstate  File \
"/home/db/src/zodb/ZODB3-3.2c1/build/lib.linux-i686-2.3/ZODB/Connection.py", line \
603, in _set_ghost_state  File \
"/home/db/src/zodb/ZODB3-3.2c1/build/lib.linux-i686-2.3/ZODB/Connection.py", line \
200, in _persistent_load  File \
"/home/db/src/zodb/ZODB3-3.2c1/build/lib.linux-i686-2.3/ZODB/Connection.py", line \
162, in __getitem__  File \
"/home/db/src/zodb/ZODB3-3.2c1/build/lib.linux-i686-2.3/ZODB/DB.py", line 128, in \
                _classFactory
AttributeError: 'module' object has no attribute 'User'
> > > 

[dbl@euler]$ python2.3
Python 2.3.2 (#1, Oct  6 2003, 10:07:16) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> > > from user import *
> > > u=get_user('db')
> > > u.name
'db'

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic