Thanks,
Vaibhav
Read Guido's words on that:
http://www.python.org/search/hypermail/python-1992/0112.html
Regards.
Adriano.
Vaibhav
print can't be assigned to variables since it's not a funcion, it's part
of the syntax of the language, like `for', `while', etc. and it can't be
assigned to variables, just as those can't be assigned.
If you need a function that prints stuff, consider these two examples:
[snip]
PrintFunc = lambda x: print x
[snip]
Or, a somewhat better solution:
[snip]
import sys
PrintFunc = sys.write
[snip]
py> printfunc = lambda x: print x
Traceback ( File "<interactive input>", line 1
printfunc = lambda x: print x
^
SyntaxError: invalid syntax
See Inappropriate use of Lambda on the Python Wiki[1]. This is also a
horrible idea as it means you can only print a single item:
py> print 1, 2, 3
1 2 3
py> def write(x):
... print x
...
py> write(1, 2, 3)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: write() takes exactly 1 argument (3 given)
py> def write(*args):
... print args
...
py> write(1, 2, 3)
(1, 2, 3)
The print statement has special spacing behavior. You could perhaps
approximate it with something like:
py> def write(*args):
... for arg in args:
... print arg,
... print
...
py> write(1, 2, 3)
1 2 3
But why go to all this effort?
STeVe