Python Forum
Beginner trying to code in python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Beginner trying to code in python (/thread-21355.html)



Beginner trying to code in python - RA0211 - Sep-26-2019

Hello,

This is my first post in this forum.

I'm a beginner and learning python in small phases. As such I'm trying to write a code where in a file is existing in a remote google cloud bucket in the format of "test_201907_link.txt" where in the middle numbers might change according to what user sends. My requirement is to find the file that starts with "text*" and then strip out the number part only. I'm trying to derive this through a function and here is the code so far that I've come up.

def list_blobs(bucket, execution_date, ):

    conn = BaseHook.get_connection(dags_config.bigquery_conn_id)
    os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = conn.extra_dejson['extra__google_cloud_platform__key_path']

    prefix = 'dailyinput/' + execution_date + "/test"

    client = storage.Client(dags_config.project_id)
    bucket = client.bucket(bucket)
    blobs = bucket.list_blobs(prefix = prefix)

    return blobs

def part_filename_extraction ():

    blobfile = list_blobs (dags_config.inbound_gcs_bucket, date)

    blobsfile = blobfile[10:15]
    print ("string extracted from filename : ", format(blobsfile))
I'm getting an error indicating that name "blobfile" is not defined

Appreciate for any help here.


RE: Beginner trying to code in python - emryscass - Sep-26-2019

Have you tried to return blobfile? Right now the blobfile variable is local to your part_filename_extraction function.