gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Fix errors and bugs in the given code, without changing its intended functionality. ONLY…
- User
Fix errors and bugs in the given code, without changing its intended functionality. ONLY return the fixed code and nothing else. Enclose the entire code in a single code block.
import os import csv
Replace 'your_directory_path' with the path to your directory containing the jpg files
directory = 'Pematangan'
Open a CSV file for writing
with open('classes.csv', 'w', newline='') as csvfile: fieldnames = ['filename', 'pematangan'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
# Write the header writer.writeheader() # Iterate through files in the directory for filename in os.listdir(directory): if filename.endswith('.jpg' or '.png'): # Write the file name and pematangan value to the CSV writer.writerow({'filename': filename, 'pematangan': 1}) - Assistant
import os import csv # Replace 'your_directory_path' with the path to your directory containing the jpg files directory = 'Pematangan' # Open a CSV file for writing with open('classes.csv', 'w', newline='') as csvfile: fieldnames = ['filename', 'pematangan'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) # Write the header writer.writeheader() # Iterate through files in the directory for filename in os.listdir(directory): if filename.endswith(('.jpg', '.png')): # Write the file name and pematangan value to the CSV writer.writerow({'filename': filename, 'pematangan': 1})