Re: Escaping my own chroot...

2009-02-13 Thread Nick Craig-Wood
Jean-Paul Calderone wrote: > On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood > wrote: > >r0g wrote: > >> I'm writing a linux remastering script in python where I need to chroot > >> into a folder, run some system commands and then come out and do some

Re: String concatenation performance with +=

2009-02-14 Thread Nick Craig-Wood
moredata = "A"*4096 test = StringConcatTest() t = time.time() for i in range(1000): test.feed(moredata) print "%0.3f ms"%(1000*(time.time() - t)) Before it was 3748.012 ms on my PC, afterwards it was 52.737 ms However that isn't a perfect solution - what if something had anot

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

2009-02-14 Thread Nick Craig-Wood
est:$1$3nvOlOaw$vRWaitT8Ne4sMjf9NOrVZ.:13071:0:9:7::: (not a real password line!) You need to work out how to write that format. >From memory: the "$1" bit means it is an md5 hash, the next "$3nvOlOaw$" is the salt and the final "$vRWaitT8Ne4sMjf9NOrVZ." is the m

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

2009-02-15 Thread Nick Craig-Wood
all platforms. I used to use > ctypes for wrapper but eventually I switched 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

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

2009-02-16 Thread Nick Craig-Wood
tly the same on all supported platforms and since it usually runs full screen that is fine. I imagine 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 -- 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
ibrary atof() does. Ie only converting as much as it can and returning 0.0 for an error. """ match = _float_pattern.search(value) if match: return float(match.group(1)) return 0.0 >>> atof("15.5 Sausages") 15.5 >>> atof(" 17.2")

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

2009-02-20 Thread Nick Craig-Wood
t; return self._A def _setA(self, value): print "Setting A" self._A = value A = property(_getA, _setA) def main(self): print self.A print self.B # dosomething self.A = "aValue" self.B = "aValue" print self.A print self.B >>> a = Stuff() >>> a.main() Getting A None None Setting A Getting A aValue aValue >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: can multi-core improve single funciton?

2009-02-23 Thread Nick Craig-Wood
fibonacci_noniterative(i) t_noniterative = time() - t0 print "%10d, %10.6f, %10.6f" % (i, t_iterative, t_noniterative) if f_iterative != f_noniterative: print "Calculation error" print "iterative", f_iterative print "non iterative", f_noniterative print "difference", f_iterative-f_noniterative -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Django Latex Permissions Problem

2008-11-25 Thread Nick Craig-Wood
is directory. I have a feeling that > pdflatex is trying to generate files using some weird access > credentials 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/pdfscrat

Re: recommended __future__ imports for 2.5?

2008-11-25 Thread Nick Craig-Wood
'm still waiting to hear that > > from __past__ import division > > will become a reality... ;-) 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: How to get a directory file descriptor?

2008-11-26 Thread Nick Craig-Wood
opendir(".") print "dir_p = %r" % dir_p dir_fd = dirfd(dir_p) print "dir_fd = %r" % dir_fd print "closed (rc %r)" % closedir(dir_p) Which prints on my linux machine dir_p = dir_fd = 3 closed (rc 0) I don't know why os doesn't wrap - opendir, cl

Re: distinct fcntl flags for stdin and stdout

2008-12-01 Thread Nick Craig-Wood
e 'r' at 0xb7d03020> fd=0 STDOUT ', mode 'w' at 0xb7d03068> fd=1 os.O_NDELAY=0800 stdin: flag=0002 stdout: flag=8001 setting non blocking on stdin... stdin: flag=0802 stdout: flag=8001 removing non blocking on stdin... stdin: flag=0002 stdout: flag=8001 So I suspect your 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
uot; And here is the test again, actually calling something with the same difference in execution speed :- $ python -m timeit -s 'from os import nice' 'nice(0)' 100 loops, best of 3: 1.21 usec per loop $ python -m timeit -s 'import os' 'os.nice(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
im have all 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
e first time it will populate itself. If None is a valid value for data then make a sentinel, eg class PayloadOnDemand(object): sentinel = object() def __init__(self, a_file, a_file_position): self._data = self.sentinel self.f = a_file self.file_position = a_file_position @property def data(self): if self._data is self.sentinel: self._data = 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: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
bar.yourclass import YourClass If this spelling causes local name clashes, then spell them import myclass 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

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 >

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 +0000, Nick Craig-Wood wrote: > > > I prefer the "from module import function". That means that if "module" > > doesn't supply "function" it raises an

Re: Do more imported objects affect performance

2008-12-03 Thread Nick Craig-Wood
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 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
Restore file position > self.f.seek(initial_pos) > # Unbind lazy attributes > del self.f > del self.ver > del self.file_position > del self.samples > > This seems to work out well. No infinite loops in __getattr__! :-) I would probably factor out the contents of the if statement into a seperate method, but that is a matter of taste! > At least it passes the unit test cases I have come up with so far. > > No guarantees though, as I may simply not have been smart enough to > bring forth unit test cases which make it crash. > > Comments on the code is still appreciated though. Looks 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_

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

2008-12-04 Thread Nick Craig-Wood
in Python? With a class is the best way IMHO. class make_counter(object): def __init__(self, start_num): self.x = start_num def __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
careful with nonlocal args & kwargs return result vs def closure(*args, **kwargs): # initialisation to local vars while 1: # normal stuff using args and kwargs yield result def make_closure(*args, **kwargs): return closure(*args, **kwargs).next I still pre

Re: Learning Python now coming from Perl

2008-12-08 Thread Nick Craig-Wood
In perl it is common to call methods without parentheses - 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: 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 meth

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

2008-12-11 Thread Nick Craig-Wood
; BTW. It is a much better practice to install from source into > /usr/local, or your $HOME, etc... Anywhere which is not /usr. easy_install can do that I think... I find it odd 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: How do I manually uninstall setuptools (installed by egg)?

2008-12-12 Thread Nick Craig-Wood
David Cournapeau wrote: > On Thu, Dec 11, 2008 at 10:30 PM, Nick Craig-Wood > wrote: > > David Cournapeau wrote: > >> On Wed, Dec 10, 2008 at 12:04 PM, Chris Rebert wrote: > >> > On Tue, Dec 9, 2008 at 6:49 PM, wrote: > >> >> On Ubun

Re: multiprocessing vs thread performance

2009-01-03 Thread Nick Craig-Wood
== Thread 7000 working == == Thread 8000 working == == Thread 9000 working == == Thread 1 working == Total time: 834.81882 -- Nick Craig-Wood -- 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
thing sensible in ctypes, c_byte * 0 is what is required plus a bit of casting. This is a non-standard GNU extension to C though. All that said though, it looks like a great time saver. -- Nick Craig-Wood -- 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 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. > &g

Re: Multiprocessing takes higher execution time

2009-01-07 Thread Nick Craig-Wood
dahl's Law too where P is approx 0, N irrelevant... Being IO bound explains why it takes longer with multiprocessing - it causes more disk seeks to run an IO bound algorithm in parallel than running it sequentially. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiprocessing takes higher execution time

2009-01-08 Thread Nick Craig-Wood
are you processing at once? And how many MB 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 -- http://www.cr

Re: Creating new instances of subclasses.

2009-01-08 Thread Nick Craig-Wood
raise ValueError("Couldn't find subclass") def __init__(self, input): super(Field, self).__init__(input) self.data = input # Raise a ValueError in init if not suitable args for this subtype class IntegerField(Field): def __init__(self, s): s = int(s) super(IntegerField, self).__init__(s) self.s = s class ListField(Field): def __init__(self, s): if ',' not in s: raise ValueError("Not a list") super(ListField, self).__init__(s) self.s = s.split(',') class StringField(Field): pass -- Nick Craig-Wood -- 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 wrote: > Nick Craig-Wood schrieb: > > Thomas Heller 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 w

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

2008-11-10 Thread Nick Craig-Wood
es. 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: How to use a contiguous memory location of n bytes in python

2008-11-14 Thread Nick Craig-Wood
m mmap import mmap >>> a = mmap(-1, 10) >>> a[0] '\x00' >>> a[0] = 'z' >>> 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: C Function Pointer Wrapping Example not working

2008-11-16 Thread Nick Craig-Wood
a look at the code SWIG generates and see if it puts some extern "C" in and match what it does in your code. We used to use SWIG in for python embedding in our C++ project, but we found that using ctypes is a lot 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
ting things into your local namespace is also the quickest, but that isn't why I 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: C Function Pointer Wrapping Example not working

2008-11-17 Thread Nick Craig-Wood
a-b; }; >int mymul( int a, int b ) { return a*b; }; > } > > Traceback (most recent call last): >File "", line 1, in >File "test.py", line 7, in > import _test > ImportError: ./_test.so: undefined symbol: binary_op Nowhere in your code is the definition of binary_op - that is why you get a linker error. Is it defined in another C file? If so you need to link 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
have_overlooked() > do_something_where_I_know_a_ValueError_can_be_raised() > catch ValueError: > handle_the_anticipated_ValueError_from_std_lib() > finally: > > > I will not notice that it was an unanticpated condition in my own > code, which cause

Re: compressed serialization module

2008-11-17 Thread Nick Craig-Wood
protool. Here's a silly example: > > >>> len(pickle.dumps([1,2,3], pickle.HIGHEST_PROTOCOL)) > 14 > >>> len(pickle.dumps([1,2,3], 0)) > 18 Or even >>> L = range(100) >>> a = pickle.dumps(L) >>> len(a) 496 >>>

Re: compressed serialization module

2008-11-18 Thread Nick Craig-Wood
ot;, "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 <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: setting permissions to a file from linux.

2008-11-18 Thread Nick Craig-Wood
hmod(0775, "directory") rather than os.chmod(775, "directory") (leading 0 implies octal) -- 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 compar

Re: Extending Python Questions .....

2009-02-23 Thread Nick Craig-Wood
thon - it all happens behind the scenes. If you are writing a python extension in C then you do need to worry about reference counting - a lot! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

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

2009-02-24 Thread Nick Craig-Wood
;, time='1:00 PM' n='4', name='Adam', a='7', b='8', day='Monday', time='2:00 PM' n='5', name='Bob', a='9', b='10', day='Monday', time='2:00 PM' n='6', name='Charlie', a='11', b='12', day='Monday', time='2:00 PM' n='7', name='Adam', a='13', b='14', day='Tuesday', time='1:00 PM' n='8', name='Bob', a='15', b='16', day='Tuesday', time='1:00 PM' n='9', name='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 -- 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
expanded > > My SLAG project does not care in reality WHICH or what language, it > is simply 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! -

Re: Extending Python Questions .....

2009-02-26 Thread Nick Craig-Wood
Ben wrote: > On Feb 24, 11:31?am, Nick Craig-Wood 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 t

Re: Using xreadlines

2009-02-28 Thread Nick Craig-Wood
e http://docs.python.org/library/linecache.html Which may be useful... -- Nick Craig-Wood -- 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
ng python as much of the time as possible and C++ only when necessary. -- Nick Craig-Wood -- 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
gt; such a job easily. I need a c parser, is there any 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 gcc

Re: A better way to timeout a class method?

2009-03-09 Thread Nick Craig-Wood
docs.python.org/library/signal.html Won't work on windows and there is only one sigalarm timer, so you can't nest them :-( -- Nick Craig-Wood -- 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
ef long_function(): duration = Duration(5) i = 0 print "starting" while duration: print i i += 1 sleep(1) print "finished" long_function() Which prints starting 0 1 2 3 4 finished -- Nick Craig-Wood -- 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
ing cannot end in a single backslash (since the backslash would escape the following quote character). The usual way round this is like this >>> r"a" "\\" 'a\\' >>> Which isn't terribly elegant, but it doesn't happen very often. -- Nick Craig-Wood -- 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
ute_key) Which I think is clearer and more 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 -- 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
y to people who haven't coded in Python for one reason > or another. Perhaps the OP is looking for something like this http://pleac.sourceforge.net/pleac_python/index.html Which is a sort of Rosetta stone for perl and python ;-) (The perl cookbook translated into python.) -- Nick Craig-Wood -- 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
dded ARM-Linux system ? Works very well. > Does cross compiling Python automatically include 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 -- 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
start = digits[0] end = digits[-1] f = open(minmax_path, "w") f.write("%s %s" % (start, end)) f.close() print "done" if __name__ == "__main__": main() -- Nick Craig-Wood -- 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
tly. 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 -- 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
python as with shell because it has almost everything you'll need built in. Using built 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 -- 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
use up all my RAM and explode. What I wanted to happen was for twisted to stop taking the data when the serial port buffer was full and to only take the data at 9600 baud. I never did solve that problem :-( -- Nick Craig-Wood -- 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 wrote: > On Sun, 22 Mar 2009 12:30:04 -0500, Nick Craig-Wood > 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 wrote: > On Mon, 23 Mar 2009 05:30:04 -0500, Nick Craig-Wood > wrote: > >Jean-Paul Calderone wrote: > > [snip] > >> > >> In the case of a TCP to serial forwarder, you don't actually have to > >> implement either a pro

Re: Using python 3 for scripting?

2009-03-23 Thread Nick Craig-Wood
.4 is still perhaps the safest bet, even though 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 u

Re: udp package header

2009-03-24 Thread Nick Craig-Wood
address is the address of the socket sending the data. -- Nick Craig-Wood -- 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
unmatched brackets, empty brackets, etc) and be sure it works exactly as specified. doctest is cool for this kind of stuff. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: C extension using GSL

2009-03-27 Thread Nick Craig-Wood
ll once you've jumped the flaming hoops of fire that setting it up is! Another thing you can try is run your process untill it leaks loads, then make it dump core. Examine the core dump with a hex editor and see what it is full of! This technique works suprisingly often. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

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

2009-03-27 Thread Nick Craig-Wood
quite a few years of python programing I'm still 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

Re: Code anntotations (copyright, autor, etc) in your code

2009-03-28 Thread Nick Craig-Wood
nt only in the source code! I think the others are just conventions and are not actually used by anything, but I'd be interested to be proved wrong! I tend to use __author__ = "Nick Craig-Wood " __version__ = "$Revision: 5034 $" __date__ = "$Date: 2009-02-03 16:50:0

Re: C extension using GSL

2009-03-28 Thread Nick Craig-Wood
y> rc(x) > 2 # the name x, and a temporary reference as parameter > py> rc([]) > 1 # only the temporary reference > py> x = y = [] > py> rc(x) > 3 > py> x = () > py> rc(x) > 954 # the empty tuple is shared That reminds me, you can use the g

Re: How to port Python to an ARM running NucleusPlus OS

2009-03-28 Thread Nick Craig-Wood
ld be easy. Try to compile python in the cross compiling environment and see what happens! However if you are running Nucleus with Linux and want to run python in the Linux bit of it then I'd suggest to use the packages available for the Linux side of it. (Eg if it is running debian then ap

Re: Interfacing python and C

2009-03-28 Thread Nick Craig-Wood
rface file? Should the user defined header be placed > > in the /usr/include directory? > > > > Any help on this is highly appreciated. My advice to you is to compile the C stuff into a .so and use ctypes instead of swig. You then write the interface code in python not C and you'll have a lot more fun! cython is very useful in this area too provided you don't mind an extra dependency. If you are developing C code from scratch to use with python, then write it in cython instead! > Should you be putting a function body in a header file? No -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python Runtime / Unladen Swallow

2009-03-28 Thread Nick Craig-Wood
n to fold their work back into CPython when done too. Sounds like a project to keep an eye on! > Now the question is will this make Vista run faster? Nothing could do that ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Programming Python 4th Edition?

2009-03-29 Thread Nick Craig-Wood
enjoyed the encyclopedic nature of it. So if it appeals to you I'd say go for it! The fact that it doesn't use the latest version of python isn't a problem - python doesn't change very quickly and emphasises backwards compatibility, even for the jump to 3.x. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Ordered Sets

2009-03-30 Thread Nick Craig-Wood
ect at 0xb7e897cc> >>> Node(1,2,3).prev 1 >>> L = [] >>> for i in xrange(100): ... L.append(Node(1,2,3)) ... >>> import os >>> os.getpid() 28203 >>> (from top) 28203 ncw 20 0 43364 38m 1900 S0 1.9 0:04.41 python So the Node class actually takes less memory 38 Mbytes vs 53 Mbytes for the list. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A design problem I met again and again.

2009-04-01 Thread Nick Craig-Wood
ion in your program will rise. I've noticed some programmers think in big classes and some think in small classes. Train yourself to do the other thing and your programming will improve greatly! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: double/float precision question

2009-04-01 Thread Nick Craig-Wood
at C calls doubles. When you do >>> float( 0.222) 0.1 Python prints as many decimal places as are significant in the answer. This is covered in the FAQ http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate If you want more precision use the built in decimal module or the third party gmpy module. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

python docs redirect on python.org is old

2009-04-04 Thread Brandon Craig Rhodes
When I visit ... http://www.python.org/doc/lib/lib.html ... I get redirected to ... http://www.python.org/doc/2.5.2/lib/lib.html ... which seems a bit old. -- Brandon Craig Rhodes [email protected] http://rhodesmill.org/brandon -- http://mail.python.org/mailman/listinfo

Re: HTML Generation

2009-04-16 Thread Nick Craig-Wood
e here http://packages.debian.org/sid/python-htmlgen But I think its original website is gone. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to extract from regex in if statement

2009-04-16 Thread Nick Craig-Wood
t;" def search(self, r, s): """ Do a regular expression search and return if it matched. """ self.value = re.search(r, s) return self.value def __getitem__(self, n): """ Return n'th matched () item. Note so the first matched item will be matcher[0] """ return self.value.group(n+1) def groups(self): """ Return all the matched () items. """ return self.value.groups() -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: interacting with an updatedb generated data file within python

