Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Splitting a common deliverative to individual variables. Python

I have written and simple program in python that monitors a COM port and converts the line into a string. I then use decode to Ascii which is working fine. My problem is that I need to split the string into seperate variables.

String:

1,40.20,23.50,NOW()

I would like to split them to to seperate variables like the following example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a    = 1
b    = 40.20
c    = 23.50
d    = NOW()

>Solution :

If you know the number of objects then you can just split on the , and assign the elements:

a, b, c, d = txt.split(',')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading