Guest User

Untitled

a guest
Aug 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Lost with encodings (shell and accents)
  2. #!/usr/bin/python
  3. # -*- coding: utf-8 -*-
  4.  
  5. def rlinput(prompt, prefill=''):
  6. readline.set_startup_hook(lambda: readline.insert_text( prefill))
  7. try:
  8. return raw_input(prompt)
  9. finally:
  10. readline.set_startup_hook()
  11.  
  12. while to_continue :
  13. to_continue, feedback = action( unicode(rlinput(u'todo > '),'utf-8') )
  14. os.system('clear')
  15. print T, u"n" + feedback
  16.  
  17. class Task()
  18. ...
  19. def __str__(self):
  20. r = (u"OK" if self._done else u"A faire").ljust(8) + self.getDesc()
  21. return r.encode('utf-8')
  22.  
  23. feedback = jaune + str(t).decode('utf-8') + vert + u" supprimée"
  24.  
  25. $ file --mime-encoding todo_shell.py task.py todo.py
  26. todo_shell.py: utf-8
  27. task.py: utf-8
  28. todo.py: utf-8
  29. $ echo $LANG
  30. fr_FR.UTF-8
  31. $ python -c "import sys; print sys.stdin.encoding"
  32. UTF-8
  33.  
  34. def rlinput(prompt, prefill=''):
  35. readline.set_startup_hook(lambda: readline.insert_text( prefill.encode(sys.stdin.encoding) ))
  36. try:
  37. return raw_input( prompt ).decode( sys.stdin.encoding )
  38. finally:
  39. readline.set_startup_hook()
Add Comment
Please, Sign In to add comment