EOF [英] eof

查看:101
本文介绍了EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个文件句柄f,是否已经达到了
的EOF。这样做的方法是什么?我不想尝试/除了EOF,我想在我读完一行后检查现在我们处于EOF状态。

在Ruby中它的含义是:


在Ruby中:


> f = File.open(" jopa")



=#< File:jopa>


> f.read()



=jopa \ n


> f.eof



=真的


是否有Python类似物?


干杯,

Alexy

解决方案

嗨勇敢,


2007年11月21日星期三15:17:14 -0800(太平洋标准时间),勇敢的

< de ********* @ gmail.comwrote:


>我想检查一下文件句柄f,已经达到了EOF。这样做的方法是什么?我不想尝试/除了EOF,我想在我读完一行后检查现在我们处于EOF状态。



检查参考手册比在这里询问更好。如果你有
有PythonWin 2.5.1(r251:54863,2007年5月1日,17:47:05)[MSC v.1310

32 bit(Intel)] on win32.例如,使用Help,Index,eof给出:


eof

用于确定文件结尾的令牌。这将在非POSIX模式下设置为空的

字符串('''),在POSIX模式下设置为None。

版本2.3中的全新内容。


如果你不使用Active State Python - 甚至你做的话 - 它有助于

有这三个官方的方便的参考:


===
http://docs.python.org/ref/ref.html

Python参考手册

Guido van Rossum


Python软件基金会

电子邮件:执行** @ python.org


Fred L. Drake,Jr。,编辑


Release 2.5

2006年9月19日

===
http:// docs .python.org / lib / lib.html


Python库参考

Guido van Rossum


Python软件基金会

电子邮件: do**@python.org


Fred L. Drake,Jr.,编辑


发布2.5

2006年9月19日

===
http://docs.py thon.org/tut/tut.html

Python教程

Guido van Rossum


Python软件基金会

电子邮件: do**@python.org


Fred L. Drake,Jr.,编辑


发布2.5

2006年9月19日

===


本教程提供了更简单的解释和示例,包括:


7.输入和输出

7.2.1方法文件对象


>> f.read()



''这是整个文件。\''


>> f.read()



''''< br $>
===


如果到达文件末尾,f .read()将返回一个空的

字符串("")。


浏览索引或TOC,或者搜索或猜测你应该

得出你想要的结论


3.9文件对象


那里,并检查EOF你会注意到read([size])和

readline([size])包括:


"只返回一个空字符串当遇到EOF时

立即。


HTH?


>在Ruby中它是f.eof:



在这里谈论Ruby也不好 - 也不是Perl。如果需要

,请参阅C / C ++。


wwwayne


> ;在Ruby中:


>> f = File.open(" jopa")


=#< File:jopa>


>> f.read()


= " jopa\\\
"


>> f.eof


= true

是否有Python类似物?

干杯,
Alexy


11月22日,3:41 am,Wayne Brehaut< wbreh ... @ mcsnet.cawrote:


如果你有PythonWin 2.5.1(r251:54863,2007年5月1日)在win32上使用帮助,索引,eof给出了:[MSC v.1310

32位(英特尔)]。


eof

令牌用于确定文件结束。这将在非POSIX模式下设置为空的

字符串('''),在POSIX模式下设置为None。

版本2.3中的全新内容。


如果你不使用Active State Python - 甚至你做的话 - 它有助于

有这三个官方的方便的参考:

如果到达文件的末尾,f.read()将返回一个空的
字符串("")。


3.9文件对象


那里,并检查EOF你会注意到read([size])和

readline([size])包括:


"只返回一个空字符串当遇到EOF时立刻就会花费



HTH?



不!我不想自己缓冲输入,也不想存储预付款并将其推回原处。 f.read()/ readline()不是非破坏性的检查,因此不会这样做。


在Ruby中它的f.eof:



在这里谈论Ruby也不好 - 也不是Perl。如果需要

,请参阅C / C ++。



好​​的人总是比较脚本语言,而且Ruby确实比C ++更接近Python。由于Ruby可以执行f.eof,这很容易在其引用中找到,而且不可能,或者它的EOF不能轻易找到
- - 一个*相当于*一个语义上清晰的

Ruby',或Pascal'的IIRC,f.eof - 这里缺少的东西......


为什么我必须计算读取行的大小并将其与某些

文件大小进行比较或做其他奇怪的技巧只是为了看,以不改变的方式

我的输入流,是否在,好吧,EOF?


干杯,

Alexy

< br>

2007-11-21,braver< de ********* @ gmail.comwrote:


I''我想检查文件句柄f是否已经达到了
它的EOF。这样做的方法是什么?我不想尝试/除了EOF,我想在我读完一行后检查现在我们处于EOF状态。

在Ruby中它的含义是:


在Ruby中:


>> f = File.open(" jopa")


=#< File:jopa>


>> f.read()


= " jopa\\\
"


>> f.eof


= true


是否有Python模拟?



是。


>> f =文件(''jopa'')
f.read()



''jopa \ n''


....而且在Ruby和Python中你都是EOF的定义。

没有必要检查。


-

Neil Cerutti


I''d like to check, for a filehandle f, that EOF has been reached on
it. What''s the way to do it? I don''t want to try/except on EOF, I
want to check, after I read a line, that now we''re in the EOF state.
In Ruby it''s f.eof:

In Ruby:

>f = File.open("jopa")

=#<File:jopa>

>f.read()

="jopa\n"

>f.eof

=true

Is there a Python analog?

Cheers,
Alexy

解决方案

Hi braver,

On Wed, 21 Nov 2007 15:17:14 -0800 (PST), braver
<de*********@gmail.comwrote:

>I''d like to check, for a filehandle f, that EOF has been reached on
it. What''s the way to do it? I don''t want to try/except on EOF, I
want to check, after I read a line, that now we''re in the EOF state.

It would be nicer to check the reference manual than ask here. If you
have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310
32 bit (Intel)] on win32.for example, using Help, Index, eof gives:

eof
Token used to determine end of file. This will be set to the empty
string (''''), in non-POSIX mode, and to None in POSIX mode. New in
version 2.3.

If you don''t use Active State Python--and even of you do--it helps to
have these three "official" references handy:

===
http://docs.python.org/ref/ref.html

Python Reference Manual
Guido van Rossum

Python Software Foundation
Email: do**@python.org

Fred L. Drake, Jr., editor

Release 2.5
19th September, 2006
===
http://docs.python.org/lib/lib.html

Python Library Reference
Guido van Rossum

Python Software Foundation
Email: do**@python.org

Fred L. Drake, Jr., editor

Release 2.5
19th September, 2006
===
http://docs.python.org/tut/tut.html

Python Tutorial
Guido van Rossum

Python Software Foundation
Email: do**@python.org

Fred L. Drake, Jr., editor

Release 2.5
19th September, 2006
===

The tutorial gives simpler explanations and examples, including:

7. Input and Output
7.2.1 Methods of File Objects

>>f.read()

''This is the entire file.\n''

>>f.read()

''''
===

If the end of the file has been reached, f.read() will return an empty
string ("").

By browsing the index or TOC, or searching, or guessing, you should
conclude that you want

3.9 File Objects

There, and checking for "EOF" you''ll note that both read( [size]) and
readline( [size]) include:

"An empty string is returned only when EOF is encountered
immediately."

HTH?

>In Ruby it''s f.eof:

It also is not nice to talk Ruby here--nor Perl. Refer to C/C++ if
necessary.

wwwayne

>
In Ruby:

>>f = File.open("jopa")

=#<File:jopa>

>>f.read()

="jopa\n"

>>f.eof

=true

Is there a Python analog?

Cheers,
Alexy


On Nov 22, 3:41 am, Wayne Brehaut <wbreh...@mcsnet.cawrote:

If you have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310
32 bit (Intel)] on win32.for example, using Help, Index, eof gives:

eof
Token used to determine end of file. This will be set to the empty
string (''''), in non-POSIX mode, and to None in POSIX mode. New in
version 2.3.

If you don''t use Active State Python--and even of you do--it helps to
have these three "official" references handy:
If the end of the file has been reached, f.read() will return an empty
string ("").

3.9 File Objects

There, and checking for "EOF" you''ll note that both read( [size]) and
readline( [size]) include:

"An empty string is returned only when EOF is encountered
immediately."

HTH?

Nope! I don''t want to buffer input myself, and don''t want to store
look-ahead and push it back. f.read()/readline() is not a non-
destructive check, and thus won''t do.

In Ruby it''s f.eof:


It also is not nice to talk Ruby here--nor Perl. Refer to C/C++ if
necessary.

Well folks compare scripting languages all the time, and surely Ruby
is closer to Python than C++. Since Ruby can do f.eof, which is
easily found in its references, and Python can''t, or its EOF can''t
easily be found -- the one *equivalent* to a semantically clear
Ruby''s, or Pascal''s IIRC, f.eof -- something''s missing here...

Why do I have to count sizes of lines read and compare it to some
filesize or do other weird tricks just to see, in a way not changing
my input stream, whether it''s at the, well, EOF?

Cheers,
Alexy


On 2007-11-21, braver <de*********@gmail.comwrote:

I''d like to check, for a filehandle f, that EOF has been reached on
it. What''s the way to do it? I don''t want to try/except on EOF, I
want to check, after I read a line, that now we''re in the EOF state.
In Ruby it''s f.eof:

In Ruby:

>>f = File.open("jopa")

=#<File:jopa>

>>f.read()

="jopa\n"

>>f.eof

=true

Is there a Python analog?

Yes.

>>f = file(''jopa'')
f.read()

''jopa\n''

....and in both Ruby and Python you are at EOF by definition.
There''s no need to check.

--
Neil Cerutti


这篇关于EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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