[Python] Regarding good coding practices, what is meant by "Useless return at end of function...

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Spyder to create a web scraper, and things are moving smoothly so far. As a rookie, Spyder's Code Analysis function is something I find useful for improving the standard of my code. However, while I usually understand its instructions/recommendations, I've recently run into a bit of a blip. I'll post some sample code first:

    def payments(): #### This is line 59 on the editor. Preceding it is another function with a a format similar to this one.
    """Obtains data on the weekly payments in the country"""
    html = get(source["Payments"]).text
    html = bs(html,"lxml")
    location = "/home/oduduwa/Desktop/Python Projects/Financial Analyser/CBN Data/Payments.csv"
    def file_check():
    headings = [i.text for i in html.find_all(width="284")][:10]
    headings.insert(0, "Date")
    if isfile(location) is False:
    with open(location,"w") as file_obj:
    writer(file_obj).writerow(headings)
    return
    file_check()
    file = open(location,"r").read()
    dates = [i.text.strip()[8:] for i in html.find_all("th",colspan="2")]
    values = [i.text.strip()[4:] for i in html.find_all(width="149") if i.text.strip()[4:]!=""]
    values = array(values).reshape(int(len(values)/10),10)
    values = insert(values,0,array(dates).transpose(),axis=1)[::-1]
    for i in range(len(values)):
    if values[0] not in file:
    with open(location,"a+",newline=("\n")) as file_obj:
    writer(file_obj).writerow(values)
    return


    The code runs fine and does everything it should. What I don't really understand, however, is Spyder's statement that there's a useless return call in the code block. Here's what it says specifically:

    [​IMG]

    But, from what I gather, every function call is necessary in this coding block. What could I have missed?

    Continue reading...

Compartilhe esta Página