print is not a function
Karl Scalet
news at yebu.de
Wed Oct 8 07:16:55 EDT 2003
Alex Martelli wrote:
> 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
>
Thank you for the answers.
I did not realize that taking only "the half of list comprehension"
is a misuse of it. That would mean list comprehension always "claim"
to be assigned to a variable. But why?
if i *had* a function doing any meaningful with the iterated values
by itstelf, why bother with the returned list.
Ex:
ignore = [ add_to_db(x) for x in my_list if x[:4]=='Hans']
Looks at least as nice to me as
for x in my_list:
if x[:4]=='Hans':
add_to_db(x)
But there might be reasons one prefers the for loop.
Back to my original desire:
I of course did not request to add a new funciton to
python built ins, I was just asking, if I miss a nice
idea to do the trick :-)
sys.stdout.write has the drawbacks:
- need to import sys, well....
- does no newline automatically, like print
- only handles strings
Again, no real pain all that :-)
Karl
More information about the Python-list
mailing list