请教各位牛人,android能js调用python脚本本吗

iOS 或android能直接运行py脚本吗(里面import了urllib2,cookielib,re) - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
已注册用户请 &
推荐学习书目
Python Sites
值得关注的项目
Python 编程
iOS 或android能直接运行py脚本吗(里面import了urllib2,cookielib,re)
18:01:57 +08:00 · 2610 次点击
有个简单的爬虫脚本,检查网页更新的,返回信息很简单,命令行显示都可以,iOS或者android下面能直接运行吗,要能行的话就太方便了,脚本就随时可用了
10 回复 &| &直到
08:00:00 +08:00
& & 18:13:48 +08:00
iOS下面看到有个python 2.7 for iOS,没有买不知道能行不
& & 18:17:42 +08:00
android上可以跑python啊,装个SL4A就行了
& & 18:20:49 +08:00
@ 请问能import这些模块吗?之前我试了下import有报错
& & 18:32:16 +08:00
没试过,可以研究下
& & 18:38:33 +08:00
@ goagent android版用到了这些模块吧
& & 18:41:43 +08:00
@ 可以,有报错的话,拿着错误去google上搜
& & 20:50:53 +08:00
越狱之后,装python就可以,最好用服务器端做,ios下面展示数据即可
& & 08:44:47 +08:00
越狱后装python肯定可以;python for iOS非so的库一般没问题,而且最近的一次更新已经宣布支持so了。。
& & 09:34:48 +08:00
理论上说Android应该能跑Jython
& & 09:58:01 +08:00
@ 果然,已购买,很好用,感谢
& · & 1649 人在线 & 最高记录 1893 & · &
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.7.3 · 47ms · UTC 05:33 · PVG 13:33 · LAX 22:33 · JFK 01:33? Do have faith in what you're doing.求教下android技术大牛 脚本语言的选择-中国学网-中国IT综合门户网站-提供健康,养生,留学,移民,创业,汽车等信息
> 信息中心 >
求教下android技术大牛 脚本语言的选择
来源:互联网 发表时间: 13:37:04 责任编辑:李志喜字体:
为了帮助网友解决“求教下android技术大牛 脚本语言的选择”相关的问题,中国学网通过互联网对“求教下android技术大牛 脚本语言的选择”相关的解决方案进行了整理,用户详细问题包括:RT,我想知道:求教下android技术大牛 脚本语言的选择,具体解决方案如下:解决方案1:
Python,JavaScript都熟悉一下,Lua,爱上工作其实没多少意义,不爱编程工作的人也不会因为一个语言多好用而爱上这份工作,自己又不是老板肯定选Python
1个回答1个回答1个回答2个回答1个回答1个回答2个回答1个回答4个回答1个回答1个回答1个回答1个回答1个回答1个回答1个回答1个回答1个回答1个回答
相关文章:
最新添加资讯
24小时热门资讯
Copyright © 2004- All Rights Reserved. 中国学网 版权所有
京ICP备号-1 京公网安备02号请教各位牛人,android能调用python脚本吗_百度知道
请教各位牛人,android能调用python脚本吗
提问者采纳
可以的哦,不过要安装插件 PythonForAndroid以便于提供了在android平台上对python语言的支持
其他类似问题
为您推荐:
python的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁使用python编写android截屏脚本双击运行即可
投稿:whsnow
字体:[ ] 类型:转载 时间:
使用python编写一个截屏的脚本,双击运行脚本就OK,截屏成功后会将截屏文件已当前时间命名,并保存在存放脚本的当前路径的screenshot文件夹下
测试的过程中经常需要截取屏幕,通常的做法是使用手机自带的截屏功能,然后将截屏文件复制出来,这种方法的优点是不需要连接数据线就可截屏,缺点则是生成的截屏文件命名是随机命名的,复制出来也比较麻烦。另一种方法是使用PC端的手机助手类软件。
这里使用python编写一个截屏的脚本,双击运行脚本就OK,截屏成功后会将截屏文件已当前时间命名,并保存在存放脚本的当前路径的screenshot文件夹下:
#!/usr/bin/env python
import time
PATH = lambda p: os.path.abspath(p)
def screenshot():
path = PATH(os.getcwd() + "/screenshot")
timestamp = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
os.popen("adb wait-for-device")
os.popen("adb shell screencap -p /data/local/tmp/tmp.png")
if not os.path.isdir(PATH(os.getcwd() + "/screenshot")):
os.makedirs(path)
os.popen("adb pull /data/local/tmp/tmp.png " + PATH(path + "/" + timestamp + ".png"))
os.popen("adb shell rm /data/local/tmp/tmp.png")
print "success"
if __name__ == "__main__":
screenshot()
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具下载Android源码时Python脚本的修改 - 推酷
下载Android源码时Python脚本的修改
在下载Android源码时,由于本机的Python版本和Android所要求的不一致,所以要重装Python。本文是在Python 3.x的情况下,对repo代码进行修改的一种尝试。通过这个尝试,结论是需要2.x版本的Python环境,而不能使用3.x。
下载Android源码的方法:/source/downloading.html#installing-repo
但在实际下载时,下载repo这一步可能会有问题。因此参考http://blog.csdn.net/zeroboundary/article/details/的blog,使用了下面的地址:
curl http://git-/files/repo-1.12 > ~/bin/repo
在下载了这个repo之后,init repo的时候会报错:
% repo init -u /platform/manifest
File "/home/test//bin/repo", line 174
except OSError, e:
SyntaxError: invalid syntax
查阅网上的分析,结论是Python版本的问题。本机的Python版本如下:
% python --version
Python 3.2.3
即版本太高了,导致repo文件中的Python语法在最新版本上通不过。为此,需要修改repo文件中捕获异常的代码。如:
if not os.path.isdir(repodir):
os.mkdir(repodir)
except OSError, e:
print >>sys.stderr, \
需要改成:
if not os.path.isdir(repodir):
os.mkdir(repodir)
except OSError as e:
print >>sys.stderr, \
repo脚本中有多处这种不兼容,需要一一修改。
以上错误修改之后,继续repo init,又出现下面的错误:
% repo init -u /platform/manifest
File "/home/test//bin/repo", line 259
os.mkdir(gpg_dir, 0700)
SyntaxError: invalid token
这同样是Python版本兼容问题,具体来讲,是Python对八进制数的表示方法有了变化。之前只需要一个0,现在则是数字0加上字母o。错误的表示方法:
Python 3.2.3 (default, Sep
[GCC 4.7.1
(prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.mkdir("aaa", 0700)
File "", line 1
os.mkdir("aaa", 0700)
SyntaxError: invalid token
>>> os.mkdir("aaa")
>>> exit()
drwxr-xr-x 2 test users 4096
1 13:00 aaa/
3.2版本所支持的语法:
Python 3.2.3 (default, Sep
[GCC 4.7.1
(prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.mkdir("bbb", 0o700)
>>> exit()
test@zhanghui-host /home/test/Android % ll
drwxr-xr-x 2 test users 4096
1 13:00 aaa/
drwx------ 2 test users 4096
1 13:10 bbb/
test@zhanghui-host /home/test/Android %
据此,再把repo中的八进制数字进行修改。
然后继续repo init,又有新的错误:
% repo init -u /platform/manifest
Traceback (most recent call last):
File "/home/test//bin/repo", line 602, in
main(sys.argv[1:])
File "/home/test//bin/repo", line 553, in main
cmd, opt, args = _ParseArguments(orig_args)
File "/home/test//bin/repo", line 458, in _ParseArguments
for i in xrange(0, len(args)):
NameError: global name 'xrange' is not defined
这是因为在Python 3.x中,xrange重命名成了range。
继续repo init,新的错误:
% repo init -u /platform/manifest
Traceback (most recent call last):
File "/home/test//bin/repo", line 602, in
main(sys.argv[1:])
File "/home/test//bin/repo", line 569, in main
_Init(args)
File "/home/test//bin/repo", line 183, in _Init
_CheckGitVersion()
File "/home/test//bin/repo", line 217, in _CheckGitVersion
if not ver_str.startswith('git version '):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
相关的repo代码:
def _CheckGitVersion():
cmd = [GIT, '--version']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
ver_str = proc.stdout.read().strip()
proc.stdout.close()
proc.wait()
if not ver_str.startswith('git version '):
print >>sys.stderr, 'error: "%s" unsupported' % ver_str
raise CloneFailure()
这是因为Python 3.x中字符串和二进制串有了区分,为此把bytes转化成string即可:
ver_str = ver_str.decode()
继续repo init,新的错误:
% repo init -u /platform/manifest
Traceback (most recent call last):
File "/home/test//bin/repo", line 603, in
main(sys.argv[1:])
File "/home/test//bin/repo", line 570, in main
_Init(args)
File "/home/test//bin/repo", line 186, in _Init
can_verify = _SetupGnuPG(opt.quiet)
File "/home/test//bin/repo", line 282, in _SetupGnuPG
proc.stdin.write(MAINTAINER_KEYS)
TypeError: 'str' does not support the buffer interface
编码问题,修改如下:
proc.stdin.write(MAINTAINER_KEYS.encode())
继续repo init:
% repo init -u /platform/manifest
gpg: /home/test/.repoconfig/gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 920F5C65:公钥“Repo Maintainer ”已导入
gpg: 合计被处理的数量:1
Traceback (most recent call last):
File "/home/test//bin/repo", line 603, in
main(sys.argv[1:])
File "/home/test//bin/repo", line 570, in main
_Init(args)
File "/home/test//bin/repo", line 191, in _Init
print >>sys.stderr, 'Getting repo ...'
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'
这是print语法变更,把:
if not opt.quiet:
print >>sys.stderr, 'Getting repo ...'
print >>sys.stderr, '
from %s' % url
if not opt.quiet:
print('Getting repo ...', file=sys.stderr)
from %s' % url, file=sys.stderr)
因为repo中有大量的print,因此需要逐一修改完成。继续:
Traceback (most recent call last):
File "/home/test//bin/repo", line 594, in
main(sys.argv[1:])
File "/home/test//bin/repo", line 561, in main
_Init(args)
File "/home/test//bin/repo", line 197, in _Init
rev = _Verify(dst, branch, opt.quiet)
File "/home/test//bin/repo", line 370, in _Verify
m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
TypeError: can't use a string pattern on a bytes-like object
对应的代码:
cur = proc.stdout.read().strip()
proc.stdout.close()
proc.stderr.read()
proc.stderr.close()
if proc.wait() != 0 or not cur:
print("", file=sys.stderr)
print("fatal: branch '%s' has not been signed" \
% branch, file=sys.stderr)
raise CloneFailure()
m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
同样是前面提过的bytes和string的关系,修改如下:
cur = proc.stdout.read().strip().decode()
同时走读所有代码,把所有这种出来都增加decode()。——一共3个地方,同时前面提及的那个修改也按照这里的方法进行修改,即:
def _CheckGitVersion():
cmd = [GIT, '--version']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
ver_str = proc.stdout.read().strip().decode()
proc.stdout.close()
proc.wait()
if not ver_str.startswith('git version '):
继续repo init,错误:
File "/home/test/Android/.repo/repo/main.py", line 285
SyntaxError: invalid syntax
现在的错误就不是repo文件了,而是已经下载的文件中的其他错误。然后在文件管理器中查看python文件,发现接下来需要修改的地方很多:
时已至此,只能选择安装一个老版本的Python,比如网上大家建议的2.7。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
没有分页内容
图片无法显示
视频无法显示
与原文不一致}

我要回帖

更多关于 hive调用python脚本 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信