Python: absolute path error in mac -


i using python on mac , open pdf file present in different directory directory main python code running. tried different options there error saying file doesn't exist when file present or [error no. 2] file cannot opened. here code use:

helpfile = os.path.abspath('~/help/help.pdf') self.help_btn = tk.button(self.help_frm, text="help!", width=8, command = lambda: os.system("open "+helpfile)) 

could 1 please.

abspath not expand ~ user's home directory, calculates absolute path of file based on path relative current working directory.

from docs, equivalent to:

normpath(join(os.getcwd(), path)) 

so in code, helpfile being set "/path/to/cwd/~/help/help.pdf"

to expand ~, use os.path.expanduser.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -