当我在脚本中使用__name__变量时,我有一个运行时警告

ant*_*790 3 python python-2.7 ubuntu-12.04

我尝试___name__在我的python脚本的开头使用:

#!/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...
Run Code Online (Sandbox Code Playgroud)

但随后Python打印出一个警告:

cigarline_by_pos.py:29: RuntimeWarning: Parent module 'cigarline_by_pos' not found while handling absolute import
  import argparse,re,sys
Run Code Online (Sandbox Code Playgroud)

我不知道它可能来自什么.

我只知道如果我删除___name__我的脚本行,但我想要这个变量.

有人能帮助我吗?

Mar*_*ers 5

你不应该__name__在脚本中设置; Python已经设置它并依赖于其他目的的值,例如导入.__name__可以更改python脚本或模块的值,但是在尝试执行此操作之前,您需要知道自己在做什么并了解Python的内部.

不要设置双下划线变量一般均匀.它们仅供Python使用; 只有在将它们记录为可设置时才设置它们,例如__all__在模块中.

有关当前正在使用的双下划线名称(dunder名称)的概述,请参阅Python数据模型文档.