title: Valid characters in a python class name
body: <p>I'm dynamically creating python classes, and I know not all characters are valid in this context. </p>
  
  <p>Is there a method somewhere in the class library that I can use to sanitize a random text string, so that I can use it as a class name? Either that or a list of the allowed characters would be a good help.</p>
  
  <hr>
  
  <p><strong>Addition regarding clashes with identifier names:</strong> Like @Ignacio pointed out in the answer below, any character that is <a href="http://docs.python.org/reference/lexical_analysis.html#identifiers" rel="noreferrer">valid as an identifier</a> is a valid character in a class name. And you can even use a <a href="http://docs.python.org/reference/lexical_analysis.html#keywords" rel="noreferrer">reserved word</a> as a class name without any trouble. But there's a catch. If you do use a reserved word, you won't be able to make the class accessible like other (non-dynamically-created) classes (e.g., by doing <code>globals()[my_class.__name__] = my_class</code>). The reserved word will always take precedence in such case. </p>