Search code examples
pythonemailmaya

email RenderLog with nice formatting


So I'm writing a script in python that dumps a renderlog to a text file and then emails it to the user inside the body of the message.

I'm using the python read like so:

f=open('filename.txt','r')
f.read()

where f is the file instance. The output I get is not very user readable.

'# \'// Warning: Render view: Selected region is too small // \r\ndefaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);\r\nrenderWindowRender redoPreviousRender renderView;\r\n

when I'd much rather have it display like

// Warning: Render view: Selected region is too small //

defaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);

renderWindowRender redoPreviousRender renderView;

Is there a simple way to convert the \r and \n to linebreaks in the email?


Solution

  • As a very quick-and-dirty way, you can use .replace(r'\r\n', '\n'), eg:

    >>> print '# \'// Warning: Render view: Selected region is too small // \r\ndefaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);\r\nrenderWindowRender redoPreviousRender renderView;\r\n'.replace(r'\r\n', '\n')
    # '// Warning: Render view: Selected region is too small // 
    defaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);
    renderWindowRender redoPreviousRender renderView;
    

    The "r" in the r'\r\n' means, that the string should be understood literally contrary to the '\n', which is the actual linebreak.

    (Actually, I don't know what is your platform's linebreak character. Change '\n' accordingly)