sass - python删除字符串中指定位置字符
巴扎黑
巴扎黑 2017-04-18 10:15:52
0
1
428

原程序是这样的:
ser = serial.Serial("/dev/ttyAMA0", 9600)
def main():
while True:

获得接收缓冲区字符

count = ser.inWaiting()
if count != 0:

读取内容并回显

count.strip('mp')
recv = ser.read(count)
ser.write(recv)

清空接收缓冲区

ser.flushInput()

必要的软件延时

time.sleep(0.1)
但这样我接收到的字符是obj_Temp:28.41 ref_Temp:39.24

巴扎黑
巴扎黑

reply all(1)
阿神

It looks like you are using a Raspberry Pi to connect the sensor. I don't know what your problem is. Is the final 'obj_Temp:28.41 ref_Temp:39.24' the obtained data result? But do you want to remove this basic string processing from 'obj'?

str = 'hello world'
If you want to remove the first letter 'o' and know it is the 5th character, index=4
1. Use sharding new_str = str[:4]+str[5:] ; # str[0:4] intercept the first to fourth characters
2. Character replacement new_str = str.replace('o','') # Replace 'o' with empty space

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!