We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Most of the common answers for how to detect the host operating system in Python involve using os, platform, or psutil. However in Python mode these don't return win
/mac
/linux
or any variation on that, they only identify the jython Java platform.
import os
print os.name
import platform
print platform.system()
Output:
java
Java
Is there any way to determine what os a Python mode / processing.py sketch is running on?
Answers
Worth to try: https://stackoverflow.com/questions/23372584/jython-how-to-retrieve-the-operating-system-name
Kf
Nice search-foo, @kfrajer. That solved it for me.
Output:
Strange, your post isn't giving me an option of accepting an answer....
Glad to help :)>-
Kf
Just use
this.platform
like I did at: :ar!https://Forum.Processing.org/two/discussion/23471/combining-two-pieces-of-code/p2#Item_87
BASH = this.platform == WINDOWS and 'cmd /C ' or 'bash -c '
Available constants: WINDOWS, LINUX, MACOSX & OTHER. :>
And you can use
this.platform
as the index value for platformNames[]: :)>-Got it. Didn't realize it was all built-in!
And b/c platform is a
static
field, we can also prefix it w/ PApplet instead: ;)https://GitHub.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L136
Although ideally we shouldn't need any prefixes if platform was global like the other PApplet members. 8-|