473,765 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function object.func_def ault off the console

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

V. interesting. Operation succeeds but with a throw. Er, raise.
Apr 25 '07 #1
3 1947
Aaron Brady wrote:
>>>f.func_defau lts[0]
[2, 3]
>>>f.func_defau lts[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>>f.func_defau lts[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_defaul ts[0]
[2, 3]
>>f.func_defaul ts[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>f.func_defaul ts[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********@gmai l.com wrote:
On Apr 25, 1:56 am, Peter Otten <__pete...@web. dewrote:
>Aaron Brady wrote:
>>>f.func_defau lts[0]
[2, 3]
f.func_defau lts[0]+=[4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
f.func_defau lts[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
3697
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 discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
0
1496
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". Everytime i run the testprogram it complains about another exotically named dll like et_kn-hl.dll or afeaqisr.dll. Even the example from msdn throws these errors. Anyone knows wuts wrong?
4
7010
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 far, my efforts have failed miserably My function takes custom objects as parameters, along the lines of: string MyFunction(XmlNode node, MyNamespace.MyObject myObject, String str) { ... I've tried using delegates, and also MethodInfo, but...
7
4471
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 System_String. I don't see a difference in the previous code and what I have now. Can anyone find where I went wrong? Thanks a bunch! //Open new stream reader and writer to read in file //And write to a new file. StreamWriter swa=new...
4
5144
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
4336
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
2898
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
1484
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 recall it didn't like the parenthesis (). I got rid of them, and it worked. What is the reasoning behind this? When are you supposed to add the () ?
2
2118
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 StartWorking(FUNCTION MyFunction) { //thread object private Thread tWorkingProcess;
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
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.