코딩, 개발에 대한 기록 저장소

파이썬(Python) 에러 AttributeError 와 처리 방법


## 파이썬(Python) 에러 AttributeError
### 원인
Python의 AttributeError는 개체에 속성이 없는데 접근하려 시도할 때 발생합니다.

아래는 AttributeError가 발생할 수 있는 코드의 예입니다.

File: test.py
```python
text = "hello world"
print(text.upper())
print(text.not_exist())
```

결과
```python
$ python test.py

  File "/test.py", line 3, in <module>
    print(text.not_exist())
AttributeError: 'str' object has no attribute 'not_exist'
```
문자열 text는 not_exist() 속성이 없기 때문에 발생했습니다.

### 처리 방법
해당 에러를 방지하려면 개체의 사용 가능한 속성을 알아야 합니다.
help(str)를 사용하여 str 개체의 사용 가능한 속성을 확인 할 수 있습니다.

File: test.py
```python
text = "hello world"
print(text.upper())
#print(text.not_exist())

print(type(text))
help(str)
```