By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

filename used by shelve

P: n/a
In the python docs about shelve module I read:

-----------------------------------------------------------------------------
open( filename[,flag='c'[,protocol=None[,writeback=False[,binary=None]]]])
Open a persistent dictionary. The filename specified is the base filename
for the underlying database. As a side-effect, an extension may be
added to the filename and more than one file may be created.
-----------------------------------------------------------------------------

So the real filename may be different from the argument passed to
"open". I have this problem, I want to delete (in some circustances) the
file created by shelve.open, how can I know which is the name of this
file (or files) ?

--
I'm not a complete idiot - several parts are missing.

|\ | |HomePage : http://nem01.altervista.org
| \|emesis |XPN (my nr): http://xpn.altervista.org

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Nemesis" <ne*****@nowhere.invalid> wrote:
So the real filename may be different from the argument passed to
"open". I have this problem, I want to delete (in some circustances) the
file created by shelve.open, how can I know which is the name of this
file (or files) ?


if you put the shelve in a subdirectory, and nuke the entire directory when
done, you don't have to know the names.

dbfile = "mydatabase"
if not os.path.isdir(dbfile):
os.makedirs(dbfile)
db = shelve.open(os.path.join(dbfile, "data"), ...)

...

db.close()
del db

...

shutil.rmtree(dbfile)

</F>

Jul 19 '05 #2

P: n/a
Mentre io pensavo ad una intro simpatica "Fredrik Lundh" scriveva:
So the real filename may be different from the argument passed to
"open". I have this problem, I want to delete (in some circustances) the
file created by shelve.open, how can I know which is the name of this
file (or files) ?

if you put the shelve in a subdirectory, and nuke the entire directory when
done, you don't have to know the names.

dbfile = "mydatabase"
if not os.path.isdir(dbfile):
os.makedirs(dbfile)
db = shelve.open(os.path.join(dbfile, "data"), ...)
shutil.rmtree(dbfile)


Hmm, this is a good idea. Thanks.

Anyway I think that shelve should provide a method which returns the
files used by the backend database, and the argument "filename" can
confuse users, it should be named "dbname".

--
Are crop circles the work of a cereal killer?

|\ | |HomePage : http://nem01.altervista.org
| \|emesis |XPN (my nr): http://xpn.altervista.org

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.