Python Forum
Python for syntax conversion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python for syntax conversion
#21
kingsman Wrote:Is this also be okay?
I cannot tell you if it's ok. You need to compare the data that you extracted from the file to the data that's in the file to see if it's OK. The problem I see is that your code seems to be extracting only a part of the data and not all the lines from all the tables as I did above.
Reply
#22
(Dec-27-2019, 04:18 PM)Gribouillis Wrote:
kingsman Wrote:Is this also be okay?
I cannot tell you if it's ok. You need to compare the data that you extracted from the file to the data that's in the file to see if it's OK. The problem I see is that your code seems to be extracting only a part of the data and not all the lines from all the tables as I did above.
Maybe I would repeat the step to obtain all the information. Give me some time to complete it Dance
Reply
#23
(Dec-27-2019, 03:49 PM)kingsman Wrote:
(Dec-27-2019, 02:15 PM)Gribouillis Wrote:
I have done something similar to yours and extract the information as you said before. Is this also be okay?
import re
SAP = open('Frame SAP.$2k', 'r')

class Statement:
    def __init__(self, data):
        self.data = data
    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, self.data)

class SAP_Material_01 (Statement):
    pass

parsed_file = []
material_data_01 = []

for line in SAP:
    e = re.compile(r'\s{3}Material=\w+\s{3}Type=\w+\s{3}')
    d = re.match(e, line)
    if d != None:
        parsed_file.append(line)

for line in parsed_file:
    L = re.split(r'(\w+)[=]', line.strip())
    assert L[0] == ''
    pairs = {}
    for i in range(1, len(L), 2):
        pairs[L[i]] = L[i + 1].strip()
    item = SAP_Material_01(pairs)
    material_data_01.append(item)

for item in material_data_01:
    print(item)
Output:
SAP_Material_01({'Material': '4000Psi', 'Type': 'Concrete', 'SymType': 'Isotropic', 'TempDepend': 'No', 'Color': 'Magenta', 'Notes': '"Customary f\'c 4000 psi 23/12/2019 2:17:43 pm"'}) SAP_Material_01({'Material': 'A615Gr60', 'Type': 'Rebar', 'SymType': 'Uniaxial', 'TempDepend': 'No', 'Color': 'White', 'Notes': '"ASTM A615 Grade 60 23/12/2019 2:18:28 pm"'}) SAP_Material_01({'Material': 'A992Fy50', 'Type': 'Steel', 'SymType': 'Isotropic', 'TempDepend': 'No', 'Color': 'Red', 'Notes': '"ASTM A992 Grade 50 23/12/2019 2:17:43 pm"'}) SAP_Material_01({'Material': 'C30', 'Type': 'Concrete', 'SymType': 'Isotropic', 'TempDepend': 'No', 'Color': 'Blue', 'Notes': '"Concrete added 23/12/2019 2:18:37 pm"'}) SAP_Material_01({'Material': 'C45', 'Type': 'Concrete', 'SymType': 'Isotropic', 'TempDepend': 'No', 'Color': 'Blue', 'Notes': '"Concrete added 23/12/2019 2:20:37 pm"'}) SAP_Material_01({'Material': 'C60', 'Type': 'Concrete', 'SymType': 'Isotropic', 'TempDepend': 'No', 'Color': 'Blue', 'Notes': '"Concrete added 23/12/2019 2:21:13 pm"'})

But how can I extract the information singly such as on C60, blue or isotropic? The output above shows that the information of that part has been totally extracted out and saved in a list. But when I re-write it, I need the information one by one.
Reply
#24
(Dec-27-2019, 04:18 PM)Gribouillis Wrote:
kingsman Wrote:Is this also be okay?
I cannot tell you if it's ok. You need to compare the data that you extracted from the file to the data that's in the file to see if it's OK. The problem I see is that your code seems to be extracting only a part of the data and not all the lines from all the tables as I did above.

I have extracted all the data, but I can't singly use them.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python format conversion bluefrog 2 2,682 Jul-22-2018, 03:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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