- 浏览: 19656 次
- 性别:
- 来自: 北京
最新评论
文章列表
python--range()函数
- 博客分类:
- python
>>> range(1,5) #代表从1到5(不包含5)
[1, 2, 3, 4]
>>> range(1,5,2) #代表从1到5,间隔2(不包含5)
[1, 3]
>>> range(5) #代表从0到5(不包含5)
[0
python--文件操作/异常捕获/继承
- 博客分类:
- python
一、文件操作
spath="D:/test/baa.txt" #设置spath值为路径f=open(spath,"w") #以写的权限打开文件夹,此时baa.txt不存在。f.write("First line 1.\n")#写入First line 1 回车f.writelines("First line 2.")+#向此前已打开的文本文件尾追加一行数据.
f.close()#关闭文件操作
f=open(spath,"r") # 以读权限打开文件
for line in f: ...
python--python文件互相引用
- 博客分类:
- python
每一个.py文件称为一个module,module之间可以互相导入.请参看以下例子:# a.pydef add_func(a,b): return a+b
# b.pyfrom a import add_func # Also can be : import a
print "Import add_func from module a"print "Result of 1 plus 2 is: "print add_func(1,2) # If using "import a" , then here should ...
python--如何获取包中.py文件
- 博客分类:
- python
module可以定义在包里面.Python定义包的方式稍微有点古怪,假设我们有一个parent文件夹,该文件夹有一个child子文件夹.child中有一个module a.py . 如何让Python知道这个文件层次结构?很简单,每个目录都放一个名为_init_.py 的文件.该文件内容可以为空.这个层次结构如下所示: parent --__init_.py --child -- __init_.py --a.py
b.py 那么Python如何找到我们定义的module?在标准包sys中,path属性记录了Python的包路径.你可以将之打印出来:
import ...
def sum(a,b): return a+b
func = sumr = func(5,6)print r
# Defines function with default argumentdef add(a,b=2): return a+br=add(1)print rr=add(1,5)print r
运行结果:
11
3
6
python--分支语句&循环语句
- 博客分类:
- python
x=int(raw_input("Please enter an integer:"))if x<0: x=0 print "Negative changed to zero"
elif x==0: print "Zero"
else: print "More"
运行结果:
Please enter an integer:0Zero
a = ['cat', 'window', 'defenestrate']for x in a: print x, le ...
import osprint "Input your Chinese name:"s=raw_input("Press enter to be continued ");print "Your name is : " +s;l=len(s)print "Length of your Chinese name in asc codes is:"+str(l);a=unicode(s,"GBK")l=len(a)print "I'm sorry we should use unicod ...
python-字符串
- 博客分类:
- python
word="abcdefg"a=word[2]print "a is: "+ab=word[1:3]print "b is: "+b # index 1 and 2 elements of word.c=word[:2]print "c is: "+c # index 0 and 1 elements of word.d=word[0:]print "d is: "+d # All elements of word.e=word[:2]+word[2:]print "e is: &q ...
python实现ping命令
- 博客分类:
- python
假设我们有这么一项任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200.
import subprocess
cmd="cmd.exe"begin=101end=200while begin<end:
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) p.s ...
利用Python获取系统当前时间 .
- 博客分类:
- python
取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年到现在时间相隔的时间。你可以试下下面 ...
aapt即Android Asset Packaging Tool.本文小结了一下该工具的用法。 1. aapt l[ist] [-v] [-a] file.{zip,jar,apk} List contents of Zip-compatible archive. 1.1 列出压缩文件目录 aapt l <file_path.apk> 参数: -v:会以table的形式输出目录,table的表目有:Leng ...
clickOnView 点不中的原因可以解决了,如果不想改源码,那么就只能 使用320*480的avd就能点中。 或者修改 AndroidManifest.xml文件 加入<supports-screens android:anyDensity="true"/> 就可以在任一分辨率都可以支持了.
Java代码
manifest.xml文件 加入<supports-screens android:anyDensity="true"/>
manifest.xml文件 加入<support ...
Monkeyrunner的id查找方法
- 博客分类:
- Android
实现方式如下:
Java代码
from com.android.monkeyrunner import MonkeyRunner as MR
from com.android.monkeyrunner import MonkeyDevice as MD
from com.android.monkeyrunner import MonkeyImage as MI
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
device=M ...
用Fiddler模拟低速网络环境
- 博客分类:
- 工具
有时候宽频网路用习惯了…在开发的过程就比较少去考虑最佳化的问题…
但当有人反应说「你的网页好慢」甚至当网路速度慢,会造成你的网页跳出什么啊哩不哒的bug时要如何重现呢?
我们可以用Fiddler 这套强大的Web Debugging 工具…
Fiddler是一个web调试代理。它能够记录所有客户端和服务器间的http请求,允许你监视,设置断点,甚至修改输入输出数 据,fiddler包含了一个强大的基于事件脚本的子系统,并且能够使用.net框架语言扩展。更多详细的信息我们可以在fiddler的官方网站上去了 解,http://www.fiddler2.com/fiddler2/,上面详细介 ...
一.XML的读取.在 NewEdit 中有代码片段的功能,代码片段分为片段的分类和片段的内容。在缺省情况下都是用XML格式保存的。下面我讲述一下,如何使用minidom来读取和保存XML文件。
下面是片段分类的一个示例文件--catalog.xml
<?xml version="1.0" encoding="utf-8"?><catalog> <maxid>4</maxid> <item id="1"> <caption>Py ...