By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

Python import search path!

P: n/a
Hy!
I'm new in Linux, and i feel little less newer in python.

I need advice and help. I'm making an application witch purpose is
irrelevant. It has a lot of code for now and I've only made interface.
So I've tried to split code into separate files and in windows as I
remember worked file when i wrote eg. import myFile but now in Ubuntu
it says Module not found. (I'm using Ubuntu and I've installed python
2.5 and wxPython 2.8.4, and I'm using GedIt as my favorite text editor).
The question is how to make this work (files are in the same folder)

Second question is about import wx. When i separate code into files i
have to write import wx into every file because all of them contains
some part of the interface. Does that make my program bigger than
putting everything into one file and use only one import.

Thanks in advance.
Dec 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Dec 14, 3:44 pm, SMALLp <po...@email.t-com.hrwrote:
Hy!
I'm new in Linux, and i feel little less newer in python.

I need advice and help. I'm making an application witch purpose is
irrelevant. It has a lot of code for now and I've only made interface.
So I've tried to split code into separate files and in windows as I
remember worked file when i wrote eg. import myFile but now in Ubuntu
it says Module not found. (I'm using Ubuntu and I've installed python
2.5 and wxPython 2.8.4, and I'm using GedIt as my favorite text editor).
The question is how to make this work (files are in the same folder)
Not sure what is going on here from this description. You may need to
use the sys module and add the path to your module temporarily.

import sys
sys.path.append("//path/to/myFile")

Second question is about import wx. When i separate code into files i
have to write import wx into every file because all of them contains
some part of the interface. Does that make my program bigger than
putting everything into one file and use only one import.

Thanks in advance.
No, importing wx in multiple files does not make it bigger. In fact,
as I understand it, Python will only import a module if it's not
already in the namespace. So if you import wx in your main module and
then import it again in some sub-module of yours, Python won't
actually import wx the second time, but will just use the one that's
in the namespace already.

See this thread for a more coherent explanation:

http://mail.python.org/pipermail/pyt...er/293861.html

Mike
Dec 14 '07 #2

P: n/a
ky******@gmail.com wrote:
On Dec 14, 3:44 pm, SMALLp <po...@email.t-com.hrwrote:
>Hy!
I'm new in Linux, and i feel little less newer in python.

I need advice and help. I'm making an application witch purpose is
irrelevant. It has a lot of code for now and I've only made interface.
So I've tried to split code into separate files and in windows as I
remember worked file when i wrote eg. import myFile but now in Ubuntu
it says Module not found. (I'm using Ubuntu and I've installed python
2.5 and wxPython 2.8.4, and I'm using GedIt as my favorite text editor).
The question is how to make this work (files are in the same folder)

Not sure what is going on here from this description. You may need to
use the sys module and add the path to your module temporarily.

import sys
sys.path.append("//path/to/myFile")


I managed to make simple thing complicated. So what i was trying to do
is to write part of my program in a separate file and than use "import
myFile as my" to use classes written in that file.

Thanks for the answer Mike!
Dec 14 '07 #3

P: n/a
SMALLp wrote:
remember worked file when i wrote eg. import myFile but now in
Ubuntu it says Module not found. (I'm using Ubuntu and I've
installed python 2.5 and wxPython 2.8.4, and I'm using GedIt as my
favorite text editor). The question is how to make this work
(files are in the same folder)
Please provide the exact error message, the part of the source code
it refers to, and the command line you called the file by.
Second question is about import wx. When i separate code into
files i have to write import wx into every file because all of
them contains some part of the interface. Does that make my
program bigger than putting everything into one file and use only
one import.
Yes, the program gets a few bytes (11 for "import wx\r\n") bigger.
No, it is no performance problem.

Regards,
Björn

--
BOFH excuse #399:

We are a 100% Microsoft Shop.

Dec 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.