PythonL: invalid syntax file “”, line 1

后端 未结 5 2027
太阳男子
太阳男子 2021-02-18 22:14

When doing python3 Webhook.py (this is the file), it gives me the error: File \"\", line 1 (%X - %x) ^ SyntaxError: invalid syntax

相关标签:
5条回答
  • 2021-02-18 22:31

    This happens when anything inside {} is not valid, in a string formatted using the f string formatting prefix. Python 3.7 in my case. The upside is you get the string causing the problem on the error message. You don't get the line number, but it's still easy to figure out once you acknowledge that line number 1 is not the correct line number of the error.

    0 讨论(0)
  • 2021-02-18 22:40

    for my code. the problem was

    I was printing {=*10} instead the right form {"="*10} that mistake generated my problem

    0 讨论(0)
  • 2021-02-18 22:41

    I pass the string in the like print(f"The length of the set is {len(s) elements}")

    So I just move my string out of and problem solved. print(f"The length of the set is {len(s)} elements")

    0 讨论(0)
  • 2021-02-18 22:45

    I just spent 1 hour reviewing my code with the same issue. In my case I started removing parts of the code to narrow down the problem.

    Finally I to the root cause of the problem.

    in my case I was printing an f"string" and inside the f string I had a space in the name of the variable I was calling example print(f"This is a statement {Var 23} "

    That space, generated my problem.

    I hope this helps :)

    0 讨论(0)
  • 2021-02-18 22:48

    it might also be that you have a python 3.8 compatible way of string formating, such as:

    f"print{count=}"
    

    which is not compatible with 3.6, 3.7.

    In that case, you can either decide to require the user to upgrade to python3.8, or downgrade your code.

    0 讨论(0)
提交回复
热议问题