2017-01-16 7 views
0

ubuntu 14.04python 2.7.6을 사용하고 있으며 팔콘 웹 프레임 워크에서 간단한 hello world 프로그램을 실행하려고합니다. 그러나이 예제를 실행하는 동안 다음과 같은 오류가 발생합니다. 이것에 대한 어떤 생각?개체에 팔콘의 'API'오류가 없습니다.

코드 :

import falcon 

class ThingsResource(object): 
    def on_get(self, req, resp): 
     """Handles GET requests""" 
     resp.status = falcon.HTTP_200 
     resp.body = 'Hello world!' 

# falcon.API instances are callable WSGI apps 
wsgi_app = api = falcon.API() 

# Resources are represented by long-lived class instances 
things = ThingsResource() 

# things will handle all requests to the '/things' URL path 
api.add_route('/hello', things) 

오류 :

Traceback (most recent call last): 
    File "falcon.py", line 1, in <module> 
    import falcon 
    File "/home/naresh/Desktop/PythonFramework/falcon.py", line 10, in <module> 
    wsgi_app = api = falcon.API() 
AttributeError: 'module' object has no attribute 'API' 
+1

파이썬 파일이 바로 falcon.py? – iFlo

답변

2

당신이하지에서, 파일의 방법 API()를 호출 falcon.API() 호출 할 때 파이썬 파일이 너무 falcon.py입니다 진짜 팔콘 모듈.

파일의 이름을 바꾸면 올바르게 작동합니다.

보다 완벽한 솔루션을

은이를 참조하십시오

Trying to import module with the same name as a built-in module causes an import error을 :

당신은 아마 이름

You will want to read about Absolute and Relative Imports which addresses this very problem. Use:

from __future__ import absolute_import Using that, any unadorned package name will always refer to the top level package. You will then 

need to use relative imports (from .email import ...) to access your own package.