Syntax error: invalid syntax for initialization component on line 691

Description of the problem:
I am designing a new project using psychopy, using builder mode with some personalized code. When I try to run the experiment, it will not let me input the participants number because I get a syntax error about 'initializationComponents = 'on line 691 but my personalized code does not include this information. I think it was made by psychopy but I was wondering how I can fix it to make the task run smoothly. I tried asking chatgpt and my lab members but no one can figure out what is causing the invalid syntax.
odor_task_WIP.psyexp (68.3 KB)

The error is probably in this:

import csv

# Assuming csv_file is your CSV file path
csv_file = 'odor_info_.csv'

# Initialize csv_data dictionary to store CSV content
csv_data = {}

    # Open and read the CSV file
    with open(csv_file, 'r') as file:
        reader = csv.DictReader(file)
        # Iterate over each row in the CSV file
        for row in reader:
                # Assuming 'odor_idx' is defined somewhere
                for idx in range(1, 11):  # Range from 1 to 10 (inclusive)
                    if int(row['idx']) == idx:
                        line1 = int(row['line1'])
                        line2 = int(row['line2'])
                        mfc1_intensity = float(row['MFC1_intensity'])
                        mfc2_intensity = float(row['MFC2_intensity'])
                        # Assuming 'odor_labels' is a key in your CSV structure
                        csv_data['odor_labels'] = row['odor_labels']  # Adjust based on your CSV structure
                        break  # Exit the loop once a matching row is found
            except ValueError as e:
                # Handle conversion errors gracefully
                print(f"Error converting values: {e}")
                continue  # Skip to the next row if conversion fails
    # Example: setting text for text_odor_0 (assuming it's a GUI widget)
    # Ensure 'odor_labels' is populated in csv_data before accessing
    if 'odor_labels' in csv_data:
        print("Error: 'odor_labels' key not found in csv_data")

Thank you so much for responding! I tried to change the section of the code and now I am getting an unexpected indentation for the section below for the time.sleep(0.005). I was wondering how I could fix the format for the entire file so I don’t keep getting repeated errors.

What I do is use Auto code components whenever possible so the transpiler spots my syntax errors. However, some of the code you are using might not translate.

1 Like