2009-04-16 Thread Nick Craig-Wood
ds" This builds a set of all the files on the filesystem and prints Found 314492 files in 1.152987957 seconds on my laptop, using about 19 MB total memory You could easily enough put that into an sqlite table instead of a set(). -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create a virtual serial port?

2009-04-19 Thread Nick Craig-Wood
>> > >> On Linux: no. > > > > I wonder if there is no way to emulate ptys from userspace? > > Didn't I just answer that question? > > On Linux: no. Actually you could do it with an LD_PRELOAD library Intercept open("/dev/ttyS0",...). You

Re: A Special Thanks

2009-04-21 Thread Nick Craig-Wood
dology above then when you re-organize (or refactor to use the modern jargon) the code you can be 100% sure that you didn't break anything which is a wonderful feeling. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pyflakes, pylint, pychecker - and other tools

2009-04-23 Thread Nick Craig-Wood
odule_name") you can then click in its output window to go to the correct line of code. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Large data arrays?

2009-04-23 Thread Nick Craig-Wood
f the other which would then speed up the two access patterns enormously. You needn't mmap the two arrays (files) at the same time either. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Memory footpring of python objects

2009-04-23 Thread Nick Craig-Wood
the most common class (several hundred thousand instances!). When doing these optimisations I ran a repeatable script and measured the total memory usage using the OS tools (top in my case). -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Large data arrays?

