title: How to convert users input to file path in Python
body: <p>I am currently trying to get the file_path (suppose ~/hello_world/) as user input and list all the files inside this directory. I can do this exact same thing if I pass ~/hello_world as sys.argv however, I can't seem to get it work if I take it as an input. I am trying to work the code from any directory and user inputted file path will be from /home/ubunut/...
  Here's my working code as sys.argv:</p>
  
  <p>This code is intended for unix based os only for now.</p>
  
  <pre><code>if len(sys.argv) == 2:
      path = sys.argv[1]
  
  files = os.listdir(path)
  for name in files:
      print(name)
  </code></pre>
  
  <p>Here's the code I am trying to work with:</p>
  
  <pre><code>path = input("file_path: ")
  files = os.listdir(path)
  for name in files:
      print(name)
  </code></pre>
  
  <p>This is when it crashed with the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 14, in &lt;module&gt;
      files = os.listdir(path)
  FileNotFoundError: [Errno 2] No such file or directory: '~/hello_world/'
  </code></pre>
  
  <p>Thanks in advance.</p>