2017-09-30 1 views
-1

enter image description here다시는 이미 파이썬에서 '경우 라인'에 불리는 함수를 호출하지 않으려면

이미 파이썬에서 전에 '경우 라인'에 불리는 함수를 호출 할 수있는 방법이있다? 나는 이미 똑같은 기능을 다시 호출하여 그 결과가 바로 전에 왔다고 생각합니다. 줄을 써서 사용하고 할당하는 방법이 있어야한다고 생각했습니다.

+4

스냅 샷 대신 코드를 게시하십시오. – aircraft

+1

아니요, 파이썬에서는 이것을 할 수 없습니다. 배정은 C 나 PHP처럼 표현식이 아닙니다. 별도의 과제와'if'로 나누어야합니다. http://effbot.org/pyfaq/why-can-t-i-use-an-assignment-in-an-expression.htm을 참조하십시오. 이런 것들을 언어에 추가하라는 제안이 있었지만 거부당했습니다. – Barmar

+0

답장을 보내 주셔서 감사합니다 @Barmar –

답변

0

비슷한 일을하는 솔루션을 공유하고 싶었습니다. 내가 원하는,

class tmp: 
    t_=None 
    def asgn(d): 
     tmp.t_=d 
     return tmp.t_ 
     #that could be called on an 'if line' to assign the result into a cache variable while the comparison is being done 


    def value(): 
     z=tmp.t_ 
     tmp.t_=None 
     return z 
     #if this is called afterward, the value could be obtained in if clause without calling the related function again 

if tmp.asgn(get_some_value_from_external_url("http//blablabla.com/..."))is not None: 
    my_value=tmp.value() 
    print(my_value) 
관련 문제