This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "~/" not working with open() function in posix systems
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, flipchan, steven.daprano
Priority: normal Keywords:

Created on 2019-06-16 11:56 by flipchan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg345743 - (view) Author: flipchan (flipchan) Date: 2019-06-16 11:56
"~/" being a shortcut to the current home directory on posix systems(bsd/linux).
its not working with the build in open() function open:

It works to get the path as a string:
    with open(str(Path.home())+'/.hey', wb') as minfil:                                                       
        minfil.write(nycklen)
        
But not out of the box:        
    with open('~/.hey', 'wb') as minfil:
        minfil.write(nycklen)          
 
        
   
However, "~/" is working with os.path modules:   
     os.path.isfile("~/.hey")


Tested with Python 3.6.8
msg345745 - (view) Author: flipchan (flipchan) Date: 2019-06-16 12:09
scratch """
However, "~/" is working with os.path modules:   
     os.path.isfile("~/.hey")

"""
that's not working either
msg345746 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-06-16 12:13
Yes, '~' is not working out of the box and never had. You need to use os.path.expanduser or pathllib.Path.expanduser to get the useable path.
msg345753 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-06-16 12:40
Support for "~" isn't strictly part of the POSIX file system standard, it is a *shell* shortcut. As far as the file system is concerned, "~" is just a regular character like any other.
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81487
2019-06-16 12:40:50steven.dapranosetnosy: + steven.daprano
messages: + msg345753
2019-06-16 12:13:45SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg345746

resolution: not a bug
stage: resolved
2019-06-16 12:09:26flipchansetmessages: + msg345745
2019-06-16 11:56:02flipchancreate