473,406 Members | 2,220 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,406 software developers and data experts.

Imports

gtb
I am working with a tool called maxQ that generates jython scripts.
The tool runs in

C:\maxq\bin.
Rather than clutter up bin I want to put the scripts and other .py
scripts in

c:\maxq\bin\testScripts.
When doing so the scripts need to import from

c:\maxq\jython, but can't find the modules.
I tried adding c:\maxq\jython to the environment variable pythonpath
but to no avail. Perhaps I missed it in Rossum's tutorial but is there
a std prgrammatic way to specify a module directory?

Could you, would you, recommend a text or another webpage for learning
more (much more) about python?

Thanx,

gtb

Mar 20 '07 #1
8 1890
On Mar 20, 1:31 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
I am working with a tool called maxQ that generates jython scripts.
The tool runs in

C:\maxq\bin.

Rather than clutter up bin I want to put the scripts and other .py
scripts in

c:\maxq\bin\testScripts.

When doing so the scripts need to import from

c:\maxq\jython, but can't find the modules.

I tried adding c:\maxq\jython to the environment variable pythonpath
but to no avail. Perhaps I missed it in Rossum's tutorial but is there
a std prgrammatic way to specify a module directory?

Could you, would you, recommend a text or another webpage for learning
more (much more) about python?

Thanx,

gtb
I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.

Mike

Mar 20 '07 #2
gtb
On Mar 20, 1:51 pm, kyoso...@gmail.com wrote:
On Mar 20, 1:31 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
I am working with a tool called maxQ that generates jython scripts.
The tool runs in
C:\maxq\bin.
Rather than clutter up bin I want to put the scripts and other .py
scripts in
c:\maxq\bin\testScripts.
When doing so the scripts need to import from
c:\maxq\jython, but can't find the modules.
I tried adding c:\maxq\jython to the environment variable pythonpath
but to no avail. Perhaps I missed it in Rossum's tutorial but is there
a std prgrammatic way to specify a module directory?
Could you, would you, recommend a text or another webpage for learning
more (much more) about python?
Thanx,
gtb

I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.

Mike
Something else going on then, does the directory path need to be the
full path or will it search sub-directories?

Traceback (most recent call last):
File "C:\maxq-0.98\bin\testScripts\compactLogin.py", line 2, in
<module>
from CompactTest import CompactTest
File "c:\maxq-0.98\jython\CompactTest.py", line 2, in <module>
from java.lang import *
ImportError: No module named java.lang

Thanks for the book recommendations.

gtb

Mar 20 '07 #3
On Mar 20, 1:59 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
On Mar 20, 1:51 pm, kyoso...@gmail.com wrote:
On Mar 20, 1:31 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
I am working with a tool called maxQ that generates jython scripts.
The tool runs in
C:\maxq\bin.
Rather than clutter up bin I want to put the scripts and other .py
scripts in
c:\maxq\bin\testScripts.
When doing so the scripts need to import from
c:\maxq\jython, but can't find the modules.
I tried adding c:\maxq\jython to the environment variable pythonpath
but to no avail. Perhaps I missed it in Rossum's tutorial but is there
a std prgrammatic way to specify a module directory?
Could you, would you, recommend a text or another webpage for learning
more (much more) about python?
Thanx,
gtb
I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.
Mike

Something else going on then, does the directory path need to be the
full path or will it search sub-directories?

Traceback (most recent call last):
File "C:\maxq-0.98\bin\testScripts\compactLogin.py", line 2, in
<module>
from CompactTest import CompactTest
File "c:\maxq-0.98\jython\CompactTest.py", line 2, in <module>
from java.lang import *
ImportError: No module named java.lang

Thanks for the book recommendations.

gtb
Usually, the sys.path.append will allow Python to search the
subfolders too, but I have noticed that sometimes it doesn't if you
use UNC paths. I don't use jython, so maybe there's another way to fix
this that is more specific to that implementation of Python?

Mike

Mar 20 '07 #4
gtb
On Mar 20, 2:25 pm, kyoso...@gmail.com wrote:
On Mar 20, 1:59 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
On Mar 20, 1:51 pm, kyoso...@gmail.com wrote:
On Mar 20, 1:31 pm, "gtb" <goodTweetieB...@hotmail.comwrote:
I am working with a tool called maxQ that generates jython scripts.
The tool runs in
C:\maxq\bin.
Rather than clutter up bin I want to put the scripts and other .py
scripts in
c:\maxq\bin\testScripts.
When doing so the scripts need to import from
c:\maxq\jython, but can't find the modules.
I tried adding c:\maxq\jython to the environment variable pythonpath
but to no avail. Perhaps I missed it in Rossum's tutorial but is there
a std prgrammatic way to specify a module directory?
Could you, would you, recommend a text or another webpage for learning
more (much more) about python?
Thanx,
gtb
I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.
Mike
Something else going on then, does the directory path need to be the
full path or will it search sub-directories?
Traceback (most recent call last):
File "C:\maxq-0.98\bin\testScripts\compactLogin.py", line 2, in
<module>
from CompactTest import CompactTest
File "c:\maxq-0.98\jython\CompactTest.py", line 2, in <module>
from java.lang import *
ImportError: No module named java.lang
Thanks for the book recommendations.
gtb

Usually, the sys.path.append will allow Python to search the
subfolders too, but I have noticed that sometimes it doesn't if you
use UNC paths. I don't use jython, so maybe there's another way to fix
this that is more specific to that implementation of Python?

Mike
Thanks for the sys.path.append info. Turns out maxq cranks thing up
with java ( I should have seen it). The sys.path.append does
everything it supposed to do.

gtb

