Can A Python Program Open An Text File On The Web?
Question: I am making a program, and was wondering if a .txt file can be hosted on the
web and be accessed by the open() function. Does anyone know about this?


Answer: You can't use `open()`, but you could use the [`requests`](http://docs.python-
requests.org/en/master/) library to do it.

    
    
    import requests
    
    url_to_txt_file = ""
    print(requests.get(url_to_txt_file).text)
    

Alternatively, you could use
[`urllib.request`](https://docs.python.org/3.5/library/urllib.request.html#module-
urllib.request).

    
    
    import urllib.request
    
    url_to_txt_file = ""
    print(urllib.request.urlopen(url_to_txt_file).read())
    

