duck2spark icon indicating copy to clipboard operation
duck2spark copied to clipboard

"hex(ord(...))" not needed on lines 65 and 66

Open holly-hacker opened this issue 7 years ago • 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.

holly-hacker avatar Mar 14 '17 18:03 holly-hacker

The same problem happen here, the code from @HoLLy-HaCKeR solved the problem.

Thanks!

ratzvasky avatar Oct 03 '17 16:10 ratzvasky

The code from @HoLLy-HaCKeR solved the issue for me too. I am using Python 3.7 Thanks

3ldidi94 avatar Jan 01 '19 19:01 3ldidi94

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

0x48piraj avatar Jan 18 '19 23:01 0x48piraj

Please merge it with the Master as the provided original code is not working with Python 3. @HoLLy-HaCKeR one works perfectly!

gstorelli avatar Feb 25 '19 09:02 gstorelli

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?

HenriquesCoutinho avatar Sep 18 '22 21:09 HenriquesCoutinho