web.py 中的继承? [英] Inheritance in web.py?
问题描述
我目前正在开发 wep.py 应用程序.这是我的 web 应用程序,它与 web.py 和 wsgi 绑定.
I am currently developing wep.py application. This is my web application which is binded with web.py and wsgi.
root/main.py
root/main.py
import web
import sys
import imp
import os
sys.path.append(os.path.dirname(__file__))
#from module import module
from exam import exam
urls = (
'/exam', 'exam'
)
application = web.application(urls, globals(), autoreload = True).wsgifunc()
我的应用在根目录下的module.py中有一个叫做module的抽象类,目的是被模块继承.
My application has an abstract class called module in module.py in root directory and its purpose is to be inherited by modules.
root/module.py
root/module.py
class module:
def fetchURL(self, url):
# ...
return content
名为exam"的低级模块将继承模块
The lower level module called "exam" would inherits module
root/exam/init.py
root/exam/init.py
from module import module
class exam(module):
def getResults(self):
# error occurs here
self.fetchURL('math.json')
当我调用父方法时,web.py 引发异常
When I call the parent method, web.py raises an exception
WalkerError: ('意外的节点类型', 339)
WalkerError: ('unexpected node type', 339)
环境:Python 2.5
Environment: Python 2.5
我该如何解决这个问题?谢谢
How can I resolve the problem? Thanks
//编辑 7 月 3 日 10:22 GMT+0
// EDIT 03 July 10:22 GMT+0
堆栈跟踪如下
mod_wsgi (pid=1028): Exception occurred processing WSGI script 'D:/py/labs_library/index.py'.
Traceback (most recent call last):
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 277, in wsgi
result = self.handle_with_processors()
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 247, in handle_with_processors
return process(self.processors)
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 244, in process
raise self.internalerror()
File "D:\csvn\Python25\lib\site-packages\web\application.py", line 467, in internalerror
return debugerror.debugerror()
File "D:\csvn\Python25\lib\site-packages\web\debugerror.py", line 305, in debugerror
return web._InternalError(djangoerror())
File "D:\csvn\Python25\lib\site-packages\web\debugerror.py", line 290, in djangoerror
djangoerror_r = Template(djangoerror_t, filename=__file__, filter=websafe)
File "D:\csvn\Python25\lib\site-packages\web\template.py", line 845, in __init__
code = self.compile_template(text, filename)
File "D:\csvn\Python25\lib\site-packages\web\template.py", line 924, in compile_template
ast = compiler.parse(code)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 51, in parse
return Transformer().parsesuite(buf)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 128, in parsesuite
return self.transform(parser.suite(text))
File "D:\csvn\Python25\lib\compiler\transformer.py", line 124, in transform
return self.compile_node(tree)
File "D:\csvn\Python25\lib\compiler\transformer.py", line 167, in compile_node
raise WalkerError, ('unexpected node type', n)
WalkerError: ('unexpected node type', 339)
如果可能,我想关闭模板功能,因为我仅将 python 用于移动应用程序的 JSON 输出.
If it is possible I would like to turn off the template functionality as I use python only for JSON output for mobile app.
推荐答案
如果你创建 python 模块,你应该在你的层次结构顶部添加 __init__.py
:
if you create python module you should add __init__.py
in top of your hierarchy:
dvedit/
__init__.py
clipview.py
filters/
__init__.py
这意味着在每个将通过 from ... import ...
导入的目录中都应该有 __init__.py
文件.
it means that in every directory which will be imported via from ... import ...
should have __init__.py
file.
更多可用信息:http://wiki.cython.org/PackageHierarchy
这篇关于web.py 中的继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!