我有我想要遍历的命令列表,因此我将这些命令放入列表中。但是,我也想使用该列表作为字符串来命名一些文件。如何将变量名称转换为字符串?将变量列表转换为字符串
itemIDScore = """SELECT * from anytime;"""
queryList = [itemIDScore, accountScore, itemWithIssue, itemsPerService]
for x in queryList:
fileName = x+".txt"
cur.execute(x) #This should execute the SQL command
print fileName #This should return "itemIDScore.txt"
我想文件命名为“itemIDScore.txt”但itemIDScore在queryList是一个SQL查询,我会在其他地方使用。我需要在查询名称后面命名文件。
谢谢!
所以...你想要诸如“itemIDScore.txt”作为文件名吗?或者你想要变量itemIDScore的字符串值吗? – Prune
我想要“itemIDScore.txt”用于其他功能,但我会在其他函数中调用itemIDScore的字符串值。 – Publiccert
请**澄清您的具体问题或添加额外的细节,以突出显示您所需要的**。正如目前所写,很难确切地说出你在问什么。请参阅[如何提问](http://stackoverflow.com/help/how-to-ask)页面以获得帮助,澄清此问题 –