• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confused about Jython/Python

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Mac mini with version 2.7.1 of python installed.

The current version of Python is 3.6. The latest version of Jython was released in May 2015.

Can I install the latest version of Python over the installed version or must I uninstall the current version of Python?

I'm a bit confused as to the Jython/Python relationship. I know that the Jython/Python syntax is identical.

Is the current version of Python compatible with the "current" version of Jython?

Since I have a Mac, is it possible to write a Python program on my Mac that will run on a Windows PC?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Clark wrote:I have a Mac mini with version 2.7.1 of python installed.
The current version of Python is 3.6. The latest version of Jython was released in May 2015.



When Python 3 was announced, it broke several parts of the language in order to streamline future development.  Python 2.7.x is still maintained to provide backward compatibility.

David Clark wrote:
Can I install the latest version of Python over the installed version or must I uninstall the current version of Python?



If you installed Python 3, it would be in parallel to the 2.7 version.  

David Clark wrote:
I'm a bit confused as to the Jython/Python relationship. I know that the Jython/Python syntax is identical.



Is Jython the same language as Python?

Yes. Jython is an implementation of the Python language for the Java platform. Jython 2.7 implements the same language as CPython 2.7, and nearly all of the Core Python standard library modules. (CPython is the C implementation of the Python language.) Jython 2.7 uses the same regression test suite as CPython, with some minor modifications.

There are a number of differences. First, Jython programs cannot currently use CPython extension modules written in C. These modules usually have files with the extension .so, .pyd or .dll. If you want to use such a module, you should look for an equivalent written in pure Python or Java. However, it is technically feasible to support such extensions, as demonstrated by IronPython. For the next release of Jython, we plan to support the C Python Extension API.

There are a number of other differences between the two implementations that are unlikely to go away. These range from the trivial - Jython's code objects currently do not have a co_code attribute because it is not possible to directly access Java bytecode from a class, without loading the file; to the significant - Jython uses Java's true garbage collection rather than Python's reference counting scheme.  



https://wiki.python.org/jython/JythonFaq/GeneralInfo

David Clark wrote:
Is the current version of Python compatible with the "current" version of Jython?



Jython 3.x development is in progress.

Jython 2.7.0 was released on May 3, 2015. Jython 2.7.1 release candidates will be released soon (September 2015).  


https://wiki.python.org/jython/JythonFaq/GeneralInfo#What_is_the_current_status_of_Jython.3F

David Clark wrote:
Since I have a Mac, is it possible to write a Python program on my Mac that will run on a Windows PC?



For the most part, yes. Be aware that there are some thing that differ between OS's, for example GUI libraries, that can cause problems for cross-platform programs.
 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been researching Jython/Python.

It appears that it's not possible to have values like >= or <= or != in For loops in Jython/Python. Is that correct? It's possible to increment & decrement but not compare values in a Jython/Python For loop. Maybe I'm wrong & comparisons are possible in Jython/Python For loops but I haven't been able to find out.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct.  If you want to do a comparison, for example, iterate through a range until you get x == 1, you can do something like this:



See here for more information
 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a Java example of my question.

for (int x = 2; x <= 4; x++)
           System.out.println("Value of x:" + x);

Obviously, the Jython/Python syntax is different from the Java syntax, but can one use the <= or >= or != sign in a Jython/Python For loop?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the documentation, it appears you'd need to do something like this:

 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, darn!

I want to learn a programming language. I want it to be cross-platform. I want it to be easy to read, not verbose like Java.

Jython/Python has its pros & cons just like every programming language. Python is easy to read but it doesn't support constants. Apparently, it also doesn't support comparisons in a For loop. It's not statically typed. I would think that would be bad programming practice. & hard to debug. It does have a lot of math & science libraries so plotting trig functions would probably be easier in Python than in Java. I've spent hours on Google & YouTube reading about Jython/Python, Groovy, Kotlin, Scala & other Java compatible languages.

