decode command line parameters - recomendend way
Hello I want add full Unicode support in my scripts. Now I have encoutered theoretical problem with command line parameters. I can't find anything in that mater. But I develop solution which seems to work. Question is: Is it recommendend way to decode command line parameters: lFileConfig = None if len(sys.argv) 1: lFileConfig = unicode(sys.argv[1], locale.getpreferredencoding()) Or maybe there is other solution? Jax ps: $ python --version Python 2.5.2 -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode(lString, utf8) vs. lString.encode(utf8) vs. urjakiś tekst
Sorry, my mistake. My interntion was post this message on pl.comp.lang.python. Jax -- http://mail.python.org/mailman/listinfo/python-list
unicode(lString, utf8) vs. lString.encode(utf8) vs. urjakiś tekst
Witam Zakładam, że kod Pythona w drugiej lini ma: # -*- coding: utf-8 -*- oraz gdzieś na początku: reload(sys) sys.setdefaultencoding('utf8') No i mam takie pytania odnośnie unicode w utf8: Czy obie poniższe linie dają ten sam efekt, czyli obiekt unicode zakodowany w utf8? lString = unicode(lString, utf8) lString = lString.encode(utf8) Konkretnie chodzi mi czy aby mieć obiekt unicode zakodowany w utf8 muszę robić coś takiego: lString = unicode(lString.decode(ISO-8859-15).encode(utf8), utf8) czy może wystarczy: lString = lString.decode(ISO-8859-15).encode(utf8) Dodatkowo mam pytanie: Czy aby mieć ze stringu podanego w kodzie pythona obiekt unicode zakodowany w utf8 zawsze muszę robić: lString = unicode(jakiś tekst, utf8) czy może wystarczy lString = urjakiś tekst Pytam, bo ciągłe klepanie unicode(xxx, utf8) jest męczące. z góry dzięki Jax -- http://mail.python.org/mailman/listinfo/python-list
regular expresions and dolar sign ($) in source string
Hi I encountered problem with dolar sign in source string. It seems that $ require special threatening. Below is copy of session with interactive Python's shell: Python 2.5.2 (r252:60911, Jan 8 2009, 12:17:37) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. import re a = unicode(r(instead of $399.99), utf8) print re.search(unicode(r^\(instead of.*(\d+[.]\d+)\)$, utf8), a).group(1) 9.99 print re.search(unicode(r^\(.*(\d+[.]\d+)\)$, utf8), a).group(1) 9.99 print re.search(unicode(r^\(.*\$(\d+[.]\d+)\)$, utf8), a).group(1) 399.99 My question is: Why only third regular expression is correct? Please help! It boggles my mind. Jax -- http://mail.python.org/mailman/listinfo/python-list