我有两个python文件,Data.py和Sql.py,我想让SQLAlchemy用一个表创建一个数据库,数据库的名称取自Data.py
ie:一个数据库,其名称取自另一个.py文件
在Data.py中编码
class ddd():
which_mkt = 'US, HK'
# user input
mkt = input("Choose a value? [" + which_mkt + "]").upper()
t = os.chdir(DirectoryListings.T_dir) # Check in folder if file exist
if os.path.isfile(t):
# code to create a .db database file with mkt as the name.
Sql.py中的代码
# Create a database engine
engine = create_engine(r"sqlite:///Data\\" + z + ".db", echo=True)
Base = declarative_base()
class Gott(Base):
__tablename__ = 'Country'
id = Column(Integer, primary_key=True)
Country = Column(String(255))
def __init__(self, country):
self.Country = country
Base.metadata.create_all(engine)
因此,在Sql.py中,z
应该是取自Data.py的数据库的变量名
我希望我的解释清楚。这应该怎么做
目前没有回答
相关问题 更多 >
编程相关推荐