[英]How to distinguish “Android” from other “Linux” operating systems in Python?
I'm running a Python script on my phone through QPython. 我正通过QPython在手机上运行Python脚本。 The title pretty much explains the question.
标题几乎解释了这个问题。 I basically need to check if the script is running on an android device.
我基本上需要检查脚本是否在Android设备上运行。 I've tried
os.name
, sys.platform
and platform.system()
but those just return various kinds of "Linux" or "Posix", which is not specific enough (as far as I know - maybe I am missing some relevant information here). 我已经尝试过
os.name
, sys.platform
和platform.system()
但是那些只返回各种“Linux”或“Posix”,这些不够具体(据我所知 - 也许我错过了一些相关的这里的信息)。
I considered trying to import the android
module, and then use the success or failure of this to determine if the OS is Android. 我考虑过尝试导入
android
模块,然后使用它的成功或失败来确定操作系统是否是Android。 I don't really need the android
module though, so this seems a bit excessive. 我不是真的需要
android
模块,所以这似乎有点过分。
You can check for 'ANDROID_STORAGE'
in environ: 您可以在environ中检查
'ANDROID_STORAGE'
:
>>> from os import environ
>>> is_android = 'ANDROID_STORAGE' in environ
>>> is_android
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.