Web2Py Working Directory

Well, I want to use WEb2Py because it's pretty nice .. I just need to change the working directory to a directory where all my modules / libraries / applications are so I can use them. I want to be able to import my real program when I use the web2py interface / applications. I need to do this instead of putting all my applications and stuff in the Web2Py folder ... I'm trying to provide my program with a web interface without installing the program in the Web2Py folder .. Sorry if this is hard to understand.

+3
source share
3 answers

os.chdir allows you to change the operating directory of the OS, but for your purposes (which allows you to import a bunch of & c modules that are limited to live in some strange place), it’s better to add the necessary sys.path directories instead .

0
source

In any multi-threaded Python program (and not just Python), you should not use os.chdir, and you should not modify sys.path if you have more than one thread. This is not safe because it affects other threads. In addition, you should not sys.path.append () in a loop because it could explode.

- . - / -, if ochchir/sys.path.append , .

web2py / -. , (, , http). , , , , , , API (request.folder, local_import).

os.chdir sys.path.append, ( web2py). , , Python.

web2py.

+5

I had to do it. I have several modules that I wanted to use from my controllers. If you want to use the code that is in the module directory in the controller, you can use:

# use this in your controller code
impname = local_import('module_in_modules', reload=True)
# reload true  will ensure that it will re load whenever
# there are changes to the module

Jay

0
source

Source: https://habr.com/ru/post/1726859/


All Articles