473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

lambdas (lambda x: printx)

Hi,

Today I started with python and I cannot understand why expresion
lambda x: print x
returns syntax error (but for example lambda x: sys.stdio.write(x) does not)
First I fought the reason is scopeing, but it shouldnt return syntax error.

misza
Jul 18 '05 #1
1 1484
Michal wrote:
Today I started with python and I cannot understand why expresion
lambda x: print x
returns syntax error (but for example lambda x: sys.stdio.write(x)
does not)
First I fought the reason is scopeing, but it shouldnt return syntax
error.


The problem is that you can only put an expression in a lambda form.
print is a statement, not an expression. Other examples of statements
are if...else control structures, variable assignments, and return
statements.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ Bring me men / Bring me men to match my plains
-- Lamya
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: gong | last post by:
hi i would like to pickle a lambda; according to the library docs in 2.3, i believe this shouldnt be possible, since a lambda is not a function defined at the top level of a module (?) ...
6
by: John Fouhy | last post by:
So I'm trying to generate Tkinter callback functions on the fly, but it's not working, and I don't understand what's going on. Here is an example program: -------------------------- from...
2
by: Fernando Perez | last post by:
Hi all, there are a couple of threads on lambdas today, which got me curious about their differences as far as bytecode goes: planck|2> lf=lambda x: x**2 planck|3> def ff(x): return x**2 |.>...
51
by: bearophileHUGS | last post by:
On Slashdot there is a discussion about the future C#3.0: http://developers.slashdot.org/developers/05/09/18/0545217.shtml?tid=109&tid=8 http://msdn.microsoft.com/vcsharp/future/ There are...
1
by: Juan Pablo Romero | last post by:
Hello! given the definition def f(a,b): return a+b With this code: fs = ]
3
by: edd | last post by:
I tried searching for an answer to this in the google groups archives but I failed to come up with anything. So I hope no one minds me asking this, though I'm sure it's been asked a million times...
5
by: Chris Johnson | last post by:
What I want to do is build an array of lambda functions, like so: a = (This is just a demonstrative dummy array. I don't need better ways to achieve the above functionality.) print ...
29
by: jmDesktop | last post by:
For students 9th - 12th grade, with at least Algebra I. Do you think Python is a good first programming language for someone with zero programming experience? Using Linux and Python for first...
1
by: Simon Woods | last post by:
Hi I'm trying to generate a simple evaluator-type app. I want to generate a list of operators and say how each is to be evaluated. So, e.g., I want to add to a list of operators ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.