Python Forum
i woule a way to parse a line python source like split
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i woule a way to parse a line python source like split
#1
i would like to parse a line of python source instead of merely split it:
    line = "blank=' '"
    parts = line.split()
    parts -> ["blank='","'"]
    pieces = ??parse??(line)
    pieces -> ["blank"."=","' '"]
i want to get what pieces ends up with.
"a[0]=int(ab[16])+2" -> ["a","[","0","]","=","int","(","ab","[","16","]",")","+","2"]
i need to parse some python source only one line at a time to make some edits by other scripts, although i am not sure how best to handle continuations. comments should be one big string. if white spaces are always included, that's ok.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
i woule a way to parse a line python source like split - by Skaperen - Nov-11-2018, 03:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 809 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  [split] Parse Nested JSON String in Python mmm07 4 1,674 Mar-28-2023, 06:07 PM
Last Post: snippsat
  python move specific files from source to destination including duplicates mg24 3 1,189 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  Python Snippets Source kucingkembar 0 691 Oct-18-2022, 12:50 AM
Last Post: kucingkembar
  python read iperf log and parse throughput jacklee26 4 2,992 Aug-27-2022, 07:04 AM
Last Post: Yoriz
  How to parse a live feed in Python? Daring_T 2 4,414 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  multi-line CMD in one-line python kucingkembar 5 4,238 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  Long-term stable source to get news headlines with Python? sandufi 4 2,067 Dec-23-2021, 09:48 AM
Last Post: sandufi
  Navigating cpython source using python quazirfan 3 2,115 Aug-09-2021, 07:52 PM
Last Post: quazirfan
  Using lambdas and map() to parse substrings in a single line Drone4four 5 3,203 Sep-20-2020, 10:38 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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