Question: import csv import re # Define the input and output file names and paths baselight _ file = / Users / alex / Documents
import csv
import re
# Define the input and output file names and paths
baselightfile UsersalexDocumentspythonProjectsBaselightexport.txt
xytechfile UsersalexDocumentspythonProjectsXytechtxt
outputfile "Output.csv
# Define the field names for the CSV file
fieldnames Producer "Operator", "Job", "Notes", "Location", "Frames"
# Define a function to parse the data from the text files using regular expressions
def parsedatabaselightfile, xytechfile:
# Create an empty list to store the data
data
# Open the baselight file and read the lines
with openbaselightfile as f:
lines freadlines
# Loop through the lines and extract the location and frames
for line in lines:
# Skip the empty lines
if line.strip:
# Use regular expressions to match the location and frames
match researchrds line
if match:
# Get the location and frames from the match object
location match.group
frames match.group
# Append the location and frames to the data list
data.appendNone None, None, None, location, frames
# Open the xytech file and read the lines
with openxytechfile as f:
lines freadlines
# Initialize variables to store Xytech data
producer None
operator None
job None
notes None
location None
frames None
# Loop through the lines and extract the producer, operator, job, notes, and location
for line in lines:
# Skip the empty lines
if line.strip:
# Use regular expressions to match the producer, operator, job, notes, and location
match researchrw:s line
if match:
# Get the key and value from the match object
key match.group
value match.group
# Assign values to corresponding variables
if key "Producer":
producer value
elif key "Operator":
operator value
elif key "Job":
job value
elif key "Notes":
notes value
elif key "Location":
location value
# If all required fields are populated, append the data to the list
if producer and operator and job and notes and location and frames:
data:producer operator, job, notes
# Reset variables for next entry
producer None
operator None
job None
notes None
location None
frames None
# Return the data list
return data
# Define a function to export the data to a CSV file using csv module
def exportdatadata outputfile, fieldnames:
# Open the output file in write mode
with openoutputfile, w newline as f:
# Create a csv writer object
writer csvwriterf
# Write the field names as the header row
writer.writerowfieldnames
# Write the data rows
writer.writerowsdata
# Call the functions and write the output to the CSV file
data parsedatabaselightfile, xytechfile
exportdatadata outputfile, fieldnames it works but its not showing anything other than Producer Operator Job Notes Location Frames
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
