Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Showing and Editing the Content of a File

Avatar image for emru67

emru67 on Jan. 18, 2024

Hi, this is what I get:

PS D:\programming\python\tests\pb_terminal> echo “print(‘Hello, Terminal!’)” > hello_terminal.py

PS D:\programming\python\tests\pb_terminal> cat hello_terminal.py print(‘Hello, Terminal!’)

PS D:\programming\python\tests\pb_terminal> python hello_terminal.py

SyntaxError: Non-UTF-8 code starting with ‘\xff’ in file D:\programming\python\tests\pb_terminal\hello_terminal.py on line 1, but no encoding declared; see peps.python.org/pep-0263/ for details

PS D:\programming\python\tests\pb_terminal> python .\hello_terminal.py

SyntaxError: Non-UTF-8 code starting with ‘\xff’ in file D:\programming\python\tests\pb_terminal\hello_terminal.py on line 1, but no encoding declared; see peps.python.org/pep-0263/ for details

What am I doing wrong? If I get it right is and encoding problem? This is what I found:

Microsoft compilers and interpreters, and many pieces of software on Microsoft Windows such as Notepad (prior to Windows 10 Build 1903[12]) treat the BOM as a required magic number rather than use heuristics. These tools add a BOM when saving text as UTF-8, and cannot interpret UTF-8 unless the BOM is present or the file contains only ASCII. Windows PowerShell (up to 5.1) will add a BOM when it saves UTF-8 XML documents. However, PowerShell Core 6 has added a -Encoding switch on some cmdlets called utf8NoBOM so that document can be saved without BOM. Google Docs also adds a BOM when converting a document to a plain text file for download.(Wikipedia)

But I’m still unsure of what it means and don’t know how to fix it… Thank you

Avatar image for emru67

emru67 on Jan. 19, 2024

My apologies…

I had to download and install Power Shell 7…now it all works as expected…

Sorry

Become a Member to join the conversation.