473,503 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing a class, please help...

Hi,

Newbie to Python and I have a question please. I am using Windows XP, SPE
0.8.2.a and Python24. I have done this:

import sys
print sys.path

no problem there, sys imports just fine. I have a folder that I called
c\JavaProjects\PythonTesting and it shows up in the output from sys.path
above. I have dropped a very simple Jar in that folder and I have attempted
to do an Import on it. This is where things fail. I cannot see the
contents of my Jar. What am I missing here?

Would somebody please drop me a hint, please? I would HIGHLY appreciate an
example; does anybody know of a website or page that would show me how to do
this? I realize this is a simple question and I appreciate any help
somebody would give me.

Regards,
joe
Feb 5 '06 #1
8 1349
"anon" <an**@nospam.nospam> writes:
to do an Import on it. This is where things fail. I cannot see the
contents of my Jar. What am I missing here?


That JARs are for Java and yo're using Python?
--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Feb 5 '06 #2
anon wrote:
Would somebody please drop me a hint, please?

Yeah, the definition of "JAR" is Java ARchive, why the hell would a
Python script be able to read a JAR in the first place (truth is it is,
a JAR file is nothing but a renamed ZIP, therefore the zipfile module
allows you to read it's content) and -- more importantly -- import Java
classes.

Notice the difference between *Python* script and *Java* class? That's
because they're two different languages.
If you want to use Java classes and modules in a Pythonic context, you
want Jython (http://www.jython.org/) not Python (http://www.python.org/)
Feb 5 '06 #3
On Sun, 05 Feb 2006 17:16:38 +0100, Xavier Morel <xa**********@masklinn.net> wrote:
anon wrote:
Would somebody please drop me a hint, please?
Yeah, the definition of "JAR" is Java ARchive, why the hell would a
Python script be able to read a JAR in the first place


You are rude to an obvious newbie here ... please keep in mind that today's
stupid newbies are tomorrow's Python professionals.

.... If you want to use Java classes and modules in a Pythonic context, you
want Jython (http://www.jython.org/) not Python (http://www.python.org/)


Maybe he /is/ running Jython and failed to explain that properly? If I
understand things correctly, jar files are not tied to Java but to the java
bytecode format -- which Java and Jython share.

In either case, we'd need more information from the original poster.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
Feb 5 '06 #4
Jorgen Grahn wrote:
Yeah, the definition of "JAR" is Java ARchive, why the hell would a
Python script be able to read a JAR in the first place
You are rude to an obvious newbie here ...

Agreed. I don't think it was intended, but we should be
cautious with our language when we address strangers...
Maybe he /is/ running Jython and failed to explain that properly?

Not likely, since he wrote "python24". I think the newest Jython
is 2.2a1...
Feb 5 '06 #5
Jorgen Grahn wrote:
You are rude to an obvious newbie here ... please keep in mind that today's stupid newbies are tomorrow's Python professionals.
I didn't mean to be rude and apologize if that's the way it came out.
Maybe he /is/ running Jython and failed to explain that properly?
No, he explicitely stated that he's using Python 2.4 (I'm pretty sure
Jython's latest release is 2.1) and SPE (which didn't handle Jython last
time I tried it)
If I
understand things correctly, jar files are not tied to Java but to the java
bytecode format -- which Java and Jython share.

Yes, it's used to store/package compiled java classes (.class bytecode
files) and various metadata associated to the classes (resources, ...)
and therefore tied to the bytecode (or the JVM) indeed.
Feb 6 '06 #6
Xavier

Yes I meant Python. I have also been using Jython and I am VERY WELL aware
what a JAR is. Jython has the ability to call methods stored in classes in
a JAR. I was only asking if this could be done with Python also.

You ask "why the hell would a Python script be able to read a JAR..". Well,
I was simply asking a newbie question. The only way to gather knowladge is
by asking questions.

You know, an old college proffesor I had was very knowladgeable and wise.
He always took the time to answer questions, no matter how 'stupid' they
would sound. One can make a bigger impression on folks by stepping down a
couple of steps and give a polite answer. I mean no disrespect, just a
suggestion when you post answers to folks like me who are just getting
started with a new language...

regards
"Xavier Morel" <xa**********@masklinn.net> wrote in message
news:ds**********@aphrodite.grec.isp.9tel.net...
anon wrote:
Would somebody please drop me a hint, please?

Yeah, the definition of "JAR" is Java ARchive, why the hell would a Python
script be able to read a JAR in the first place (truth is it is, a JAR
file is nothing but a renamed ZIP, therefore the zipfile module allows you
to read it's content) and -- more importantly -- import Java classes.

Notice the difference between *Python* script and *Java* class? That's
because they're two different languages.
If you want to use Java classes and modules in a Pythonic context, you
want Jython (http://www.jython.org/) not Python (http://www.python.org/)

Feb 6 '06 #7
On Sun, 5 Feb 2006 10:41:51 -0500
"anon" <an**@nospam.nospam> wrote:
Newbie to Python and I have a question please. I am using
Windows XP, SPE 0.8.2.a and Python24. I have done this:

import sys
print sys.path

no problem there, sys imports just fine. I have a folder
that I called c\JavaProjects\PythonTesting and it shows
up in the output from sys.path above. I have dropped a
very simple Jar in that folder and I have attempted to do
an Import on it. This is where things fail. I cannot see
the contents of my Jar. What am I missing here?


As others have pointed out, ".jar" is going to be Java
bytecode, and from that strange looking path (was, I assume
supposed to be "C:\JavaProjects\PythonTesting"), it looks
very much like you really wanted to be using Jython (a.k.a
"Java Python") rather than Python (a.k.a. "C Python").

Perhaps you have both Jython and Python 2.4 installed and
you are launching the latter when you meant the former?

In any case, C Python cannot load Java classes (that's the
main raison d'etre for Jython).

--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Feb 6 '06 #8
anon <an**@nospam.nospam> wrote:
Xavier

Yes I meant Python. I have also been using Jython and I am VERY WELL aware
what a JAR is. Jython has the ability to call methods stored in classes in
a JAR. I was only asking if this could be done with Python also.


Classic Python is able to import Python modules from a .zip file; it
would be a reasonably easy tweak to allow the extension to be .jar or
..foo or .zap as well as .zip -- but they'd still have to be Python
modules. Java classes use a completely different bytecode from Classic
Python: if you need to access such JVM bytecode, use Jython instead.
Alex
Feb 6 '06 #9

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

Similar topics

11
3053
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
7
3026
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
3
1802
by: Mark | last post by:
All, As you can see below, I have had problems with inquisitive souls looking at data they shouldn't be. I though disabling the ability to create new databases using my workgroup would stop this...
5
3152
by: dixie | last post by:
If I sent a user an empty database container - dB with no tables and I needed them to import their tables into it and one of their tables was a hidden table with the prefix Usys, is there any way...
7
3287
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
1
2100
by: em | last post by:
Hi all, I'm getting some problems importing a DLL that I made in C# within VB6.0. The C# is quite easy, just for trying: namespace TestDll { public class Class1
29
4177
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
2
7359
by: Alun Jones | last post by:
I'm getting the above error in a dialog box from Visual Studio 2005 when trying to sign an assembly using a PFX file, and would like to know how to resolve the problem. Background: The PFX...
0
959
by: Mani Chandra | last post by:
--- On Wed, 13/2/08, Mani Chandra <mc_i2020@yahoo.co.inwrote: Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
0
7199
marktang
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,...
0
7076
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
7274
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
7323
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...
1
6984
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
5576
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
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.