用于脚本的Django-extension runscript No(有效)模块

时间:2016-12-30 13:13:41

标签: django python-3.x django-models django-extensions

我尝试创建一个脚本,用我的模型families填充从文本文件中提取的信息。 这是我在StackOverflow的第一篇文章,请保持温和,抱歉,如果问题没有得到很好的表达或格式不正确。

Django V 1.9并在Python 3.5上运行 已安装Django-extensions

这是我的模型:它位于名为 browse

的应用中
from django.db import models
from django_extensions.db.models import TimeStampedModel


class families(TimeStampedModel):
     rfam_acc = models.CharField(max_length=7)
     rfam_id = models.CharField(max_length=40)
     description = models.CharField(max_length=75)
     author = models.CharField(max_length=50)
     comment = models.CharField(max_length=500)
     rfam_URL = models.URLField()

我这里有我的脚本familiespopulate.py。位于PROJECT_ROOT/scripts目录。

import csv
from browse.models import families

file_path =       "/Users/work/Desktop/StructuRNA/website/scripts/RFAMfamily12.1.txt"

def run(file_path):
    listoflists = list(csv.reader(open(file_path, 'rb'), delimiter='\t'))
    for row in listoflists:
        families.objects.create(
                rfam_acc=row[0],
                rfam_id=row[1],
                description=row[3],
                author=row[4],
                comment=row[9],
        )

从终端i运行时:

python manage.py runscript familiespopulate

它返回:

No (valid) module for script 'familiespopulate' found
Try running with a higher verbosity level like: -v2 or -v3

问题必须在于导入模型families,我是django的新用户,我在StackOverflow或其他任何地方都找不到任何解决方案。 这就是我请求你帮助的原因!

您知道应该如何导入模型吗? 或者......我做错了什么。

重要的信息是,如果我将脚本修改为PRINT参数,脚本就会运行,而不是在族中创建对象。

为了您的信息和好奇心,我还会在这里发布我正在使用的文本文件的摘录。

RF00001 5S_rRNA 1302    5S ribosomal RNA    Griffiths-Jones SR, Mifsud W, Gardner PP    Szymanski et al, 5S ribosomal database, PMID:11752286   38.00   38.00   37.90   5S ribosomal RNA (5S rRNA) is a component of the large ribosomal subunit in both prokaryotes and eukaryotes. In eukaryotes, it is synthesised by RNA polymerase III (the other eukaryotic rRNAs are cleaved from a 45S precursor synthesised by RNA polymerase I). In Xenopus oocytes, it has been shown that fingers 4-7 of the nine-zinc finger transcription factor TFIIIA can bind to the central region of 5S RNA. Thus, in addition to positively regulating 5S rRNA transcription, TFIIIA also stabilises 5S rRNA until it is required for transcription.    NULL    cmbuild -F CM SEED  cmcalibrate --mpi CM    cmsearch --cpu 4 --verbose --nohmmonly -T 24.99 -Z 549862.597050 CM SEQDB   712 183439  0   0   Gene; rRNA; Published; PMID:11283358    7946    0       0.59496 -5.32219    1600000 213632  305 119 1   -3.78120    0.71822 2013-10-03 20:41:44 2016-04-21 23:07:03

这是第一行,从列表列表中提取的结果是:

RF00002
5_8S_rRNA
5.8S ribosomal RNA
Griffiths-Jones SR, Mifsud W
5.8S ribosomal RNA (5.8S rRNA) is a component of the large subunit of    the eukaryotic ribosome. It is transcribed by RNA polymerase I as part of the 45S precursor that also contains 18S and 28S rRNA. Functionally, it is thought that 5.8S rRNA may be involved in ribosome translocation [2]. It is also known to form covalent linkage to the p53 tumour suppressor protein [3]. 5.8S rRNA is also found in archaea.

4 个答案:

答案 0 :(得分:1)

尝试将空文件__init__.py(双下划线)添加到/ scipts文件夹中并运行:

python manage.py runscript scipts.familiespopulate

答案 1 :(得分:0)

除了添加 init .py之外,您不应该在run方法中传递任何参数。

numberOfLines

答案 2 :(得分:0)

感谢您提供有用的评论。 我用这种方式修改了代码:

example.setMyVector(std::move(newMyVector));

这就是全部。现在它运作顺利。 我想向大家确认我的文件:familiespopulate.py位于文件夹脚本中,文件为 init .py

当我提出

时,问题似乎得到了解决
import csv
from browse.models import families


def run():
   file_path =   "/Users/work/Desktop/StructuRNA/website/scripts/RFAMfamily12.1.txt"
   listoflists = list(csv.reader(open(file_path, 'r'),delimiter='\t'))
print(listoflists)
for row in listoflists:
    families.objects.create(
                rfam_acc=row[0],
                rfam_id=row[1],
                description=row[3],
                author=row[4],
                comment=row[9],
    )

在run函数内部,从run(file_path)中删除参数file_path。

对我的代码的另一个修改是在open(file_path,'r')之前的参数r,在它打开之前(file_path,'rb')应该对应于读取二进制文件。

答案 3 :(得分:0)

我也遇到了完全相同的错误,我尝试了上述所有解决方案,但不幸的是,该方法对我没有用。然后我意识到自己的错误,并且找到了。

在脚本文件中(位于脚本/文件夹中),我为该函数使用了不同的名称,应将其命名为“运行”。因此,如果出现此错误,请确保也选中了它。

Here you can read more about "runscript"