title: How to use pathlib.Path.expanduser() and amend and use a PosixPath value?
body: <p>Below shows how I obtained user1's home directory, create a new sub-directory name and create a new sub-directory there via python 3.6's <code>os</code> module.   </p>
  
  <pre><code>&gt;&gt;&gt; import os.path
  &gt;&gt;&gt; import os
  &gt;&gt;&gt; a = os.path.expanduser('~')
  &gt;&gt;&gt; a
  '/home/user1'
  &gt;&gt;&gt; a_sub_dir = a + '/Sub_Dir_1'
  &gt;&gt;&gt; a_sub_dir
  '/home/user1/Sub_Dir_1'
  &gt;&gt;&gt; def create_sub_dir( sub_dir ):
      try:
          os.makedirs( sub_dir, mode=0o777, exist_ok=False )
      except FileExistsError:
          print('Sub_directory already exist, no action taken.')
      else:
          print('Created sub_directory.')
  &gt;&gt;&gt; create_sub_dir( a_sub_dir )
  Created sub_directory.
  &gt;&gt;&gt; create_sub_dir( a_sub_dir )
  Sub_directory already exist, no action taken.
  </code></pre>
  
  <p>I would like to achieve the same as above via python 3.6's <code>pathlib</code> module. However, I can't seem to get it to work (see below). My questions:</p>
  
  <ol>
  <li>How do I use <code>Path.expanduser()</code>?  </li>
  <li>How do I amend the info in a
  <code>PosixPath(......)</code> since it is not a string so that I can reuse it?</li>
  <li>I would like to amend the PosixPath and use it in my
  <code>make_sub_dir()</code> function. Will it work? Presently, I explicitly
  defined the new sub directory that i want to create to check that my
  <code>make_sub_dir()</code> function works.</li>
  </ol>
  
  <p>Appreciate guidance on how to use pathlib. Thanks in advance.</p>
  
  <pre><code>&gt;&gt;&gt; from pathlib import Path
  &gt;&gt;&gt; b = Path.expanduser('~')
  Traceback (most recent call last):
    File "&lt;pyshell#87&gt;", line 1, in &lt;module&gt;
      b = Path.expanduser('~')
    File "/usr/lib/python3.6/pathlib.py", line 1438, in expanduser
      if (not (self._drv or self._root) and
  AttributeError: 'str' object has no attribute '_drv'
  &gt;&gt;&gt; b = Path.expanduser('~/')
  Traceback (most recent call last):
    File "&lt;pyshell#88&gt;", line 1, in &lt;module&gt;
      b = Path.expanduser('~/')
    File "/usr/lib/python3.6/pathlib.py", line 1438, in expanduser
      if (not (self._drv or self._root) and
  AttributeError: 'str' object has no attribute '_drv'
  &gt;&gt;&gt; b = Path.home()
  &gt;&gt;&gt; b
  PosixPath('/home/user1')
  &gt;&gt;&gt; b_sub_dir = b + '/Sub_Dir_1'
  Traceback (most recent call last):
    File "&lt;pyshell#91&gt;", line 1, in &lt;module&gt;
      b_sub_dir = b + '/Sub_Dir_1'
  TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
  &gt;&gt;&gt; def make_sub_dir( sub_dir ):
      try:
          Path(sub_dir).mkdir(mode=0o777, parents=False, exist_ok=False)
      except FileNotFoundError:
          print('Parent directory do not exist, no action taken.')
      except FileExistsError:
          print('Sub_directory already exist, no action taken.')
      else:
          print('Created sub_directory.')
  &gt;&gt;&gt; make_sub_dir( '/home/user1/Sub_Dir_1' )
  Sub_directory already exist, no action taken.
  &gt;&gt;&gt; make_sub_dir( '/home/user1/Sub_Dir_1' )
  Created sub_directory.
  &gt;&gt;&gt; make_sub_dir( '/home/user1/Sub_Dir_1' )
  Sub_directory already exist, no action taken.
  </code></pre>