如何在特定字符处拆分Python中的值? [英] How to split values in Python at specific character?
本文介绍了如何在特定字符处拆分Python中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从串口读取值,我需要在特定字符上设置换行符。怎么做到这一点。
我尝试过的事情:
我尝试用时间戳显示终端中的数据。我需要将数据拆分为下一行,依此类推一组特定字符。
解决方案
4。内置类型 - Python 3.6.3文档 [ ^ ]
如果特定字符是常量,您可以将数据保存到字符串中并使用拆分
方法,将此字符指定为分隔符。
例如:
>> data = FF43 // A64B // FFFF
>> split_data = list(data.split( //))
>> [< span class =code-string>' FF43',' A648',' FFFF']
Hi,
I am reading values from serial port, i need to put a line break on a specific character. How to achieve this.
What I have tried:
I have tried in displaying the data in terminal with timestamp. I need to split the data to next line and so on a specific set of character.
解决方案
4. Built-in Types — Python 3.6.3 documentation[^]
If the specific character is constant, you could save the data into a string and use thesplit
method by specifying this character as the delimiter.
For example:
>>data = "FF43//A64B//FFFF" >>split_data = list(data.split("//")) >>['FF43','A648','FFFF']
这篇关于如何在特定字符处拆分Python中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文