You can not have text from IDLE/REPL which is interactive testing in a script.
In a script there is no
To show how it work as script,also a
In a script there is no
>>>
or start text of REPL Python 3.6.5 (default, Jan 16 2019, 21:12:16)
. To show how it work as script,also a
.py
file.# names.py import csv from pprint import pprint pprint(dir(csv)) # display the contents of the csv module ['Dialect', 'DictReader', 'DictWriter', 'Error', 'OrderedDict', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONE', 'QUOTE_NONNUMERIC', 'Sniffer', 'StringIO', '_Dialect', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'excel', 'excel_tab', 'field_size_limit', 'get_dialect', 'list_dialects', 're', 'reader', 'register_dialect', 'unix_dialect', 'unregister_dialect', 'writer'] print('-'*20) path = 'names.csv' file = open(path, newline = '') reader = csv.reader(file) header = next(reader) data = [row for row in reader] print(header) print(data[0])
Output:E:\div_code\egg
λ python names.py
['Dialect',
'DictReader',
'DictWriter',
'Error',
'OrderedDict',
'QUOTE_ALL',
'QUOTE_MINIMAL',
'QUOTE_NONE',
'QUOTE_NONNUMERIC',
'Sniffer',
'StringIO',
'_Dialect',
'__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'__version__',
'excel',
'excel_tab',
'field_size_limit',
'get_dialect',
'list_dialects',
're',
'reader',
'register_dialect',
'unix_dialect',
'unregister_dialect',
'writer']
--------------------
['first_name', 'last_name', 'email']
['John', 'Doe', '[email protected]']
If i start REPL eg ptpython interact shell,and do first part it look this.E:\div_code\egg λ ptpython >>> import csv >>> dir(csv)[:10] ['Dialect', 'DictReader', 'DictWriter', 'Error', 'OrderedDict', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONE', 'QUOTE_NONNUMERIC', 'Sniffer']See now is
>>>
there,and command get executed bye Enter.