I have a python script that I want to test/debug. It contains a class
which extends from some other class which is located in some other
python file in a different directory.
For example:
[script to test]
c:\python_code\foo.py
[needed python files]
c:\some\other\directory\bar.py
....so I want to test/debug foo.py, which needs bar.py. foo.py imports
bar.py ...but in order to test out foo (in the python shell) I normally
copy bar.py into the same directory as foo.py...but this is painful.
Is there some way that I can have python know about the directory where
bar.py is located, like a system variable, etc? If so, how do I set
that up?
Thanks. 10 34342
This question seems to come up in this newsgroup quite often, so looking
through past threads will sure provide more details.
Here from "Re: how to import a module from a arbitraty path?"
posted to comp.lang.python by Simon Brunning on May 26, 2005 09:20 :
" I have a program which is going to dynamicly load components from some arbitrary defined paths. How to do that?
You can locate them with os.walk and fnmatch. Then you can temporarily
add the directory to sys.path, and import using __import__().
"
so this should work in your case:
import sys
sys.path.append("C:\some\other\directory")
import bar
Claudio
"py" <co*******@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com... I have a python script that I want to test/debug. It contains a class which extends from some other class which is located in some other python file in a different directory.
For example:
[script to test] c:\python_code\foo.py
[needed python files] c:\some\other\directory\bar.py
...so I want to test/debug foo.py, which needs bar.py. foo.py imports bar.py ...but in order to test out foo (in the python shell) I normally copy bar.py into the same directory as foo.py...but this is painful. Is there some way that I can have python know about the directory where bar.py is located, like a system variable, etc? If so, how do I set that up?
Thanks.
This question seems to come up in this newsgroup quite often, so looking
through past threads will sure provide more details.
Here from "Re: how to import a module from a arbitraty path?"
posted to comp.lang.python by Simon Brunning on May 26, 2005 09:20 :
" I have a program which is going to dynamicly load components from some arbitrary defined paths. How to do that?
You can locate them with os.walk and fnmatch. Then you can temporarily
add the directory to sys.path, and import using __import__().
"
so this should work in your case:
import sys
sys.path.append("C:\some\other\directory")
import bar
Claudio
"py" <co*******@gmail.com> schrieb im Newsbeitrag
news:11**********************@g14g2000cwa.googlegr oups.com... I have a python script that I want to test/debug. It contains a class which extends from some other class which is located in some other python file in a different directory.
For example:
[script to test] c:\python_code\foo.py
[needed python files] c:\some\other\directory\bar.py
...so I want to test/debug foo.py, which needs bar.py. foo.py imports bar.py ...but in order to test out foo (in the python shell) I normally copy bar.py into the same directory as foo.py...but this is painful. Is there some way that I can have python know about the directory where bar.py is located, like a system variable, etc? If so, how do I set that up?
Thanks.
Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
....that will certainly work. Only issue is that each time I start up
foo.py in the python shell I have to retype those three lines....kind
of why I was hoping for a environment variable or path setting that i
could stick in.
This will do for now...
Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
....that will certainly work. Only issue is that each time I start up
foo.py in the python shell I have to retype those three lines....kind
of why I was hoping for a environment variable or path setting that i
could stick in.
This will do for now...
On Thu, 2005-11-17 at 08:41, py wrote: Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
...that will certainly work. Only issue is that each time I start up foo.py in the python shell I have to retype those three lines....kind of why I was hoping for a environment variable or path setting that i could stick in.
That would be PYTHONPATH.
-Carsten
On Thu, 2005-11-17 at 08:41, py wrote: Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
...that will certainly work. Only issue is that each time I start up foo.py in the python shell I have to retype those three lines....kind of why I was hoping for a environment variable or path setting that i could stick in.
That would be PYTHONPATH.
-Carsten
"py" <co*******@gmail.com> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.com... Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
...that will certainly work. Only issue is that each time I start up foo.py in the python shell I have to retype those three lines....kind of why I was hoping for a environment variable or path setting that i could stick in.
This will do for now...
See the recent threads
"IDLE question" and
"newbie - How do I import automatically?"
in THIS newsgroup for further help.
Claudio
"py" <co*******@gmail.com> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.com... Claudio Grondi wrote: so this should work in your case:
import sys sys.path.append("C:\some\other\directory") import bar
...that will certainly work. Only issue is that each time I start up foo.py in the python shell I have to retype those three lines....kind of why I was hoping for a environment variable or path setting that i could stick in.
This will do for now...
See the recent threads
"IDLE question" and
"newbie - How do I import automatically?"
in THIS newsgroup for further help.
Claudio This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Colin Brown |
last post by:
I have instances where Python 2.3.2 import both does not work or error. It
can be demonstrated under Win2k and Linux by doing the following:
1. Create a subdirectory "abc"
2. In directory "abc"...
|
by: Matt Whiteley |
last post by:
I have some python code in a directory called customModules and this sits
under the main directory which contains a piece of server.py code. Under
2.1.x and 2.2.x, I did the following in server.py...
|
by: atlantis |
last post by:
Hi,
I have a very strange problem with xsl:import when usig RELATIVE path
on AIX 5.2 server.
I have two XSL files in the same directory: "ists_xslt3.xsl" and
"ists_xslt3_layout.xsl". This...
|
by: Jon |
last post by:
It appears that (windows) python searches in the current working
directory before looking in the local site-packages directory, or that
'.' comes first in sys.path? The problem arises when I made...
|
by: Ron Adam |
last post by:
from __future__ import absolute_import
Is there a way to check if this is working? I get the same results with or
without it.
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
on win 32
...
|
by: Laszlo Nagy |
last post by:
ohad frand wrote:
So this is what you have:
/1/tmp1.py
/1/tmp2.py
/2/tmp1.py
/2/tmp2.py
|
by: rsoh.woodhouse |
last post by:
Hi,
I'm trying to work out some strange (to me) behaviour that I see when
running a python script in two different ways (I've inherited some
code that needs to be maintained and integrated with...
|
by: tow |
last post by:
I have a python script (part of a django application, if it makes any
difference) which is exhibiting the following behaviour:
import my_module # succeeds
imp.find_module("my_module") # fails,...
|
by: Gabriel Genellina |
last post by:
En Sat, 18 Oct 2008 05:52:04 -0300, Stef Mientki <stef.mientki@gmail.com>
escribió:
Why don't you let the caller tell you its own location, using __file__?
The above code is too much magic for...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |