daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Open a file stream to an interactive Python session
  2. set pystream [open "|/usr/bin/python -i wombat.py" r+]
  3. fconfigure $pystream -blocking 0
  4.  
  5. # Ask Python to calculate Pi
  6. puts $pystream "w = pi_computing_device(1000)"
  7. puts $pystream "print w.compute_pi()"
  8. flush $pystream
  9.  
  10. # Spin until we get a response from Python
  11. # Probably better to use "filevent"
  12. while {1} {
  13.     set L [gets $pystream foo]
  14.  
  15.     # Print it to the screen in Tcl
  16.     if {$foo != ""} {
  17.         puts "Pi is approximately equal to $foo"
  18.         break
  19.     }
  20. }
  21.  
  22. # Close the stream to shut down Python
  23. close $pystream
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top