Mar 20 '07 #5
En Tue, 20 Mar 2007 16:25:41 -0300, <ky******@gmail.comescribió:
Usually, the sys.path.append will allow Python to search the
subfolders too, but I have noticed that sometimes it doesn't if you
use UNC paths. I don't use jython, so maybe there's another way to fix
this that is more specific to that implementation of Python?
Python does not search subfolders during a normal import. Perhaps you were
thinking about subpackages?

--
Gabriel Genellina

Mar 20 '07 #6
On Mar 20, 12:51 pm, kyoso...@gmail.com wrote:
I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.

Mike
I can't access any modules using the sys.path.append() method. Here
is my directory structure:

/
----Users
---------Me
------------2testing
------------------dir1
---------------------test1.py
---------------------programs_python
-----------------------------testA.py

testA.py:
------------------------
def show(x):
print x

if __name__ == "__main__":
show("hello")
------------------------

test1.py:
------------------------
import sys

sys.path.append("/Users/Me/2testing/dir1/programs_python")
testA.show("hello")
------------------------

command:
~/2testing/dir1$ python test1.py

output:
Traceback (most recent call last):
File "test1.py", line 4, in ?
testA.show("hello")
NameError: name 'testA' is not defined

Any idea how to do that?

Mar 21 '07 #7
On Mar 20, 6:33 pm, "7stud" <bbxx789_0...@yahoo.comwrote:
On Mar 20, 12:51 pm, kyoso...@gmail.com wrote:
I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.
Mike

I can't access any modules using the sys.path.append() method. Here
is my directory structure:

/
----Users
---------Me
------------2testing
------------------dir1
---------------------test1.py
---------------------programs_python
-----------------------------testA.py

testA.py:
------------------------
def show(x):
print x

if __name__ == "__main__":
show("hello")
------------------------

test1.py:
------------------------
import sys

sys.path.append("/Users/Me/2testing/dir1/programs_python")
testA.show("hello")
------------------------

command:
~/2testing/dir1$ python test1.py

output:
Traceback (most recent call last):
File "test1.py", line 4, in ?
testA.show("hello")
NameError: name 'testA' is not defined

Any idea how to do that?
Hmmm...I got it to work like this:

test1.py:
---------
import sys
sys.path.append("/Users/Me/2testing/dir1/programs_python")

import testA
testA.show("hello")

Mar 21 '07 #8
7stud wrote:
On Mar 20, 6:33 pm, "7stud" <bbxx789_0...@yahoo.comwrote:
>On Mar 20, 12:51 pm, kyoso...@gmail.com wrote:
>>I typically just import sys and then do a
sys.path.append(directoryPath). This basically makes whatever modules
in that path available at run time. If you need a beginners reference
book, I recommend "Beginning Python" by Hetland. "Python Programming
for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
get into the internals of the language like Hetland does. Once you're
a snake charmer too, you can "graduate" to the "Programming Python"
book by Lutz.
Mike
I can't access any modules using the sys.path.append() method. Here
is my directory structure:

/
----Users
---------Me
------------2testing
------------------dir1
---------------------test1.py
---------------------programs_python
-----------------------------testA.py

testA.py:
------------------------
def show(x):
print x

if __name__ == "__main__":
show("hello")
------------------------

test1.py:
------------------------
import sys

sys.path.append("/Users/Me/2testing/dir1/programs_python")
testA.show("hello")
------------------------

command:
~/2testing/dir1$ python test1.py

output:
Traceback (most recent call last):
File "test1.py", line 4, in ?
testA.show("hello")
NameError: name 'testA' is not defined

Any idea how to do that?

Hmmm...I got it to work like this:

test1.py:
---------
import sys
sys.path.append("/Users/Me/2testing/dir1/programs_python")

import testA
testA.show("hello")
That's how it's s'posed to work. You still have to explicitly import the
modules you want - the sys.path just tells Python where to look for them.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 21 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven K | last post by:
Hello, Is there a way to declare imports so that they don't have to be declared both in Master Page.vb and the Content Page.vb? For example, I have the following in the Master Page.vb Imports...
19
by: Tiraman | last post by:
Hi , I have an assembly that hold few class and few imports which are not used in all of the class's . so my question is when to use the "Imports XXX" And when to use this kind of statement...
4
by: Jeff Jarrell | last post by:
I am not really there yet with namespaces. I have a "common.dll" that is referenced from another project. now in the consuming project, source file to i'd like to have a "imports common". ...
7
by: pcnerd | last post by:
In Java I can use, for example, " Imports java.util.* ". Can I use, for example, " Imports System.* " instead of several different "Imports" statements? Thank you. David
1
by: Arpan | last post by:
What's the difference between "Imports" & "Inherits"? For e.g. both the codes below work without any errors: Imports System Imports System.Data Imports System.Web.UI Namespace Constructors...
1
by: Thomas Wittek | last post by:
Hi! Is there any possibility/tool to automatically organize the imports at the beginning of a module? I don't mean automatic imports like autoimp does as I like seeing where my...
5
by: kimiraikkonen | last post by:
Hello, I want to ask about "imports" statement. Some projects must be inserted with "imports xxxx" statements before beginning coding. But how do i know when to use or do i have to use "imports"...
0
by: Kay Schluehr | last post by:
Since their introduction in Python 2.5 I only reviewed the new "relative import" notation briefly by reading the "What's new in Python 2.5" article. Now I wanted checkout if I get comfortable with...
4
by: Albert | last post by:
Hi, when do i need this: Imports System.Data and when this: Imports System.Data.SqlClient? More specifically, when i want to perform a select or update of a table using: connection = New...
3
by: Mohamed Yousef | last post by:
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
0
isladogs
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...

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.