"hex(ord(...))" not needed on lines 65 and 66
Opened this issue · 5 comments
The following code is line 64, 65 and 66 from the main .py file:
for c in range(l - 1):
declare += str(payload[c]) + ", "
declare += str(payload[l - 1]) + "\n};\nint i = %d; //-snip-\n" % loop_count
I ran this code with python 3.6, and got the following error:
Traceback (most recent call last):
File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 155, in <module>
main(sys.argv[1:])
File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 140, in main
result = generate_source(payload, init_delay=init_delay, loop_count=loop_count, loop_delay=loop_delay, blink=blink)
File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 65, in generate_source
declare += str(hex(ord(payload[c]))) + ", "
TypeError: ord() expected string of length 1, but int found
Since I know some python, I decided to look into the problem and it turns out that simply removing the calls to hex() and ord() makes the script run without problems. I verified that the output still works.
Changed code becomes this:
for c in range(l - 1):
declare += str(payload[c]) + ", "
declare += str(payload[l - 1]) + "\n};\nint i = %d; //-snip-\n" % loop_count
I have not tested with python 2.x.
The same problem happen here, the code from @holly-hacker solved the problem.
Thanks!
The code from @holly-hacker solved the issue for me too.
I am using Python 3.7
Thanks
Throws TypeError: ord()
$> py duck2spark.py -i raw.bin -l 1 -f 2000 -o sketch.ino
Traceback (most recent call last):
File "duck2spark.py", line 155, in <module>
main(sys.argv[1:])
File "duck2spark.py", line 140, in main
result = generate_source(payload, init_delay=init_delay, loop_count=loop_count, loop_delay=loop_delay, blink=blink)
File "duck2spark.py", line 65, in generate_source
declare += str(hex(ord(payload[c]))) + ", "
TypeError: ord() expected string of length 1, but int found
Ping @mame82
Please merge it with the Master as the provided original code is not working with Python 3. @holly-hacker one works perfectly!
I changed lines 64, 65 and 66.
now it is showing the error:
File "C:\Users\HENRIQUES COUTINHO\Documents\Get-Chrome80Dump-main\duck2spark\duck2spark.py", line 7
def generate_source(payload, init_delay=2500, loop_count=-1, loop_delay=5000, blink=True, c):
^
SyntaxError: non-default argument follows default argument
How to solve?