TIL/Python

input = sys.stdin.readline() 과 input = sys.stdin.readline 의 차이

아람2 2025. 5. 23. 13:03
반응형

오랜만에 백준 문제를 풀다가, input() 에서 TypeError 가 났다 

Traceback (most recent call last):
  File "/Users/ahram/Desktop/Algorithm/After/12_심화2/04_2108_통계학.py", line 14, in <module>
    n = int(input()) # 수의 개수 
TypeError: 'str' object is not callable
ahram@Ahram-MacBook-Pro Algorithm %

 

Python 을 너무 오랜만에 봐서 sys 로 input 만드는 것도 까먹었다 

이렇게 했더니 String 이라고 Error 가 뜬 거였음 

import sys 
input = sys.stdin.readline()

n = int(input()) # 수의 개수

 

readline() <- 이렇게 하면 input 이 문자열 값이 되어 버려서, 이후로는 input() 을 쓸 수 없다고 한다 

그래서 () 를 떼고 정의해 줬더니 숫자 입력이 잘 됐다 

input = sys.stdin.readline

 

입사하고 처음 쓰는 TIL 끗 

반응형