Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92937 > unrolled thread

How to check in script if Python or Jython is used

Started byCecil Westerhof <Cecil@decebal.nl>
First post2015-06-21 10:12 +0200
Last post2015-06-22 12:39 -0700
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  How to check in script if Python or Jython is used Cecil Westerhof <Cecil@decebal.nl> - 2015-06-21 10:12 +0200
    Re: How to check in script if Python or Jython is used Laura Creighton <lac@openend.se> - 2015-06-21 11:22 +0200
      Re: How to check in script if Python or Jython is used Cecil Westerhof <Cecil@decebal.nl> - 2015-06-21 12:24 +0200
    Re: How to check in script if Python or Jython is used Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-21 18:12 +0200
    Re: How to check in script if Python or Jython is used Dan Stromberg <drsalists@gmail.com> - 2015-06-22 12:39 -0700

#92937 — How to check in script if Python or Jython is used

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-06-21 10:12 +0200
SubjectHow to check in script if Python or Jython is used
Message-ID<87r3p5pjjd.fsf@Equus.decebal.nl>
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

[toc] | [next] | [standalone]


#92945

FromLaura Creighton <lac@openend.se>
Date2015-06-21 11:22 +0200
Message-ID<mailman.673.1434878583.13271.python-list@python.org>
In reply to#92937
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

[toc] | [prev] | [next] | [standalone]


#92951

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-06-21 12:24 +0200
Message-ID<87d20p8im6.fsf@Equus.decebal.nl>
In reply to#92945
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

[toc] | [prev] | [next] | [standalone]


#92968

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-21 18:12 +0200
Message-ID<2671202.GDDaZ1Saa3@PointedEars.de>
In reply to#92937
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.

[toc] | [prev] | [next] | [standalone]


#93016

FromDan Stromberg <drsalists@gmail.com>
Date2015-06-22 12:39 -0700
Message-ID<mailman.711.1435001958.13271.python-list@python.org>
In reply to#92937
IMO, it's usually better to test for features and use them if they are
present, than to build a list of features available in specific
interpreters.

I see it as analogous to the difference between huge C #ifdef's on OS,
and autoconf.

On Sun, Jun 21, 2015 at 1:12 AM, Cecil Westerhof <Cecil@decebal.nl> 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.
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
> --
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web