Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Nick Craig-Wood
learning new things from c.l.py As a long time usenet user I find it easy to ignore the occasional flame wars. Posters with the wrong sort of attitude are brought gently into line by the majority. If usenet groups had ratings I'd give c.l.py 5 stars. -- Nick Craig-Wood n...@craig-wood.com

Re: udp package header

2009-03-24 Thread Nick Craig-Wood
and address is the address of the socket sending the data. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Bash-like brace expansion

2009-03-24 Thread Nick Craig-Wood
the corner cases (unmatched brackets, empty brackets, etc) and be sure it works exactly as specified. doctest is cool for this kind of stuff. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Async serial communication/threads sharing data

2009-03-23 Thread Nick Craig-Wood
Jean-Paul Calderone exar...@divmod.com wrote: On Sun, 22 Mar 2009 12:30:04 -0500, Nick Craig-Wood n...@craig-wood.com wrote: I wrote a serial port to TCP proxy (with logging) with twisted. The problem I had was that twisted serial ports didn't seem to have any back pressure. By that I

Re: Async serial communication/threads sharing data

2009-03-23 Thread Nick Craig-Wood
Jean-Paul Calderone exar...@divmod.com wrote: On Mon, 23 Mar 2009 05:30:04 -0500, Nick Craig-Wood n...@craig-wood.com wrote: Jean-Paul Calderone exar...@divmod.com wrote: [snip] In the case of a TCP to serial forwarder, you don't actually have to implement either a producer

Re: Using python 3 for scripting?

2009-03-23 Thread Nick Craig-Wood
it is more awkward for writing code close to Python 3 syntax. I tend to target whatever is in Debian stable, which starting from this month is 2.5 (recently upgraded from 2.4). 2.6 or 3.x is nowhere to be seen in Debian stable, testing or unstable :-( -- Nick Craig-Wood n...@craig-wood.com

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Nick Craig-Wood
() print done if __name__ == __main__: main() -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: 3.0 - bsddb removed

2009-03-22 Thread Nick Craig-Wood
. You would need to make a dictionary interface to sqlite, eg http://code.activestate.com/recipes/576638/ Or do something a bit simpler yourself. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Nick Craig-Wood
in functions is much quicker than fork()-ing an external command too. So much to learn, so little time (but so much fun!) ;-) -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Async serial communication/threads sharing data

2009-03-22 Thread Nick Craig-Wood
buffer was full and to only take the data at 9600 baud. I never did solve that problem :-( -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: cross compile Python to Linux-ARM

2009-03-19 Thread Nick Craig-Wood
the standard Python library, or is that yet another adventure ? If you use the debian compiled version then you get the lot. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python to Perl transalators

2009-03-18 Thread Nick Craig-Wood
/pleac_python/index.html Which is a sort of Rosetta stone for perl and python ;-) (The perl cookbook translated into python.) -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Special keyword argument lambda syntax

2009-03-14 Thread Nick Craig-Wood
obvious. It gives you the opportunity for a docstring also. Yes it is a bit more typing, but who wants to play code golf all day? -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw String Question

2009-03-12 Thread Nick Craig-Wood
\\ 'a\\' Which isn't terribly elegant, but it doesn't happen very often. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python worth learning as a second language?

2009-03-09 Thread Nick Craig-Wood
++ only when necessary. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Any c header parser for generate ctypes module?

2009-03-09 Thread Nick Craig-Wood
C parser written in python? GCCXML is usually used to create ctypes-structures from headers. Look at http://pypi.python.org/pypi/ctypeslib/ And the h2xml and xml2py scripts that are part of it. You'll need gccxml too as Diez pointed out. A definite time saver! -- Nick Craig-Wood n

Re: A better way to timeout a class method?

