Open text file either locally or remotely via url with python -
i working on project need potentially open , read textfile either on local server or remotely (via url). there python function works php's :
file_get_contents() that can this? right have:
def get_data_from_file(path): i, line in enumerate(open(path)): ..... i pass in path either locally or remotely.
you try:
def file_get_contents(path): try: urllib.urlretrieve(path, filename=path) except: print 'not page' if os.path.exists(path): open(path, r) file: info = file.read() print info else: print 'no such file' python
No comments:
Post a Comment