2009-04-23 Thread Nick Craig-Wood
Ole Streicher wrote: > Hi Nick, > > Nick Craig-Wood writes: > > mmaps come out of your applications memory space, so out of that 3 GB > > limit. You don't need that much RAM of course but it does use up > > address space. > > Hmm. So I have

Re: bug with os.rename in 2.4.1?

2009-04-28 Thread Nick Craig-Wood
27;.0') except OSError: pass Which isn't racy. Or if you wanted to be more thorough import errno try: os.rename(paths.xferin_dir+'/COMM.DAT',paths.xferin_dir+'/COMM.DAT'+'.0') except OSError, e: if e.errno != err

Re: bug with os.rename in 2.4.1?

2009-04-30 Thread Nick Craig-Wood
Steven D'Aprano wrote: > On Tue, 28 Apr 2009 14:30:02 -0500, Nick Craig-Wood wrote: > > > t123 wrote: > >> It's running on solaris 9. Here is some of the code. It's actually > >> at the beginning of the job. The files are ftp'd over. Th

Re: wxPython menu creation refactoring

2009-04-30 Thread Nick Craig-Wood
andler, item) menuBar.Append(submenu, menuLabel) self.SetMenuBar(menuBar) That is the way I normally do it anyway! You create the submenu as a seperate menu then attach it to the menuBar with the label. Note there is a wxpython list also which you may get more help in! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: object query assigned variable name?

2009-05-01 Thread Nick Craig-Wood
; Any thoughts? Read up on introspection and learn how to look up through the stack frames. When you've mastered that look for an object matching self in all the locals in those stack frames. That will give some kind of answer. I have no idea whether this will work - the keyboard of my phone is too small to produce a proof ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How should I use grep from python?

2009-05-07 Thread Nick Craig-Wood
gt;> p.wait() # returns the error code 0 >>> There was talk of removing the other methods from public use for 3.x. Not sure of the conclusion. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Python process utility (psutil) 0.1.2 released

2009-05-09 Thread Nick Craig-Wood
uot; returned something useful also! You could do this by replacing your current __init__.py (which just contains "from _psutil import *") with _psutil.py -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Problems with datetime.datetime.strptime

2009-05-10 Thread Nick Craig-Wood
ts and the documentation then submit the patch to the python bugtracker. If I couldn't fix it then I'd report it as a bug. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode bit me

2009-05-10 Thread Nick Craig-Wood
code byte 0xc2 in position 1: ordinal not in range(128) >>> unicode('[\xc2\xa9au]') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1: ordinal not in range(128) >>> L.__unicode__ Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute '__unicode__' >>> unicode(str(L),"utf-8") u'[\xa9au]' -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning C++ for Python Development

2009-05-11 Thread Nick Craig-Wood
he C++ symbols into the python code at runtime with ctypes. A bit of C++ implements the shims for the callbacks from python -> C++ (which are exported by ctypes). > P.S. I want to develop on Linux not Windows. Should be just the same on both. Once you've made your setup.py (for

Re: Q's on my first python script

2009-05-11 Thread Nick Craig-Wood
def __init__(self): usage = '''Usage: %prog [options] YYMMDD %prog -h|--help ''' parser = OptionParser(usage=usage) parser.add_option("-n", "--no-newline", dest="nonl",

Re: how GNU stow is complementary rather than alternative to distutils

2009-05-11 Thread Nick Craig-Wood
it follows a very dumb, completely reversible > (uninstallable) process of symlinking those files into the system > directory structure. Once you've got that well formed directory structure it is very easy to make it into a package (eg deb or rpm) so that idea is useful in general for package managers, not just stow. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping comments

2009-05-11 Thread Nick Craig-Wood
now what I mean), just to the left of the > RETURN key. Emacs is my editor of choice, and I've never once come > across anything like this. You probably haven't used MAC OS X then! I vnc to a mac and use emacs and I just can't type a #. "Ctrl-Q 43 Return" is my best effort! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

<    2   3   4   5   6   7   8   9   >