\\\\ n或\ n记事本编辑器结束行??? [英] \r\n or \n notepad editor end line ???

查看:86
本文介绍了\\\\ n或\ n记事本编辑器结束行???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我使用Windows记事本编辑器来编写文本。


例如我写的(在d:\ myfile中。 txt):

Helo

世界

如果我用python打开它:

FName =打开(d:\ myfile.txt,''r'')

h = FName.readlines()

打印h


我得到h:[''Helo \ n'',''世界'']


我以为记事本使用\\\\ n来结束这一行。


这有什么问题?


pujo

Hello,

I use windows notepad editor to write text.

For example I write (in d:\myfile.txt):
Helo
World

If I open it with python:
FName = open(d:\myfile.txt,''r'')
h = FName.readlines()
print h

I get h : [''Helo\n'', ''World'']

I thought notepad use \r\n to to end the line.

What''s wrong with it?

pujo

推荐答案

aj****@gmail.com 写道:
你好,

我使用Windows记事本编辑器来编写文本。

例如我写的(在d:\ myfile.txt中):
Helo
世界

如果我用python打开它:
FName = open(d:\ myfile.txt,''r'')
h = FName.readlines()<打印h

我得到了h: [''Helo \ n'','''世界''

我以为记事本用\\ n来结束这条线。

什么'错了吗?
Hello,

I use windows notepad editor to write text.

For example I write (in d:\myfile.txt):
Helo
World

If I open it with python:
FName = open(d:\myfile.txt,''r'')
h = FName.readlines()
print h

I get h : [''Helo\n'', ''World'']

I thought notepad use \r\n to to end the line.

What''s wrong with it?



Python试图变得聪明。以二进制模式打开它以避免它:


FName = open(d:\ myfile.txt,''rb'')

-


hilsen /问候丹麦Max M

http://www.mxm.dk/

IT的疯狂科学


Python tries to be clever. Open it in binary mode to avoid it:

FName = open(d:\myfile.txt,''rb'')
--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT''s Mad Science


2005年6月8日06:24:05 -0700, aj****@gmail.com < aj **** @ gmail.com> ;写道:
On 8 Jun 2005 06:24:05 -0700, aj****@gmail.com <aj****@gmail.com> wrote:
你好,

我使用windows notepad编辑器来编写文本。

例如我写的(在d:\ myfile.txt中) ):
Helo
世界

如果我用python打开它:
FName = open(d:\ myfile.txt,''r'')
h = FName.readlines()
打印h

我得到h:[''Helo \''',''世界''

我以为记事本用\\ n来结束这条线。

它出了什么问题?
Hello,

I use windows notepad editor to write text.

For example I write (in d:\myfile.txt):
Helo
World

If I open it with python:
FName = open(d:\myfile.txt,''r'')
h = FName.readlines()
print h

I get h : [''Helo\n'', ''World'']

I thought notepad use \r\n to to end the line.

What''s wrong with it?




在Windows上,在文件类型参数中打开一个没有''b''的文件确实会有一些你可能没想到的事情,包括将/ r / n更改为/ n。尝试:



On windows, opening a file without ''b'' in the file type argument does
some things you might not expect, including changing /r/n to /n. Try:

f = file(''d:/deteteme.txt'',''rb'' )
f.read()
''testing\r\\\
1\r\\\
2\r\\\
3''f = file(''d:/deleteme.txt' ',''r'')
f.read()
f = file(''d:/deleteme.txt'', ''rb'')
f.read() ''testing\r\n1\r\n2\r\n3'' f = file(''d:/deleteme.txt'', ''r'')
f.read()



''testing\\\
1\\\
2\\\
3' '


和平

Bill Mill

bill.mill at gmail.com


''testing\n1\n2\n3''

Peace
Bill Mill
bill.mill at gmail.com

大家好,谢谢大家,


这意味着在Windows中我们应该使用''wb''来写和''rb''来阅读?
$ b $我是对的吗?


pujo

Hello thanks everyone,

It means in windows we should use ''wb'' to write and ''rb'' to read ?
Am I right?

pujo


这篇关于\\\\ n或\ n记事本编辑器结束行???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