code_junkie

Python's os.path choking on Hebrew filenames

Nov 14th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. files = os.listdir('test_source')
  2.  
  3. for f in files:
  4. pf = os.path.join('test_source', f)
  5. print pf, os.path.exists(pf)
  6.  
  7. test_sourceex True
  8. test_sourcejoe True
  9. test_sourcemie.txt True
  10. test_source__()'''.txt True
  11. test_source????.txt False
  12.  
  13. files = os.listdir(u'test_source')
  14.  
  15. for f in files:
  16.  
  17. pf = os.path.join(u'test_source', f)
  18. print pf.encode('ascii', 'replace'), os.path.exists(pf)
  19.  
  20. test_sourceex True
  21. test_sourcejoe True
  22. test_sourcemie.txt True
  23. test_source__()'''.txt True
  24. test_source????.txt True
  25.  
  26. subdir/bar.txt True
  27. subdir/foo.txt True
  28. subdir/עִבְרִית.txt True
  29.  
  30. for f in os.listdir(u'subdir'):
  31. pf = os.path.join(u'subdir', f)
  32. print pf, os.path.exists(pf)
  33.  
  34. subdir/bar.txt True
  35. subdir/foo.txt True
  36. subdir/עִבְרִית.txt True
  37.  
  38. >>>os.listdir(u'listdir')[2]
  39. u'u05e2u05b4u05d1u05b0u05e8u05b4u05d9u05ea.txt'
Add Comment
Please, Sign In to add comment