Python 当我在脚本中使用_name__变量时,会出现运行时警告
我试图在python脚本的开头使用Python 当我在脚本中使用_name__变量时,会出现运行时警告,python,python-2.7,ubuntu-12.04,Python,Python 2.7,Ubuntu 12.04,我试图在python脚本的开头使用\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu: #!/usr/bin/python # Comments... # blabla # __name__="cigarline_by_pos.py" __synopsis__ = "cigarline_by_pos.py | INPUT_BAM_FILE --output OUTPUT_FILE [--output OUTPUT_FILE_R2 --readsplit]" _
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
:
#!/usr/bin/python
# Comments...
# blabla
#
__name__="cigarline_by_pos.py"
__synopsis__ = "cigarline_by_pos.py | INPUT_BAM_FILE --output OUTPUT_FILE [--output OUTPUT_FILE_R2 --readsplit]"
__example__ = "cigarline_by_pos.py hg18.bam --output hg18_read1.csv --output hg18_read2.csv --readsplit"
__date__ = "05/2013"
__authors__ = "Frederic Escudie & Antoine Leleu"
__keywords__ = "SAM Alignment"
__description__ = "Sum by position the status of reads. This provides for example the number of reads that have a mismatch at first base."
__version__ = '2.3.1'
import argparse,re,sys
the rest of the code...
但是Python会打印一条警告:
cigarline_by_pos.py:29: RuntimeWarning: Parent module 'cigarline_by_pos' not found while handling absolute import
import argparse,re,sys
我也不知道它是从哪里来的
我只知道,如果我用\uuuuuuu name\uuuuuu
删除该行,我的脚本可以工作,但我需要这个变量
有人能帮我吗?你不应该在脚本中设置
\uuu name\uuu
;Python已经设置了该值,并将其用于导入等其他目的。python脚本或模块的\uuu name\uu
值可以更改,但在尝试更改之前,您需要知道自己在做什么,并了解python的内部结构
一般情况下,不要设置双下划线变量。它们仅保留给Python使用;仅当它们记录为可设置时才进行设置,例如模块中的\uuuu all\uuu
有关当前使用的双下划线名称(dunder名称)的概述,请参阅。非常感谢您的回答!我不知道这件事,现在我不那么愚蠢了;)没问题,你做得很好。:-)我只是注意到,如果我将所有带有下划线变量的行移到导入行下面,它就会工作。我只是不知道它为什么会这样工作。@antoine4790:因为
\uuuu name\uuuu
在Python中有特殊的含义,它被用来确定相对导入。通过移动import
下面的行,您将其移动到import
语句可以看到\uuuu name\uuuu
的正确值的位置。