Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在osx上使用python打开/关闭wifi_Python_Macos_Python 2.7_Phantomjs_Wifi - Fatal编程技术网

在osx上使用python打开/关闭wifi

在osx上使用python打开/关闭wifi,python,macos,python-2.7,phantomjs,wifi,Python,Macos,Python 2.7,Phantomjs,Wifi,这可能是因为我的ISP提供商,有时当我不在时,互联网关闭,直到我重新启动wifi连接才工作。因此,我的脚本开始引发超时异常,直到我关闭然后打开wifi连接。在osx el capitan上使用python 2.7自动打开/关闭wifi有没有一种有效的方法 解决方案: 无需使用任何复杂模块或子流程模块即可轻松高效地完成此任务: 多亏了黑客狂 给你: >>> import subprocess >>> child = subprocess.Popen(["netw

这可能是因为我的ISP提供商,有时当我不在时,互联网关闭,直到我重新启动wifi连接才工作。因此,我的脚本开始引发超时异常,直到我关闭然后打开wifi连接。在osx el capitan上使用python 2.7自动打开/关闭wifi有没有一种有效的方法

解决方案:

无需使用任何复杂模块或子流程模块即可轻松高效地完成此任务:

多亏了黑客狂

给你:

>>> import subprocess
>>> child = subprocess.Popen(["networksetup", "-setairportpower", "airport", "off"], stdout=subprocess.PIPE)
>>> output, error = child.communicate()
>>> print output
airport is not a Wi-Fi interface.
Turning off the only airport interface found: en1

小谷歌可以帮上忙:使用子流程模块来执行威尔,在我确定并看到那个页面之前,我已经用谷歌搜索过了。但是我不知道子流程模块以及如何使用它。我想医生会有帮助的,谢谢。请不要在问题中包含解决方案。你应该自己发布一个问题的答案,然后返回到没有答案的问题的早期版本。
>>> import subprocess
>>> child = subprocess.Popen(["networksetup", "-setairportpower", "airport", "off"], stdout=subprocess.PIPE)
>>> output, error = child.communicate()
>>> print output
airport is not a Wi-Fi interface.
Turning off the only airport interface found: en1