Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > error at "import anydbm"

Reply
Thread Tools

error at "import anydbm"

 
 
=?ISO-8859-1?Q?=22C=E9dric_V=2E=22?=
Guest
Posts: n/a
 
      01-13-2004
Hi,

I am unable to import anydbm without error under Python2.2 or 2.3 (Linux).

this script:
>#!/usr/bin/env python
>import anydbm
>
>if __name__ == "__main__":
> db = anydbm.open("test", "rwc")
> db["test"] = "ok"



returns at execution:

>cedric@dev _test $ python dbm.py
>Traceback (most recent call last):
> File "dbm.py", line 2, in ?
> import anydbm
> File "/usr/lib/python2.3/anydbm.py", line 59, in ?
> _errors.append(_mod.error)
>AttributeError: 'module' object has no attribute 'error'



(the same with python2.2)


do I have forgotten something? or is it another problem?

thanks in advance,

-- CV

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      01-13-2004
"CÚdric V." wrote:
> I am unable to import anydbm without error under Python2.2 or 2.3 (Linux).
>
> this script:
> >#!/usr/bin/env python
> >import anydbm
> >
> >if __name__ == "__main__":
> > db = anydbm.open("test", "rwc")
> > db["test"] = "ok"

>
> returns at execution:
>
> >cedric@dev _test $ python dbm.py
> >Traceback (most recent call last):
> > File "dbm.py", line 2, in ?
> > import anydbm
> > File "/usr/lib/python2.3/anydbm.py", line 59, in ?
> > _errors.append(_mod.error)
> >AttributeError: 'module' object has no attribute 'error'


Do you have any modules of your own creation called any of the following?

['dbhash', 'gdbm', 'dbm', 'dumbdbm']

These are the names of the modules anydbm tries to import, and it appears
to expect each of them to have an "error" name defined. Most likely your
module, with a conflicting name, is being found first and it does not
have an "error" attribute.

Generally speaking, you should try to avoid using the same names as
the standard library modules for your own code.

-Peter
 
Reply With Quote
 
 
 
 
Paul McGuire
Guest
Posts: n/a
 
      01-13-2004
"Peter Hansen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Generally speaking, you should try to avoid using the same names as
> the standard library modules for your own code.
>
>

This is an understandable limitation, but for new (and some not-so-new)
Python users, it is not always obvious what module names to avoid.

What if the standard library modules were put into a "std" package, to help
get them out of the global import namespace? (Of course, this would break
*scads* of code, so maybe should be deferred to 3.0. Or for migration
purposes, implement this in a 2.x release, and provide shadow xxx imports
that import the std.xxx modules.)

-- Paul


 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      01-13-2004

Paul> What if the standard library modules were put into a "std"
Paul> package, to help get them out of the global import namespace? (Of
Paul> course, this would break *scads* of code, so maybe should be
Paul> deferred to 3.0. Or for migration purposes, implement this in a
Paul> 2.x release, and provide shadow xxx imports that import the
Paul> std.xxx modules.)

This has come up before. It is definitely PEP territory. I think it would
be a good idea, though in the short term (e.g., 2.4, 2.5) the best you can
probably hope for is that a std package and the current modules live
side-by-side.

A couple problems were raised during the last go-round on python-dev. Any
PEP would have to address them:

1. In a naive implementation these two statements:

import std.sys
import sys

will result in two separate entries in sys.modules and thus the
module level code will be executed twice. During a transition period
you have to assume that an application will have a combination of
both styles of imports.

2. A simple way to achieve a std package parallel to the current global
namespace on Unix-y systems would be to use symbolic links. This
won't work on Windows. You'd like to avoid duplicating modules, in
part because it would probably make it harder to solve #1 above.

Skip

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      01-14-2004
Paul McGuire wrote:
>
> "Peter Hansen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > Generally speaking, you should try to avoid using the same names as
> > the standard library modules for your own code.
> >
> >

> This is an understandable limitation, but for new (and some not-so-new)
> Python users, it is not always obvious what module names to avoid.


This gives a good summary: http://www.python.org/doc/current/modindex.html

I think the issue actually comes up relatively rarely. I say that partially
because problems stemming from this seem relatively infrequent in the
mailing list/newsgroup, and partly because the standard library modules
are fairly loosely coupled, and the issue above arose (I believe) only because
one standard library module was importing another which the user didn't
know would be imported, and it matched a name he had used.

Avoiding the basic ones, like "sys", "os", and "math", along with any that
you are actually importing elsewhere in your application will probably avoid
the issue 99% of the time.

-Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments