QOTW: Such infrastructure building is in fact fun and instructive -- as
long as you don't fall into the trap of *using* such complications in
production code, where Python's simplicity rules;-). -- Alex Martelli
QOTW: Such infrastructure building is in fact fun and instructive -- as
long as you don't fall into the trap of *using* such complications in
production code, where Python's simplicity rules;-). -- Alex Martelli
archives first).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
is essentially a class (in the OOP sense, not the python-
specific classobj sense). You can call a type or class to create an
instance of that class or type. Here, you call the 'instancemethod' type
to create an instance of type 'instancemethod'. Makes sense ... in
hindsight.
--
Craig Ringer
--
http
to your ISP's news server, *then* you can subscribe
to comp.lang.python.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
-- or if they are,
they can find it in comp.lang.python.
Going by the general reaction on c.l.py, I think it'd be more accurate
if you left that at Please stop posting.
Sorry for the cross-post, and for this perl-python moron who appears
to have nothing to do with either, or any knowledge of them.
--
Craig Ringer
of objects into a functionally
styled processing pipeline, say a series of functions that each just
return the result of a listcomp/genexp.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
of 'binary
files'. :)
non-ascii
That's not really safe when dealing with utf-8 files though, and IIRC
with UCS2 or UCS4 as well. The Unicode BOM its self might (I'm not sure)
qualify as ASCII.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
(':',1)))
. data = ''.join(x for x in initer)
because that seems like a pretty ugly hack (and please ignore the
variable names). Perhaps a way to get the file to seek back to the point
last read from the iterator when the iterator is destroyed?
--
Craig Ringer
--
http://mail.python.org/mailman
of the iterator when read() etc are called? If not, I
favour the suggestion in the referenced post - file should probably fail
noisily, or at least emit a warning.
What are others thoughts on this?
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 2005-01-22 at 12:20 +0100, Alex Martelli wrote:
Craig Ringer [EMAIL PROTECTED] wrote:
. data = ''.join(x for x in infile)
Maybe ''.join(infile) is a better way to express this functionality?
Avoids 2.4 dependency and should be faster as well as more concise.
Thanks - for some
On Fri, 2005-01-21 at 22:38 +0800, Craig Ringer wrote:
consecutive_sets = ( x[offset:offset+subset_size]
for subset_size in xrange(2, len(x))
for offset in xrange(0, len(x) + 1 - subset_size) )
Where 'x' is list to operate on, as I should've initially
and library modules
return generators for things.
I know this is now the case for reading lines in a file or with the
new iterator package. But what else ? Does Craig Ringer answer mean
that list comprehensions are lazy ?
Nope, but generator expressions are, and they're pretty similar.
Where can I
http://docs.python.org/whatsnew/node4.html
http://www.python.org/dev/doc/newstyle/ref/genexpr.html
for details.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
in the error message to that effect.
I've just checked the OSX 10.3 machine here, and it fails to import
tkinter there too. I'd say Apple just don't build Python with Tk
support.
What do I do to set it up so I can use Tkinter?
Try Google - this seems to be a moderately FAQ for MacOS/X.
--
Craig
://docs.python.org/api/tupleObjects.html
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
and/or failing to detect and
handle or propagate an exception.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
this - as that can often be
very helpful both in understanding what you're thinking and in
suggesting a suitable approach or alternative.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
of referencing deleted memory by accident.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
.
That said, I do think the rules deserve consideration and respect -
they're usually there because of many others' experience over time. It's
interesting to learn those lessons first hand, but it's nice to be able
to avoid repeating every single one of them.
--
Craig Ringer
--
http://mail.python.org
(generator expressions, list comprehensions, for loops, ...?) over
(sequences, iterators, generators)
I happen to be extremely fond of the flexibility this provides, but one
obvious way to do it there is not.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
]
;-)
If it means I _never_ have to see that list comprehension again, then
seeing 'flatten' go into itertools would make me very, very happy :-P
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
:
That'll work fine in Python 2.3. I think you meant:
print sum(ord(x) for x in PyPy)
which is a different matter entirely (well, regarding compatibility
anyway).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
.
I'd use:
os.popen(/bin/exe.x, w).write(\
CategorY = GRIB
etc.
)
myself, but that's just taste (well, and performance I suspect).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
specific to the
Python/C API).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
str.encode(), str.decode() and
unicode() calls where appropriate.
On a side note, PEP 263 handles the text encoding interpretation of
Python program source, and is well worth reading and following.
http://python.org/peps/pep-0263.html
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo
, but
I hope I made sense.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
. print %s %s % tuple(x.split()[4:6])
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
didn't have
the GNU readline development headers installed, so Python disabled
readline support when it was compiled. That's just a guess, but seems
pretty likely.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
with it?
I think your question is the same problem as another recent poster -
that is, you didn't have the Tcl and Tk headers installed when you
installed Python. Please see my answer to Help uninstalling/installing
Python 2.4 (Yes, I know yours isn't Python 2.4 - it doesn't matter).
--
Craig Ringer
On Thu, 2005-01-06 at 23:05, Peter Maas wrote:
Craig Ringer schrieb:
It would certainly be difficult to track all harmful code constructs.
But AFAIK the idea of a sandbox is not to look at the offending code
but to protect the offended objects: files, databases, URLs, sockets
etc
about the best way to solve
your problem, you'll probably need to explain a bit more of your problem
- like what your extension module is doing that makes it have to pass
PyCObjects around and get Python code to work with them.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
lots of other handy tools, so I strongly recommend checking
it out.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
providers would like to have to do all the
time for many hosted sites.
I wonder if SCGI or a similar persistent CGI solution might be more
practical for running CGI scripts under specific user accounts.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
) installed.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
a global and
local environment for your script to run in.
I do not know if it is possible to disable or override 'import'..
You can do a fair bit to it by wrapping/replacing __builtin__.__import__
. Preventing people from getting around what you've done, though... not
sure.
--
Craig Ringer
it.
My first thought would be to express your 'A and B' regex as:
(A.*B)|(B.*A)
with whatever padding, etc, is necessary. You can even substitute in the
sub-regex for A and B to avoid writing them out twice.
--
Craig Ringer
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
to keep an eye on the licenses of any
extensions you used, like ReportLab, PIL, mx, database interfaces,
twisted, etc. Many are licensed under the same license as Python or an
MIT-like license, but of course some Python extensions are not and you
would need to consider that.
--
Craig Ringer
--
http
sock.py
but ./sock.py results in a :bad interpreter error
how do i troubleshoot something like this?
You probably have Windows-style line endings in the file. The kernel
sees the ^M at the end of the line and gets all confused.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python
module
that uses your C module internally (see PIL for a good example of this).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
you to do so, and it's hardly worth repeating
the work if you don't have to.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
' on many UNIX systems; no idea about Windows.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
; however, it's my understanding that compressing individual files
also means that in the case of damage to the archive it is possible to
recover the files after the damaged file. This cannot be guaranteed when
the archive is compressed as a single stream.
--
Craig Ringer
--
http://mail.python.org
, rightstring)
or
%20s: %-40s % (leftstring, rightstring)
That's Python's 'printf' style string formatting.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
):
cls.class_level_variable = newval
setvaluecls = classmethod(setvaluecls)
sevaluecls and setvalue look the same to callers calling them on an
instance of the class.
I have no idea if that's actually appropriate for your needs, it's just
a stab in the dark, but perhaps it might be.
--
Craig
. This is
probably not the right place.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
it.
It wouldn't hurt to point C extension authors at things like the 'es'
encoded string format for PyArg_ParseTuple to help them make their code
better behaved with non-ascii text.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 2004-12-29 at 02:08, Cameron Laird wrote:
In article [EMAIL PROTECTED],
Craig Ringer [EMAIL PROTECTED] wrote:
.
.
.
IMO the reference behaviour of functions in the C API could be
clearer. [snip
in this situation is don't
use __slots__. If you think you need __slots__, still don't use
__slots__.
I've made use of __slots__ once myself for an optimisation when
subclassing `str', but if you're not using it for a serious optimisation
need it's probably best to steer clear.
--
Craig Ringer
--
http
often :-P
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh wrote:
Craig Ringer wrote:
It's hard to consistently support Unicode in extension modules without
doing a lot of jumping through hoops. Unicode in docstrings is
particularly painful. This may not be a big deal for normal extension
modules, but when embedding Python it's a source
- it might be a good idea to search the archives.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
think
it'd certainly be well worth a try, especially if you're writing any
more complex applications.
That said, for 90% of users development time matters more than execution
speed, and that's another matter entirely.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
of these issues would make it
a fair bit nicer again, especially for people embedding Python in apps
(a place were it can seriously excel as a scripting/extension/glue
language).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
the issue. After all, these two are the
same:
def callfunc(function,args):
return apply(function,args)
and
def callfunc(function,args):
return function(*args)
its just an (IMO trivial) difference in syntax. I'd be interested in
knowing if there is in fact more to it than this.
--
Craig
comp.lang.python (this
list/newsgroup).
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
it directly to a file to be accessed
as needed?
I'm afraid I just don't understand that. Do a DOS directory? If you
want to list the contents of a directory, see help(os.listdir) .
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
scope(instead of file scope as I want). Is there any solution to
my problem? Or should I solve it in another way?
def import_xml:
try:
import libxml
except ImportError,err:
# handle the error
return libxml
libxml = import_xml()
--
Craig Ringer
--
http
On Wed, 2004-12-15 at 21:44, Craig Ringer wrote:
def import_xml:
try:
import libxml
except ImportError,err:
# handle the error
return libxml
libxml = import_xml()
Though my personal approach would actually be:
try:
import libxml
except ImportError,err
(or
anything that means you have to seek around the file), I'd say you're
SOL.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
'
byte_chr = chr(int(byte,2))
byte_chr
'@'
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
%x % int(escapeseq[2:-1])).decode(unicode_escape)
...
print ' '.join([ unescape(x) for x in entities ])
비 행 기 로 보 낼 거 에 요 내 면 금 이 얼 마 지 잠
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 2004-12-10 at 16:09, Craig Ringer wrote:
On Fri, 2004-12-10 at 08:36, harrelson wrote:
I have a list of about 2500 html escape sequences (decimal) that I need
to convert to utf-8. Stuff like:
I'm pretty sure this somewhat horrifying code does it, but is probably
an example
On Wed, 2004-12-08 at 13:43, Craig Ringer wrote:
Hi folks
I'm currently working on a fairly well internationalised app that embeds
a Python intepreter. I'd like to make the docstrings translatable, but
am running into the issue that the translation function returns unicode
data
frustrating bugs.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
like
doing so.
In general, it'll be _much_ safer to use a generic object with
getattr/setattr or a dict than to try to work with your local or global
namespaces like this...
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
is translated with.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
, so I'm hoping so...
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
be in the exception code.
Much appreciated.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
the bindings are going to
be both simple and quite powerful. However, I need a way to do class
methods...
If anybody has any tips on this, It'd be much appreciated.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
for the noise everybody, I could've sworn I looked over that
already.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
Python what encoding is
used for program text passed using PyRun_String() if anybody knows.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
because the code contains trade
secrets.
My understanding is that that's never guaranteed safe, no? Or are
restrictions against reverse engineering now commonly enforcable?
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
76 matches
Mail list logo