¿Cómo importar archivos .py en una página psp?
Publicado por Sioli (3 intervenciones) el 04/02/2009 19:40:10
Buenas tardes.
Actualmente me encuentro estudiando la plataforma Web para Python, ya configure el servidor Web apache en Debian. He realizado varios ejercicios sencillos para verificar que el servidor funciona correctamente. Pero ahora se me presenta otro inconveniente, estoy tratando de usar algunas funciones matematicas que tengo en un archivo llamado funciones.py, por ejemplo:
# este archivo se llama funciones.py y contiene el siguiente código:
import math
from numpy import array
def PbEstandar(Rsb,T,gegas,API):
f1= float ((10 **((0.00091*T)-(0.0125*API))))
F= float(((Rsb/gegas)**0.83)*f1)
Pb=float(18.2*(F-1.4))
return Pb
Es una funcion que realiza una operacion matemática y que recibre Rsb, T, gegas y API como parámetros y después de realizar el cálculo devuelve el resultado en la variable Pb.
Ahora bien, este es el ejemplo de la página prueba.psp que es donde se llama a la funcion PbEstandar del archivo funciones.py, de la siguiente manera:
# este es el archivo prueba.psp y contiene el siguiente código
<% import time %>
<% import math %>
<%@ import funciones.py %>
<html>
<meta content_type = 'text/html'>
<body>
<% tiempo = time.strftime('%Y') %>
<table width="200" border="1">
<tr>
<td><%= funciones.PbEstandar(650.00,200.00,0.75,36.00)%></td>
</tr>
<tr>
<td><%= tiempo %></td>
</tr>
<tr>
<td><%--= funciones.PbEstandar(650.00,200.00,0.75,36.00) --%></td>
</tr>
</table>
<h1>Current time is: <%= time.ctime() %></h1>
<br>
<h1>The square root of 25 is: <%= math.sqrt(25) %></h1>
</body>
</html>
Los archivos funciones.py y prueba.psp se encuentra en el mismo directorio, /www/prueba_general/
Al ejecutarse en el navegador la página prueba.psp da el siguiente error:
Mod_python error: "PythonHandler mod_python.psp"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 302, in handler
p.run()
File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 213, in run
exec code in global_scope
File "/var/www/prueba_general/prueba_psp.psp", line 1, in ?
NameError: name 'funciones' is not defined
Si alguien me puede ayudar a descifrar este error se lo agradece... gracias!
Actualmente me encuentro estudiando la plataforma Web para Python, ya configure el servidor Web apache en Debian. He realizado varios ejercicios sencillos para verificar que el servidor funciona correctamente. Pero ahora se me presenta otro inconveniente, estoy tratando de usar algunas funciones matematicas que tengo en un archivo llamado funciones.py, por ejemplo:
# este archivo se llama funciones.py y contiene el siguiente código:
import math
from numpy import array
def PbEstandar(Rsb,T,gegas,API):
f1= float ((10 **((0.00091*T)-(0.0125*API))))
F= float(((Rsb/gegas)**0.83)*f1)
Pb=float(18.2*(F-1.4))
return Pb
Es una funcion que realiza una operacion matemática y que recibre Rsb, T, gegas y API como parámetros y después de realizar el cálculo devuelve el resultado en la variable Pb.
Ahora bien, este es el ejemplo de la página prueba.psp que es donde se llama a la funcion PbEstandar del archivo funciones.py, de la siguiente manera:
# este es el archivo prueba.psp y contiene el siguiente código
<% import time %>
<% import math %>
<%@ import funciones.py %>
<html>
<meta content_type = 'text/html'>
<body>
<% tiempo = time.strftime('%Y') %>
<table width="200" border="1">
<tr>
<td><%= funciones.PbEstandar(650.00,200.00,0.75,36.00)%></td>
</tr>
<tr>
<td><%= tiempo %></td>
</tr>
<tr>
<td><%--= funciones.PbEstandar(650.00,200.00,0.75,36.00) --%></td>
</tr>
</table>
<h1>Current time is: <%= time.ctime() %></h1>
<br>
<h1>The square root of 25 is: <%= math.sqrt(25) %></h1>
</body>
</html>
Los archivos funciones.py y prueba.psp se encuentra en el mismo directorio, /www/prueba_general/
Al ejecutarse en el navegador la página prueba.psp da el siguiente error:
Mod_python error: "PythonHandler mod_python.psp"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 302, in handler
p.run()
File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 213, in run
exec code in global_scope
File "/var/www/prueba_general/prueba_psp.psp", line 1, in ?
NameError: name 'funciones' is not defined
Si alguien me puede ayudar a descifrar este error se lo agradece... gracias!
Valora esta pregunta


0