2009-03-09 Thread Nick Craig-Wood
/signal.html Won't work on windows and there is only one sigalarm timer, so you can't nest them :-( -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A better way to timeout a class method?

2009-03-09 Thread Nick Craig-Wood
duration: print i i += 1 sleep(1) print finished long_function() Which prints starting 0 1 2 3 4 finished -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using xreadlines

2009-02-28 Thread Nick Craig-Wood
/linecache.html Which may be useful... -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python Questions .....

2009-02-26 Thread Nick Craig-Wood
Ben bnsili...@gmail.com wrote: On Feb 24, 11:31?am, Nick Craig-Wood n...@craig-wood.com wrote: So do you want to embed python into your code? I'm still not clear what you are trying to achieve with python, though I have a better idea what SLAG is now! Actually no, I want to EXTEND

Re: intermediate python csv reader/writer question from a beginner

2009-02-24 Thread Nick Craig-Wood
='Charlie', a='17', b='18', day='Tuesday', time='1:00 PM' And leaves newfile.csv with the contents 1,2,3,Monday,1:00 PM 7,8,9,Tuesday,1:00 PM 4,5,6,Monday,2:00 PM -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python Questions .....

2009-02-24 Thread Nick Craig-Wood
handling menu and screen control. So do you want to embed python into your code? I'm still not clear what you are trying to achieve with python, though I have a better idea what SLAG is now! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman

Re: can multi-core improve single funciton?

2009-02-23 Thread Nick Craig-Wood
Calculation error print iterative, f_iterative print non iterative, f_noniterative print difference, f_iterative-f_noniterative -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python Questions .....

2009-02-23 Thread Nick Craig-Wood
a python extension in C then you do need to worry about reference counting - a lot! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I declare global vars or class vars in Python ?

2009-02-20 Thread Nick Craig-Wood
print self.B a = Stuff() a.main() Getting A None None Setting A Getting A aValue aValue -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Nick Craig-Wood
this GUI toolkit fits the same niche. Presumably since it uses SDL then all the GUI will appear in one window? So windows within windows in the MDI style? -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way to determine if a string is a number

2009-02-16 Thread Nick Craig-Wood
= _float_pattern.search(value) if match: return float(match.group(1)) return 0.0 atof(15.5 Sausages) 15.5 atof( 17.2) 17.199 atof(0x12) 0.0 atof(8.3.2) 8.3007 atof(potato) 0.0 -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http

Re: Easier to wrap C or C++ libraries?

2009-02-15 Thread Nick Craig-Wood
to Cython. What sort of problems have you had? I find as long as I use the same types as the C code actually uses it all works fine. If on a 64 bit platform long is 64 bits then it will be under ctypes too. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http

Re: String concatenation performance with +=

2009-02-14 Thread Nick Craig-Wood
'import array' -s 'a = array.array(c)' 'a.extend(x)' 10 loops, best of 3: 2.01 usec per loop There are many other possibilities though like the mmap module. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: encrypting lines from file with md5 module doesn't work?

2009-02-14 Thread Nick Craig-Wood
means it is an md5 hash, the next $3nvOlOaw$ is the salt and the final $vRWaitT8Ne4sMjf9NOrVZ. is the md5 hash in some encoded format or other! Some googling should reveal the correct algorithm! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org

Re: Escaping my own chroot...

2009-02-13 Thread Nick Craig-Wood
Jean-Paul Calderone exar...@divmod.com wrote: On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood n...@craig-wood.com wrote: r0g aioe@technicalbloke.com wrote: I'm writing a linux remastering script in python where I need to chroot into a folder, run some system commands

Re: Escaping my own chroot...

2009-02-11 Thread Nick Craig-Wood
packages for it if you look! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Code critique xmlrpclib

2009-02-04 Thread Nick Craig-Wood
flagg ianand0...@gmail.com wrote: On Feb 3, 7:32?am, Nick Craig-Wood n...@craig-wood.com wrote: flagg ianand0...@gmail.com wrote: ?This xmlrpc server is designed to parse dns zone files and then ?perform various actions on said files. \ ?It uses dnspython, and xmlrpclib ? I'd like

Re: Cross platform compilation?

2009-02-04 Thread Nick Craig-Wood
commitment from the python maintainers. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb and MySQL stored functions

2009-02-04 Thread Nick Craig-Wood
kurt.forrester@googlemail.com kurt.forrester@googlemail.com wrote: Any ideas on how to suppress the warning output: __main__:1: Warning: No data - zero rows fetched, selected, or processed You can use the warnings module to suppress these I would have thought. -- Nick Craig-Wood n

Re: Code critique xmlrpclib

2009-02-03 Thread Nick Craig-Wood
for examples) Don't catch all exceptions - find out which exceptions are thrown. Consider just letting it propagate - hopefully the find_rdataset error is descriptive enough. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

[issue5131] pprint doesn't know how to print a set or a defaultdict

2009-02-02 Thread Nick Craig-Wood
New submission from Nick Craig-Wood n...@craig-wood.com: I noticed this the other day when debugging a program that neither set() nor defaultdict() pprint() properly Same under 3.1 and 2.5 (Not tried 2.6/2.7 but I assume it is the same) pprint(set(range(100))) set([0, 1, 2, 3, 4, 5, 6, 7, 8

Re: Python 2.6's multiprocessing lock not working on second use?

2009-01-19 Thread Nick Craig-Wood
() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == __main__: #test_lock(processes=5, process=True) test_lock(processes=5) -- Nick Craig-Wood n...@craig-wood.com

Re: Python 2.6's multiprocessing lock not working on second use?

2009-01-19 Thread Nick Craig-Wood
to me. I'd love to be proved wrong though! If you were thinking of passing time.time() / clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll want to know that it can differ by significant amounts on different processors :-( Good luck! -- Nick Craig-Wood n...@craig-wood.com -- http

Re: ctype problem

2009-01-14 Thread Nick Craig-Wood
) ] myclib.myfunction.restype = c_int # or whatever If you do that then you should be able to pass in myiface directly or byref(myiface). -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: initialising a class by name

2009-01-14 Thread Nick Craig-Wood
'__main__.ThingTwo' class '__main__.ThingThree' -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python tricks

2009-01-13 Thread Nick Craig-Wood
or for i in infinite_loop(10): print iteration, i but I agree with Tim that a for ... else loop for the limit is clearer. Probably yes -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C or C++

2009-01-09 Thread Nick Craig-Wood
Thomas Heller thel...@python.net wrote: Nick Craig-Wood schrieb: Thomas Heller thel...@python.net wrote: Nick Craig-Wood schrieb: Interesting - I didn't know about h2xml and xml2py before and I've done lots of ctypes wrapping! Something to help with the initial drudge work

Re: Multiprocessing takes higher execution time

2009-01-08 Thread Nick Craig-Wood
of zip files is it? As reading zip files does lots of disk IO I would guess it is disk limited rather than anything else, which explains why doing many at once is actually slower (the disk has to do more seeks). -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http

Re: Creating new instances of subclasses.

2009-01-08 Thread Nick Craig-Wood
ValueError(Not a list) super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C or C++

2009-01-07 Thread Nick Craig-Wood
Thomas Heller thel...@python.net wrote: Nick Craig-Wood schrieb: Interesting - I didn't know about h2xml and xml2py before and I've done lots of ctypes wrapping! Something to help with the initial drudge work of converting the structures would be very helpful. ( http

Re: Multiprocessing takes higher execution time

2009-01-07 Thread Nick Craig-Wood
it sequentially. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C or C++

2009-01-06 Thread Nick Craig-Wood
saver. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: multiprocessing vs thread performance

2009-01-03 Thread Nick Craig-Wood
9000 working == == Thread 1 working == Total time: 834.81882 -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I manually uninstall setuptools (installed by egg)?

2008-12-12 Thread Nick Craig-Wood
David Cournapeau courn...@gmail.com wrote: On Thu, Dec 11, 2008 at 10:30 PM, Nick Craig-Wood n...@craig-wood.com wrote: David Cournapeau courn...@gmail.com wrote: On Wed, Dec 10, 2008 at 12:04 PM, Chris Rebert c...@rebertia.com wrote: On Tue, Dec 9, 2008 at 6:49 PM, excor...@gmail.com

Re: How do I manually uninstall setuptools (installed by egg)?

2008-12-11 Thread Nick Craig-Wood
that easy_install doesn't have a) a list what you installed with easy_install b) uninstall in an otherwise excellent program. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python now coming from Perl

2008-12-09 Thread Nick Craig-Wood
Roy Smith [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Nick Craig-Wood [EMAIL PROTECTED] wrote: My favourite mistake when I made the transition was calling methods without parentheses. In perl it is common to call methods without parentheses - in python this does

Re: Learning Python now coming from Perl

2008-12-08 Thread Nick Craig-Wood
- in python this does absolutely nothing! pychecker does warn about it though. perl - $object-method python - object.method() -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I do this (from Perl) in Python? (closures)

2008-12-04 Thread Nick Craig-Wood
__call__(self): x = self.x self.x += 1 return x -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I do this (from Perl) in Python? (closures)

2008-12-04 Thread Nick Craig-Wood
and kwargs yield result def make_closure(*args, **kwargs): return closure(*args, **kwargs).next I still prefer doing it explicitly with a class though ;-) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-03 Thread Nick Craig-Wood
. Then, *if it doesn't work fast enough*, make it work faster. You are 100% right of course Steve. I was just trying to answer the specific question which is faster question which probably isn't helpful for new Python programmers to focus on. PS I enjoyed your book :-) -- Nick Craig-Wood [EMAIL

Re: How to instantiate in a lazy way?

2008-12-03 Thread Nick Craig-Wood
fine! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-03 Thread Nick Craig-Wood
Slaunger [EMAIL PROTECTED] wrote: On 3 Dec., 11:30, Nick Craig-Wood [EMAIL PROTECTED] wrote: ? ? ? ? ?cls = self.__class__ ? ? ? ? ?if attr_name in cls.data_attr_names: self.data_attr_names should do instead of cls.data_attr_names unless you are overriding it in the instance (which

Re: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
import foo.bar.yourclass and use myclass.MyClass and foo.bar.yourclass.YourClass Ultimately it is a matter of taste I think! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Nick Craig-Wood
Slaunger [EMAIL PROTECTED] wrote: On 2 Dec., 11:30, Nick Craig-Wood [EMAIL PROTECTED] wrote: For 4 attributes I'd probably go with the __getattr__. OK, I'll do that! Or you could easily write your own decorator to cache the result... Eg http://code.activestate.com/recipes

Re: How to instantiate in a lazy way?

2008-12-02 Thread Nick Craig-Wood
Slaunger [EMAIL PROTECTED] wrote: On 1 Dec., 16:30, Nick Craig-Wood [EMAIL PROTECTED] wrote: I wouldn't use __getattr__ unless you've got lots of attributes to overload. ?__getattr__ is a recipe for getting yourself into trouble in my experience ;-) Just do it like this... class

Re: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
Steven D'Aprano [EMAIL PROTECTED] wrote: On Tue, 02 Dec 2008 11:12:31 +, Nick Craig-Wood wrote: I prefer the from module import function. That means that if module doesn't supply function it raises an exception at compile time, not run time when you try to run module.function

Re: distinct fcntl flags for stdin and stdout

2008-12-01 Thread Nick Craig-Wood
result is because stdin and stdout refer to the same file (eg /dev/tty0 or /dev/pts/25). No idea whether this is correct behaviour or not though! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-01 Thread Nick Craig-Wood
(0)' 100 loops, best of 3: 1.48 usec per loop -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Emacs vs. Eclipse vs. Vim

2008-12-01 Thread Nick Craig-Wood
these features, don't know about Eclipse. In fact if I had to pick one feature that a programmer's editor must have it would be keyboard macros. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-01 Thread Nick Craig-Wood
= self.really_read_the_data() return self._data -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a directory file descriptor?

2008-11-26 Thread Nick Craig-Wood
at 0xb7d13cd4 dir_fd = 3 closed (rc 0) I don't know why os doesn't wrap - opendir, closedir, dirfd, readdir etc - I guess because except if you are doing something esoteric, then os.list and os.walk do everything you could possibly want. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig

Re: Python Django Latex Permissions Problem

2008-11-25 Thread Nick Craig-Wood
that dont have access to /tmp/pdfscratch{id} Unlikely - it takes root to change user and I wouldn't have thought any of the files would be setuid. Try chdir to /tmp/pdfscratch{id} first would be my suggestion. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http

Re: recommended __future__ imports for 2.5?

2008-11-25 Thread Nick Craig-Wood
... ;-) I think that is called using // instead of / which works without any from __future__ import from python 2.2 onwards. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: compressed serialization module

