1

i am confused..

i just start learning python i created a file using command line and when i execute it ... it through error..

command i use are

PS E:\python\mystuff> echo /n > test.py
PS E:\python\mystuff> type test.py
PS E:\python\mystuff> start 'C:\Program Files (x86)\Notepad++\notepad++.exe' .\test.py

file

then i edit it and print some stuff .. and when i run it .. it through error file test.py print ("hello world") print "this is pyrhon"

SyntaxError: Non-ASCII character '\xff' in file test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

after a while i run python and print those thinks .. it work well ... then i create a file ex1.py without command.. it works ... why the file i created using command line is not working and how do i solve it... i am very new to python and powershell .. i just start learning ... please help

1 Answer 1

2

When checking the url in the error message (https://www.python.org/dev/peps/pep-0263/), it confirms my suspicion that Python doesn't handle a Unicode file well.

You can either apply the fixes mentioned on that page, or you can enforce an ASCII encoding on your file from within Powershell:

"" | Out-File ".\test.py" -Encoding ascii

This replaces the echo /n command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.