accessing a function in another controller

67 views
Skip to first unread message

Vlad

unread,
May 15, 2019, 3:44:24 PM5/15/19
to web2py-users
this must be a very basic question; I just don't have full clarity on how web2py handles this: 

can code in one controller somehow access a function in another controller? Or I have to move such a function to model code? 

Dave S

unread,
May 15, 2019, 7:40:45 PM5/15/19
to web2py-users


On Wednesday, May 15, 2019 at 12:44:24 PM UTC-7, Vlad wrote:
this must be a very basic question; I just don't have full clarity on how web2py handles this: 

can code in one controller somehow access a function in another controller? Or I have to move such a function to model code? 

It's not clear what you're asking.


Consider

web2py
 
\--- applications
         
|------ appX
         
\------ appY
             
| ----controllers
             
|     \-- default
             
|        |---- hiddenY0(somearg)
             
|        |---- funcY1
             
|        \---- funcY2
             
|             \---- innie1_Y2
             
\---- modules
                   
\-- calculator
                           
|---- calc1
                           
|        \--- innie_calc1
                           
\---- calc2


I believer funcY1 can call funcY2, although the usual way to handle that is by redirect().
But funcY1 cannot call innie_Y2 because of scoping.
Both funcY1 and funcY2 can call hiddenY0, but because hiddenY0 has an arg, no function outside of default can access it directly, and it is not an endpoint for a URL (er, URI).
Also, after import, either funcY1 or funcY2 can call either calc1 or calc2, but cannot call innie_calc1.

(There is a special case in Python where the innie_calc1 function is returned by calc1 to the caller, but that puts the innie into the scope of the caller)

Are any of those what you are asking about?  What are you trying to do?

/dps

                     

Eliezer (Vlad) Tseytkin

unread,
May 15, 2019, 7:45:17 PM5/15/19
to web...@googlegroups.com
c1.py and c2.py are controllers. 
c2 has a function f in it. 
Can code in c1.py call the function f?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/LVQkZVfaoZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/81313021-7181-4f6c-870e-24d199f47c7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave S

unread,
May 15, 2019, 9:35:41 PM5/15/19
to web2py-users


On Wednesday, May 15, 2019 at 4:45:17 PM UTC-7, Vlad wrote:
c1.py and c2.py are controllers. 
c2 has a function f in it. 
Can code in c1.py call the function f?

If f is a function in the URL sense (that is, it is top level in c2.py, and has no arguments, and the URL /.../appY/c2/f makes sense) you can redirect to it.  I do not know, and have never tried, to call f directly, but the py-dotted notation c2.f might maybe work, imports done correctly.
If f has arguments and isn't an endpoint, then it could be in a file module/m1.py, and imported by c1 and c2, or the might-maybe could be in play.

That would depend, I suppose, on how the custom importer works.  It is known to work for modules.

/dps



 

Eliezer (Vlad) Tseytkin

unread,
May 15, 2019, 9:39:39 PM5/15/19
to web...@googlegroups.com
Got it, thank you!

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/LVQkZVfaoZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Massimo Di Pierro

unread,
May 16, 2019, 11:35:07 AM5/16/19
to web2py-users
This is why we are making web3py. controllers are not regular modules in web2py.

Eliezer (Vlad) Tseytkin

unread,
May 16, 2019, 12:52:55 PM5/16/19
to web...@googlegroups.com
web2py is so amazingly great that the only excuse to come up with web3py is if it's going to be much better than web2py, if such a thing is possible:)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/LVQkZVfaoZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Massimo Di Pierro

unread,
Jul 5, 2019, 1:21:58 AM7/5/19
to web2py-users
maybe. I can tell you it is a challenge. :-)


On Thursday, 16 May 2019 09:52:55 UTC-7, Vlad wrote:
web2py is so amazingly great that the only excuse to come up with web3py is if it's going to be much better than web2py, if such a thing is possible:)

On Thu, May 16, 2019 at 11:35 AM Massimo Di Pierro <massimo....@gmail.com> wrote:
This is why we are making web3py. controllers are not regular modules in web2py.

On Wednesday, 15 May 2019 18:35:41 UTC-7, Dave S wrote:


On Wednesday, May 15, 2019 at 4:45:17 PM UTC-7, Vlad wrote:
c1.py and c2.py are controllers. 
c2 has a function f in it. 
Can code in c1.py call the function f?

If f is a function in the URL sense (that is, it is top level in c2.py, and has no arguments, and the URL /.../appY/c2/f makes sense) you can redirect to it.  I do not know, and have never tried, to call f directly, but the py-dotted notation c2.f might maybe work, imports done correctly.
If f has arguments and isn't an endpoint, then it could be in a file module/m1.py, and imported by c1 and c2, or the might-maybe could be in play.

That would depend, I suppose, on how the custom importer works.  It is known to work for modules.

/dps



 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/LVQkZVfaoZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages