Q
在Python
0
A
回答
2
您可以使用re模塊替換不可打印的符號,但這可能無法解決您在此處遇到的問題。 DBF是一種二進制文件格式,其中有很多非ascii字符。
import re
ascii_sym_re = re.compile(r'[\x00-\x09\x0b-\x1f\x7f-\xff]', re.DOTALL|re.MULTILINE)
print ascii_sym_re.sub('.', 'hello\x1athere')
with open('somefile','rb') as fp_in, open('somefile-scrubbed', 'wb') as fp_out:
fp_out.write(ascii_sym_re.sub('.', fp_in.read())
相關問題
- 1. 的Python:在Python
- 2. 的Python:在Python
- 3. 在python sum()python
- 4. Python代碼在python
- 5. 在Python
- 6. 在Python
- 7. 在Python
- 8. 在Python
- 9. 在Python
- 10. 在Python
- 11. 在Python
- 12. 在Python
- 13. 在Python
- 14. 在Python
- 15. 在Python
- 16. 在Python
- 17. 在python
- 18. 在Python
- 19. 在Python
- 20. 在Python
- 21. 在Python
- 22. 在Python
- 23. 在Python
- 24. 在python
- 25. 在Python
- 26. 在python
- 27. 在Python
- 28. 在Python
- 29. 在python
- 30. 在Python
您是否試過在二進制模式下打開文件呢? – 2014-10-30 14:24:48
Python不會將\ x1a作爲文件結束標記。你必須使用某種類型的dbf解析器,這就是有問題的代碼。你能給我們提供更多關於你正在使用的細節嗎? – tdelaney 2014-10-30 15:43:07
@ IgnacioVazquez-Abrams--文本模式改變了行尾,但是隻留下其他字符。 \ x1a不應該受到影響。 – tdelaney 2014-10-30 15:46:57