[Python] How do I 'send' an environ value to another function? [closed]

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I have this assignment where they implemented a function fetch(url) that fetches a url and caches it per user if it was fetched by that user before. I need to write a function did_fetch(user, url) that checks if some url was fetched by some user, and when I try to set the os.environ['USER'] to user I get a lot of errors, is there a way to 'send' an environ variable to a function written in a different file?

    I tried this code:

    from Root.fetch import fetch
    import time
    import os

    def did_fetch(user, url): #return if url has been fetched by user
    os.environ['USER'] = user
    start = time.time()
    fetch(url)
    if time.time() - start > 0.1: #simulate the time it takes to fetch a non cached url
    return False
    return True


    Obviously it's not the right way to go about it, any ideas what I did wrong?

    Continue reading...

Compartilhe esta Página