Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 07/01/10 23:19, Stephen Hansen wrote: >> >> As long as setattr() exists in Python, that will be not so ordinary. :) > > setattr is perfectly ordinary. If you think setattr() is as ordinary as a trivial assignment, I will argue with you, this is personal taste. However, I think setattr() is a

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 07/01/10 22:53, Stephen Hansen wrote: > > One uses assignment syntax when the name of the attribute they are > setting is known at the time when one writes the code. > > One uses the setattr function when the name of the attribute is not > known until runtime. > > The difference has *nothing a

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 06/28/10 17:43, Bruno Desthuilliers wrote: > Carl Banks a écrit : >> On Jun 27, 3:49 am, Bruno Desthuilliers >> wrote: >>> WANG Cong a écrit : >>> >>>> On 06/26/10 00:11, Neil Hodgson wrote: >>>>> WANG Cong: >>&g

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 06/27/10 09:06, Steven D'Aprano wrote: >> In that situation, certainly: adding an attribute on the fly to that >> formal definition seems entirely strange and special of an activity. But >> that's only because you *chose* to *see* and *use* the object that way. >> The "special"ness of the acti

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 07/01/10 13:49, Stephen Hansen wrote: Hi, Stephen, >> >> It may not be "the" primary concern, but elegance certainly is *a* >> primary concern. > > I concur. > > Its not explicitly stated, but it is the Zen 0. This is further > supported by its implied presence in many of the Axioms and Truth

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 06/30/10 01:20, Stephen Hansen wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > What do

Re: Python dynamic attribute creation

2010-07-01 Thread WANG Cong
On 06/30/10 01:25, Ethan Furman wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > Setattr a

Re: Python dynamic attribute creation

2010-06-29 Thread WANG Cong
On 06/27/10 12:01, Carl Banks wrote: > On Jun 25, 8:24 pm, WANG Cong wrote: >> Understand, but please consider my proposal again, if we switched to: >> >> setattr(foo, 'new_attr', "blah") >> >> by default, isn't Python still dynamic as

Re: Python dynamic attribute creation

2010-06-29 Thread WANG Cong
On 06/29/10 17:48, Andre Alexander Bell wrote: > On 06/25/2010 03:15 PM, WANG Cong wrote: >> 1) Modifying a class attribute is metaprogramming, and this is modifying >> a class, i.e. adding a new attribute to it, thus this should belong >> to metaprogramming. (I know, strict

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 20:22, Ian Kelly wrote: > On Fri, Jun 25, 2010 at 12:51 PM, Stephen Hansen > wrote: >>> Using assignments to create an attribute hides metaprogramming behide, >>> while using delattr() exposes it. >> >> I don't understand what you're saying here either. > > I think he's saying that w

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 22:11, Mark Lawrence wrote: > On 25/06/2010 19:23, WANG Cong wrote: >> On 06/25/10 14:31, Richard Thomas wrote: >> >> >> >>> >>> If you desperately want to limit the attribute assignments that can be >>> performed on an obje

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 19:38, Ethan Furman wrote: > WANG Cong wrote: >> On 06/25/10 15:34, Bruno Desthuilliers >> wrote: >> >>> WANG Cong a écrit : >>>> Hi, list! >>>> >>>> I have a doubt about the design of dynamic attribute creation by &

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/26/10 00:11, Neil Hodgson wrote: > WANG Cong: > >> 4) Also, this will _somewhat_ violate the OOP princples, in OOP, >> this is and should be implemented by inherence. > >Most object oriented programming languages starting with Smalltalk > have allowed adding

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/26/10 03:31, Carl Banks wrote: > On Jun 25, 6:15 am, WANG Cong wrote: >> Hi, list! >> >> I have a doubt about the design of dynamic attribute creation by >> assignments in Python. >> >> As we know, in Python, we are able to create a new attribute of

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 14:31, Richard Thomas wrote: > > If you desperately want to limit the attribute assignments that can be > performed on an object you can set the __slots__ attribute of its > type. However, the Python ethos has always been to restrict as little > as necessary to provide the tools it

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 15:34, Bruno Desthuilliers wrote: > WANG Cong a écrit : >> Hi, list! >> >> I have a doubt about the design of dynamic attribute creation by >> assignments in Python. >> >> As we know, in Python, we are able to create a new attribute of

Re: Python dynamic attribute creation

2010-06-25 Thread WANG Cong
On 06/25/10 17:25, Steven D'Aprano wrote: > On Fri, 25 Jun 2010 14:15:12 +0100, WANG Cong wrote: > >> Hi, list! >> >> I have a doubt about the design of dynamic attribute creation by >> assignments in Python. >> >> As we know, in Python, w

Python dynamic attribute creation

2010-06-25 Thread WANG Cong
Hi, list! I have a doubt about the design of dynamic attribute creation by assignments in Python. As we know, in Python, we are able to create a new attribute of a class dynamically by an assignment: >>> class test: pass ... >>> test.a = "hello" >>> test.a 'hello' >>> However, I still don't

Re: Injecting a global into a defined function??

2009-01-15 Thread Cong Ma
alternative would be to write > a function with two parameters that takes a tuple of names and the code > quoted as a string as arguments. It would insert the global statement > into the string, execute it, and return the function. Thank you for your elaborate explanation :) Regards, Cong. -- http://mail.python.org/mailman/listinfo/python-list

Injecting a global into a defined function??

2009-01-15 Thread Cong Ma
hon 2.x). I'd like to hear your opinions. Thank you. Regards, Cong. -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python 2.x] Pickling a datetime.tzinfo subclass instance?

2008-12-09 Thread Cong Ma
Gabriel Genellina wrote: > En Mon, 08 Dec 2008 12:34:03 -0200, Cong Ma <[EMAIL PROTECTED]> escribió: > >> I'm writing a program that pickles an instance of a custom subclass of >> datetime.tzinfo. I followed the guides given in the Library Reference >> (vers

[Python 2.x] Pickling a datetime.tzinfo subclass instance?

2008-12-08 Thread Cong Ma
methods is better? Both seems to unpickle to the correct result, but are there subtle side-effects? Or there are better solutions? Regards, Cong. -- http://mail.python.org/mailman/listinfo/python-list

Re: Don't you just love writing this sort of thing :)

2008-12-04 Thread Cong Ma
Lawrence D'Oliveiro wrote: > for \ > Entry \ > in \ > sorted \ > ( > f for f in os.listdir(PatchesDir) if PatchDatePat.search(f) != > None > ) \ > : > Patch = (open, > gzip.GzipFile)[Entry.endswith(".gz")](os.path.join(PatchesDir, Entry), "r

Re: How to get a directory file descriptor?

2008-11-26 Thread Cong Ma
Nick Craig-Wood wrote: > Here is how you do exactly that in python using ctypes > > from ctypes import CDLL, c_char_p, c_int, Structure, POINTER > from ctypes.util import find_library > > class c_dir(Structure): > """Opaque type for directory entries, corresponds to struct DIR""" > c_dir_p =

Re: How to get a directory file descriptor?

2008-11-26 Thread Cong Ma
alex23 wrote: > On Nov 26, 3:26 pm, greg <[EMAIL PROTECTED]> wrote: >> os.O_DIRECTORY must be fairly new -- it doesn't exist >> in my 2.5 installation. But os.O_RDONLY seems to work >> just as well for this purpose. > > Which OS are you using? > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)

Re: How to get a directory file descriptor?

2008-11-25 Thread Cong Ma
alex23 wrote: > On Nov 26, 12:31 am, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote: >> Is this what you want? >> >> ofiles = [open(x) for x in os.listdir(os.getcwd())] > > 'open' returns a "file object", whereas the OP is after "file > descriptors", which are returned by 'os.open'. > > -- > http:/

Re: How to get a directory file descriptor?

2008-11-25 Thread Cong Ma
r0g wrote: > Cong Ma wrote: >> Dear all, >> >> Can you give me some hint on getting a directory file descriptor in Python? >> Besides, what's good about os.fchdir() if I can't get a directory fd in the >> first place? >> >> Thanks for

How to get a directory file descriptor?

2008-11-24 Thread Cong Ma
Dear all, Can you give me some hint on getting a directory file descriptor in Python? Besides, what's good about os.fchdir() if I can't get a directory fd in the first place? Thanks for your reply. Regards, Cong. -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for lots of words in lots of files

2008-06-18 Thread Cong
On Jun 18, 11:01 pm, Kris Kennaway <[EMAIL PROTECTED]> wrote: > Calvin Spealman wrote: > > Upload, wait, and google them. > > > Seriously tho, aside from using a real indexer, I would build a set of > > thewordsI'mlookingfor, and then loop over each file, looping over > > thewordsand doing quick ch

Re: Xah's edu corner: on Microsoft hatred

2005-07-18 Thread Cong Wang
M$ is evil! -- http://mail.python.org/mailman/listinfo/python-list