Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help parsing file
#1
I'm looking for general guidance/suggestions on how to extract grid data points from a text file. Lines beginning with "GRID*" have node numbers and x y z coordinate information. I would like to extract that information. Each "GRID" line is segmented into '6' columns. The first and last column are eight characters wide, columns 2,3,4, and 5 are 16 characters wide. An example coordinate would be '-3.69374569427+0'. I would also like to know how to convert that format into a real number. I studied the "strings" documentation but haven't found an answer on my own yet. Any help/suggestions/guidance appreciated.

Thanks!,
Andrew

sample file contents:

Output:
GRID* 1 0-3.69374569427+09.077207667771+0 * 5.000014684254-1 0 GRID* 2 0-3.69374569427+0-9.07720766777+0 * 4.999985315745-1 0 GRID* 3 08.978071514315+03.928573996764+0 * 4.999963281080-1 0 GRID* 4 08.978071514315+0-3.92857399676+0 * 5.000036718919-1 0
etc..

PS.
I tried to show the "column widths" in the sample file contents but the forum post removes the white space. The coordinate information begins in column 4 and continues on the next line. For anyone curious, this is from a NASTRAN input file
Reply


Messages In This Thread
help parsing file - by aslezak - Oct-18-2019, 06:04 PM
RE: help parsing file - by buran - Oct-18-2019, 06:11 PM
RE: help parsing file - by aslezak - Oct-22-2019, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,892 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,679 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Parsing xml file deletes whitespaces. How to avoid it? Paqqno 0 1,043 Apr-01-2022, 10:20 PM
Last Post: Paqqno
  Parsing a syslog file ebolisa 11 4,146 Oct-10-2021, 05:15 PM
Last Post: snippsat
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 2,280 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B
  File Name Parsing millpond 5 3,621 Aug-26-2020, 08:04 AM
Last Post: bowlofred
  Error while parsing tables from docx file aditi 1 3,734 Jul-14-2020, 09:24 PM
Last Post: aditi
  Python Script for parsing dictionary values from yaml file pawan6782 3 4,962 Sep-04-2019, 07:21 PM
Last Post: pawan6782
  Parsing an MBOX file Oliver 1 8,198 May-26-2019, 07:12 AM
Last Post: heiner55
  parsing complex text file anna 1 2,078 Apr-10-2019, 09:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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