473,231 Members | 2,009 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,231 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 12270
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.