#!/usr/bin/env python

import agate

from csvkit.cli import CSVKitUtility


class CSVPy(CSVKitUtility):
    description = 'Load a CSV file into a CSV reader and then drop into a Python shell.'
    override_flags = ['l', 'zero', 'H']

    def add_arguments(self):
        self.argparser.add_argument('--dict', dest='as_dict', action='store_true',
                                    help='Load the CSV file into a DictReader.')
        self.argparser.add_argument('--agate', dest='as_agate', action='store_true',
                                    help='Load the CSV file into an agate table.')

    def main(self):
        # Attempt reading filename, will cause lazy loader to access file and raise error if it does not exist
        filename = self.input_file.name

        if self.args.as_dict:
            reader_class = agate.csv.DictReader
            descriptor = 'agate.csv.DictReader'
        elif self.args.as_agate:
            reader_class = agate.Table.from_csv
            descriptor = 'agate.Table'
        else:
            reader_class = agate.csv.reader
            descriptor = 'agate.csv.reader'

        reader = reader_class(self.input_file, **self.reader_kwargs)

        welcome_message = 'Welcome! "%s" has been loaded in an %s object named "reader".' % (filename, descriptor)

        try:
            from IPython.frontend.terminal.embed import InteractiveShellEmbed
            ipy = InteractiveShellEmbed(banner1=welcome_message)
            ipy()
        except ImportError:
            import code
            code.interact(welcome_message, local={'reader': reader})


def launch_new_instance():
    utility = CSVPy()
    utility.run()


if __name__ == '__main__':
    launch_new_instance()

@@ -799,32 +799,25 @@
             
-reader_c
+k
 lass = agate
@@ -840,34 +840,34 @@
             
-descriptor
+class_name
  = 'agate.cs
@@ -880,16 +880,53 @@
 Reader'%0A
+            variable_name = 'reader'%0A
         
@@ -958,32 +958,25 @@
             
-reader_c
+k
 lass = agate
@@ -999,34 +999,34 @@
             
-descriptor
+class_name
  = 'agate.Ta
@@ -1030,16 +1030,52 @@
 .Table'%0A
+            variable_name = 'table'%0A
         
@@ -1092,24 +1092,17 @@
         
-reader_c
+k
 lass = a
@@ -1129,26 +1129,26 @@
         
-descriptor
+class_name
  = 'agat
@@ -1161,25 +1161,28 @@
 reader'%0A
-%0A
+    
         
 reader =
@@ -1177,25 +1177,54 @@
     
-reader
+variable_name
  = 
+'
 reader
-_c
+'%0A%0A        variable = k
 lass
@@ -1344,22 +1344,18 @@
  named %22
-reader
+%25s
 %22.' %25 (f
@@ -1367,18 +1367,33 @@
 me, 
-descriptor
+class_name, variable_name
 )%0A%0A 
@@ -1671,24 +1671,31 @@
 al=%7B
-'reader': reader
+variable_name: variable
 %7D)%0A%0A

Change variable name to table if --agate