简体   繁体   中英

Hidden .db files using Python and SQLite3

I am using sqlite3 and python for a new website I am creating. The problem is, the "files_storage.db" file I am trying to create will not appear in any Windows 10 Folder Window, PyCharm's Directory View, nor will it appear via the command line interface. The catch to this is, if I execute my python script multiple times, I get an error that states the database file already exists... So this file is somewhere, I guess it is a game of cat and mouse to find it. I have ran into this problem before, but I have ALWAYS been able to find the file via the command line. Usually, I wouldn't both yall with such a question but, this is really irking me and I am going to run into serious issues when it comes time to put this baby on a server. :( thanks in advance, and here's some screenshots I suppose. PyCharm IDE

命令行界面

You are using a relative file path.

Relative paths are converted to absolute ones by something like os.path.join(os.getcwd(), <relative path>) . So they depend on the current working directory of the process.

Try to open it with an absolute path (starting with drive letter) to avoid any ambiguities.

If you use just a filename without a path, the file will be saved in whatever the current working directory of the Python interpreter is.

To see where the current working directory is, add the following code to the beginning of your program:

import os
print(os.getcwd())

You should then see the working directory in the output.

There is a setting for the current working directory in your IDE somewhere. See eg the answers to this question .

You can also do something like:

import os

path = os.path.expanduser("~") + '/Documents'
print(path)

This will allow you to access the directories for the current user. For me, this prints:

'/Users/thomasweeks/Documents'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM