在Djang导入csv

2024-09-28 01:25:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将csv文件从导入db管理.py但它给了我错误

import csv
with open(r"C:\Users\yousa\Desktop\xp\exp\Dist_Extended_TissuesWise_ClusteredAnnotated_21nov2018_qaz.csv", 'r') as f:
        reader = csv.reader(f)
        lines = list(reader)
        del lines[0]
        objects = []
        for line in lines:
            obj =Maize_clustert()
            obj.chromosome = int(line[0])
            obj.cluster_start = int(line[1])
            obj.cluster_end = int(line[2])
            obj.strand = line[3]
            obj.pac = int(line[4])
            obj.pac_suppoort = int(line[5])
            obj.cluster_support = int(line[6])
            obj.region = line[7]
            obj.gene_id = line[8]
            obj.transcript_id = line[9]
            obj.distance = line[10]
            obj.transcript_code = line[11]
            obj.gene_cord = line[12]
            obj.utr_length = int(line[13])
            obj.gene_biotype = line[14]
            obj.cluster_size = int(line[15])
            obj.number_pas = int(line[16])
            obj.zygote = int(line[17])
            obj.sperm = int(line[18])
            obj.egg = int(line[19])
            obj.root = int(line[20])
            obj.embryo = int(line[21])
            obj.basal = int(line[22])
            obj.ear = int(line[23])
            obj.apical = int(line[24])
            obj.ovule = int(line[24])
            objects.append(obj)
        Maize_clustert.objects.bulk_create(objects)

在运行此代码时管理.py告诉我结果

Traceback (most recent call last):
  File "<input>", line 8, in <module>
NameError: name 'Maize_clustert' is not defined

在里面的时候型号.py我已经创建了我的数据的完整模型 有没有别的办法或者我做错了 请帮帮我


Tags: csvinpyidobjobjectslinereader
2条回答

您需要在文件中导入Maize_clustert。比如:

# Please read the PEP-8 Style Guide on Naming convention
# Class Name should be 'PascalCase'
from yourapp.models import Maize_clustert

仔细阅读信息:

NameError: name 'Maize_clustert' is not defined

这意味着在您执行CSV读取的文件中没有定义此类。因此,即使是玉米簇也存在于你的生活中型号.py你必须将它导入到使用它的文件中。你知道吗

基本上在文件顶部添加以下内容:

来自应用模型进口玉米

相关问题 更多 >

    热门问题