| Newsgroups |
gmane.comp.lang.jython.user |
| Message-ID |
<[email protected]> |
Dear all,
Happy new year!
The isinstance method return diffrent value for a certain object with differenct conditions.
1. Create a 'point.py' file which contains a Point class:
class Point():
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def __str__(self):
return "({0},{1})".format(self.x, self.y)
def __add__(self, other):
print 'Type test inside: ' + str(isinstance(other, Point))
print str(other)
x = self.x + other.x
y = self.y + other.y
return Point(x, y)
@staticmethod
def output():
print 'Output test'
#Run test in module
print '-------------Test inside module ---------------'
p1 = Point(2,3)
p2 = Point(-1,2)
print 'Type test outside: '+ str(isinstance(p2, Point))
p3 = p1 + p2
print str(p2)
Point.output()
2. Create a 'test_type.py' file to call the 'point' module:
import sys
sys.path.append('D:/Working/MIScript/Jython/mis') #You may change the path
import point
from point import Point
reload(point)
#Run test
print '-------------Test outside module ---------------'
p1 = Point(2,3)
p2 = Point(-1,2)
print 'Type test outside: '+ str(isinstance(p2, Point))
p3 = p1 + p2
print str(p2)
Point.output()
The running result is:
-------------Test inside module ---------------
Type test outside: True
Type test inside: True
(-1,2)
(-1,2)
Output test
-------------Test outside module ---------------
Type test outside: True
Type test inside: False
(-1,2)
(-1,2)
Output test
I can not understand why the diffrence occured (with red color lines). Can anybody help me to expain it ? Thanks a lot!
By the way, I tested the diffrent version of Jython and also CPython 2.6 with same result.
Regards
Yaqiang
*************************************************
Dr. Yaqiang Wang
Chinese Academy of Meteorological Sciences (CAMS)
46, Zhong-Guan-Cun South Avenue
Beijing, 100081
China
[email protected]
http://www.meteothinker.com
**************************************************
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users