Hi Victor,

this is how modules work. From a module you can import a definition (a
class, a function, a variable) but the module cannot see variables
defined by the importer.
This is why web2py executes models/controllers/views instead of
importing them.

The suggested way around your problem is put something like this in
the module:

from gluon.html import *
from gluon.sqlhtml import *
from gluon.validators import *
class MyModulo:
    def __init__(self,request,response,session,cache,T,db):
 
self.request,self.response,self.session,self.cache,self.T,self.db=\
          request,response,session,cache,T,db
    def my_funcion(self):
          request,response,session,cache,T,db=\
 
self.request,self.response,self.session,self.cache,self.T,self.db
    print "una funcion"
    return "hello %s" % request.client

and import it as

from applications.blog.modules.modulo import MyModulo
modulo=MyModulo(request,response,session,cache,T,db)

now you can use modulo.my_function() and my_function will see the
global objects that are passed to it.

Massimo

On Jan 11, 7:05 pm, "b-global.net" <bglobal...@yahoo.com.mx> wrote:
> Hello:
>
> I'm new using python and web2py, and I think that web2py is great!!!.
> I'm making some tests but now I have some problems!!!
>
> I want to  make some plugins  to be used in all the applications, and
> I think the use of modules will be the solution. In the modules
> directory I made a file that I called "modulo.py" and I wrote this:
>
> def mi_funcion():
>    print "una funcion"
>    return "hello"
>
> And then I import the module using this:
>
> import applications.blog.modules.modulo as modulo
>
> And the module works fine!!!
>
> But when I use db and SQLDB in the module to create the database and
> to use the database I received an error:
> the SQLDB in not defined.
>
> If somebody know how to fix this problem, or can give me a detailed
> explanation, to fix this will be appreciated
>
> Thank you,
>
> Best regards,
>
> Victor.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to