python error : __init__() missing 1 required positional argument:

2020. 3. 7. 17:19·Error code 모음/4. Python errors
반응형

아... 너무 쪽팔리는 에러를 만났네여..

함수를 만들어 놓고도.. 안에 값을 넣지 않아서..

저런 에러를 만나고 30분을 고민햇다니..!!!으!!!

 

일단 에러를 낸것이니 기록!

 

class Thing():
    def __init__(self, example):
        self.example = example


thin = Thing(#이 부분이 문제였음)

위에 class 를 만들어주고 이를  thin 이라는 객체에 담아주었는데 

 

__init__ 라는 초기화 함수를 써주었는데요.

처음에는 이해가 안되었지만, 이 에러를 풀고 원인을 공부하는 과정에서 이 함수를 왜 쓰는지 짐작을 할 수 

있게 된 것 같네요

 

__init__ 는 초기화 함수라고 해서 객체를 만들때마다 클래스를 초기화해서 

새것처럼 사용할 수 있게 만들어줍니다..

 

하지만 __init__사용하는만큼 (self, --) 뒤에 사용할 변수를 담아주어만 하는데요

이것이 바로 __init__가 초기화 함수라고 불리는 이유였었네요...

 

새로운 객체를 만들때마다 변수를 담게끔 만들어 준다.

그러기에  

thin = Thing( )를 담아줄때 ( ) 괄호 안에 변수를 써줘야만 했던것이다.

 

https://stackoverflow.com/questions/19929626/init-missing-1-required-positional-argument

 

__init__() missing 1 required positional argument

I am trying to learn Python. This is a really simple code. All I am trying to do here is to call a class's constructor. Initialize some variables there and print that variable. But it is giving me an

stackoverflow.com

 

 

반응형

'Error code 모음 > 4. Python errors' 카테고리의 다른 글

python error: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.  (0) 2020.03.17
python error L “TypeError: __str__ returned non-string” but still prints to output?  (0) 2020.03.07
파이썬 에러 : 'tuple' object has no attribute 'get'  (0) 2020.03.04
python error : "<stdin>", line1, in <module> IndexError: list index out of range  (0) 2020.02.29
파이썬 에러: ValueError: invalid literal for int() with base10: '4.3'  (0) 2020.02.29
'Error code 모음/4. Python errors' 카테고리의 다른 글
  • python error: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
  • python error L “TypeError: __str__ returned non-string” but still prints to output?
  • 파이썬 에러 : 'tuple' object has no attribute 'get'
  • python error : "<stdin>", line1, in <module> IndexError: list index out of range
쟈누
쟈누
Ad astra per aspera
    반응형
  • 쟈누
    쟈누의 기록공간
    쟈누
  • 전체
    오늘
    어제
    • 분류 전체보기 (444)
      • AWS (31)
        • Glue (4)
        • S3 (1)
      • 클라우드 (0)
      • Data Engineering (37)
        • GitHub (10)
        • NiFi (11)
        • Spark (10)
        • Snowflake (0)
        • 머신러닝, AI (6)
      • 언어 (118)
        • 데이터 베이스 (42)
        • JAVA (9)
        • Python (34)
        • Java Script (15)
        • Linux (18)
      • 프로젝트, 인강 그리고 책 (30)
        • Spotify Project (7)
        • RASA chatbot Project (9)
        • Naver shopping Project (6)
        • 빅데이터를 지탱하는 기술 (8)
      • OLD (56)
        • IT 용어 사전 (13)
        • Front End (12)
        • Back End (31)
      • Error code 모음 (165)
        • 1. SQL errors (17)
        • 2. Hadoop errors (20)
        • 3. Linux Errors (14)
        • 4. Python errors (33)
        • 5. JAVA, Spring errors (41)
        • 6. Jav Script errors (10)
        • 7. Dev Tools errors (9)
        • 8. Git errors (8)
        • 9. Jenkins Errors (4)
        • 10. airflow Errors (2)
        • 11. Aws errors (7)
      • 개인 (1)
        • 책 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 블로그 관리
    • 글쓰기
  • 링크

  • 공지사항

    • 간단한 블로그 소개
  • 인기 글

  • 태그

    error
    SQL
    설치
    파이썬
    자바
    AWS
    java
    MySQL
    json
    에러
    node
    install
    python error
    NiFi
    리눅스
    linux
    Python
    Spring
    Git
    API
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
쟈누
python error : __init__() missing 1 required positional argument:
상단으로

티스토리툴바