functional programming - Passing arguments through several functions in Python -


this question related best practice.

let's have following code:

def clean_text(text, idx):    title = sqlalchemy.query("select title page_titles id = %s" % idx)    return {title: text}  def scrape_webpage(idx):    """ stuff here"""    response = requests.get(link)    return clean_text(response.text, idx)  def main():    idx in range(10):       scrape_webpage(idx)  if __name__ == '__main__':    main() 

the main problem have code there statefulness required (namely idx) being passed through scrape_webpage. can imagine if have many functions before clean_text() invoked, idx has passed through of them without being used in of them.

is there better way clean_text can know state of loop without having passed argument (and incidentally, through of functions use it)? perhaps generators or callbacks? appreciate example.


Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -