Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在数据库中引用不同的表/图纸_Python_Excel_Database_Csv - Fatal编程技术网

Python 在数据库中引用不同的表/图纸

Python 在数据库中引用不同的表/图纸,python,excel,database,csv,Python,Excel,Database,Csv,我想引用数据库中名为StudentNames 我将在何处实施参考点,以便仅访问问题表 def QuestionGenerator(): questionlist_file = open('StudentNames.csv') reader=csv.reader(questionlist_file) rownum=0 array2=[] for row in reader: array2.append(row) rownum=

我想引用数据库中名为
StudentNames

我将在何处实施参考点,以便仅访问
问题

def QuestionGenerator():
    questionlist_file = open('StudentNames.csv')
    reader=csv.reader(questionlist_file)
    rownum=0
    array2=[]
    for row in reader:
        array2.append(row)
        rownum=rownum+1
    print(array2)

如评论中所述,csv可能不是您尝试执行的最佳格式。如果已经有一个带有此信息的Excel文件,那么可以考虑为Excel构建的Python库,比如熊猫。引用可传递到pandas
read\u excel
函数的参数(即
sheet\u name
),以确保您仅使用特定的工作表

    import pandas as pd
    def QuestionGenerator():
       questionlist_file = pd.ExcelFile('StudentNames.csv')
       sheet_of_interest = pd.read_excel(questionlist_file, 'Questions')
       ...

我已将电子表格文档保存为csv文件。在excel中,您可以有不同的工作表。那么我是否将excel文档另存为excel文件?或者将其保存为CSV。您必须将其保存为excel文件,是的-尽管,如果它还不是excel文件,我不确定您首先会如何拥有“工作表”