I can't decide!
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Clark wrote:
I can't decide!



Yes, there is no simple answer other than trying out a few tools and seeing what works best for you.
 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yes, there is no simple answer other than trying out a few tools and seeing what works best for you.  



And that's exactly what I'm doing.

I have 3 IDEs on my Mac - Netbeans, Eclipse & IntelliJ. IntelliJ has the most extensive support for Java & other programming languages. So, ideally, I want to import my Netbeans demos into IntelliJ & learn some JVM language. I've made a list of JVM languages so I'll use Google & Wikipedia & YouTube to research each one & use a process of elimination.
 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Today I installed Jython on my Mac mini with High Sierra. I downloaded the .jar file & went thru the setup. I accepted all of the defaults.

When I type "python" into the terminal, python starts. But when I type "jython" into Terminal, the Terminal tells me "command not found".

I'm unable to determine the python path. How do I find the python path in Finder?

Here's the path for jython: Macintosh HD/Users/davidsimpson/jython2.7.0.

How do I add the jython path? Or do I uninstall jython & reinstall jython & choose the current path during setup? Can I just delete the folders & start over again?
 
Ranch Hand
Posts: 44
1
Python VI Editor Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Clark wrote:This is a Java example of my question.

for (int x = 2; x <= 4; x++)
           System.out.println("Value of x:" + x);

Obviously, the Jython/Python syntax is different from the Java syntax, but can one use the <= or >= or != sign in a Jython/Python For loop?


Python does not need comparison operators in the for loop.  The equivalent code in python would look like:


Python loop variables (i.e. "x") only need to iterate over something.  They are not restricted to integers as in Java or C#.

For example, if I have a container of objects (e.g. a "fleet" container of "car" objects) and each car object has a boolean property called "oil_change_needed" then I can walk through the fleet in either of the following ways:


Many people turn to python because it is easier to read and maintain - and faster to write.  Python also has a number of thoughtful additions to make a developer's life easier.  For example, want to walk though two lists at the same time?  Python has the zip function to make that simple.

[These examples were tested with Python 3.6 (CPython).]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Travis Risner wrote:Python loop variables (i.e. "x") only need to iterate over something.  They are not restricted to integers as in Java or C#.


They aren't restricted to integers in Java either. For instance:
 
David Clark
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first, I was intrigued by Python, but now I'm not so sure.

I'm primarily interested in graphing parametric equations. I did a program in DOS Basic, where the X coordinate was a parametric equation, say sine, & the Y coordinate was a parametric equation, say cosine. The program plotted both coordinates. It looked right neat. I know that Python has a lot of math & science libraries. That's what initially intrigued me. I also want to do fractals.

The more research I do, the more cryptic I find the syntax.
For example:
the multiple uses of the underscore
comment blocks are so much easier to do in Kotlin

Python doesn't support static typing. I have mixed feelings about dynamic typing. Sometimes it's probably helpful to use dynamic typing.
Python doesn't have a Boolean variable type.

I want to learn Jython. I know that Jython/Python syntax is identical. But I have to have BOTH Jython AND Python installed. There are different versions of both. There would probably be conflicts between the 2.
I read about Python virtual environments. I don't completely understand them. I also read about pip.

At this point, I'm leaning more towards learning Kotlin over Python.

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Clark wrote:Python doesn't have a Boolean variable type.


That's new to me. Support for boolean types has been added way back in Python 2.3.
 
Travis Risner
Ranch Hand
Posts: 44
1
Python VI Editor Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rob for the correction.  In the future I will verify my comments about Java since it has been several years since I wrote any Java code.

David, perhaps it would be best for you to concentrate on Kotlin.  In my five minutes of reviewing the documentation, it seems a bit more like Java - especially the static typing.

I agree that Jython and Python (a.k.a CPython) are currently significantly different in that Jython is base on python 2 syntax at the moment.  Hopefully, the folks working to complete the python 3 implementation for Jython will be done soon.  You may want to revisit python then.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic