Pytesser in Python 3.4: name 'image_to_string' is not defined?

后端 未结 3 895
北恋
北恋 2020-12-21 11:29

First off, I would like to say that I know pytesser is not for Python 3.4, but I read from http://ubuntuforums.org/archive/index.php/t-1916011.html that pytesser should als

3条回答
  •  半阙折子戏
    2020-12-21 11:35

    Your code will not work for Python 3. The reason is because when you do from pytesser import * (or simply import it in the first place), the if __name__ == '__main__' conditional will be True, and the code below it will run.

    As I'm sure you're aware, in Python 3, print is no longer a statement but a function. Hence, a SyntaxError will occur at the line print text.

    I'm not sure why you're not seeing this SyntaxError in your code, but if this error passed silently, that means that nothing was imported in the first place, hence the error.

    To fix this, use Python 2.7.

    Python 2.7:

    >>> from pytesser import *
    >>> print image_to_string
    
    

    Python 3:

    >>> from pytesser import *
    Traceback (most recent call last):
      File "", line 1, in 
      File "./pytesser.py", line 61
        print text
                 ^
    SyntaxError: invalid syntax
    

提交回复
热议问题