473,395 Members | 1,931 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,395 software developers and data experts.

Simple but fundamental: How to import a jython class?

I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"
---------------------- Y.py----------------------
import X
x = X()
x.hello()
I get TypeError: call of non function (module 'X')
Both files are in the same directory.

Tanks!

Mar 23 '06 #1
3 1283
az**********@gmail.com wrote:
I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"
---------------------- Y.py----------------------
import X
x = X()
x.hello()
I get TypeError: call of non function (module 'X')
Both files are in the same directory.


try
from X import X
or
x = X.X()
Frank
Mar 23 '06 #2
az**********@gmail.com wrote:
I wrote a jython class bus I can not use it in another jython script
:-(
Example:
---------------------- X.py----------------------
class X:
def hello():
print "Hello"
---------------------- Y.py----------------------
import X
x = X()
x.hello()

I get TypeError: call of non function (module 'X')
Both files are in the same directory.


after you've done "import X", the name X refers to the namespace of the
module X.py, not the class (or any other object) in that module. to access
the class, use dot notation:

x = X.X()

</F>

Mar 23 '06 #3
Thanks Frank. It works :_)

Mar 23 '06 #4

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

Similar topics

4
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad...
2
by: Kevin Dahlhausen | last post by:
Been digging and could not find the answer to this. I'd be very grateful if someone could help. I can't import a class from a packackge that is nested: -- import sys...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
3
by: donkeyboy | last post by:
All, I'm having issues installing Jython on Windows XP. I've looked on the web and this newsgroup but to no avail. Any suggestions? The shell listing is below: NB I've got Cygwin installed,...
2
by: donkeyboy | last post by:
All, I've tried the jythonc compiler to try and create an applet to see how it works, but I get a number of Java compile errors that are way above my knowledge. Does anyone know what any of the...
2
by: HMS Surprise | last post by:
Greetings. What is the implication of the error message 'cannot import name .....'? It occurs when executing the line: from nBaseTest import nBaseTest The file exists and the class within...
1
by: nmin | last post by:
Hi. I'm using Jython in combination with Java, webservices and jboss4.0.4. The webservice is implemented in java and creates an PythonInterpreter object which loads the jython scripts. I...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
tracyyun
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 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.