Absolute linking in Python -


how can make links relative home directory (absolute linking)? have program use file given anywhere in user account. code:

file_name = input("enter file path") try:     file = open("../" + file_name)     print(file) except:     print("failed open") 

currently assumes program in desktop (which is). can make work same regardless of how many folders in?

edit: want make relative user's home directory.

import os 

home_dir = os.path.expanduser('~')

file_name = input("enter file path") try:     file = open(os.path.join(home_dir, file_name))     print(file) except:     print("failed open") 

os.path.expanduser('~') should return home directory of user.

though can't quite tell if want absolute or relative path, , whether home directory or desktop directory want. may want reword question.


Comments