[Python] from __future__ import print_function

    728x90

    모듈 소스를 볼 때, 아래와 같은 코드를 발견할 때가 있습니다.

     

    from __future__ import print_function

     

    짧게 설명하면 Python2를 Python3으로 일일히 고쳐주기 싫을 때, 해당 모듈을 쓰면 사용 가능합니다.

     

    # In python version 2
    print 'hello world'
    
    # From python version 3
    print('hello world')

     

    다른 모듈의 종류는 이렇게 있습니다.

    from __future__ import absolute_import, division, 
                           print_function,
                           nested_scopes, 
                           generators, 
                           with_statement, 
                           unicode_literals

     

    728x90

    댓글