argparse模块在Python中不起作用 [英] argparse module not working in Python

查看:267
本文介绍了argparse模块在Python中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使argparse模块在Python中工作.我的问题是,在全新安装中,我得到以下信息:

I'm trying to get the argparse module working in Python. My problem is that on a fresh install, I get the following:

File "test.py", line 3, in <module>
import argparse
File "/home/jon/Pythons/realmine/argparse.py", line 3, in <module>
parser = argparse.ArgumentParser(description='Short sample app')
AttributeError: 'module' object has no attribute 'ArgumentParser'

test.py是:

import argparse

很明显,我缺少了一些东西.有人可以帮忙吗?

Clearly, I'm missing something. Can anyone help?

推荐答案

通常,此症状是用您自己的一个遮盖内置模块的结果.并从错误消息:

Usually this symptom is the result of shadowing a builtin module with one of your own. And from the error message:

File "/home/jon/Pythons/realmine/argparse.py", line 3, in <module>

您似乎拥有自己的模块argparse.py,这引起了问题,因为它是test.py试图导入的模块,并且缺少ArgumentParser.将您的argparse.py重命名为其他名称(并删除所有.py [c/o]文件).

it looks like you have your own module argparse.py, which is causing the problem, because it's the one which test.py is trying to import, and which lacks ArgumentParser. Rename your argparse.py to something else (and remove any .py[c/o] files).

这篇关于argparse模块在Python中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