Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

i'm trying to execute this python script :

#! /usr/bin/python

import stackexchange
so = stackexchange.Site(stackexchange.StackOverflow)

my_favourite_guy = so.user(41981)
print my_favourite_guy.reputation.format()
print len(my_favourite_guy.answers), 'answers'

But i got this error

Jarvis:Documents Adeel$ python stackexchange.py
Traceback (most recent call last):
  File "stackexchange.py", line 3, in <module>
    import stackexchange
  File "/Users/Adeel/Documents/stackexchange.py", line 5, in <module>
    so = stackexchange.Site(stackexchange.StackOverflow)
AttributeError: 'module' object has no attribute 'Site'

It works fine when I copy and paste it on the python shell :

Jarvis:~ Adeel$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import stackexchange
>>> so = stackexchange.Site(stackexchange.StackOverflow)
>>> my_favourite_guy = so.user(41981)
>>> print my_favourite_guy.reputation.format()
11.2k
>>> print len(my_favourite_guy.answers), 'answers'
239 answers

I don't understand why..can anyone help me ?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Your file is named stackexchange.py, so Python is recursively loading it instead. This is a very common Python pitfall:

Fix

Change the filename: call your script se-test.py or something.

share|improve this answer
    
Thanks it's working –  Adeel ASIF Jan 25 at 13:09
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .