Is it possible to get the database file name in a shelf using the file object attribute? (Python)

I have a python3 script that creates several database files using the shelve module. FYI, the shelf module wraps the dbm module, as can be seen from defer the source code . The shelf.open () method is used to create a database file on disk and takes the desired path to the output file as an argument. However, the name of the generated file depends on the dbm modules available on the user system. This means that the behavior is not platform aggregated, as described elsewhere on SO: here .

I could not find a simple method to search for file names. I was hoping that I could access the file name (s) as the attribute (s) of the shelf object, for example, can be done using the FileIO file name attribute . How to get the file name (s) of a shelf object through an attribute or method of an object?

Otherwise, I could resort to passing the self-destructive tempfile object to the .open () shelf instead. However, I do not understand how to do this. Please note that the question about the time shelf was asked on SO here ... but the provided answer will not work if the user is on the system with the dbm module, which will attach the suffix fname.

Thank you for your time.

+4
source share
1 answer

I just found this answer that suggests creating shelf files in a temporary subdirectory and then deleting the entire directory. I think this is the best solution available at this time.

+4
source

Source: https://habr.com/ru/post/1501687/


All Articles