Scripting Tools: Specify file encoding

595
3
Jump to solution
01-19-2022 06:23 PM
AlfredBaldenweck
Regular Contributor

I'm making a scripting tool, and embedding the script in the tool when I'm done.

If I try to edit the script after doing this, I run into this message

AlfredBaldenweck_0-1642645233214.png

The file's encoding is invalid for Python 3.x. IDLE will convert it to UTF-8. What is the current encoding of the file?

I haven't had this pop up at all before, despite doing this same thing with other script tools, including previous versions of this same tool.

The script is just a normal .py file, created in Notepad++

What does this message mean? What do I enter to let me edit it? 

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

did you set the encoding in Notepad ++? and it didn't work?

then load the *.py into plain old Notepad, add the line to the top of the script, then try it in your ide


... sort of retired...

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Add this to the top of your scripts on the first line

# -*- coding: utf-8 -*-

 


... sort of retired...
0 Kudos
AlfredBaldenweck
Regular Contributor

I just tried this and got the same error. Iʻm very confused.

0 Kudos
DanPatterson
MVP Esteemed Contributor

did you set the encoding in Notepad ++? and it didn't work?

then load the *.py into plain old Notepad, add the line to the top of the script, then try it in your ide


... sort of retired...
0 Kudos