Python新手。 [英] New to Python.

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

问题描述



您好!


我刚开始学习python并遇到问题。

我想做的一切,是打开文本文件搜索并计算

单个单词的出现次数并打印该计数。

感谢您的帮助。


Hello!

I have just started learning python and encountered a problem.
All I wanted to do, was to open a text file search and count the
number of occurances of a single word and print that count.
Thanks for help.

推荐答案

2004年3月18日星期四02:53:48 GMT,droog写道:
On Thu, 18 Mar 2004 02:53:48 GMT, droog wrote:
我刚刚开始学习python并遇到了问题。
我想做的就是打开一个文本文件搜索并计算单个单词的出现次数并打印该计数。
感谢您的帮助。
I have just started learning python and encountered a problem.
All I wanted to do, was to open a text file search and count the
number of occurances of a single word and print that count.
Thanks for help.




您能告诉我们您尝试过的代码无法满足您的需求吗?


-

\我永远不会忘记一张脸,但在你的情况下,我很高兴能够做到这一点。

` \是一个例外。 - Groucho Marx |

_o__)|

Ben Finney< http://bignose.squidly.org/>



Can you show us code that you''ve tried that fails to do what you want?

--
\ "I never forget a face, but in your case I''ll be glad to make |
`\ an exception." -- Groucho Marx |
_o__) |
Ben Finney <http://bignose.squidly.org/>


在文章< sg ******************************** @ 4ax.com>中,

droog< dr *** @ orange.gov>写道:
In article <sg********************************@4ax.com>,
droog <dr***@orange.gov> wrote:
你好!

我刚开始学习python并遇到了问题。
我想做的一切,就是打开一个文本文件搜索并计算单个单词的出现次数并打印该计数。
感谢您的帮助。
Hello!

I have just started learning python and encountered a problem.
All I wanted to do, was to open a text file search and count the
number of occurances of a single word and print that count.
Thanks for help.




嗯,我'' ll指向正确的方向。


要打开文件,请使用打开按钮。功能。您可以使用类似for line in file:的内容循环使用

行。根据你究竟如何定义单词,你可能想看看split()字符串方法,或者

可能是一些正则表达式与&相匹配。重新"模块。


那里应该足以让你开始做作业

作业:-)



Well, I''ll point you in the right direction.

To open a file, use the "open" function. You can loop through the lines
with something like "for line in file:". Depending on exactly how you
define "word", you might want to look at the split() string method, or
maybe some regular expression matching with the "re" module.

There, that should be enough to get you started with your homework
assignment :-)

我一直在寻找最简单的方法。这就是我尝试做的



f = open(''C:\Python23 \ Samples \Bob.txt'',' 'r'')

counter = 0

而True:

line = f.readline()

if len(line)== 0:

break

if line.find(''customer''):

counter = counter + 1

打印''找到它''+ str(柜台)


2004年3月18日星期四02:53:48 GMT,droog< dr ***@orange.gov>写道:
I was looking for the simpliest way of doing it. This is what I tried
to do.

f = open(''C:\Python23\Samples\Bob.txt'', ''r'')
counter = 0
while True:
line = f.readline()
if len(line) == 0:
break
if line.find(''customer''):
counter = counter + 1
print ''Found it '' + str(counter)

On Thu, 18 Mar 2004 02:53:48 GMT, droog <dr***@orange.gov> wrote:

你好!

我刚开始学习python并遇到了问题。
我想做的就是打开文本文件搜索并计算单个单词的出现次数并打印该计数。
感谢您的帮助。

Hello!

I have just started learning python and encountered a problem.
All I wanted to do, was to open a text file search and count the
number of occurances of a single word and print that count.
Thanks for help.






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

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