Guest User

Untitled

a guest
Oct 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment