【发布时间】:2021-01-21 10:15:27
【问题描述】:
我的 Python 脚本有多种方法可以处理 csv 文件。它在我的本地机器上运行,但当我使用存储在 Google Cloud Storage 存储桶中的同一个 csv 文件时它不会。我需要跟踪文件中的 current_position,所以这就是我使用seek() 和tell() 的原因。我尝试使用 pandas 库,但没有这样的方法。有没有人有一个 Python 脚本的基本示例来使用这些方法读取存储在 GCP 存储桶中的 csv?
def read_line_from_csv(position):
#df = pandas.read_csv('gs://trends_service_v1/your_path.csv')
with open('keywords.csv') as f:
f.seek(position)
keyword = f.readline()
position = f.tell()
f.close()
return position, keyword
def save_new_position(current_positon):
f = open("position.csv", "w")
f.write(str(current_positon))
f.close()
update_csv_bucket("position.csv")
def get_position_reader():
try:
with open('position.csv') as f:
return int(f.readline())
except OSError as e:
print(e)
【问题讨论】:
标签: python google-cloud-platform google-cloud-functions google-cloud-storage