title: Creating files and directories via Python
body: <p>I'm having trouble creating a directory and then opening/creating/writing into a file in the specified directory. The reason seems unclear to me. I'm using os.mkdir() and </p>
  
  <pre><code>path=chap_name
  print "Path : "+chap_path                       #For debugging purposes
  if not os.path.exists(path):
      os.mkdir(path)
  temp_file=open(path+'/'+img_alt+'.jpg','w')
  temp_file.write(buff)
  temp_file.close()
  print " ... Done"
  </code></pre>
  
  <p>I get the error </p>
  
  <pre>OSError: [Errno 2] No such file or directory: 'Some Path Name'</pre>
  
  <p>Path is of the form 'Folder Name with un-escaped spaces'</p>
  
  <p>What am I doing wrong here?</p>
  
  <hr>
  
  <p>Update: I tried running the code without creating the directory</p>
  
  <pre><code>path=chap_name
  print "Path : "+chap_path                       #For debugging purposes
  temp_file=open(img_alt+'.jpg','w')
  temp_file.write(buff)
  temp_file.close()
  print " ... Done"
  </code></pre>
  
  <p>Still get an error. Confused further.</p>
  
  <hr>
  
  <p>Update 2:The Problem seems to be the img_alt, it contains a '/' in some cases, which makes is causing the trouble.</p>
  
  <p>So I need to handle the '/'.
  Is there anyway to escape the '/' or is deletion the only option?</p>