why cannot assign to function call

John Machin sjmachin at lexicon.net
Mon Dec 29 10:34:15 CET 2008


On Dec 29, 5:01 pm, scsoce <scs... at gmail.com> wrote:
> I have a function return a reference,

Stop right there. You don't have (and can't have, in Python) a
function which returns a reference that acts like a pointer in C or C+
+. Please tell us what manual, tutorial, book, blog or Usenet posting
gave you that idea, and we'll get the SWAT team sent out straight
away.

> and want to assign to the
> reference, simply like this:
>  >>def f(a)
>           return a

That's not a very useful function, even after you fix the syntax error
in the def statement. Would you care to give us a more realistic
example of what you are trying to achieve?

>      b = 0
>     * f( b ) = 1*

Is the * at the start of the line meant to indicate pointer
dereferencing like in C? If not, what is it? Why is there a * at the
end of the line?

> but the last line will be refused as "can't assign to function call".
> In my thought , the assignment is very nature,

Natural?? Please tell us why you would want to do that instead of:

    b = 1

> but  why the interpreter
> refused to do that ?

Because (the BDFL be praised!) it (was not, is not, will not be) in
the language grammar.



More information about the Python-list mailing list