遇到运算量大的程序,学习了下python并行运算的方法,在自己的程序上进行了修改,看看是否可以增加效率.原始代码是: import gt_apps as my_apps f=file('sample.txt','r') for i in range(1,114): print i line=f.readline() source=line.rstrip() print source.split(' ') name = source.split(' ')[0] ra = source.split(
一.引用 使用到的全局变量只是作为引用,不在函数中修改它的值的话,不需要加global关键字.如: #! /usr/bin/python a = 1 b = [2, 3] def func(): if a == 1: print("a: %d" %a) for i in range(4): if i in b: print("%d in list b" %i) else: print("%d not in list b" %i) if __nam
1.文件操作(2) 代码 f = open('a.txt','a') # "a" 如果源文件不在,会自动创建 f.write('abc') result = f.read() print(result) f.close() # r read 能读,不能写,打开不存在的文件会报错 # w write 能写,不能读 # a add 能写,不会清空以前的内容,不能读
先学习之前未完成的冒泡算法 li = [13,22,6,99,11] 从小到大 从第一个数字比较把大的往后移位 for m in range(4): num1 = li[m] num2 = li[m+1] if num1 > num2: temp = li[m] li[m] = num2 li[m+1] = temp print li 循环四次就把最大数放到列表的最后 for m in range(3): num1 = li[m] num2 = li[m+1] if num1 > num2:
使用示例1.创建用户>>> from django.contrib.auth.models import User>>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')# At this point, user is a User object that has already been saved# to the database. You can con