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.
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
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:
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
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
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:
'...
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,
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.
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
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:
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
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
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
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
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
--
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
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
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
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
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)
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
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
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
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:
... 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
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
Jython exists.
--
http://mail.python.org/mailman/listinfo/python-list
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 +=
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)
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,
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),
--
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
... 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
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
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
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
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
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
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
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
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
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
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
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
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)
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:
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:
///
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
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
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
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
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
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
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
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
55 matches
Mail list logo