Getting 'set' to print
I've found a great little piece of code to scan bar codes from an iOS device. If you would like to see the full code sample got to this link on the infragistics web page.
The code works really well, considering what the author basic premise is (scanning and interpreting bar codes). The only issue I am running into getting it to work perfectly on my iOS 13.3.1 iPhone and iPad, is when exiting the code the script directs a printout to the console of content of the variable 'found_codes'.
print ('All scanned codes:\n'), '\n'.join(found_codes)
This bit of code prints only the line 'All Scanned codes:' to the console.
I had modified this from the original code removing a + sign and inserting a comma (,)
print ('All scanned codes:\n') + '\n'.join(found_codes)
Pythonista protested with...
unsupported operand type(s) for +: 'NoneType'...
The code block that adds the bar code reading to 'found_codes is:
objects = ObjCInstance(_metadata_objects) for obj in objects: s = str(obj.stringValue()) if s not in found_codes: found_codes.add(s)
I'm puzzled by the fact that replacing the plus sign with a comma, clears the error message but after doing that, the print to the console doesn't take place.
I will stress I'm relatively new to python and pythonista, so I may be missing something obvious to the rest of you.
In your original code move the first closing bracket “)” to the end of the line, the idea being than in python 3.x the print statement needs the arguments in brackets, i.e.
print ('All scanned codes:\n' + '\n'.join(found_codes) )
(The original code was ok in python 2.x)
Thanks, and I should have picked up on that even with my limited experience in Python, since all I've been working in is 3x Python.
This DID cause the code to print the set after "All scanned codes:' , but then as usual popped another 'No method found for stringValue' error with it. That likely is an issue nested in P2x v P3x code as this was.
For what I want to use this code for, it really doesn't matter at all, because what i want to do is build a function and nest it in the seeding of the found_codes to send off the data to a database, so this was more a frustration/curiosity that I really wanted to see resolved for my own benefit more than the project I'm working on.