Print real time instead of waiting until the end

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 13:20, xxxxxxxx wrote:

I need to output a number for a loading bar within one of my plugins.

But the issue is that python wont print until the end of a function.

for example:

import sys
import time
  
def main() :
  
    print "one"
    sys.stdout.flush()
    time.sleep(5)
    print "two"
  
if __name__=='__main__':
    main()

waits 5 seconds and then prints "one"  and "two" at the same time.

how can a make them output realtime.

I tried adding

sys.stdout.flush()

which would be the solution if this wasnt python within c4d.

thanks

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 23:43, xxxxxxxx wrote:

It works on R13 and 14 for me, but not on R12, I assume this is the version you are using.
The same problem with this code:

import sys  
import time  
  
def main() :  
  
  for i in xrange(10) :  
      print i  
      time.sleep(0.5)  
  
main()

The Console in R12 seems to be updated only when the Script Manager ends. Don't know for sure, but it should actually work for a plugin, except the Python Console is updating periodically.

-Niklas

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/08/2012 at 23:47, xxxxxxxx wrote:

You can use c4d.GePrint() instead of Python standard print:

import time
import c4d
  
def main() :
    c4d.GePrint("one")
    time.sleep(5)
    c4d.GePrint("two")
  
if __name__=='__main__':
    main()

c4d.GePrint() is currently undocumented but it is useful in some cases like this one.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/08/2012 at 13:23, xxxxxxxx wrote:

Im actually using r13, so Im not sure why it doesnt work for me but it does for you. In any event, the GePrint() function worked. So thank you both for your help!