import anydbm

Roman Suzi rnd at onego.ru
Tue Jun 19 06:19:19 EDT 2001


On Tue, 19 Jun 2001, Morten Gulbrandsen wrote:

> #!/usr/bin/python
> import anydbm
> file = anydbm.open("filename.txt") # link to external file
> file['key'] = 'data'           # store data by key
> data = file['key']             # fetch data by key
> 
> import cgi
> form = cgi.FieldStorage()      # parse form data (stdin, environ)
> if form.has_key('name'):
>     showReply('Hello, ' + form['name'].value)
> 
> morten at debian:~/Python/lpython/unix/examples$ ./page054.py
> Traceback (innermost last):
>   File "./page054.py", line 5, in ?
>     file = anydbm.open("filename.txt") # link to external file
>   File "/usr/lib/python1.5/anydbm.py", line 80, in open
>     raise error, "need 'c' or 'n' flag to open new db"
> anydbm.error: need 'c' or 'n' flag to open new db
> morten at debian:~/Python/lpython/unix/examples$

> what am I doing wrong ?

You forgot to create database. To do so you
need to call

anydbm.open("filename.txt", "c")

before you could use database. Only once.
After that your example will work.

.txt is not good name for the db file, BTW.


Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list