1
$\begingroup$

When using print command in ExternalEvaluate["Python","print(1+1)"] or ExternalLanguage cell using >, there is always an extra cell generated after the print. This is particularly annoying when debugging code where print is inside a loop. Am i the only one facing this problem or others also see this? Help.

I am using version WL-11.3 and Python-3.

As an example consider the following python function.

def solution(N):
    max_gap=0
    current_gap=0

    while N>0 and N%2==0:
        print([N,current_gap,max_gap,"{0:b}".format(N)])
        N//=2

    while N>0:
        if N%2==0:
            current_gap+=1
        else:
            if current_gap!=0:
                max_gap=max(current_gap,max_gap)
                current_gap=0

        print([N,current_gap,max_gap,"{0:b}".format(N)])
        N//=2

    return max_gap

try calling the following as follows:

solution(1042)
$\endgroup$
  • $\begingroup$ Does it help that ExternalEvaluate["Python", "1+1"] returns its value without the need of the Python print function. $\endgroup$ – Edmund Dec 12 '18 at 22:52
  • 1
    $\begingroup$ No because in a large function when debugging the only way to get intermediate results is by printing them out before the final return in a function. $\endgroup$ – user13892 Dec 13 '18 at 0:27
  • 1
    $\begingroup$ It would help if you were to provide a minimal example of the Python looping function with the print. $\endgroup$ – Edmund Dec 13 '18 at 1:07
  • $\begingroup$ @Edmund I have added an example for python function where loops are involved. $\endgroup$ – user13892 Dec 13 '18 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.