2008-11-19 Thread Nick Craig-Wood
greg [EMAIL PROTECTED] wrote: Nick Craig-Wood wrote: (Note that basic pickle protocol is likely to be more compressible than the binary version!) Although the binary version may be more compact to start with. It would be interesting to compare the two and see which one wins

Re: compressed serialization module

2008-11-18 Thread Nick Craig-Wood
efficient. Eg import bz2 import pickle L = range(100) f = bz2.BZ2File(z.dat, wb) pickle.dump(L, f) f.close() f = bz2.BZ2File(z.dat, rb) M = pickle.load(f) f.close() M == L True (Note that basic pickle protocol is likely to be more compressible than the binary version!) -- Nick Craig-Wood

Re: setting permissions to a file from linux.

2008-11-18 Thread Nick Craig-Wood
Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: C Function Pointer Wrapping Example not working

2008-11-17 Thread Nick Craig-Wood
it with the swig wrapper before you make the .so -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Best practise hierarchy for user-defined exceptions

2008-11-17 Thread Nick Craig-Wood
if the above code worries you, then MyParseError isn't a ValueError and you shouldn't inherit from ValueError. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: compressed serialization module

2008-11-17 Thread Nick Craig-Wood
len(pickle.dumps([1,2,3], 0)) 18 Or even L = range(100) a = pickle.dumps(L) len(a) 496 b = a.encode(bz2) len(b) 141 c = b.decode(bz2) M = pickle.loads(c) M == L True -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman

Re: C Function Pointer Wrapping Example not working

2008-11-16 Thread Nick Craig-Wood
easier. You just write C .so/.dll and use ctypes to access them. You can do callbacks and embedding python like this too. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Good practice when writing modules...

2008-11-16 Thread Nick Craig-Wood
do it! There are arguments against doing this, which I'm sure you'll hear shortly ;-) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to use a contiguous memory location of n bytes in python

2008-11-14 Thread Nick Craig-Wood
' a[9] '\x00' a[9]='q' a[9] 'q' del a -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: why does this call to re.findall() loop forever?

2008-11-10 Thread Nick Craig-Wood
examples. Eg http://bugs.python.org/issue1515829 I'd attack this problem using beatifulsoup probably rather than regexps! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple parameter unpacking in 3.x

2008-10-04 Thread Nick Craig-Wood
(ai, bi): return ai * bi ci.addCallback(f) def f(i, s): return field(i + 1), s map(f, enumerate(si)) PEP-3113 needs updating as it is certainly confusing here! 2to3 is doing the wrong thing also by the look of it. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig

Re: Advice for a replacement for plone.

2008-09-30 Thread Nick Craig-Wood
minutes probably! It will take you a couple of hours the first time though. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing float and decimal

2008-09-25 Thread Nick Craig-Wood
] on linux2 Linux 2.6.26-1-686 Intel(R) Core(TM)2 CPU T7200 -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Eggs, VirtualEnv, and Apt - best practices?

