0

Background:

I have a string SourceString which is comma separated floating numbers returned by an instrument. Printing it shows this:

"364.3889926095051E-3,15.0529859951886E+3,29.5266606165309E+3,148.7897394963915E+3,1.0681575514441E+6"

Next, in order to extract individual floating numbers, I convert it to a list using this code: Readback_list=SourceString.split(",")

Printing Readback_list displays the resultant list as:

['"364.3889926095051E-3', '15.0529859951886E+3', '29.5266606165309E+3', '148.7897394963915E+3', '1.0681575514441E+6"\n']

Question:

When I print individual elements of this list, I see that the first and last elements have a " in the output shown in attached photo.

  • How to remove the " from these elements?
  • I am unsure why is split() not getting rid of the " by itself.

enter image description here

Sinha
  • 431
  • 1
  • 5
  • 12
  • Use `strip('"')` before splitting – user47 Aug 26 '22 at 18:27
  • `SourceString.strip('"')` makes no change to `SourceString`. I still get the same output: `"364.3889926095051E-3,15.0529859951886E+3,29.5266606165309E+3,148.7897394963915E+3,1.0669996574743E+6"` – Sinha Aug 26 '22 at 18:44
  • `Readback_list = SourceString.strip('"').split(",")` -- didn't work? – user47 Aug 26 '22 at 18:47
  • it works when I added the split. Sorry I misunderstood your initial suggestion. Thanks. – Sinha Aug 26 '22 at 18:57
  • Sorry I spoke too soon, it does strip " from the beginning, but not from the end. With `Readback_list = SourceString.strip('"').split(",")` I see this output: `['15.0529859951886E+3', '29.5266606165309E+3', '148.7897394963915E+3', '1.0675786044592E+6"\n']` – Sinha Aug 26 '22 at 19:11

0 Answers0