473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trouble creating bsddb database

I am trying to create a bsddb database where I would like to store all the relevant database files created by my application under one directory.

My code looks as follows:

Expand|Select|Wrap|Line Numbers
  1. from bsddb import db
  2. from os import mkdir
  3. from os.path import exists
  4.  
  5. homeDir = 'pidgindb'
  6. db_env = db.DBEnv()
  7. db_env.set_cachesize(0, 1024*1024*50)
  8. if not exists(homeDir):
  9.     homeDir = mkdir(homeDir)
  10. db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
  11.  
  12. pidgin = db.DB(db_env)
  13. pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
  14. pidgin['apple'] = 'fruit'
  15. pidgin['carrot'] = 'vegetable'
  16. pidgin.close()
  17.  
When I run the script for the first time, it creates all the database files (__db.001
, __db.002, pidgin) in the current directory. When I run it for the second time, it behaves correctly and creates the database files in the dir specified while opening DBEnv. Is this a bug, or am I doing something wrong?

My environment: Windows, Python 2.4.3, bsddb 4.3.0.1

Thanks!
May 14 '07 #1
2 1778
bartonc
6,596 Expert 4TB
I am trying to create a bsddb database where I would like to store all the relevant database files created by my application under one directory.

My code looks as follows:

Expand|Select|Wrap|Line Numbers
  1. from bsddb import db
  2. from os import mkdir
  3. from os.path import exists
  4.  
  5. homeDir = 'pidgindb'
  6. db_env = db.DBEnv()
  7. db_env.set_cachesize(0, 1024*1024*50)
  8. if not exists(homeDir):
  9.     homeDir = mkdir(homeDir)
  10. db_env.open(homeDir, db.DB_INIT_MPOOL|db.DB_CREATE)
  11.  
  12. pidgin = db.DB(db_env)
  13. pidgin.open('pidgin',None,db.DB_BTREE,db.DB_CREATE,0660)
  14. pidgin['apple'] = 'fruit'
  15. pidgin['carrot'] = 'vegetable'
  16. pidgin.close()
  17.  
When I run the script for the first time, it creates all the database files (__db.001
, __db.002, pidgin) in the current directory. When I run it for the second time, it behaves correctly and creates the database files in the dir specified while opening DBEnv. Is this a bug, or am I doing something wrong?

My environment: Windows, Python 2.4.3, bsddb 4.3.0.1

Thanks!
I'd throw a print statement in here:
Expand|Select|Wrap|Line Numbers
  1. if not exists(homeDir):
  2.     homeDir = mkdir(homeDir)
  3.     print homeDir
I'm guessing that you are getting a fully qualified path that has spaces in it. You'll want to us some os.path functions to strip or otherwise convert to a valid db_env.open() path.
May 14 '07 #2
I'd throw a print statement in here:
Expand|Select|Wrap|Line Numbers
  1. if not exists(homeDir):
  2.     homeDir = mkdir(homeDir)
  3.     print homeDir
I'm guessing that you are getting a fully qualified path that has spaces in it. You'll want to us some os.path functions to strip or otherwise convert to a valid db_env.open() path.
Thanks, printing that out did solve the problem! homeDir was getting set to None when running the script for the first time.
May 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Anthony McDonald | last post by:
PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>>...
3
by: Harry Pehkonen | last post by:
Stats: Python2.3 windows2000 professional If I have ``Full Control'' of a bsddb file, no problem: >>> import bsddb >>> a = bsddb.btopen("c:/sharedrw/db/npanxx2pseudo.db", "r") >>> a.close()...
1
by: Mike Moum | last post by:
Greetings all, I have some questions about the bsddb package that comes with Python 2.3 that I can't find answers for. I've googled and read the documentation. 1. Does the Berkeley database...
4
by: Michele Simionato | last post by:
I was browsing through the source tree of Python 2.4b2 and in Lib/bsddb/test I found a lot of interesting stuff. It seems that the support for the bsd database is much better than documented in the...
0
by: martijn | last post by:
H! I have a big bsddb database created with python and that works fast. I know that I can use the python_apache module to show the data results online. //--- python_apache module <form...
0
by: Barry | last post by:
I have python2.4.1 installed on two machines: -- one is Fedora core 1, where the bsddb module works fine -- one is Redhat ES 3.0, and I installed mysql 4.1 (and mysql-python2.1) after putting the...
0
by: Marc Jeurissen | last post by:
Hi all, I have a small web application (Pandion) wich uses the bsddb package on Windows XP. Since Python 2.5 I get an error when accessing the database. Code snippet: from bsddb import db...
1
by: BjornT | last post by:
Have a rather big problem with bsddb I can't figure out. I upgraded an Ubuntu machine from 7.05 to 7.10 which upgraded python to 2.5.1 I run a local website that uses bsddb, and suddenly I get a...
2
by: cocobear | last post by:
How to deal with multiple databases in an file. I want to get the content of several databases. it's the code I wrote: $ python Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11) on linux2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.