Quantcast

How to check in script if Python or Jython is used

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to check in script if Python or Jython is used

Cecil Westerhof
I installed Jython and will start playing with it. There probably will
be differences between Python and Jython. Is there a way to determine
if a script is run by Python or Jython? Then different execution paths
could be taken. With sys.version(_info) you do not get this
information.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to check in script if Python or Jython is used

Laura Creighton-2
In a message of Sun, 21 Jun 2015 10:12:06 +0200, Cecil Westerhof writes:

>I installed Jython and will start playing with it. There probably will
>be differences between Python and Jython. Is there a way to determine
>if a script is run by Python or Jython? Then different execution paths
>could be taken. With sys.version(_info) you do not get this
>information.
>
>--
>Cecil Westerhof
>Senior Software Engineer
>LinkedIn: http://www.linkedin.com/in/cecilwesterhof
>--
>https://mail.python.org/mailman/listinfo/python-list

import platform
platform.python_implementation()

If your jython is old (pre 2.6) you will not have this.

Then try
platform.system()
which will give you 'Java'

Laura



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to check in script if Python or Jython is used

Cecil Westerhof
In reply to this post by Cecil Westerhof
On Sunday 21 Jun 2015 11:22 CEST, Laura Creighton wrote:

> In a message of Sun, 21 Jun 2015 10:12:06 +0200, Cecil Westerhof
> writes:
>> I installed Jython and will start playing with it. There probably
>> will be differences between Python and Jython. Is there a way to
>> determine if a script is run by Python or Jython? Then different
>> execution paths could be taken. With sys.version(_info) you do not
>> get this information.
>>
>> --
>> Cecil Westerhof
>> Senior Software Engineer
>> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
> import platform
> platform.python_implementation()
>
> If your jython is old (pre 2.6) you will not have this.
>
> Then try
> platform.system()
> which will give you 'Java'

Works like a charm. CPython gives (on my system) 'Linux'. But as long
I only work with CPython and Jython, I only have to check for 'Java'.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to check in script if Python or Jython is used

Thomas 'PointedEars' Lahn
In reply to this post by Cecil Westerhof
Cecil Westerhof wrote:

> I installed Jython and will start playing with it. There probably will
> be differences between Python and Jython. Is there a way to determine
> if a script is run by Python or Jython? Then different execution paths
> could be taken. With sys.version(_info) you do not get this
> information.

?print sys.__doc__? in (C)python(2) hinted at ?sys.platform?.  And so:

$ python -V
Python 2.7.10

$ python -c 'from sys import platform; print platform'
linux2

$ python3 -V
Python 3.4.3+

$ python3 -c 'from sys import platform; print(platform)'
linux

$ jython -V
"my" variable $jythonHome masks earlier declaration in same scope at
/usr/bin/jython line 15.
Jython 2.5.3

$ jython -c 'from sys import platform; print platform'
"my" variable $jythonHome masks earlier declaration in same scope at
/usr/bin/jython line 15.
java1.7.0_79

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Loading...