Mercurial > hg > config
annotate python/is_interactive.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Wed, 09 Jul 2014 16:26:49 -0700 |
| parents | 7eaaf99e3182 |
| children |
| rev | line source |
|---|---|
| 346 | 1 #!/usr/bin/env python |
| 2 | |
| 3 """ | |
| 4 illustrates usage of isatty | |
| 5 | |
| 6 Ref: http://www.tutorialspoint.com/python/file_isatty.htm | |
| 7 """ | |
| 8 | |
| 9 import optparse | |
| 10 import os | |
| 11 import sys | |
| 12 | |
| 13 # DOES NOT WORK! :( | |
| 14 # > echo 'foo' | is_interactive.py | |
| 15 # Usage: is_interactive.py [options] | |
| 16 | |
| 17 # is_interactive.py: error: missing input | |
| 18 | |
| 19 | |
| 20 def main(args=sys.argv[1:]): | |
| 21 parser = optparse.OptionParser() | |
| 22 options, args = parser.parse_args(args) | |
| 23 | |
| 24 function = str.upper | |
| 25 | |
| 26 if args: | |
| 27 # take input from command line args | |
| 28 input = ' '.join(args) | |
| 29 elif not sys.stderr.isatty(): | |
| 30 # take input from stdin | |
| 31 input = sys.stdin.read() | |
| 32 else: | |
| 33 # no input! cry! | |
| 34 parser.error("missing input") | |
| 35 | |
| 36 print function(input) | |
| 37 | |
| 38 if __name__ == '__main__': | |
| 39 main() |
