omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Getting 'set' to print

    Pythonista
    print bar code set
    2
    3
    1656
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • KipCarter
      KipCarter last edited by

      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.

      Thanks!

      1 Reply Last reply Reply Quote 0
      • pulbrich
        pulbrich last edited by pulbrich

        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(“something”)
        
        print ('All scanned codes:\n' + '\n'.join(found_codes) )
        

        should work.

        (The original code was ok in python 2.x)

        1 Reply Last reply Reply Quote 0
        • KipCarter
          KipCarter last edited by

          @pulbrich ,
          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.

          THANKS!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors