找不到关于Python的read()方法(Python 2.7)的任何信息

2024-04-25 05:10:27 发布

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

我试图通过阅读zedshaw的《艰难地学习Python》来学习Python,但我却陷入了一个看似微不足道的问题上。我找不到有关.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.pypydoc.py -kpydoc.py -ppydoc.py -g、和{}的简短列表

当我试图拨打python -m pydoc read时,我收到了以下消息:

no Python documentation found for 'read'

默认情况下,.read方法是嵌入在Python中的,还是必须先导入它?我应该注意我在Windows7上使用的是Powershell。有什么问题吗?在


Tags: andthe方法runpyyou信息read
2条回答

注意Exercise 15中的格式:

  1. Run pydoc file and scroll down until you see the read() command (method/function)...

这不是偶然的;您需要的命令就在这里:

python -m pydoc file
              # ^ note argument

read是一个文件对象的方法。使用:

python -m pydoc file

获取文件对象的文档。请注意,这正是本书告诉您要做的,但它似乎是您离开了file参数。在

或者,只要求方法:

^{pr2}$

然而,官方文件要丰富和有用得多。例如,请参阅有关File Objects的文档。在

相关问题 更多 >