Copy and pasting code into the Python interpreter

Posted by wpeters on Stack Overflow See other posts from Stack Overflow or by wpeters
Published on 2010-03-23T15:34:15Z Indexed on 2010/03/25 8:23 UTC
Read the original article Hit count: 208

Filed under:
|

There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a file.

This is just an small example but if there is a lot of code I would like to avoid typing everything from the definition of the function or copy and pasting line by line.

class bcolors: 
    HEADER = '\033[95m' 
    OKBLUE = '\033[94m' 
    OKGREEN = '\033[92m' 
    WARNING = '\033[93m' 
    FAIL = '\033[91m' 
    ENDC = '\033[0m' 

    def disable(self):  
        self.HEADER = '' # I think stuff gets mangled because of the extra level of indentation 
        self.OKBLUE = '' 
        self.OKGREEN = '' 
        self.WARNING = '' 
        self.FAIL = '' 
        self.ENDC = ''

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner