Python 退出Spyder中脚本的一部分

Python 退出Spyder中脚本的一部分,python,csv,exit,spyder,Python,Csv,Exit,Spyder,我正在做一个简单的任务,就是在多个CSV文件中添加一个额外的列 以下代码在Python提示shell中运行良好: import csv import glob import os data_path = "C:/Users/mmorenozam/Documents/Python Scripts/peptidetestivory/" outfile_path = "C:/Users/mmorenozam/Documents/Python Scripts/peptidetestivory/alld

我正在做一个简单的任务,就是在多个CSV文件中添加一个额外的列

以下代码在Python提示shell中运行良好:

import csv
import glob
import os

data_path = "C:/Users/mmorenozam/Documents/Python Scripts/peptidetestivory/"
outfile_path = "C:/Users/mmorenozam/Documents/Python Scripts/peptidetestivory/alldata.csv"

filewriter = csv.writer(open(outfile_path,'wb'))
file_counter = 0
for input_file in glob.glob(os.path.join(data_path,'*.csv')):
        with open(input_file,'rU') as csv_file:
                filereader = csv.reader(csv_file)
                name,ext = os.path.splitext(input_file)
                ident = name[-29:-17]
                for i, row in enumerate(filereader):
                    row.append(ident)
                    filewriter.writerow(row)            
        file_counter += 1
但是,当我使用Spyder运行此代码时,为了获得所需的.csv文件,我必须添加

exit()
或在IPython控制台中键入“%reset”

有没有更好的方法来完成这部分脚本?因为我的代码的以下部分使用在这一部分中生成的.csv文件,并且使用上面的选项很烦人