title: Python: Use an import done inside of a class in a function
body: <p>Can anyone explain how to make the following example work?  Since several functions inside of the class will use the same function from platform I thought it would be better to import it right inside of the class, but I don't see how I can use it inside of the function (since I constantly get errors about it).</p>
  
  <pre><code>#!/usr/bin/python
  
  class test:
     from platform import system
     is_linux(self):
        system = system()
        if system == "Linux": return True
  </code></pre>
  
  <p>A better example:</p>
  
  <pre><code>#!/usr/bin/python
  
  # Add ANSI colour strings
  class stdout:
      from sys import stdout
      def message(message, self):  stdout.write(message)
  </code></pre>
  
  <p>Note: This is just a snippet, there are some parts missing but an example of what I mean.<br >
  I know I could probably just move <code>system = system()</code> and use self.system but perhaps a better way?</p>