Python: Which encoding is used for processing sys.argv?
        Posted  
        
            by 
                EOL
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by EOL
        
        
        
        Published on 2010-10-25T07:23:47Z
        Indexed on 
            2011/01/10
            1:53 UTC
        
        
        Read the original article
        Hit count: 622
        
What encoding are the elements of sys.argv in, in Python?  are they encoded with the sys.getdefaultencoding() encoding?
sys.getdefaultencoding(): Return the name of the current default string encoding used by the Unicode implementation.
PS: As pointed out in some of the answers, sys.stdin.encoding would indeed be a better guess.  I would love to see a definitive answer to this question, though, with pointers to solid sources!
PPS: As Wim pointed out, Python 3 solves this issue by putting str objects in sys.argv (if I understand correctly).  The question remains open for Python 2.x, though.  Under Unix, the LC_CTYPE environment variable seems to be the correct thing to check, no?  What should be done with Windows (so that sys.argv elements are correctly interpreted whatever the console)?
© Stack Overflow or respective owner