utf 8 - Character encoding - copy/paste from web -


this more educational question character encoding (hobbyist coder here) - have encountered specific problem:

1) wrote silly program in python 3, in editor using utf-8 (german keyboard here).

2) share "creation" interested family-members... pasted code private pastebin.com (with instructions: copy/paste (raw) file text-file , change file extension .py)

here trouble starts:

3) following these instructions not allow run program.

4) not sure why doesn't work, since character-encoding ansi know problem. changing encoding utf-8 in code-editor solves problem.

the questions are:

a) why change ansi?

b) why doesn't work anyway in ansi (since eye whole code looks same)

c) how conserve utf-8 encoding? mean: family doesn't know how change encoding... (i know... send them executable file. said... educational)

edit: clarified python-3.x version

when copy paste text editor , press save, that's trouble starts. when saving, must specify encoding, or @ mercy of default "ansi". text file cannot saved without using kind of encoding.

it might not work because have declared # -*- coding: utf-8 -*- in file, text editor saving file in "ansi" has no knowledge of , leave of course. parser try read file utf-8 , fail because it's not utf-8.

you use \uxxxx escapes non-ascii characters in source.

so instead of:

str = u"€" 

do

str = u"\u20ac" 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -