垃圾代码

 tips: 和上次有关的程序 需要状态机

round()  ##四舍五入 
abs()    ##绝对值
string.rstrip()    ##除去字符串最后的空格和回车
chr(97)            ##返回asiic码对应的字符串

将(-67,80)对应到(-11,11)

blast = 1000
deta = 100.0
bnow= 1000
i=-100
for a in range(-67,80):
    b=a*11./67+23
    bnow=round(b)
    if(bnow== blast):
        pdeta=abs(bnow-b)
        if pdeta <deta:
            deta =pdeta
            i=a
            blast=bnow
    else:
        print i,blast
        deta=1
        blast=bnow

 处理 文献题录,以后可以加个GUI

import string
fi=open('1.ris','r')
fo=open('out.txt','w')
for line in fi.xreadlines():
	aa=line.split('  - ')
	print aa[0]
	if aa[0] == 'A1' :
		fo.write(aa[0])
		fo.write('  - ')
		fo.write(string.capwords(aa[1])+'\n')
	else:
		fo.write(line)
fi.close()
fo.close() 

 串口操作

import serial
ser = serial.Serial(1)   #COM2 look up 设备管理器
ser.write()      # write a string
s = ser.read(100)       # read up to one hundred bytes
ser.close()             # close port


import serial
ser = serial.Serial(0)  # open first serial port
ser = serial.Serial(1,
                    38400,
                    timeout=0,
                    parity=serial.PARITY_EVEN,
                    rtscts=1
)
print ser.portstr       # check which port was really used
ser.write("hello")      # write a string
s = ser.read(100)       # read up to one hundred bytes
ser.close()             # close port 


 


 

 

你可能感兴趣的:(垃圾代码)