auto compiled like in django

183 views
Skip to first unread message

黄祥

unread,
Nov 17, 2013, 3:02:02 AM11/17/13
to web...@googlegroups.com
hi,

just wondering, why web2py didn't have auto compiled like in django? 
e.g. everytime create the new python file in django and then execute it (cli or browser), i observe that django always create the *.pyc (python compiled) for the file that executed.
honestly, i don't know what exactly happen in the django background process, but i assume that django auto compiled the python file so that the *.pyc file generated.
yet in the book about development recipes said to bytecode compile the app, so why web2py didn't adopt auto compiled like in django?

please correct me if i'm wrong.

ref:

best regards,
stifan

Marin Pranjić

unread,
Nov 17, 2013, 6:28:16 AM11/17/13
to web2py-users
I am not a django user but what happens if you edit a file in django? Do you need to restart the webserver to make it work?
In web2py you don't (except for modules). Web2py behaves different and it has its advantages.

But can you tell me why does one need compiled files during development?

(In fact, I don't even compile files in production and no one ever complained)

It could be possible to make auto compilation in web2py but I don't see why would anyone need that.
Also ,it is not a django feature, it is a python feature.

pyc files should be created in web2py in /modules automatically. If you want more django-like behavior, you can write your code inside modules.

Marin


--
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 the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Anthony

unread,
Nov 17, 2013, 9:37:31 AM11/17/13
to web...@googlegroups.com
Python will create a .pyc file for any module (same for modules in web2py). However, unlike in Django, web2py model and controller files are not Python modules. Instead, they are executed by the framework. The advantage is that changes are active immediately, without needing to restart the web server. Of course, you can compile the web2py model and controller files, but you must do that as an explicit step (usually only in production once you have finalized the code). Note, when you compile a web2py application (which you can do in the admin interface), it also compiles the views, not just models and controllers.

Anthony

黄祥

unread,
Nov 17, 2013, 8:24:56 PM11/17/13
to web...@googlegroups.com
On Sunday, November 17, 2013 9:37:31 PM UTC+7, Anthony wrote:
Python will create a .pyc file for any module (same for modules in web2py). However, unlike in Django, web2py model and controller files are not Python modules.
 
so that's the reason, why only in modules folder, web2py automatic generate *.pyc files..
 
Instead, they are executed by the framework. The advantage is that changes are active immediately, without needing to restart the web server. Of course, you can compile the web2py model and controller files, but you must do that as an explicit step (usually only in production once you have finalized the code). Note, when you compile a web2py application (which you can do in the admin interface), it also compiles the views, not just models and controllers.

Anthony


thank you so much for detail explaination, anthony.

best regards,
stifan 

Anthony

unread,
Nov 17, 2013, 9:56:45 PM11/17/13
to web...@googlegroups.com
On Sunday, November 17, 2013 8:24:56 PM UTC-5, 黄祥 wrote:
On Sunday, November 17, 2013 9:37:31 PM UTC+7, Anthony wrote:
Python will create a .pyc file for any module (same for modules in web2py). However, unlike in Django, web2py model and controller files are not Python modules.
 
so that's the reason, why only in modules folder, web2py automatic generate *.pyc files..

It is not web2py that is creating the .pyc files (likewise, Django doesn't create any .pyc files). Rather, the Python interpreter automatically creates .pyc files for any module when it is imported. Files in the web2py /modules folder are imported modules, so just like any other imported Python module, the interpreter generates .pyc files for them. The reason .pyc files are not generated for controller and model files is because they are not modules and are never imported. Similarly, in Django, no .pyc files are generated for templates because the templates are not Python modules.

Keep in mind that once you have finalized your app code in web2py, you can bytecode compile the application, so you get .pyc files for all model, controller, and view files.

Anthony 

黄祥

unread,
Nov 18, 2013, 2:07:01 PM11/18/13
to web...@googlegroups.com
very straight to the point, it's make me clear now, thank you so much for detail explaination, anthony.

best regards,
stifan
Reply all
Reply to author
Forward
0 new messages