Python Forum
Beginner trying to code in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner trying to code in python
#1
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.
Reply
#2
Have you tried to return blobfile? Right now the blobfile variable is local to your part_filename_extraction function.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 817 May-19-2023, 11:19 AM
Last Post: deanhystad
  Code not reading http link from .txt file (Beginner level) plarrip 3 2,404 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Beginner: I need help understanding few lines of a code. hop_090 1 1,685 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,738 Jun-18-2020, 04:59 PM
Last Post: QTPi
  A beginner code... TheDude 7 3,278 Jun-18-2020, 05:39 AM
Last Post: TheDude
  [Beginner] Code is not producing desired result fakej171 2 2,423 Mar-21-2020, 10:26 AM
Last Post: buran
  what function should i use to tidy up my code (extreme beginner) scraig0117 4 2,287 Dec-16-2019, 04:03 PM
Last Post: scraig0117
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,407 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Beginner Code bh3282 9 4,512 Mar-18-2019, 03:58 PM
Last Post: samsonite
  [Help] Beginner's code Owenix 3 2,743 Sep-15-2018, 08:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020