G
G
guitarjedi2018-05-23 12:31:32
Python
guitarjedi, 2018-05-23 12:31:32

How to open Sqlite3 database from Python?

Good day!
There is a task:
-Take data from the 1C Log file
-Create a flat table, based on several tables from the Log file (it is on the Sqlite3 engine), upload this beauty to CSV, for further manipulations
On the test log file, everything turned out to be hardcoded, the data is converted, recorded, uploaded in the right format to the right place.
I wanted to put the values ​​of the variables in a separate file, in which case you can change the path to the Log file, the name of the CSV file where to upload, and so on, so as not to constantly climb into the script.
The first version looks like this:

import sqlite3

conn = sqlite3.connect('\\пусть-до-места-где-лежит\\1Cv8.lgd')
cursor = conn.cursor()

sql = "SELECT трали-вали..."

Everything is working.
But if I put my "path" in a separate file:
import sqlite3

#Конфиг
Config = open('\\Путь-до-"конфига"\\Config.ini')
LogFile = Config.readlines()[1]  #Строка в которой прописан путь

conn = sqlite3.connect(LogFile)
cursor = conn.cursor()

and then an error like "Unable to open database file" occurs.
The path is passed. But the database does not open.
What permissions need to be given, and to whom, at point blank range, I can’t imagine, Google advises to simply check the permissions to the place where the base is located, but I think that this is not it. Because pointing the way to a straight line, everything works out well. But as soon as the value is taken from a third-party file, an error pops up.
If anyone has experienced this, or just can tell what the problem is, I ask for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
guitarjedi, 2018-05-25
@guitarjedi

I've only been learning Python for the second week.
It turned out that the .strip() method had to be added to LogFile = Config.readlines()[1]:
Config = open('\\Path-to-"config"\\Config.ini')
LogFile = Config.readlines() [1] .strip() #String containing the path
conn = sqlite3.connect(LogFile)
cursor = conn.cursor() Line feed was strictly passed
with elements \n

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question