Re: Injecting a global into a defined function??

2009-01-15 Thread Cong Ma
Terry Reedy wrote: > Not to me. You are using the module as a singleton class. The > alternative is to write a class, make the functions methods, and > instantiate the class. If that instance must be a singleton, more work > is required. If multiple instances make sense, you can go the class > r

Injecting a global into a defined function??

2009-01-15 Thread Cong Ma
Hi, I'd appreciate your hints on this problem. I'm writing a module in which several functions can alter the value of a global variable (I know this sounds evil, please forgive me...). What I'm trying to do is to eliminate the "global foo" lines in those functions' bodies and to use a decorator fo

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
Hello, 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 (version 2.5.2, chapter 5.1.6), which contain the note: "Special requirement for pickling: A tzinfo subclass must have an __init__ method that can be

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