Sunday, December 11, 2022

[FIXED] How can I debug this Python syntax error with f string

Issue

def write_users_group(heading_writer, heading, user_writer, users):

    heading_writer.writerow([f"{heading}", f"{len(users)} users"])
    user_writer.writeheader()
    for user in users:
        user_writer.writerow(user)
    heading_writer.writerow([" "])

Error:

File "/Users/ashirwadniv/Downloads/gitlab/users.py", line 59

heading_writer.writerow([f"{heading}", f"{len(users)} users"])
                                    ^
SyntaxError: invalid syntax

Solution

This syntax is only allowed for Python version 3.6 and above. Check/Upgrade your Python version.

Fyi, there is nothing wrong with your syntax provided the python version supports it.



Answered By - Beast
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.