【发布时间】:2021-07-04 11:51:27
【问题描述】:
我正在尝试使用以下代码创建一个 python 可执行文件。
import pandas as pd
import pyodbc as po
import os
#variables
server = 'DESKTOP-9B94UPJ'
database = 'DB1'
username = 'etluser'
password = 'password'
rawfile_directory='E:\\Projects\\Ebay\\ETLApp\\'
cnxn = po.connect('DRIVER={SQL
Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
df=pd.read_csv(rawfile_directory+"SPSS_Files\\"+filename,usecols=var_filteredCols)
cnxn = po.connect('DRIVER={SQL
Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
sql_stmt = "INSERT INTO "+var_table+" ("+var_DBCols+") values("+var_placeholder+")"
cursor = cnxn.cursor()
cursor.fast_executemany = True
cursor.executemany(sql_stmt, df.values.tolist())
# print(f'{len(df)} rows inserted to the {MY_TABLE} table')
cursor.commit()
cursor.close()
cnxn.close()
我使用 pyinstaller 创建了一个 exe
pyinstaller --onefile etl.py
我想将运行时上的数据库凭据和文件夹路径传递给 exe。任何专家都可以告诉我如何实现这一目标吗?提前致谢
【问题讨论】:
-
你可以使用
argparse
标签: python