2008-09-25 Thread Nick Craig-Wood
be really helpful! Suggestions on build/rollout tools (like zc.buildout, Paver, etc) would also be appreciated. Use setup.py to build into .debs is what we do. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing float and decimal

2008-09-24 Thread Nick Craig-Wood
the exact conversions in for floats to Decimal and Fraction by default and add a new section to the FAQ! In that way people will see floats for what they really are - a crude approximation to a rational number ;-) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http

Re: How can I use a PyObject in C++?

2008-09-24 Thread Nick Craig-Wood
*/ if (my_result == 0) { PyErr_Print(); printf(Couldn't read result from MyModule.SubModule.my_function); goto out; } my_result = strdup(my_result); /* keep in our own memory */ out:; Py_XDECREF(result); Py_XDECREF(module); return my_result; } -- Nick Craig

Re: PyRun_SimpleFile() crashes

2008-09-24 Thread Nick Craig-Wood
-simplefile-crashes-on-windows-but-not-on-unix-why.htm -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: dict slice in python (translating perl to python)

2008-09-12 Thread Nick Craig-Wood
Steven D'Aprano [EMAIL PROTECTED] wrote: On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote: As an ex-perl programmer and having used python for some years now, I'd type the explicit v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars Or maybe even

Re: dict slice in python (translating perl to python)

2008-09-11 Thread Nick Craig-Wood
,v3 = [ mydict[k] for k in 'one two two'.split()] # 54 chars Unlike perl, it will also blow up if mydict doesn't contain 'one' which may or may not be what you want. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple UDP server

2008-09-10 Thread Nick Craig-Wood
-select.html Actually if I really had to do this I'd use twisted. Right tool for the job! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: creating an (inefficent) alternating regular expression from a list of options

2008-09-09 Thread Nick Craig-Wood
;-) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: use str as variable name

2008-09-04 Thread Nick Craig-Wood
is supposed to achieve rather than : if arg == 'height': a.height = new_value elif arg == 'width'; a.width = new_value Can I do this with python ? How ? setattr(a, arg, new_value) See: http://docs.python.org/lib/built-in-funcs.html -- Nick Craig-Wood [EMAIL PROTECTED] -- http

Re: Numeric literal syntax (was: Py 2.6 changes)

2008-09-02 Thread Nick Craig-Wood
* -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: export sites/pages to PDF

2008-08-12 Thread Nick Craig-Wood
for some more info on dcop :- http://www.ibm.com/developerworks/linux/library/l-dcop/ -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A Question about ctypes and a function f(void **)

2008-08-11 Thread Nick Craig-Wood
to somewhere else. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with global variables

2008-08-09 Thread Nick Craig-Wood
Test(object): def __init__(self): self.foo = [] def goo(self): self.foo.append(2) def moo(self): print self.foo test = Test() from test2 import test test.foo [] test.goo() test.foo [2] test.moo() [2] -- Nick Craig-Wood [EMAIL PROTECTED

Re: Interconvert a ctypes.Structure to/from a binary string?

2008-08-04 Thread Nick Craig-Wood
' Which I think is probably acceptable... Some to/from binary methods would be nice, or failing that an explicit section in the docs! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes - unloading implicitly loaded dlls

2008-07-28 Thread Nick Craig-Wood
the code into two or three processes though. Perhaps use http://pypi.python.org/pypi/processing to communicate between them. That should get you out of DLL Hell! (Don't load any of the DLLs before you start the worker processes off.) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com

Re: ActiveState Code (the new Python Cookbook) has been launched

2008-07-28 Thread Nick Craig-Wood
telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is recursion so slow?

2008-07-02 Thread Nick Craig-Wood
Rich Harkins [EMAIL PROTECTED] wrote: Nick Craig-Wood wrote: [snip] By definition any function in a functional language will always produce the same result if given the same arguments, so you can memoize any function. Ah, so that's why time.time() seems to be stuck

Re: Why is recursion so slow?

2008-07-01 Thread Nick Craig-Wood
the recursive algorithm run fast... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52201 -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   >