473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

function object.func_default off the console

>>f.func_defaults[0]
[2, 3]
>>f.func_defaults[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>f.func_defaults[0]
[2, 3, 4]

V. interesting. Operation succeeds but with a throw. Er, raise.
Apr 25 '07 #1
3 1934
Aaron Brady wrote:
>>>f.func_defaults[0]
[2, 3]
>>>f.func_defaults[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>>f.func_defaults[0]
[2, 3, 4]

V. interesting. Operation succeeds but with a throw. Er, raise.
This is not specific to func_defaults:
>>t = ([1],)
t[0] += [2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>t
([1, 2],)

t[0] += [2]

is resolved to

t.__setitem__(t[0].__iadd__([2]))

where list.__iadd__() succeeds but __setitem__() fails (because tuples don't
have that method).

Peter
Apr 25 '07 #2
On Apr 25, 1:56 am, Peter Otten <__pete...@web.dewrote:
Aaron Brady wrote:
>>f.func_defaults[0]
[2, 3]
>>f.func_defaults[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>f.func_defaults[0]
[2, 3, 4]
V. interesting. Operation succeeds but with a throw. Er, raise.

This is not specific to func_defaults:
>t = ([1],)
t[0] += [2]

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment>>t

([1, 2],)

t[0] += [2]

is resolved to

t.__setitem__(t[0].__iadd__([2]))

where list.__iadd__() succeeds but __setitem__() fails (because tuples don't
have that method).

Peter
Curious why t.__setitem__ is called. Wouldn't it still refer to the
same list?

Apr 26 '07 #3
ca********@gmail.com wrote:
On Apr 25, 1:56 am, Peter Otten <__pete...@web.dewrote:
>Aaron Brady wrote:
>>>f.func_defaults[0]
[2, 3]
f.func_defaults[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
f.func_defaults[0]
[2, 3, 4]
V. interesting. Operation succeeds but with a throw. Er, raise.

This is not specific to func_defaults:
>>t = ([1],)
t[0] += [2]

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment>>t

([1, 2],)

t[0] += [2]

is resolved to

t.__setitem__(t[0].__iadd__([2]))

where list.__iadd__() succeeds but __setitem__() fails (because tuples
don't have that method).

Peter

Curious why t.__setitem__ is called. Wouldn't it still refer to the
same list?
How is Python to know? Consider
>>items = [[], 0]
items[0] += [42] # could do without __setitem__()
items[1] += 42 # __setitem__() required
items
[[42], 42]

When the item is immutable the += operation can only work by replacing it
with another value.

Peter

Apr 26 '07 #4

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
0
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
4
by: Jonathan Roewen | last post by:
Hi I've got loading assemblies dynamically done (wasn't too difficult). Now I want to lookup a static function in the loaded assembly, and if found, return it somehow, and call it from my app. So...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
4
by: H.B. | last post by:
Hi, I successfully implement a static callback function for my dll usign delegates. Now, I need to use member function instead of static function. How can I make that (in Managed C++). Hugo
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
2
by: Eran.Yasso | last post by:
Hi, I saw that there's the delegate feature that handles as pointer to function but in safe mode. Can I send function name to other function to call it? for example: printmeA() {
12
by: ed | last post by:
Hi there, I just remembered this from a few days ago, and was looking for a reason for it. I was trying to call a function as so: addEvent( whatever, whatever, functionName() ); and as I...
2
by: Franck | last post by:
I am looking for a way to pass a function as parameter, NOT A DELEGATE. what i am trying to do is a worker process as for example of what i want to do : public static void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.