在Python的read()方法(python 2.7)中找不到任何信息 [英] Can't find any info on Python's read() method (python 2.7)

查看:294
本文介绍了在Python的read()方法(python 2.7)中找不到任何信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Python,通过Zed Shaw的学习Python的艰难的方式,我被困在可能看起来像一个非常微不足道的事情。我无法在.read()方法上找到任何信息。这是他在书中所说的:

I'm trying to learn Python by going through Zed Shaw's "Learn Python the hard way" and I'm stuck at what may seem as a very trivial thing. I'm unable to find any info on the .read() method. This is what he says in the book:


运行pydoc文件并向下滚动直到看到.read()命令(方法/函数)。
看到你可以使用的所有其他的?跳过在
前面有__(两个下划线)的那些,因为那些是垃圾。尝试一些其他命令。

Run pydoc file and scroll down until you see the .read() command (method/function). See all the other ones you can use? Skip the ones that have __ (two underscores) in front because those are junk. Try some of the other commands.

如果我调用 python -m pydoc 我只收到有关 pydoc.py pydoc.py -k pydoc.py -p pydoc.py -g pydoc.py -w

If I call python -m pydoc I only get a very short list of information regarding pydoc.py, pydoc.py -k, pydoc.py -p, pydoc.py -g, and pydoc.py -w

当我尝试调用 python -m pydoc read 我收到以下消息:

When I tried calling python -m pydoc read I got the following message:


没有找到read的Python文档

no Python documentation found for 'read'

是默认情况下嵌入Python中的 .read 方法,还是先要导入?我应该注意到我在Windows 7上使用Powershell。这里可能是什么问题?

Is the .read method embedded in Python by default or does it have to be imported first? I should note that I'm using Powershell on Windows 7. What could be the problem here?

推荐答案

读取是文件对象的一种方法。使用:

read is a method on file objects. Use:

python -m pydoc file

获取文件对象的文档。请注意,这正是这本书告诉你要做的,但它似乎留下了文件参数。

to get the documentation for file objects. Note that this is exactly what the book told you to do, but it appears you left of the file argument.

或者,请求方法:

python -m pydoc file.read

然而,官方文档更加丰富和实用。请参阅有关文件对象 的文档例如。

The official documentation, however, is far richer and useful. See the documentation on File Objects for example.

这篇关于在Python的read()方法(python 2.7)中找不到任何信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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