diff options
Diffstat (limited to 'python/pyspark/shell.py')
-rw-r--r-- | python/pyspark/shell.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/python/pyspark/shell.py b/python/pyspark/shell.py new file mode 100644 index 0000000000..bd39b0283f --- /dev/null +++ b/python/pyspark/shell.py @@ -0,0 +1,33 @@ +""" +An interactive shell. +""" +import optparse # I prefer argparse, but it's not included with Python < 2.7 +import code +import sys + +from pyspark.context import SparkContext + + +def main(master='local', ipython=False): + sc = SparkContext(master, 'PySparkShell') + user_ns = {'sc' : sc} + banner = "Spark context avaiable as sc." + if ipython: + import IPython + IPython.embed(user_ns=user_ns, banner2=banner) + else: + print banner + code.interact(local=user_ns) + + +if __name__ == '__main__': + usage = "usage: %prog [options] master" + parser = optparse.OptionParser(usage=usage) + parser.add_option("-i", "--ipython", help="Run IPython shell", + action="store_true") + (options, args) = parser.parse_args() + if len(sys.argv) > 1: + master = args[0] + else: + master = 'local' + main(master, options.ipython) |