Modifying script: NameError: name '' is not defined

Modifying script: NameError: name '' is not defined

我在修改别人编写的代码时遇到问题。基本上,试图让脚本读取输入列表(基因名称),但出现以下错误:

NameError: name 'gene_name' is not defined

代码如下:

import csv

fullout = np.empty((1,3704))

def gene_list(gene_name):
    gene_list = open('C:\Users\Work\Desktop\Book1.csv', 'rU'), f
    gene_list = []
    reader = csv.reader(f)
    for row in reader:
        gene_name = "row.strip()"

for gene_name in gene_list(gene_name):
    if __name__ == '__main__':
        with gene_list:
            reader = csv.reader(f)
        for row in reader: 
            gene_name = row
            probes_dict = get_probes_from_genes(gene_name)
        expression_values, well_ids, donor_names = get_expression_values_from_probe_ids_hdf(
                probes_dict.keys())
        print get_mni_coordinates_from_wells(well_ids)`

gene_name 是在函数范围内定义的,正如 Padraic Cunningham 所说。一旦函数结束,就不能再使用这个变量了

我建议您阅读有关范围的文档。 Scopes and Namespaces