The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

alister alister.ware at ntlworld.com
Tue Mar 15 05:20:24 EDT 2016


On Mon, 14 Mar 2016 20:31:06 +0000, BartC wrote:

> On 14/03/2016 19:45, alister wrote:
>> On Mon, 14 Mar 2016 14:43:22 +0000, BartC wrote:
>>
>>> On 13/03/2016 09:39, Steven D'Aprano wrote:
>>>> On Sun, 13 Mar 2016 04:54 am, BartC wrote:
>>>
>>>>> Common sense tells you it is unlikely.
>>>>
>>>> Perhaps your common sense is different from other people's common
>>>> sense. To me, and many other Python programmers, it's common sense
>>>> that being able to replace functions or methods on the fly is a
>>>> useful feature worth having. More on this below.
>>>>
>>>> Perhaps this is an example of the "Blub Paradox":
>>>
>>> Perhaps it's time to talk about something which many languages have,
>>> but Python hasn't. Not as far as I know anyway.
>>>
>>> That's references to names (sometimes called pointers). So if I write:
>>>
>>>    a = 100 f(a)
>>>
>>> then function f gets passed the value that a refers to, or 100 in this
>>> case. But how do you pass 'a' itself?
> 
>> Congratulations you have just proven that you have faild in your
>> understanimg of python @
>> stage 1 becuae you keep tying to us it a C
>>
>> try the following
>>
>> def test(x):
>> 	print (id(x)
>>
>> a=100 print (id(a))
>> test(a)
>> a="Oops i was an idiot"
>> print (id(a))
>> test(a)
>>
>> python always passes the object bound to a, not the value of a or a
>> pointer to a
> 
> Yes, and? I colloquially used 'value' instead of 'object', 'id' or
> 'reference'. The latter would added confusion as I'm talking about a
> different kind of reference. And if you get rid of 'id' in your code,
> you will get values displayed.
> 
> But how do you pass something that refers to a itself?
> 
> There are good reasons for wanting to do so. Try writing this function
> in Python:
> 
> def swap(a,b):
>      b,a = a,b
> 
> x="one"
> y="two"
> swap(x,y)
> 
> print (x,y)
> 
> so that it displays "two" "one".

Why would i do somthing so pointless?
)
how does this grab you (it often catches newbies out)

def test(x):
	a.append('oops')

a=['a list']
test(a)
print (a)

I sugest you may want to start reading a good python tutorial.
 





-- 
Between 1950 and 1952, a bored weatherman, stationed north of Hudson
Bay, left a monument that neither government nor time can eradicate.
Using a bulldozer abandoned by the Air Force, he spent two years and
great effort pushing boulders into a single word.

It can be seen from 10,000 feet, silhouetted against the snow.
Government officials exchanged memos full of circumlocutions (no Latin
equivalent exists) but failed to word an appropriation bill for the
destruction of this cairn, that wouldn't alert the press and embarrass
both Parliament and Party.

It stands today, a monument to human spirit.  If life exists on other
planets, this may be the first message received from us.
		-- The Realist, November, 1964.



More information about the Python-list mailing list