how easily can glob.glob say Unix bash `echo *`

2007-11-03 Thread p . lavarre
http://wiki.python.org/moin/glob now mentions: The glob module lists names in folders that match Unix shell patterns. If the elemental function emulating Unix bash `echo *` really is missing from the 2.5 Python batteries included, then here's a brief clear way of adding that function to Python.

Re: platform system may be Windows or Microsoft since Vista

2007-09-07 Thread p . lavarre
Log a bug @ bugs.python.org http://bugs.python.org/issue1082 TITLE ... platform system may be Windows or Microsoft since Vista Six days gone with no feedback. Something wrong with the input? Maybe the blank Priority field? I agree Severity Major. I'm thinking no priority because there is

Re: platform system may be Windows or Microsoft since Vista

2007-09-01 Thread p . lavarre
suppose you get Python for Vista Windows today if platform.system() in ('Windows', 'Microsoft'): if not (platform.system() in ('Windows', 'Microsoft')): Good analysis. Yes I am sane!! Thank you for saying. Log a bug @ bugs.python.org Glad to hear I can help. I created:

platform system may be Windows or Microsoft since Vista

2007-08-31 Thread p . lavarre
Let's suppose you get Python for Vista Windows today from http://www.python.org/download/. Should you then conclude that the tests: if platform.system() in ('Windows', 'Microsoft'): if not (platform.system() in ('Windows', 'Microsoft')): are now exactly what you should write for that 2.5.1

CTypes FAQs - buffer memmove offsetof uchar ((void *) -1) etc.

2007-07-13 Thread p . lavarre
http://wiki.python.org/moin/ctypes now tries to answer: '''FAQ: How do I copy bytes to Python from a ctypes.Structure?''' '''FAQ: How do I copy bytes to a ctypes.Structure from Python?''' '''FAQ: Why should I fear using ctypes.memmove?''' '''FAQ: How do I change the byte length of a

Abort trap - Fatal Python error: GC object already tracked

2007-07-10 Thread p . lavarre
Is this interesting Python output? $ gc-object-already-tracked.py ** File /Users/admin/Desktop/lxio/gc-object-already-tracked.py, line 770, in __main__.REDACTED Failed example: nqzhexes(self.send()) Expected: '...

Re: Abort trap - Fatal Python error: GC object already tracked

2007-07-10 Thread p . lavarre
Is this interesting Python output? ... Fatal Python error: GC object already tracked Abort trap ... tell me I can help by solving it, and I'll look more closely. Sorry, never mind, not interesting after all. Newbie me did somehow forget the fact that ctypes.memmove doesn't bounds-check,

Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-06-04 Thread p . lavarre
http://docs.python.org/lib/module-pickle.html ... concise Python ways of pickling and unpickling the (0xFF ** N) possible ways of packing N strings of byte lengths of 0..xFE together ... Aye, looks like an exercise left open for the student to complete: pickle.dumps() S''\np0\n.

Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-06-01 Thread p . lavarre
Often it helps to ask yourself the question: How would I do this in C? ... *Not* by using a structure. A structure is fine if the definition is fixed, or at most has *one* variable sized field at the very end. http://docs.python.org/lib/module-pickle.html might be near where I'll find concise

FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-05-31 Thread p . lavarre
How do I vary the byte offset of a field of a ctypes.Structure? How do I use the dynamic nature of Python, and (re-)define the data type after the required size is already known, on a case by case basis? \\\ For example, suppose sometimes I receive the value '\x03hi' + \x04bye' for the struct:

Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-05-31 Thread p . lavarre
ctypes.sizeof(a) is still zero, as if ctypes.Structure.__init__ fetches a.__class__._fields_ rather than a._fields_ -- http://mail.python.org/mailman/listinfo/python-list

Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-05-31 Thread p . lavarre
Thomas, Ouch ouch I must have misunderstood what you meant by use the dynamic nature of Python, and (re-)define the data type after the required size is already known, on a case by case basis. Do you have an example of what you meant? I searched but did not find. Are those your words? Yes, to

Re: FAQ: how to vary the byte offset of a field of a ctypes.Structure

2007-05-31 Thread p . lavarre
I see that changing self._fields_ doesn't change ctypes.sizeof(self). I guess ctypes.Structure.__init__(self) fetches self.__class__._fields_ not self._fields_. -- http://mail.python.org/mailman/listinfo/python-list

Re: FAQ: How do I calculate what quoted strings and numbers mean?

2006-11-15 Thread p . lavarre
A FAQ that discusses good ways to handle Python-like literals and expressions would definitely be a useful addition to the FAQ. if nobody else does anything about it, I'll get there sooner or later. Thank you. eval(source, {'builtins': {}}) works enough like an evaluator of literals to

announce: FAQs suggested

2006-11-10 Thread p . lavarre
http://effbot.org/pyfaq/suggest.htm has new FAQ's: FAQ: How do I ask to exit from a doctest FAQ: How do I say unsigned char in ctypes? FAQ: How do I say returns void in ctypes? FAQ: How do I calculate what quoted strings and numbers mean? Enjoy, Pat LaVarre --

FAQ: How do I calculate what quoted strings and numbers mean?

2006-11-10 Thread p . lavarre
Subject: announce: FAQs suggested ... http://effbot.org/pyfaq/suggest.htm has new FAQ's ... FAQ: How do I calculate what quoted strings and numbers mean? A: eval(source, {'builtins': {}}) works, without also accidentally accepting OS commands as input. Note: Eval might surprise you if you

Re: announce: FAQs suggested

2006-11-10 Thread p . lavarre
http://effbot.org/pyfaq/suggest.htm FAQ: How do I say returns void in ctypes? That's in the ctypes documentation, where it belongs. Thank you, before I never had found Use None for void a function not returning anything at: http://starship.python.net/crew/theller/ctypes/reference.html

Re: pack a three byte int

2006-11-09 Thread p . lavarre
Not as concisely as a one-byte struct code Help, what do you mean? you presumably... read... the manual ... Did I reread the wrong parts? I see I could define a ctypes.Structure since 2.5, but that would be neither concise, nor since 2.3. when 24-bit machines become ... popular Indeed the

Re: pack a three byte int

2006-11-09 Thread p . lavarre
cdb0 = '\x08' '\x01\x23\x45' '\x80' '\0' cdb = '' cdb += struct.pack('B', 0x08) cdb += struct.pack('I', skip)[-3:] cdb += struct.pack('BB', count, 0) The change from [-3:] to [1:] is a minor cosmetic improvement, Ouch, [1:] works while sizeof I is 4, yes, but that's not what I

Re: pack a three byte int

2006-11-09 Thread p . lavarre
Help, what did you mean by the question? How does Python express the idea: i) Produce the six bytes '\x08' '\x01\x23\x45' '\x80' '\0' at run-time when given the tuple (0x08, 0x12345, 0x80, 0). ii) Produce the six bytes '\x12' '\0\0\0' '\x24' '\0' when given the tuple (0x12, 0, 0x24, 0). iii)

Re: pack a three byte int

2006-11-09 Thread p . lavarre
struct == Python struct module Struct module has (concise) codes B, H, I, Q for unsigned integers of lengths 1, 2, 4, 8, but does *not* have a code for 3-byte integers. I thought that's what the manual meant, but I was unsure, thank you. 1. Not as concisely as a one-byte struct code

Re: pack a three byte int

2006-11-09 Thread p . lavarre
when talking the 1960's lingo ... X12Inquiry = 0x12 xxs = [0] * 6 xxs[0] = X12Inquiry xxs[4] = allocationLength rq = ''.join([chr(xx) for xx in xxs]) It looks wrong (and a few other adjectives), Ah, we agree, thank you for saying. Looks like little-endian 4-byte integer

Re: pack a three byte int

2006-11-09 Thread p . lavarre
Speaking as the OP, perhaps I should mention: [-3:] to [1:] is a minor cosmetic improvement To my eye, that's Not an improvement. '\x08' '\x01\x23\x45' '\x80' '\0' is the correct pack of (0x08, 0x12345, 0x80, 0) because '\x01\x23\x45' are the significant low three bytes of a big-endian

Re: pack a three byte int

2006-11-09 Thread p . lavarre
Perhaps Python can't concisely say three-byte int ... But Python can say six-nybble hex: import binascii cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 0x12345, 0x80, 0)) binascii.hexlify(cdb) '080123458000' Thanks again for patiently helping me find this. A shortcut is:

Re: pack a three byte int

2006-11-09 Thread p . lavarre
... Python can say six-nybble hex: import binascii cdb = binascii.unhexlify('%02X%06X%02X%02X' % (0x08, 0x12345, 0x80, 0)) binascii.hexlify(cdb) '080123458000' The only problem I can see is that this code is endianness-dependent; the suggested versions using pack(...) not. But

to Doctest as SystemExit is to Python

2006-11-09 Thread p . lavarre
From: http://docs.python.org/lib/doctest-soapbox.html ... Regression testing is best confined to dedicated objects or files ... Can I somehow tell doctest that it's time to quit? I ask because not all doctest examples are created equal. Some failures are catastrophic, making all subsequent

Re: how is python not the same as java?

2006-11-09 Thread p . lavarre
Jython exists. -- http://mail.python.org/mailman/listinfo/python-list

pack a three byte int

2006-11-08 Thread p . lavarre
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? import struct skip = 0x123456 ; count = 0x80 cdb = '' cdb += struct.pack('B', 0x08) cdb += struct.pack('I', skip)[-3:] cdb +=

Re: call Mac gcc -framework from CTypes how

2006-10-25 Thread p . lavarre
can I somehow call the IONotificationPortCreate in the Framework that Apple built instead, $ cd /System/Library/Frameworks/ $ cd IOKit.framework/Versions/Current/ $ file IOKit ... Mach-O dynamically linked shared library ... $ nm -m IOKit | grep IONotificationPortCreate ... (__TEXT,__text)

FAQ - How do I declare that a CTypes function returns void?

2006-10-25 Thread p . lavarre
Now at http://pyfaq.infogami.com/suggest we have: FAQ: How do I declare that CTypes function returns void? A: c_void = None is not doc'ed, but is suggested by: ctypes.POINTER(None) class 'ctypes.c_void_p' Remembering c_void = c_int from KR C often works, but if you say a restype is c_int,

FAQ - How do I declare that a CTypes function returns unsigned char?

2006-10-25 Thread p . lavarre
Now at http://pyfaq.infogami.com/suggest we have: FAQ: How do I declare that a CTypes function returns unsigned char? A: c_uchar = ctypes.c_ubyte This irregularity actually is doc'ed, it's just pointlessly annoying. Hope this helps (and of course I trust you'll dispute if I'm nuts), --

Re: call Mac gcc -framework from CTypes how

2006-10-25 Thread p . lavarre
can I somehow call the IONotificationPortCreate in the Framework that Apple built instead, $ cd /System/Library/Frameworks/ $ cd IOKit.framework/Versions/Current/ $ file IOKit Also ctypes.util.find_library('CoreFoundation') -- http://mail.python.org/mailman/listinfo/python-list

Re: doctest quiet again before exit how

2006-10-18 Thread p . lavarre
... every run of doctest after the first is verbose ... *** DocTestRunner.merge: '__main__' in both testers; summing outcomes. Another path to the same bug: import doctest print doctest.testfile(__file__, verbose=False) print doctest.testfile(__file__, verbose=False) Mystifiedly yours, rank

call Mac gcc -framework from CTypes how

2006-10-18 Thread p . lavarre
gcc -dynamiclib -framework CoreFoundation builds C code for Mac OS X that I call from Py code. Can I somehow get rid of the C, such as: #include CoreFoundation/CoreFoundation.h void const * kCFTypeDictionaryKeyCallBacks_p(void) { return kCFTypeDictionaryKeyCallBacks; } ? Thanks in

doctest quiet again before exit how

2006-10-16 Thread p . lavarre
Looks like every run of doctest after the first is verbose: $ python2.5 quiet-once.py (0, 0) *** DocTestRunner.merge: '__main__' in both testers; summing outcomes. (0, 0) *** DocTestRunner.merge: '__main__' in both testers; summing outcomes. (0, 0) $ $ cat quiet-once.py import doctest print

ctypes.c_void_p(-1) might not be C return (void *) -1

2006-09-28 Thread p . lavarre
Subject: Python CTypes translation of (pv != NULL) And so then the next related Faq is: Q: How should I test for ((void *) -1)? A: (pv == 0x) works often. (ctypes.cast(pv, ctypes.c_void_p).value == 0x) works better. ((void *) -1) appears often in 32-bit Windows, behind the

Re: Python CTypes translation of (pv != NULL)

2006-09-28 Thread p . lavarre
Where did you find that? Quoted in full from the gift: Subject: Re: Python CTypes translation of (pv != NULL) Date: Tue, 26 Sep 2006 11:48:52 +0200 Message-ID: [EMAIL PROTECTED] http://groups.google.com/group/comp.lang.python/msg/f9f13e731ea3cad7 Cached and pondered just slightly before the

eval(source, {'builtins': {}}) archived as Faq

2006-09-28 Thread p . lavarre
Absent from http://www.python.org/doc/current/lib/built-in-funcs.html but now copied to the Faq list of http://pyfaq.infogami.com/suggest, from these clp archives: /// Q: How can I tell Python to calculate what quoted strings and numbers mean, without also accidentally accepting OS commands as

Re: ctypes.c_void_p(-1) might not be C return (void *) -1

2006-09-28 Thread p . lavarre
I've started a wiki page where I already added an entry about the above question. Do you think the entry would have answered your question? http://starship.python.net/crew/theller/moin.cgi/CodeSnippets As concise as I now can imagine, yes thank you. I see the main point leads: The truth

Re: Python CTypes translation of (pv != NULL)

2006-09-28 Thread p . lavarre
Future Googlers might like this thread to end with the Thomas Heller's brief conclusive review: /// Copied 2006-09-28 from /// http://starship.python.net/crew/theller/moin.cgi/CodeSnippets 1.2 Check for NULL ctypes pointers The truth value of any NULL ctypes pointer instance is False. So, this

Re: Python CTypes translation of (pv != NULL)

2006-09-27 Thread p . lavarre
http://starship.python.net/crew/theller/ctypes/tutorial.html ... direct discussion only of how to construct null pointers, no discussion of how to test for them ... ... could be read to mean try ... == ... is ... False ... None ... CTypes nulls fetched from a struct feel more like None

Re: Python CTypes translation of (pv != NULL)

2006-09-27 Thread p . lavarre
It says: NULL pointers have a False boolean value: null_ptr = POINTER(c_int)() print bool(null_ptr) False Yes. That means that NULL pointers are considered False in a boolean expression (and you could assume that non-NULL pointers are True, as any other object in general), I see

Re: Python CTypes translation of (pv != NULL)

2006-09-26 Thread p . lavarre
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? Perhaps reading the ctypes tutorial? (both in the 2.5 docs and in http://starship.python.net/crew/theller/ctypes/tutorial.html) Actually, no. I see three answers or zero, depending on how you like to count. Yes that

Re: Python CTypes translation of (pv != NULL)

2006-09-26 Thread p . lavarre
Q: The C idea of (pv != NULL) ... CTypes tutorial ... == False ... == None ... is None ... Generally ... 'if pv: ' ... should work. Except for c_void_p, c_char_p and c_wchar_p instances. Please can we give me an example of these exceptions? Indeed those types are the _p types I

Re: shlex.split != shlex.shlex get_token til eof

2006-09-26 Thread p . lavarre
Kindly offline the answer is: (a) Python installation usually includes source, and thus (b) UTSL: $ pwd C:\Python25\Lib\shlex.py $ ... $ pwd /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5 $ grep -A 5 def split shlex.py def split(s, comments=False): lex = shlex(s, posix=True)

Re: shlex.split != shlex.shlex get_token til eof

2006-09-26 Thread p . lavarre
Correspondingly, to the Faq Wiki I added: /// http://pyfaq.infogami.com/installed-index Q: Where is Python installed on my machine? A: Binaries in bin/, source in lib/, doc somewhere else. Read the module source when you find its doc incomplete. On Linux, ... On the Mac, straight from Apple:

Re: Reverse a String?

2006-09-25 Thread p . lavarre
http://pyfaq.infogami.com/suggest is the right place to submit new entries. Thanks for sharing the secret. Now there I have added: Q: How can I reverse a string, an array, a list, etc. And to share our secret with future newbies, to http://pyfaq.infogami.com/ I've added the suggestion: ///

Python CTypes translation of (pv != NULL)

2006-09-25 Thread p . lavarre
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? A: We are of course supposed to write something like: def c_not_null(pv): return (ctypes.cast(pv, ctypes.c_void_p).value != None) Yes? Working from the doc, me the clueless newbie, I was slow to

Re: shlex.split != shlex.shlex get_token til eof

2006-09-25 Thread p . lavarre
I see shlex.split gives me what I want ... shlex.shlex surprisingly gives me something else ... I can get closer ... by hacking ... .wordchars += .+- Kindly offline I was told, Try patching .whitespace_split = True instead. Compare: shlex.split(//./PhysicalDrive9 //./Cdrom9 //./Tape9

Re: Reverse a String?

2006-09-24 Thread p . lavarre
http://pyfaq.infogami.com/ Tell me more? Clueless newbie me, thru this door I'm at three deaths and counting. Does that Py Faq Wiki have a sandbox a la alt.test, and/or a tutorial? // Death One: http://pyfaq.infogami.com/_account/in?path=/ requires me to create a persisting ID between 3 and

Re: ruby %w equivalent

2006-09-24 Thread p . lavarre
is there a python equivalent for the ruby %w operator? %w{a b c} creates an array with strings a, b, and c in ruby... The expression 'a b c'.split() creates the ['a', 'b', 'c'] list of str, if that helps. Also dir('a b c') briefly lists much of what

Re: help with debugging a ctypes problem

2006-09-23 Thread p . lavarre
help figuring out how to debug ... ctypes ... a commercial dll. A certain function takes five arguments, foo(a, b, c, d, e). Can I view the appropriate stack? ... Any other ideas or advice? etc? Did you call the foo of _cdecl ctypes.cdll or the foo of _stdcall = ctypes.windll? What is the

Re: Reverse a String?

2006-09-23 Thread p . lavarre
That 'foo'[::-1] is the Python reverse string idiom I'll try here forward, thanks. Also '.h.e.l.l.o'[1::2] to pick out every second char, etc., thanks. Three footnotes: 1) Reverse string isn't yet in http://www.python.org/doc/faq/ 2) Google Groups searches here yesterday instead pushed me

shlex.split != shlex.shlex get_token til eof

2006-09-22 Thread p . lavarre
How can I instantiate shlex.shlex to behave like shlex.split does? I see shlex.split gives me what I want: import shlex print shlex.split(1.2e+3)[0] # 1.2e+3 But every doc'ed instantiation of shlex.shlex surprisingly gives me something else: s1 = shlex.shlex(1.2e+3, None, False) print

Re: shlex.split != shlex.shlex get_token til eof

2006-09-22 Thread p . lavarre
shlex.split gives me what I want ... every doc'ed instantiation of shlex.shlex ... gives me something else ... Aye, the discrepancies are gross legion - presumably astonishing only newbies like me. Here's a more dramatic example: import shlex shlex.split(//./PhysicalDrive9 //./Cdrom9