Python under PowerShell adds characters

Chris Angelico rosuav at
Wed Mar 29 14:09:33 EDT 2017

On Thu, Mar 30, 2017 at 4:42 AM, Jay Braun <lyngwyst at> wrote:
> Consider the following simple script named (Python 2.7):
> print "Hello"
> If I enter:
> python > out.txt
> from cmd.exe I get a 6-character file (characters plus new-line).
> from PowerShell I get an extract ^@ character after every character

Sounds like cmd and PS are setting the output encodings differently.
Does the same thing occur with Python 3.6?

Try adding this to your script:

import sys

and run it in the same two environments (no redirection needed). Do
they give you the same thing?

My suspicion is that you're running cmd.exe in the default Windows
console, and PowerShell in some different console. But it's hard to be


More information about the Python-list mailing list