I'm following this tutorial trying to implement argparse into a python script I'm writing.
When I run this snippet of code from the tutorial I receive the following error:
[05:51 PM] user Scripts> cat argparse.py
import argparse
parser = argparse.ArgumentParser()
parser.parse_args()
[05:51 PM] user Scripts> python3 argparse.py
Traceback (most recent call last):
File "argparse.py", line 1, in <module>
import argparse
File "/home/brian/Documents/Scripts/argparse.py", line 2, in <module>
parser = argparse.ArgumentParser()
AttributeError: 'module' object has no attribute 'ArgumentParser'
I'm running Python 3.3.2 and have installed argparse 1.2.1 using easy_install so I know it's on the system but I cannot determine what is causing the error.
Note: I've read this post and it is not related.
From the error message I am guessing your script is trying to import not from argparse package but from local /home/brian/Documents/Scripts/argparse.py module. Rename your file and try again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With