Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object has no attribute using argparse

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.

like image 771
ProfessionalAmateur Avatar asked May 29 '26 10:05

ProfessionalAmateur


1 Answers

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.

like image 57
zero323 Avatar answered May 31 '26 22:05

zero323



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!