在python中保存csv文件

问题描述 投票:-1回答:2

我已经使用此代码提取推文并将其存储在csv文件中。

import tweepy
import csv
auth = tweepy.auth.OAuthHandler('xxx', 'xxx')
auth.set_access_token('xx-xx', 'xxx')
api = tweepy.API(auth)

# Open/create a file to append data to
csvFile = open('result.csv', 'a')

#Use csv writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
                           q = "#Seeman").items(500):

    # Write a row to the CSV file. I use encode UTF-8
    csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
    print (tweet.created_at, tweet.text)
csvFile.close()

但我需要在我的本地磁盘中保存一个csv文件,其中包含提取数据中的推文。我该怎么做?谢谢。

python csv
2个回答
1
投票

要获取脚本的工作目录,您需要执行以下操作:

import os 
os.getcwd()

0
投票

要获取存储csv文件的位置,您需要执行以下操作:

import os 
os.getcwd()
© www.soinside.com 2019 - 2024. All rights reserved.