当我在我的纸条中使用\uuu name\uuuu变量时,我有一个运行时警告

2024-06-08 23:07:49 发布

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

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

#!/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

我也不知道这是怎么回事。你知道吗

我只知道,如果我删除带有___name__的行,我的脚本可以工作,但我需要这个变量。你知道吗

有人能帮我吗?你知道吗


Tags: ofthenamepyposimport脚本output
1条回答
网友
1楼 · 发布于 2024-06-08 23:07:49

您不应该在脚本中设置__name__;Python已经设置了它,并且依赖该值用于其他目的,例如导入。python脚本或模块的__name__值可以更改,但您需要知道自己在做什么,并且在尝试这样做之前了解python的内部结构。你知道吗

通常不要设置双下划线变量甚至它们只保留给Python使用;只有当它们被记录为可设置时才设置它们,例如模块中的__all__。你知道吗

请参阅Python data model documentation,了解当前使用的双下划线名称(dunder名称)的概述。你知道吗

相关问题 更多 >