python 注意的问题

来源:互联网 发布:gta5网际网络连线 编辑:程序博客网 时间:2024/06/07 05:46

import requests: 获取网页信息,简单高效
用python解压文件模板

zip_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/00228/smsspamcollection.zip'    r = requests.get(zip_url)    z = ZipFile(io.BytesIO(r.content))    file = z.read('SMSSpamCollection')    # Format Data    text_data = file.decode()    text_data = text_data.encode('ascii',errors='ignore')    text_data = text_data.decode().split('\n')

存文件

with open(os.path.join(data_dir, data_file), 'w') as file_conn:        for text in text_data:            file_conn.write("{}\n".format(text))

读取csv文件

with open(save_file_name, 'r') as temp_output_file:        reader = csv.reader(temp_output_file)        for row in reader:            text_data.append(row)

正则表达式表

0 0
原创粉丝点击