• <bdo id='0E242'></bdo><ul id='0E242'></ul>
      <tfoot id='0E242'></tfoot>

      <legend id='0E242'><style id='0E242'><dir id='0E242'><q id='0E242'></q></dir></style></legend>
    1. <i id='0E242'><tr id='0E242'><dt id='0E242'><q id='0E242'><span id='0E242'><b id='0E242'><form id='0E242'><ins id='0E242'></ins><ul id='0E242'></ul><sub id='0E242'></sub></form><legend id='0E242'></legend><bdo id='0E242'><pre id='0E242'><center id='0E242'></center></pre></bdo></b><th id='0E242'></th></span></q></dt></tr></i><div id='0E242'><tfoot id='0E242'></tfoot><dl id='0E242'><fieldset id='0E242'></fieldset></dl></div>

      <small id='0E242'></small><noframes id='0E242'>

      GCS - 从 Google Cloud Storage 直接读取文本文件到 python

      时间:2023-11-07
    2. <i id='L0AAe'><tr id='L0AAe'><dt id='L0AAe'><q id='L0AAe'><span id='L0AAe'><b id='L0AAe'><form id='L0AAe'><ins id='L0AAe'></ins><ul id='L0AAe'></ul><sub id='L0AAe'></sub></form><legend id='L0AAe'></legend><bdo id='L0AAe'><pre id='L0AAe'><center id='L0AAe'></center></pre></bdo></b><th id='L0AAe'></th></span></q></dt></tr></i><div id='L0AAe'><tfoot id='L0AAe'></tfoot><dl id='L0AAe'><fieldset id='L0AAe'></fieldset></dl></div>
        <tbody id='L0AAe'></tbody>
      <tfoot id='L0AAe'></tfoot>

                <bdo id='L0AAe'></bdo><ul id='L0AAe'></ul>

                <small id='L0AAe'></small><noframes id='L0AAe'>

                <legend id='L0AAe'><style id='L0AAe'><dir id='L0AAe'><q id='L0AAe'></q></dir></style></legend>
                本文介绍了GCS - 从 Google Cloud Storage 直接读取文本文件到 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我现在觉得有点傻.我一直在阅读大量文档和 stackoverflow 问题,但我无法正确理解.

                I feel kind of stupid right now. I have been reading numerous documentations and stackoverflow questions but I can't get it right.

                我在 Google Cloud Storage 上有一个文件.它在一个桶'test_bucket'中.在此存储桶内有一个文件夹temp_files_folder",其中包含两个文件,一个名为test.txt"的 .txt 文件和一个名为test.csv"的 .csv 文件.这两个文件只是因为我尝试同时使用这两个文件,但结果都是一样的.

                I have a file on Google Cloud Storage. It is in a bucket 'test_bucket'. Inside this bucket there is a folder, 'temp_files_folder', which contains two files, one .txt file named 'test.txt' and one .csv file named 'test.csv'. The two files are simply because I try using both but the result is the same either way.

                文件中的内容是

                hej
                san
                

                我希望像在本地使用

                textfile = open("/file_path/test.txt", 'r')
                times = textfile.read().splitlines()
                textfile.close()
                print(times)
                

                给了

                ['hej', 'san']
                

                我尝试过使用

                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)
                

                但它给出了输出

                <bound method Blob.download_as_string of <Blob: test_bucket, temp_files_folder/test.txt>>
                

                如何获取文件中的实际字符串?

                How can I get the actual string(s) in the file?

                推荐答案

                download_as_string是一个方法,你需要调用它.

                download_as_string is a method, you need to call it.

                print(blob.download_as_string())
                

                更可能的是,您希望将其分配给一个变量,以便您下载它一次,然后可以打印它并用它做任何您想做的事情:

                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)
                

                这篇关于GCS - 从 Google Cloud Storage 直接读取文本文件到 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 Google Cloud Run 中生成 Blob 签名 URL? 下一篇:使用 gcloud-python 在 Google Cloud Storage 中设置元数据

                相关文章

              • <i id='In2M9'><tr id='In2M9'><dt id='In2M9'><q id='In2M9'><span id='In2M9'><b id='In2M9'><form id='In2M9'><ins id='In2M9'></ins><ul id='In2M9'></ul><sub id='In2M9'></sub></form><legend id='In2M9'></legend><bdo id='In2M9'><pre id='In2M9'><center id='In2M9'></center></pre></bdo></b><th id='In2M9'></th></span></q></dt></tr></i><div id='In2M9'><tfoot id='In2M9'></tfoot><dl id='In2M9'><fieldset id='In2M9'></fieldset></dl></div>

                <small id='In2M9'></small><noframes id='In2M9'>

                    <bdo id='In2M9'></bdo><ul id='In2M9'></ul>
                1. <legend id='In2M9'><style id='In2M9'><dir id='In2M9'><q id='In2M9'></q></dir></style></legend>

                  1. <tfoot id='In2M9'></tfoot>