Skip to content

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

@holly-hacker

Description

@holly-hacker

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions