I feel a bit stupid right now. I’ve been reading tons of documentation and stackoverflow questions, but I can’t get it right.
I have a file on Google Cloud Storage. It is in a bucket ‘test_bucket’. In this bucket there is a folder ‘temp_files_folder’ which contains two files, one named ‘test.txt’ .txt file and a .csv file called ‘test.csv’. Both files are just because I tried using both files but the result is the same.
The contents of the file are
I want to read it into python, just like I use locally
textfile = open("/file_path/test.txt", 'r') times = textfile.read().splitlines() textfile.close() print(times)
I tried using
from google.cloud import storage client = storage.Client() bucket = client.get_bucket('test_bucket') blob = bucket.get_blob('temp_files_folder/test.txt') print(blob.download_as_string)
But it gives the output
<bound method Blob.download_as_string of >
How to get the actual string in the file?
1> Daniel Rosem..:
download_as_string is a method, you need to call it.
More likely, you want to assign it to a variable so that you download it once and can then print it and do whatever else you want with it:
downloaded_blob = blob.download_as_string() print(downloaded_blob) do_something_else(downloaded_blob)