Tengo este código de Python 2.x. No me funciona en Visual Studio Community 2019 (Gratuito).
Código
import os, sys, tkFileDialog,Tkinter root = Tkinter.Tk() root.withdraw() formats = [ ('Roms Super Nintendo SMC','.smc'),('Roms Super Nintendo SFC','.sfc'),('Fichier Bin','.bin'),('Roms Super Nintendo','.smc .sfc .bin') ] input = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=formats,title='Select file to swap bin HI to LO like A16->A15, A17->A16...A21->A20 and A15->21') if not input: print "Error: Cannot open file" sys.exit() output = tkFileDialog.asksaveasfile(parent=root,mode='wb',filetypes=formats,title='Create output file name') if not output: print "Error: cannot create output file" sys.exit() # reading input file to a byte array data = bytearray(input.read()) # calculating rom size in 2 exponants expsize = 0 bytesize = len(data) while bytesize > 1: expsize += 1 bytesize = bytesize // 2 # init a proper size empty bytearray buffer = bytearray() for i in range(2**expsize): buffer.append(0) # let's do the swap count = 0 for i in range(len(data)): addr = (i & 0x7fff) + ((i & 0x008000) << (expsize - 16)) + ((i & 0x010000) >> 1) + ((i & 0x020000) >> 1) + ((i & 0x040000) >> 1) + ((i & 0x080000) >> 1) + ((i & 0x100000) >> 1) + ((i & 0x200000) >> 1) if addr != i: count += 1 buffer[addr] = data[i] print "Swapped %s (%s) addresses" % (count, hex(count)) # writing output file output.write(buffer) # close file handles input.close() output.close()
Me sale estos errores.
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 429, in main
run()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 266, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 236, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "C:\Users\Meta\Documents\Visual Studio 2019\Python_consola_01\Python_consola_01\Python_consola_01.py", line 10
print "Error: Cannot open file"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Error: Cannot open file")?
Press any key to continue . . .
¿Les dicen algo?
Saludos.