Pythonos.popen公司和联通

2024-06-01 09:20:01 发布

您现在位置:Python中文网/ 问答频道 /正文

在PC上使用法语(4.4)

for line in os.popen('dir'): print(line.rstrip())

我如期到达第一行

Le volume dans le lecteur C s'appelle SYSTEME

但对于第二个(用é

Le numéro de série du volume est C250-47DD

我收到错误消息:

^{pr2}$

我能做什么? 提前谢谢你的帮助


Tags: inleforosdirlineprintpopen
1条回答
网友
1楼 · 发布于 2024-06-01 09:20:01

在打印之前,您需要通过正确的编码对行进行编码:

for line in os.popen('dir'): 
      print(line.rstrip().encode('UTF-8')) # as utf8 is a universal encoding i use it you can use another too

相关问题 更多 >