打印不是一个功能 [英] print is not a function
问题描述
通常需要打印出列表中的项目。
[prt(x) for my in my_list]
这样会很好,除了prt()不存在,而print是一个
语句而不是函数,因此不能替换prt如上所述。
我不喜欢写d
def prt(x):
print x
事先并且任何lambda构造都不会那么方便。
它应该是一个简短的单行。
任何想法?
Karl
2003年10月8日星期三11:32:20 +0200,卡尔Scalet< ne ** @ yebu.de>写道:
经常需要打印出列表中的项目。
[prt (x)for my in my_list]
这将是不错的,除了prt()不存在,并且print是
语句而不是函数,因此不能替换上面的prt。
我不想事先写好
def prt(x):
打印x
任何lambda构造都不会那么方便。它应该是一个简短的单行。
任何想法?
Karl
怎么样,
import sys
sys.stdout.write(" Hello world!\ n")
你好,世界!
help(sys)
[text snipped]
stdin - 标准输入文件对象;由raw_input()和
输入使用()
stdout - 标准输出文件对象;打印声明使用
stderr - 标准错误对象;用于错误消息
通过为这些对象分配其他文件对象(或行为类似
文件的对象)
,可以重定向所有文件对象翻译的'
I / O.
[文字继续]
希望它有所帮助,我最诚挚的问候,
G. Rodrigues
Gon?alo Rodrigues写道:
10月8日星期三2003 11:32:20 +0200,Karl Scalet< ne ** @ yebu.de>写道:
经常需要打印清单中的项目。
[prt(x)for my in my_list]
这样会很好,除了prt()不存在,而print是
语句而不是函数,因此无法替换prt如上所述。
我不想事先写下
def prt(x):
打印x
任何lambda构造都不会如此方便。
应该是一个简短的单行。
任何想法?
Karl
怎么样,
import sys
sys.stdout.write(" Hello world!\ n")
我遇到过这个,但这需要一个额外的导入系统
并不总是存在,谢谢无论如何。
Karl
Karl Scalet写道:
... > sys.stdout.write(" Hello world!\ n")
我碰到了这个,但这需要一个额外的导入系统
并不总是存在,谢谢无论如何。
啊,在我之前没见过这个回答了你的另一篇文章。
好吧。复制
a *内置*功能中的打印语句功能,让你滥用列表理解
的副作用并扔掉结果只是不能
会发生。内置函数是(或者应该是:那里可能会在Python 3.0中清除
)只是为了那么重要的任务
并且普遍认为''import''不能被视为。
Alex
Hi,
quite often there is a need to just print out the items of a list.
[ prt(x) for x in my_list ]
that would be nice, except prt() does not exist, and print is a
statement not a function, hence cannot replace prt as of above.
I don''t like to write d
def prt(x):
print x
beforehand and any lambda construct would not be so handy.
It should be a short one-liner.
Any ideas?
Karl
On Wed, 08 Oct 2003 11:32:20 +0200, Karl Scalet <ne**@yebu.de> wrote:
Hi,
quite often there is a need to just print out the items of a list.
[ prt(x) for x in my_list ]
that would be nice, except prt() does not exist, and print is a
statement not a function, hence cannot replace prt as of above.
I don''t like to write d
def prt(x):
print x
beforehand and any lambda construct would not be so handy.
It should be a short one-liner.
Any ideas?
Karl
How about,
import sys
sys.stdout.write("Hello world!\n") Hello world! help(sys)
[text snipped]
stdin -- standard input file object; used by raw_input() and
input()
stdout -- standard output file object; used by the print statement
stderr -- standard error object; used for error messages
By assigning other file objects (or objects that behave like
files)
to these, it is possible to redirect all of the interpreter''s
I/O.
[text continues]
Hope it helps, with my best regards,
G. Rodrigues
Gon?alo Rodrigues wrote:
On Wed, 08 Oct 2003 11:32:20 +0200, Karl Scalet <ne**@yebu.de> wrote:Hi,
quite often there is a need to just print out the items of a list.
[ prt(x) for x in my_list ]
that would be nice, except prt() does not exist, and print is a
statement not a function, hence cannot replace prt as of above.
I don''t like to write d
def prt(x):
print x
beforehand and any lambda construct would not be so handy.
It should be a short one-liner.
Any ideas?
Karl
How about,import sys
sys.stdout.write("Hello world!\n")
I came across this, but this requires an extra import sys
which not always is there, thanks anyhow.
Karl
Karl Scalet wrote:
...>sys.stdout.write("Hello world!\n")
I came across this, but this requires an extra import sys
which not always is there, thanks anyhow.
Ah, hadn''t seen this before I answered your other post.
Well. duplicating the print statement functionality in
a *built-in* function to let you abuse a list comprehemsion
for the side effects and throw away the results just ain''t
gonna happen. Built-in functions are (or should be: there
may well be purges in Python 3.0) just for tasks so important
and widespread that an ''import'' cannot be considered.
Alex
这篇关于打印不是一个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!