I am having some troubles moving one *.sqlite ddbb that I've created from one folder to another.
this is my attempt:
Import os
Import sqlite3
Import pandas as pd
#There is some code here to get my pandas dataframe
Then the goal of the following code is: To create a sqlite ddbb from a pandas dataframe (dfGlobalProcess) and then move it to another subfolder named "Projects_ddbb".If I could save it directly to this another folder it would be great.
This is the code:
ddbbName='ExampleProject1' #I know this line does nothing right now... but in the future this should be an user input
ddbbName2= ddbbName + '.sqlite'
conn = sqlite3.connect('' + ddbbName2 +'')
dfGlobalProcess.to_sql('ProcessesElemFlows', conn, index=False, if_exists='replace')
conn.close()
prevName='' + ddbbName2 + ''
newName='Projects_ddbb/' + prevName + ''
os.rename(prevName,newName)
When I run this code I get the following error:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'ExampleProject1.sqlite' -> 'Projects_ddbb/ExampleProject1.sqlite'
I've searched for solutions here in stackoverflow but I am not able to figure out how to solve it
if I run the same code but moving a *.txt file that is in the same folder in which the ddbb is stored, the *.txt file is moved to the 'Projects_ddbb' folder as expected.
It looks like I have the ddbb opened in some way, but as I am fairly new to Python and programming in general I don't have any idea how to proceed.
I've also tried something like this, but I don't know if it makes any sense... probably not because it does not work:
os.close('ExampleProject1.sqlite')
Any help will be much appreciated.