使用Python test给文件test.html中所有的hello world中间添加一个the

问一个python问题_百度知道
问一个python问题
y=input(&#39.pydev_3;myjava\testHelloWorld.py&quot.&#92?&E, in &;)
File &d&#39, in &plugins&#92, line 3;)
print x&#47,
y=input(&#39:'NameEThat wasnot a number:&#39, in input
return eval(raw_input(prompt))
File &quot: name &#39:\myjava\pysrc\myeclipse2014\The second number cannot be zero&quot.0.0, was it:
print &quot.py&quot:&#39.&
Enter the first number:
x=input(';&except TypeError:2Ent
, line 210;string&helloWorld\E;EnTpydev_sitecustomize&#92:&#92:dTraceback (most recent call last);module&gt:
File &quot, line 1;WorkPlace\testpython\module&myeclipse2014\Ent is not defined为什么输出不是print &yexcept ZeroDivisionEEnter the second number?而是直接红色字体出现异常:
print &quot
提问者采纳
而是NameError在Python2.X下你应该用raw_input来请求输入,而不是input这时候错误已经不是TypeError
input输入不能是字符串吗?
Python2raw_input才是输入字符串Python3input变成了raw_input的功能
提问者评价
来自团队:
其他类似问题
为您推荐:
其他1条回答
&)&y=input('&quotprint&&zero&print&name&the&first&nbsp,&)&That&&NameEsecond&input的输入直接被当成python表达式评估:'&except&&&nbsp?&&variab&the&number&&&nbsp:'a&nbsp:&wasnot&Enter&&nbsp:&&&was&&&&x/yexcept&TypeEnot&&ZeroDivisionEexcept&was&表示字符串;print&print&The&second&&nbsp:&be&a&&&That&nbsp,输入d,就表示变量&&nbsp:&x=input(&#39,输入&Enter&cannot&d&quot
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁write快测试后的结果。可能的原因,具体不是很清楚:print && log_file,"Hello world!\n"是一个重定向形式,是将"Hello world!\n"的值输出到log_file的write方法中,可能这个过程比直接write要多消耗时间吧。
经过测试是write速度更快。&br&具体测试过程如下:&br&&div class=&highlight&&&pre&&code class=&language-python&&&span class=&c&&# -*- coding: utf-8 -*-&/span&
&span class=&kn&&from&/span& &span class=&nn&&time&/span& &span class=&kn&&import&/span& &span class=&n&&clock&/span&
&span class=&k&&def&/span& &span class=&nf&&speedTest&/span&&span class=&p&&(&/span&&span class=&n&&func&/span&&span class=&p&&):&/span&
&span class=&k&&def&/span& &span class=&nf&&_deco&/span&&span class=&p&&():&/span&
&span class=&n&&startTime&/span& &span class=&o&&=&/span& &span class=&n&&clock&/span&&span class=&p&&()&/span&
&span class=&n&&func&/span&&span class=&p&&()&/span&
&span class=&n&&endTime&/span& &span class=&o&&=&/span& &span class=&n&&clock&/span&&span class=&p&&()&/span&
&span class=&k&&print&/span& &span class=&s&&&Cost time is &&/span& &span class=&o&&+&/span& &span class=&nb&&str&/span&&span class=&p&&(&/span&&span class=&n&&endTime&/span& &span class=&o&&-&/span& &span class=&n&&startTime&/span&&span class=&p&&)&/span&
&span class=&k&&return&/span& &span class=&n&&_deco&/span&
&span class=&nd&&@speedTest&/span&
&span class=&k&&def&/span& &span class=&nf&&method1&/span&&span class=&p&&():&/span&
&span class=&k&&with&/span& &span class=&nb&&open&/span&&span class=&p&&(&/span&&span class=&s&&'a.txt'&/span&&span class=&p&&,&/span&&span class=&s&&'w'&/span&&span class=&p&&)&/span& &span class=&k&&as&/span& &span class=&n&&fp&/span&&span class=&p&&:&/span&
&span class=&k&&for&/span& &span class=&n&&x&/span& &span class=&ow&&in&/span& &span class=&nb&&xrange&/span&&span class=&p&&(&/span&&span class=&mi&&1000000&/span&&span class=&p&&):&/span&
&span class=&n&&fp&/span&&span class=&o&&.&/span&&span class=&n&&write&/span&&span class=&p&&(&/span&&span class=&s&&&Hello world!&/span&&span class=&se&&\n&/span&&span class=&s&&&&/span&&span class=&p&&)&/span&
&span class=&nd&&@speedTest&/span&
&span class=&k&&def&/span& &span class=&nf&&method2&/span&&span class=&p&&():&/span&
&span class=&k&&with&/span& &span class=&nb&&open&/span&&span class=&p&&(&/span&&span class=&s&&'b.txt'&/span&&span class=&p&&,&/span&&span class=&s&&'w'&/span&&span class=&p&&)&/span& &span class=&k&&as&/span& &span class=&n&&fp&/span&&span class=&p&&:&/span&
&span class=&k&&for&/span& &span class=&n&&x&/span& &span class=&ow&&in&/span& &span class=&nb&&xrange&/span&&span class=&p&&(&/span&&span class=&mi&&1000000&/span&&span class=&p&&):&/span&
&span class=&k&&print&/span& &span class=&o&&&&&/span& &span class=&n&&fp&/span&&span class=&p&&,&/span& &span class=&s&&&Hello world!&&/span&
&span class=&k&&print&/span& &span class=&s&&&write method:&&/span&
&span class=&n&&method1&/span&&span class=&p&&()&/span&
&span class=&k&&print&/span&
&span class=&k&&print&/span& &span class=&s&&&&& method:&&/span&
&span class=&n&&method2&/span&&span class=&p&&()&/span&
&/code&&/pre&&/div&&br&&img src=&/244dabb044cf_b.jpg& data-rawwidth=&277& data-rawheight=&95& class=&content_image& width=&277&&&br&&br&但是需要指出题主的一个问题,就是print是会自己在行末加上一个换行符的。所以测试的时候需要考虑这个误差。&br&&br&至于为什么write更快,在python的官方文档是这么描述的:&br&&br&&blockquote&&a class=& wrap external& href=&///?target=https%3A//docs.python.org/2/reference/simple_stmts.html%23print& target=&_blank& rel=&nofollow noreferrer&&print&i class=&icon-external&&&/i&&/a& also has an extended form, defined by the second portion of the syntax described above. This form is sometimes referred to as “&a class=& wrap external& href=&///?target=https%3A//docs.python.org/2/reference/simple_stmts.html%23print& target=&_blank& rel=&nofollow noreferrer&&print&i class=&icon-external&&&/i&&/a& chevron.” In this form, the first expression after the && must evaluate to a “file-like” object, specifically an object that has a write() method as described above. With this extended form, the subsequent expressions are printed to this file object. If the first expression evaluates to None, then sys.stdout is used as the file for output.&/blockquote&&br&可以看出在在使用&&的时候,python会先验证&&后是不是一个None,如果是的话就使用sys.stdout,这样的话多了验证工作所以速度就慢下来了喵~
经过测试是write速度更快。具体测试过程如下:# -*- coding: utf-8 -*-
from time import clock
def speedTest(func):
def _deco():
startTime = clock()
endTime = clock()
print "Cost time is " + str(endTime - startTime)
return _d…
为什么不自己benchmark一下
为什么不自己benchmark一下
已有帐号?
无法登录?
社交帐号登录使用python给文件test.html中所有的hello world中间添加一个the_百度知道
使用python给文件test.html中所有的hello world中间添加一个the
')+&#39.strip();hello the world&#39:n'.replace(&#39fileopen= open(')for i in fileopen.html'new_test.html'.close()&#92,'w')fileopen.write(hello world')filrout = open(&#39
来自团队:
其他类似问题
为您推荐:
python的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 Python test 的文章

 

随机推荐