title: Errno 22 invalid mode w+ or filename
body: <pre><code>IOError: [Errno 22] invalid mode ('w+') or filename: 'hodor_2017-05-09_14:03:38.txt'
  </code></pre>
  
  <p>So I was having issues creating a file where as it is "name" [delimiter] "datetime" .txt</p>
  
  <p>I was looking up different bits of code such as:</p>
  
  <p><a href="https://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename">Turn a string into a valid filename?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4182603/python-how-to-convert-a-string-to-utf-8">python: how to convert a string to utf-8</a></p>
  
  <p><a href="https://github.com/django/django/blob/master/django/utils/safestring.py" rel="nofollow noreferrer">https://github.com/django/django/blob/master/django/utils/safestring.py</a></p>
  
  <p>and it still seems to not work for me.</p>
  
  <p>My concept is simple:  given a name and content write a file with that name and that content.</p>
  
  <p>My code is:</p>
  
  <pre><code>def create_json_file(name, contents):
      filename = u"%s_%s.json" % (name, datetime.datetime.now().strftime("%Y/%m/%d_%H:%M:%S"))
      print "%s" % filename
      filename = slugify(filename)
      f = open(filename, "w+")
      f.write(contents)
      f.close()
  </code></pre>
  
  <p>and as you can see i have been tweaking it.  I was looking up the results that django does, which uses slugify.</p>
  
  <p>My original did not have that line.  Maybe there is a better way to name the file too.  I think the name and datetime is pretty normal but i wasnt sure what delimiters I should be using between name and datetime etc.</p>
  
  <p>For the record, I am not currently using Django because i dont have a need for the framework.  I am just trying to test a way to pass in a string and a json map and turn it into a <code>config.json</code> file essentially.</p>
  
  <p>Eventually, I will want to leverage an AJAX request from a website to do this, but that is outside the scope of this question.</p>