|
Luis Sousa
llsousa at ualg.pt
Fri Mar 8 10:56:08 EST 2002
I know the problem is mine, so there's goes a simple example !
I have two files, one that I used to define a class and other one that
calls the class:
- file that defines the class: pessoalWEB.py
class MyClass:
def __init__ (self):
self.x = ''
self.y = ''
- file that uses the class: callClassWEB.py
import pessoal
def testFunc():
MyClass = pessoal.MyClass()
saida = MyClass.x
saida = MyClass.y
if saida=='':
saida="NULL"
return saida
I call this file using
http://machinename/~llsousa/gpessoal/callClassWEB.py/testFunc in my browser.
The definition that I'm using on httpd.conf for this directory in apache is:
<Directory /home/llsousa/public_html/gpessoal>
AddHandler python-program .py
PythonHandler mod_python.publisher
PythonDebug On
PythonPath "sys.path+['/home/llsousa/public_html/gpessoal']"
</Directory>
The output that I will expect to return was NULL.
The problem is that in the browser, if I make Reload several times,
sometimes I get what I expect, other times I got this message:
Mod_python error: "PythonHandler mod_python.publisher"
Traceback (most recent call last):
File "/usr/lib/python2.1/site-packages/mod_python/apache.py", line
193, in Dispatch
result = object(req)
File "/usr/lib/python2.1/site-packages/mod_python/publisher.py", line
171, in handler
result = apply(object, (), args)
File "/home/llsousa/public_html/gpessoal/callClassWEB.py", line 6, in
testFunc
saida = MyClass.x
AttributeError: MyClass instance has no attribute 'x'
I was suppose to work all the time. Using the same example in python,
everything went OK !.
What I'm I doing wrong ????
Thanks, Luis Sousa
Matt H wrote:
>On Fri, 08 Mar 2002 09:35:53 +0000
>"Luis Sousa" <llsousa at ualg.pt> wrote:
>
>>Where can I find some examples to implement classes using mod_python ?
>>
>>I'm using the example that is in the documentation in python.org to
>>build a class but something is going wrong.
>>
>
>I can build classes just fine, what's the actual problem?
>
>
>>Thanks, Luis Sousa
>>
>
>
|