Why I don't need to declare encoding when using python interpreter? -


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

i understand line of code necessary when non-ascii characters involved in python script file.

when learning python, told 2 ways of running python code (line line in interpreter vs run script file) yield same result. , do, in cases. when non-ascii characters involved in scripts, turns out have declare encoding first.

moreover, have tried exec() function, trying execute string containing python codes.

>>> exec ("b='你'") 

it works.

but if save "b = '你'" script , run it, syntax error.

i curious why don't need declare encoding when running python codes line line in interpreter.

is there difference in executing procedures of these 2 way?

thank you.

i suppose interactive session of python use system encoding (see python unicode strings , python interactive interpreter).

when read source file, need know how interpret data it's parsing it's logical script not necessary written in same encoding terminal executing it; , more when script ran without environment specifying encoding.

also, interesting read joel spolsky the absolute minimum every software developer absolutely, positively must know unicode , character sets might explain why python choose require developers explicit encoding (which have preferred set default utf8, way coherent zen of python).


Comments

Popular posts from this blog

Upgrade php version of xampp not success -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -