IT/Python

Python Trouble Cheatsheet

트래이닝맨 2018. 1. 23. 06:25
728x90
반응형

문제: Python2.x:   end= 가 syntax 에러가 남.


해결:  아래를 임포트해주면 해결.

 from __future__ import print_function


for i in range(2,10):

        for j in range(1, 10):

                print (i*j , end=" ")

        print(' ')





문제:  test.py 를 실행시킬때 아래의 메시지가 나온다면, 

Error message:

-bash: ./test-py.py: python: bad interpreter: No such file or directory


or 


./test-py.py: line 2: from: command not found


해결: test.py파일 최상단에 interpreter를 넣어준다.


#!/usr/bin/python

#!python





Q: Encoding issue

Error: Message

SyntaxError: Non-ASCII character '\xeb' in file /home/jooho/PycharmProjects/sample_project/sample.py on line 14, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 


A: Add this declare at the first file.

 #!/usr/bin/env python
# -*- coding: utf-8 -*-




Q: Recursion depth 리미트에 걸려 에러가 날때


A: 리미트를 올려준다.

sys.setrecursionlimit(100000000) 


반응형