在android上,我们可以使用QPython来编写、执行Python脚本。它对很多android
系统函数进行了方便的封装,使用QPython编写功能简单的小程序异常方便。
这个示例是我之前用来读取手机位置信息并作为进一步处理数据的基础脚本。
# -*- coding: utf-8 -*-
import androidhelper
import time
from math import radians
droid = androidhelper.Android()
droid.startSensingTimed(1, 250)
droid.startLocating()
while 1:
gpsdata = droid.readLocation().result
s6data = droid.sensorsReadOrientation().result
if len(gpsdata)>0:
print gpsdata['gps']['bearing'] #取得Gps导向(bearing)(角度)
if len(s6data)>0:
print s6data[0] #取得罗盘方位角(azimuth)(弧度)
time.sleep(0.5)
droid.stopLocating()
droid.stopSensing()
Python复制目录结构脚本代码分享
引言有个需要,需要把某个目录下的目录结构进行复制,不要文件,当目录结构很少的时候可以手工去建立,当目录结构复杂,目录层次很深,目录很
Python中运行并行任务技巧
示例标准线程多进程,生产者/消费者示例:Worker越多,问题越大#-*-coding:utf8-*-importosimporttimeimportQueueimportthreadingfromPILimportImagedefcreate_thumbnail(filename,size=(12
Python map和reduce函数用法示例
先看map。map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回。举例说明,比如