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

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

Re: OOP & Abstract Classes

2009-05-11 Thread Nick Craig-Wood
;", line 5, in getMeasurement NotImplementedError >>> base.setPressure(14) Traceback (most recent call last): File "", line 1, in File "", line 7, in setPressure NotImplementedError >>> >>> real = RealDevice("/dev/ttyS1") >>> real RealDevice('/dev/ttyS1') >>> real.getMeasurement() 0 >>> real.setPressure(14) >>> real.getMeasurement() 14 >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: issue with twisted and reactor. Can't stop reactor

2009-05-12 Thread Nick Craig-Wood
callbacks or deferred objects). To get your program to do something immediately after it is started, use reactor.callLater() before calling reactor.run(). You can't mix and match programming styles with twisted - it is all asynchronous callbacks or nothing in my experience! That takes a bit of

Re: itertools question

2009-05-14 Thread Nick Craig-Wood
if not out: break yield out g = Grouper(5, xrange(20)) print list(g) g = Grouper(4, xrange(19)) print list(g) Which produces [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)] [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11), (12, 13, 14, 15), (16, 17,

Re: Need advice on distributing small module

2009-05-16 Thread Nick Craig-Wood
plejson as json Is more pythonic... You aren't relying on what came with particular python versions which may not be true in jython/ironpython/etc. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Options for creating a statistics screen on a Mac with Python?

2009-05-16 Thread Nick Craig-Wood
be even a bit > easier. I'd use pygame for a really clean full screen display. Probably a bit more work, but you'll get something really cool at the end of it! here is how to use matplotlib on a pygame surface http://www.pygame.org/wiki/MatplotlibPygame -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a Par construct to Python?

2009-05-21 Thread Nick Craig-Wood
=10**6 because I got bored of waiting ;-) map 9.85280895233 pmap 28.4256689548 So the pmap took nearly 3 times as long. I expect this is because the task was divided into 5 sections each competing madly for the GIL. I ran the same script under the latest jython beta which was very interesting! pmap showing a slight improvement, and faster than cPython! $ jython2.5rc2/jython pmap.py map 6.242000103 pmap 5.8881144 -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Spawn a process with P_NOWAIT and pass it some data ?

2009-05-21 Thread Nick Craig-Wood
nder.py\n' (printed with a 1 second pause between each line) ---- If you want to interact with a subprocess (eg send, receive, send, receive) then use the pexpect module - buffering in subprocess will cause you nothing but pain otherwise! > (Or, is there a way to create a subprocess.Popen object from what I assume = > is the process handle integer ?) Errr, not as far as I know. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Ah, ctypes

2009-06-01 Thread Nick Craig-Wood
uld potentially note that function types don't have enough references to them when passed in as arguments to C functions? It might slow it down microscopically but it would fix this problem. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Ah, ctypes

2009-06-01 Thread Nick Craig-Wood
David Bolen wrote: > Nick Craig-Wood writes: > > > ctypes could potentially note that function types don't have enough > > references to them when passed in as arguments to C functions? It > > might slow it down microscopically but it would fix this problem. &

Re: Using C++ and ctypes together: a vast conspiracy? ;)

2009-06-02 Thread Nick Craig-Wood
ointers etc. If you want to dig into virtual classes with multiple bases or the STL then you are probably into the territory you describe. That said I've used C++ with ctypes loads of times, but I always wrap the exported stuff in extern "C" { } blocks. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: easiest way to plot x,y graphically during run-time?

2009-06-04 Thread Nick Craig-Wood
radius -= 1 screen.fill(background_colour) for dot in dots: pygame.draw.circle(screen, foreground_colour, dot, radius, 1) dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in dots ] pygame.display.flip() if __name__ == "__main__"

Re: Get the hard disk hardware serial number

2009-06-04 Thread Nick Craig-Wood
Enabled According to the man page smartctl also runs under windows/mac/solaris etc -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What text editor is everyone using for Python

2009-06-04 Thread Nick Craig-Wood
, press Ctrl-C Ctrl-C and have the output shown in a different window. If you messed up, clicking on the error will put the cursor in the right place in the code). -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What text editor is everyone using for Python

2009-06-05 Thread Nick Craig-Wood
Ben Finney wrote: > Emile van Sebille writes: > > > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > > > In message , Nick Craig- > > > Wood wrote: > > > > > >> You quit emacs with Ctrl-X Ctrl-C. > > > > > > That'

Re: unladen swallow: python and llvm

2009-06-05 Thread Nick Craig-Wood
m concerned is that it is more of a port of CPython to a new architecture than a complete re-invention of python (like PyPy / IronPython / jython) so stands a chance of being merged back into CPython. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: sys.excepthack...

2008-05-15 Thread Nick Craig-Wood
error_text = "".join(format_exception(type, value, traceback)) wx.MessageDialog(None, error_text, 'Custom Error:', wx.OK).ShowModal() def OnClick(self, evt): "Click with a deliberate mistake" adsfsfsdf if __name__ == "__main__": a

Re: TPCServer and xdrlib

2008-05-16 Thread Nick Craig-Wood
rd with xmlrpc. > > I have looked at various solutions including: > > - PyOrbit - too heavy weight > - Pyro - uses pickle, I do not trust it It is possible to change the serialization used by Pyro http://pyro.sourceforge.net/manual/9-security.html#pickle to the the 'g

Re: Get all the instances of one class

2008-05-19 Thread Nick Craig-Wood
est.instances() Which prints [] [<__main__.Test object at 0xb7d4eb6c>, <__main__.Test object at 0xb7d4eb4c>] [<__main__.Test object at 0xb7d4eb6c>] [] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: TPCServer and xdrlib

2008-05-20 Thread Nick Craig-Wood
hon with a bit of searching. Also I believe twisted supports them directly or you could easily roll your own. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: scaling problems

2008-05-20 Thread Nick Craig-Wood
do more of those!" - as a battle scarred C programmer I'd agree ;-) -- 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   >