title: how to open a file by passing a variable name which contains the directory where the file is located in python?
body: <p>I'm working on a function where I need to open a file e.g. &quot;hello.txt&quot; by passing a variable name that contains a directory of where the file is located instead of the file name. Below is a dummy code that I have designed for this. In short I need to be able to open a file which is located in that directory by passing a directory name as you can see in updated.</p>
  <pre><code>def folder_things():
  path = 'C:\\Users\\blazh\\Documents\\Vladyslav\\City-Project\\Python\\'
  folder_code = &quot;518Z%&quot;
  updated = path + folder_code
  cwd = os.listdir(updated)
  print(&quot;You have:&quot;, cwd)
  
  st = &quot;&quot;
  for x in cwd:
      st += x
  
  print(st)
  
  # BECOMES A STRING
  str(st)
  print(type(st))
  print(st)
  final = (&quot;'&quot;+st+&quot;'&quot;)
  f = open(st, &quot;r&quot;)
  print(f)
  </code></pre>