<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 19 May 2014 23:25, Emilio J. Rodríguez-Posada <span dir="ltr"><<a href="mailto:emijrp@gmail.com" target="_blank">emijrp@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>When I test my Python script in tools-dev, prints are OK. But when I launch the script with jsub, I receive errors of Unicode:<br>
</div><br>UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 6: ordinal not in range(128)<br>
<br></div>Why does it change among boxes?<br><br></div></div></blockquote><div><br></div><div>There are several reasons for this, but the most important one is output redirection. When writing to a terminal, Python will encode your unicode string with the current terminal encoding, but for a file, Python needs to know which encoding to use.</div>
<div><br></div><div>See <a href="https://bugzilla.wikimedia.org/show_bug.cgi?id=58784">https://bugzilla.wikimedia.org/show_bug.cgi?id=58784</a> for some suggestions. The easiest option is making sure you write bytes to your output (i.e. explicitly .encode('utf-8') the unicode object).</div>
<div><br></div><div>An easy way to test is running </div><div><br></div><div>python scriptname.py | tee</div><div><br></div><div>which should give you the same result as jsub -- apart from environment options. </div></div>
</div></div>