473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Python import search path!

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
3 12275
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen Ferg | last post by:
I need a little help here. I'm developing some introductory material on Python for non-programmers. The first draft includes this statement. Is this correct? ...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
3
by: Peter Schwalm | last post by:
I'd like to modify the python search path depending on the source directory of the script being started. The reason is: I use a version control system, and the python scripts and modules are...
13
by: fuzzyman | last post by:
I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to...
10
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I...
28
by: Jay | last post by:
OK, I have this XML doc, i dont know much about XML, but what i want to do is take certain parts of the XML doc, such as </title> blah </title> and take just that and put onto a text doc. Then...
2
by: KraftDiner | last post by:
I have a class that is defined in a file called MyClass.py How do I use that class in another python script.. import MyClass ? (Does it need to be in a specific location?)
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 342 open (-38) / 3712 closed (+54) / 4054 total (+16) Bugs : 951 open (-14) / 6588 closed (+33) / 7539 total (+19) RFE : 257 open...
3
by: david | last post by:
You learn something new every day: On my ubuntu, update-manager is supposed to use the python2.5 installed on /usr/bin. Well, I had subsequently installed a whole bunch of stuff in /usr/local...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.