python for web programming
hello, Can you show me some reference datas for python web programming?Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: python for web programming
Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Socket and array
Hello, How to send an array via socket to the other end?Thanks. -- http://mail.python.org/mailman/listinfo/python-list
sort sort sort
I do need sorting a dict via its values. Please help give some reference or code samples. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Newbie question about Class
I'm reading the book of "Dive into Python" and got these code pieces: class UserDict: def __init__(self, dict=None): self.data = {} if dict is not None: self.update(dict) My question is,for the statement of: if dict is not None: self.update(dict) Why it's not this one below? if dict is not None: self.data.update(dict) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about Class
[quote]The idea behind that class is to act "as-if" it were a real dictionary. Dicts have an update method, and UserDict should too. But it's not listed in the book (should appear a few lines below that code); this is a possible implementation: def update(self, other): for key in other.keys(): self.data[key] = other[key] Given this method, __init__ works fine. Using self.data.update(dict) is OK if the dict argument is a real dictionary, but not if it's another UserDict.[/quote] Thank you. But I'm still confused that what's the "real dictionary"?I can't know this point.Please help and thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about Class
Thanks a lot.I've got it. En Tue, 13 Feb 2007 13:01:59 -0300, <[EMAIL PROTECTED]> escribió: > But I'm still confused that what's the "real dictionary"?I can't know > this > point.Please help and thanks again. I'm talking about a Python dictionary (a "real" one, as opposed to UserDict, which is a "fake" dictionary; it looks and acts like a dictionary but it's not). py> from UserDict import UserDict py> d = {"a": 1, "b": 2, "c": 3} # This is a "real" dictionary # I create an UserDict instance, its initial contents come from a dictionary py> ud1 = UserDict(d) py> ud1 {'b': 2, 'a': 1, 'c': 3} # Now I create a second UserDict instance, its initial contents come from the UserDict instance py> ud2 = UserDict(ud1) py> ud2 {'b': 2, 'a': 1, 'c': 3} -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Please help about an instance var
>>> from UserDict import UserDict >>> d = {1:2,3:4,5:6} >>> d1 = UserDict(d) >>> d1 {1: 2, 3: 4, 5: 6} >>> d1.data {1: 2, 3: 4, 5: 6} Here why both d1 and d1.data have the same values?As shown below,they're different types. >>> type(d1) >>> type(d1.data) Please help.Thanks! -- http://mail.python.org/mailman/listinfo/python-list
I'm faint why this can't work
Hello, I got this similar sample script from books: $ cat sampdict.py #!/usr/bin/python class SampDict(dict): def __init__(self, filename=None): self["name"] = filename But when I run it I got the errors: >>> from sampdict import SampDict >>> SampDict("/etc/passwd") Traceback (most recent call last): File "", line 1, in ? File "sampdict.py", line 4, in __init__ self["name"] = filename AttributeError: SampDict instance has no attribute '__setitem__' I'm using Python 2.3.4. Please help.Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: I'm faint why this can't work
> Hello, > I got this similar sample script from books: > $ cat sampdict.py > #!/usr/bin/python > class SampDict(dict): > def __init__(self, filename=None): > self["name"] = filename > Are you sure you copied it exactly as it appears? Where did you find it? Thank you for the help,Gabriel. The codes got by me from the book of "Dive into Python".The original codes are below: class FileInfo(dict): "store file metadata" def __init__(self, filename=None): self["name"] = filename It's in the chapter 5.5. -- http://mail.python.org/mailman/listinfo/python-list