Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lost with encodings (shell and accents)
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- def rlinput(prompt, prefill=''):
- readline.set_startup_hook(lambda: readline.insert_text( prefill))
- try:
- return raw_input(prompt)
- finally:
- readline.set_startup_hook()
- while to_continue :
- to_continue, feedback = action( unicode(rlinput(u'todo > '),'utf-8') )
- os.system('clear')
- print T, u"n" + feedback
- class Task()
- ...
- def __str__(self):
- r = (u"OK" if self._done else u"A faire").ljust(8) + self.getDesc()
- return r.encode('utf-8')
- feedback = jaune + str(t).decode('utf-8') + vert + u" supprimée"
- $ file --mime-encoding todo_shell.py task.py todo.py
- todo_shell.py: utf-8
- task.py: utf-8
- todo.py: utf-8
- $ echo $LANG
- fr_FR.UTF-8
- $ python -c "import sys; print sys.stdin.encoding"
- UTF-8
- def rlinput(prompt, prefill=''):
- readline.set_startup_hook(lambda: readline.insert_text( prefill.encode(sys.stdin.encoding) ))
- try:
- return raw_input( prompt ).decode( sys.stdin.encoding )
- finally:
- readline.set_startup_hook()
Add Comment
Please, Sign In to add comment