Syntaxerror without apparent errors

Asked

Viewed 58 times

0

import sys

entrada = input("DLL Nome: ")
saida = entrada+"_output.txt"

file = bytearray(open(entrada, 'rb').read())

with open(saida, 'w') as output:

    for count, byte in enumerate(file, 1):

        output.write(f'{byte:#0{4}x},' + ('\n' if not count % 16 else ' '))

My mistake is:

output.write(f'{byte:#0{4}x},' + ('\n' if not count % 16 else ' '))
                              ^
SyntaxError: invalid syntax

EDIT1: I’m using Python 3.7

  • To be seen, it’s okay - there’s a chance you typed a non-trintable character, of control, right in the middle - it causes a syntax error with no visible cause ( if that’s what that character didn’t come to when you pasted the code - here it worked). Try commenting on this line (and adding a "pass") - if the error is gone, write the line (copy and paste will paste the invisible character together)

  • When copying the code to my virtual environment, it worked correctly, it was giving syntax error when trying to run in python 2, but when using python3 specifically it works, make sure you are actually using the python3 version, if running from the terminal, run using: python3 name.py

1 answer

-1

I solved the problem by reinstalling Python, I don’t know exactly what happened, but I believe that at the time of installation I must have selected some string option or something like that. But if anyone else has this problem, I recommend uninstalling the Python version(s) and reinstalling, for me, this solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.