Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
10135 มุมมอง

Hello,

In a custom module, I'm trying to import a file that doesn't exist in the addons directory.

My file path: /home/wided/settings.py

Addons path: /usr/local/lib/python2.7/dist-packages/openerp-server/addons

How can I import settings.py to my module?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Make a symbolic link to the file in your module?

cd /usr/local/lib/python2.7/dist-packages/openerp-server/addons/my_module/
ln -s /home/wided/settings.py

This creates the symlink settings.py in the folder my_module. Then in a different script in that folder,

import settings

I can't think of a situation where I'd want to use this setup over just putting the settings.py file in the module folder itself though. Even making a symlink from the module folder to your home folder sounds like a better idea.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for your answer. Actually, I have resolved my problem by copying the file to my module folder. This file serves for an other python project, this is why I didn't want to have it twice in the system. Anyways, your idea is better than mine because when the file is edited, it is edited in both folders.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ต.ค. 23
4097
Import py file of a custom module แก้ไขแล้ว
1
มี.ค. 21
18980
1
มี.ค. 15
5392
2
พ.ค. 25
1360
Import from Winbooks แก้ไขแล้ว
4
พ.ค. 25
5080