Python의 클래스 본문 내에서 클래스 정적 메서드 호출
Python 버전 3.10 이상의 경우 클래스 본문 내에서 정적 메서드를 호출하는 것은 간단합니다. 그러나 3.9 이하 버전에서는 이것이 문제가 됩니다.
오류 발생
클래스 본문 내에서 정적 메소드를 호출하려고 하면 다음 오류가 발생할 수 있습니다.
TypeError: 'staticmethod' object is not callable
이 오류는 정적 메서드 데코레이터를 사용하여 선언된 정적 메서드가 설명자가 되기 때문에 발생합니다. 설명자는 인스턴스 대신 클래스에 바인딩되므로 클래스 본문 내에서 액세스할 수 없게 됩니다.
__func__ 속성을 사용한 해결 방법
한 가지 해결 방법은 인스턴스의 __func__ 속성을 통해 원래 원시 함수에 액세스하는 것입니다. 정적 메서드 객체:
<code class="python">class Klass(object): @staticmethod def stat_func(): return 42 _ANS = stat_func.__func__() # call the staticmethod def method(self): ret = Klass.stat_func() return ret</code>
추가 참고 사항
- 위의 해결 방법은 작동하지만 __func__ 속성은 구현 세부 사항이며 향후 Python 버전에서 변경될 수 있습니다.
- Python 버전 3.10 이상의 경우 클래스 본문 내에서 정적 메서드를 호출하는 것은 아래와 같이 간단합니다.
<code class="python">class Klass(object): @staticmethod def stat_func(): return 42 def method(self): ret = Klass.stat_func() return ret</code>
위 내용은 Python의 클래스 본문 내에서 클래스 정적 메서드를 호출하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Dreamweaver Mac版
시각적 웹 개발 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!