Skip to content

Instantly share code, notes, and snippets.

@suxue
Created March 11, 2014 05:09
Show Gist options
  • Save suxue/9479817 to your computer and use it in GitHub Desktop.
Save suxue/9479817 to your computer and use it in GitHub Desktop.
inter-operation between python and shell by using ipython script
#!/usr/bin/ipython
# vim: ft=python:
# to run it as ipython script, suffix must be .ipy
tmpfile = !mktemp
tmpfile = tmpfile[0]
files = !ls
file = open (tmpfile, "w")
file.writelines(files.n) # get it as newline separated string
file.close()
!cat $tmpfile # refer to python variable in shell
!echo
!rm $tmpfile # equals %sc rm $tmpfile
!echo $$HOME # REFER to shell variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment