Python Forum
Is there a better way? Python parsing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a better way? Python parsing
#2
Why not just keep the minus symbol with your number? Then, I think you don't care if it's positive or negative, you just print it.

res = r'X(-?\d+\.\d*)
>>> re.search(r'X(-?\d+\.\d*)', "Z1.371 Y-1.279 X-0.0003").groups()[0]
'-0.0003'
>>> re.search(r'X(-?\d+\.\d*)', "Z1.371 Y-1.279 X0.0003").groups()[0]
'0.0003'
tlewick1 likes this post
Reply


Messages In This Thread
Is there a better way? Python parsing - by tlewick1 - Oct-17-2020, 04:40 PM
RE: Is there a better way? Python parsing - by bowlofred - Oct-17-2020, 05:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Parsing link from html tags with Python Melcu54 0 1,674 Jun-14-2021, 09:25 AM
Last Post: Melcu54
  XML Parsing in python aarushprathap 2 2,403 Jul-11-2020, 09:29 AM
Last Post: j.crater
  python realtime parsing logs anna 2 3,041 Jul-05-2020, 06:36 AM
Last Post: anna
  Parsing Text file having repeated value key pair using python manussnair 3 3,433 Aug-04-2018, 11:48 PM
Last Post: micseydel
  Python file parsing, can't catch strings in new line Philia 5 4,220 Apr-29-2018, 01:09 PM
Last Post: snippsat
  Parsing csv using python Firstname_Lastname 4 4,095 Sep-03-2017, 06:26 PM
Last Post: Larz60+
  Text file parsing with python and with a list in grammar pitanga 2 3,371 Aug-31-2017, 02:21 PM
Last Post: pitanga

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020