Re: How to use a timer in Python?

2005-09-23 Thread Nick Craig-Wood
time.sleep(1) and try again. This kind of locking works cross platform too. You can use it in shell too, eg "mkdir /tmp/lock || exit 1" in your cronjob. You could wrap the locking up into a module of course, and I bet someone already did. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to use a timer in Python?

2005-09-23 Thread Nick Craig-Wood
) f.close() os.rmdir(lock_file) print "Done!" You need to do the same thing to the program which currently creates transfer.lock - so it waits if the transfer.lock is in existence too. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess and non-blocking IO (again)

2005-10-11 Thread Nick Craig-Wood
tence in speech: print sentence.rstrip('\n') sys.stdout.flush() # sanity check else: # EOF speakers.remove( speaker ) gives b o x 1 b o x 3 b o x 2 pause... g o o d b y e etc... I'm not sure why readline only returns 1 cha

xml.minidom and user defined entities

2005-11-09 Thread Nick Craig-Wood
g xml.minidom? I've spend some time searching the docs/code/google but I haven't found the answer to this question! Thanks -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: xml.minidom and user defined entities

2005-11-09 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > I'm using xml.minidom to parse some of our XML files. Some of these > > have entities like "°" in which aren't understood by xml.minidom. > > ° is not a standard entity

Re: gmpy 1.01 rc near... anybody wanna test>

2005-11-10 Thread Nick Craig-Wood
system). Thanks and look forward to the release Nick -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: gmpy/decimal interoperation

2005-11-14 Thread Nick Craig-Wood
en > implicitly None I'd say! Perhaps make a less laborious manual conversion function, but I don't think implicit conversion is that useful since decimal and gmpy are solving quite different problems. Implicit conversions also opens the can of worms - what is the preferred promotion type?

Re: How to avoid "f.close" (no parens) bug?

2005-11-14 Thread Nick Craig-Wood
hecker catches, so install pychecker and run it on all your programs is the answer! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

simulating #include in python

2005-11-15 Thread Nick Craig-Wood
he symbols from the import back in for name in dir(module): if not (name.startswith("__") and name.endswith("__")): setattr(parent, name, getattr(module, name)) # Restore sys.path sys.path = old_sys_path -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: simulating #include in python

2005-11-15 Thread Nick Craig-Wood
Peter Otten <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > I'd really like to be able to run an __import__ in the context of the file > > thats running the include() but I haven't figured that out. > > execfile()? Yes thats exactly what

Re: sort the list

2005-11-22 Thread Nick Craig-Wood
ll the cmp function N log N times. Its expensive in terms of memory though. With python 2.4 you can wrap it up into one line if you want [ x[-1] for x in sorted([ (x[1],x) for x in lst ]) ] or even [ x[-1] for x in sorted((x[1],x) for x in lst) ] -- Nick Craig-Wood <[EMAIL PROTECTED

Re: sort the list

2005-11-23 Thread Nick Craig-Wood
Neil Hodgson <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood: > > > Since no-one mentioned it and its a favourite of mine, you can use the > > decorate-sort-undecorate method, or "Schwartzian Transform" > > That is what the aforementioned key argument

Re: Writing pins to the RS232

2005-11-29 Thread Nick Craig-Wood
al port. You need to set the serial port up not to do automatic handshaking first (eg setDsrDtr() & setRtsCts()) RS232 levels are +/- 12V, though a lot of computers only generate +/- 5V. The threshold is +/- 3V IIRC. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.

Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
bit OS though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
search *= 2 lines = lines[-nlines-1:] print "\n".join(lines) if __name__ == "__main__": if len(sys.argv) != 3: print "Syntax: %s n file" % sys.argv[0] else: main(int(sys.argv[1]), sys.argv[2]) -- Nick Craig-Wood &

Re: windows mem leak

2005-01-10 Thread Nick Craig-Wood
etc. [sorry not Python related but may solve your problem!] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Nick Craig-Wood
# raise NoMimeError return t[0] for f in ("index.php", "index.php3", "prog.cc", "prog.cpp", "flodge.xsl", "Makefile", "myMakefile", "potato.123"): print f, detectMimeType(f) ... prints index.php applicatio

Re: Debian says "Warning! you are running an untested version of Python." on 2.3

2005-01-13 Thread Nick Craig-Wood
2.2.3-10 An interactive high-level object-oriented la ii python2.3 2.3.4-18 An interactive high-level object-oriented la ii python2.4 2.4-2 An interactive high-level object-oriented la -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Debian says "Warning! you are running an untested version of Python." on 2.3

2005-01-13 Thread Nick Craig-Wood
unstable -> testing (and eventually) -> stable. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: rotor replacement

2005-01-19 Thread Nick Craig-Wood
Cast5+6, DES, Serpent, Twofish, TEA, etc. The linux kernel+source surely goes everywhere python does so I don't think adding strong crypto modules to python is a problem now-a-days. AES in the core python library would be very useful and it would discourage people from writing the

Re: Overloading ctor doesn't work?

2005-01-21 Thread Nick Craig-Wood
Why is that? Its a bug! http://sourceforge.net/tracker/index.php?func=detail&aid=720908&group_id=5470&atid=105470 However its been fixed in a recent Python 2.3. (I was bitten by the same thing which used to fail but now works after an upgrade of python 2.3!) -- Nick Cr

Re: rotor replacement

2005-01-22 Thread Nick Craig-Wood
Note that some of these are being worked on at sourceforge just like python. Surely it must be possible to add a few simple crypto modules to python? That said a) IANAL b) 'apt-get install python-crypto' works for me ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: default value in a list

2005-01-22 Thread Nick Craig-Wood
use this old trick... a, b, c = (line+"::").split(':')[:3] Or this version if you want something other than "" as the default a, b, b = (line.split(':') + 3*[None])[:3] BTW This is a feature I miss from perl... -- Nick Craig-Wood <[EMAIL PROTECTED]>

Re: default value in a list

2005-01-22 Thread Nick Craig-Wood
Alex Martelli <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > ... > > Or this version if you want something other than "" as the default > > > > a, b, b = (line.split(':') + 3*[None])[:3] > >

Re: best way to do a series of regexp checks with groups

2005-01-23 Thread Nick Craig-Wood
7;, line)): do_add(m.value.group(1), m.value.group(2)) elif m.set(re.search(r'mult (\d+) (\d+)', line)): do_mult(m.value.group(1), m.value.group(2)) elif m.set(re.search(r'help (\w+)', line)): show_help(m.value.group(1)) -- Nick Craig-Wood <[EMAIL PROTECTED]> --

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
ming(), 4) return result PS interesting thread - never heard of Hamming sequences before! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
, hamming5) ): yield n hamming2, hamming3, hamming5, result = tee(_hamming(), 4) return result (Note the iter(...) seemed not to be doing anything useful so I removed them) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Thinking about this some more leads me to believe a general purpose > > imerge taking any number of arguments will look neater, eg > > > > def imerge(*generators): > >

Re: Classical FP problem in python : Hamming problem

2005-01-27 Thread Nick Craig-Wood
code] Thanks for some more examples of fp-style code. I find it hard to get my head round so its been good exercise! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Help With Python

2005-01-27 Thread Nick Craig-Wood
order()] * 7 > py> ', '.join(orders) > 'Spam, Spam, Spam, Spam, Spam, Spam, Spam' Thats still one Viking making 7 orders surely? Eg >>> vikings = [Viking()] * 7 >>> vikings[0] is vikings[1] True whereas >>> vikings = [Viking() for _ in rang

Re: Inherting from object. Or not.

2005-01-27 Thread Nick Craig-Wood
;>> raise MyOldException Traceback (most recent call last): File "", line 1, in ? __main__.MyOldException: <__main__.MyOldException instance at 0xb7df4cac> >>> After that I recalled a thread on python-dev about it http://mail.python.org/pipermail/python-dev

Re: XOR on string

2005-01-27 Thread Nick Craig-Wood
it -s'import operator; string = "abcdefghij13123kj12l3k1j23lk12j3l12kj3"' \ 'reduce(operator.xor, map(ord, string))' 10 loops, best of 3: 15.6 usec per loop -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Elliptic Code

2005-01-28 Thread Nick Craig-Wood
Philip Smith <[EMAIL PROTECTED]> wrote: > I understand the algorithm quite well but how to code the multiplication > stage most efficiently in python eludes me. You might want to look at http://gmpy.sourceforge.net/ It has very fast multiplication up to any size you like! --

Re: debugging os.spawn*() calls

2005-01-28 Thread Nick Craig-Wood
ng wrong. > > While not a 'real' answer - I use pexpect to automate my ssh scripts > these days as I had a few problems using ssh with the os.* family > perhaps you may find pexpect a wee bit easier... If using 2.4 the subprocess module is a good solution

Re: What's so funny? WAS Re: rotor replacement

2005-01-29 Thread Nick Craig-Wood
ome up with, via Google's Cache. http://www.google.com/search?q=cache:U5-RsbkSs0MJ:www.cs.chalmers.se/Cs/Grundutb/Kurser/krypto/lect04_4.pdf -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Nick Craig-Wood
depend on any other library or application. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Nick Craig-Wood
API. The cryptkit way is better than ECB > example I gave, but the ECB example shows it's possible to do it in > one call. There is a PEP about this... API for Block Encryption Algorithms v1.0 http://www.python.org/peps/pep-0272.html -- Nick Craig-Wood <[EMAIL PROTEC

Re: limited python virtual machine

2005-01-30 Thread Nick Craig-Wood
. ...it also uses python for its control programs. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so funny? WAS Re: rotor replacement

2005-01-31 Thread Nick Craig-Wood
sions of DES for instance). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Where are list methods documented?

2005-02-01 Thread Nick Craig-Wood
tation which is only available in HTML format - I'd much rather type "pydoc whatever" to see it all, rather than have to load my browser, and click through several layers of web pages. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Which kid's beginners programming - Python or Forth?

2005-06-30 Thread Nick Craig-Wood
n Python would make a much better first language than FORTH. The batteries included approach make a young programmers life much, much more fun, rather than starting from almost nothing (in modern terms) with FORTH. And like FORTH, Python has the interactive console which is essential when starting out. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: sending binary files to a 16 micro controller.

2005-08-22 Thread Nick Craig-Wood
iment TCP yourself. Actually I'd recommend the OP uses UDP, not TCP. I've implemented a few systems which speak UDP directly and its very easy. I wouldn't like to implement TCP though! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Revised PEP 349: Allow str() to return unicode strings

2005-08-23 Thread Nick Craig-Wood
analogous to this... >>> int(100L) 100L > Wouldn't also a new function make the intent clearer? > > So I think I'm +1 on the text() built-in, and -0 on changing str. Couldn't basestring() perform this function? Its kind of what bases

Re: dual processor

2005-09-05 Thread Nick Craig-Wood
elected at compile time using C Macro magic. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: dual processor

2005-09-05 Thread Nick Craig-Wood
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Splitting the GIL introduces performance and memory penalties > > However its crystal clear now the future is SMP. Modern chips seem to > > have hit the GHz barrier, and now the

Re: dual processor

2005-09-08 Thread Nick Craig-Wood
hip. It's the most radical multicore design to date from a mainstream server processor manufacturer and arrives more or less on time. It goes on later to say "The physical processor has 8 cores and 32 virtual processors" and runs at 1080 MHz. So fewer GHz but more CPUs is the fu

Re: Premature wakeup of time.sleep()

2005-09-12 Thread Nick Craig-Wood
er /proc/interrupts | awk '{print $2}'`; echo $(($end-$start)) Which prints a number about 1000 on my 2.6 machine. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient checksum calculating on lagre files

2005-02-08 Thread Nick Craig-Wood
5sum(files): for filename in files: try: print "%s %s" % (md5file(filename), filename) except IOError, e: print >> sys.stderr, "Error on %s: %s" % (filename, e) if __name__ == "__main__": md5sum(sys.argv[1:]) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Java Integer.ParseInt translation to python

2005-02-09 Thread Nick Craig-Wood
0 176 ° > de 222 Þ > 8a 138 > e3 227 ã > b5 181 µ > b7 183 · > 51 81 Q > a7 167 § > c4 196 Ä > d8 216 Ø > e9 233 é > ed 237 í > eb 235 ë > > which is not even close, and yes, I know that it's not the same > code. Actually the hex digi

Re: Is Python as capable as Perl for sysadmin work?

2005-02-09 Thread Nick Craig-Wood
27;... or die "You [EMAIL PROTECTED]"' works even better ;-) Thanks for a very amusing post! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient checksum calculating on lagre files

2005-02-09 Thread Nick Craig-Wood
ile = open(fn, "rb") >>> size = os.path.getsize(fn) >>> size 8590983168L >>> hash = md5.md5(mmap.mmap(file.fileno(), size)).hexdigest() Traceback (most recent call last): File "", line 1, in ? OverflowError: memory mapped size is too large (limited by C int) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient checksum calculating on lagre files

2005-02-09 Thread Nick Craig-Wood
Thomas Heller <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > Here is an implementation of md5sum in python. Its the same speed > > give or take as md5sum itself. This isn't suprising since md5sum is > > dominated by CPU usage

Re: probably weird or stupid newbie dictionary question

2005-02-10 Thread Nick Craig-Wood
ble objecst is the comparability. In java, this is done using the > equals method. > > So in the end, the actual mapping of key, value looks like this: > > hash(key) -> [(key, value), ] Thats called hashing with chaining. See Knuth: Sorting and Searching if you want to kno

Re: convert list of tuples into several lists

2005-02-10 Thread Nick Craig-Wood
) [(1, 4), (2, 5), (3, 6)] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and version control

2005-02-10 Thread Nick Craig-Wood
gt; > Emacs + CVS (or CVSNT) should work just fine in Windows either. When I have to edit stuff on windows I use emacs. Cvs works fine on windows too. I haven't tried cvs in emacs on windows, but I suspect it will work fine as all emacs does is shell out to the cvs binaries. -- Nick

Re: Efficient checksum calculating on lagre files

2005-02-11 Thread Nick Craig-Wood
Christos TZOTZIOY Georgiou <[EMAIL PROTECTED]> wrote: > On 09 Feb 2005 10:31:22 GMT, rumours say that Nick Craig-Wood > <[EMAIL PROTECTED]> might have written: > > >But you won't be able to md5sum a file bigger than about 4 Gb if using > >a 32bit processor (

Re: goto, cls, wait commands

2005-02-11 Thread Nick Craig-Wood
else: # do stuff when not found The last language I saw with this very useful feature was FORTH in about 1984! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: pyMinGW support for Python 2.3.5 (final) is available

2005-02-12 Thread Nick Craig-Wood
indows) on a linux build host. The windows builds are done with a mingw cross compiler. It would be interesting if we could do this with python + extensions also. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: pyMinGW support for Python 2.3.5 (final) is available

2005-02-13 Thread Nick Craig-Wood
lds are done with plain gcc of course. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: For American numbers

2005-02-13 Thread Nick Craig-Wood
Yes. Unless you work in the telcoms industry, where, for example if you order a 2 Mbit/s line you'll get 2 * 1024 * 1000 bits / s ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: [PATCH] allow partial replace in string.Template

2005-02-14 Thread Nick Craig-Wood
ners with one-liners. c) add a documentation patch d) add a test suite patch -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: low-end persistence strategies?

2005-02-16 Thread Nick Craig-Wood
ish (being lazy) that there was a seperate debian package for just it and not the whole of Zope. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't join() call str() on its arguments?

2005-02-17 Thread Nick Craig-Wood
er method to do this? I propose joinany which will join any type of object together, not just strings That way it becomes less of a poke in the eye to backwards compatibility too. > Nick "Explicit is better than Implicit" Aye! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http:

Re: low-end persistence strategies?

2005-02-18 Thread Nick Craig-Wood
f and fcntl is unspecified.)" see man lockf and man flock -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comm. between Python and PHP

2005-02-22 Thread Nick Craig-Wood
he data you want to pass is structured then you might consider XML-RPC which is a cross platform way of passing structured data around. XML-RPC is part of the python standard library (SimpleXMLRPCServer and xmlrpclib) and there seem to be several implementations for PHP http://www.google.co.uk/sea

Re: accessor/mutator functions

2005-02-28 Thread Nick Craig-Wood
y the get method) which is often the encapsulation you really want - and that is something you can't do in C++. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Flushing print()

2005-02-28 Thread Nick Craig-Wood
Cameron Laird <[EMAIL PROTECTED]> wrote: > gf, remember to write > >sys.stdout.flush() > > rather than > >sys.stdout.flush > > That's a mistake that catches many. Many old perl programmers anyway (me included)! Its also a mistake pychecker

Re: Explicit or general importing of namespaces?

2005-02-28 Thread Nick Craig-Wood
pe (like the warnings subsystem). This is surely a job for pychecker / pylint? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Decimal, __radd__, and custom numeric types...

2005-02-28 Thread Nick Craig-Wood
ept the right operand: when an instance of a given class is expected, an instance of a subclass of that class is always acceptable. You could try this with a local copy of decimal.py since it is written in Python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: accessor/mutator functions

2005-03-01 Thread Nick Craig-Wood
Dan Sommers <[EMAIL PROTECTED]> wrote: > On 28 Feb 2005 10:30:03 GMT, > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > Actually I would say just access the attribute directly for both get > > and set, until it needs to do something special in which case use

Re: accessor/mutator functions

2005-03-01 Thread Nick Craig-Wood
complicated code into a method with a useful name, or add well named intermediate variables, or add an assertion. Its a point of view... Not 100% sure I agree with it but I see where he is coming from. I like a doc-string per public method so pydoc looks nice myself... -- Nick Craig-Wood <[

Re: Regular Expressions: large amount of or's

2005-03-01 Thread Nick Craig-Wood
t|in|t|ts)|ret(?:ch|ry)|re(?:use|v)|rev's|rev(?:el|s|ue) As you can see its not perfect. Find it in http://www.craig-wood.com/nick/pub/words-to-regexp.pl Yes its perl and rather cludgy but may give you ideas! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system()

2005-03-07 Thread Nick Craig-Wood
7 S+ 0:00 \_ sh -c sleep 60 > z 5150 pts/77 S+ 0:00 \_ sleep 60 Things to check 1) quoting, python vs shell 2) PATH - check PATH is set the same in shell / python 3) check the whole of the environment Also if you are using 2.4 check the subprocess module

Re: shuffle the lines of a large file

2005-03-08 Thread Nick Craig-Wood
was forever blowing up the server with scripts which used too much memory. sort was always the solution! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: An Odd Little Script

2005-03-10 Thread Nick Craig-Wood
e, and selecting that output file as the default for print() statements. The solution posted previously using mmap actually does it in-place though which will work very well for files < 4GB. (And not at all for files > 4GB unless you are on a 64 bit machine). -- Nick Cra

Re: Python becoming less Lisp-like

2005-03-15 Thread Nick Craig-Wood
s will complain about removals, but we'll knuckle down and take our medicine eventually ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-11-30 Thread Nick Craig-Wood
st ram it in a hash, and write lots of functions acting on it) rather than creating a specific class for the job which is dead easy in python anyway and to which you can attach methods etc. YMMV ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-12-01 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Steven Bethard <[EMAIL PROTECTED]> wrote: > > > >> I promised I'd put together a PEP for a 'generic object' data type for > >> Python 2.5 that allows one to replac

Re: pre-PEP generic objects

2004-12-02 Thread Nick Craig-Wood
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > class Hash: > > def __init__(self, **kwargs): > > for key,value in kwargs.items(): > > setattr(self, key, value) > > def __getitem__(self, x): > >

Re: pre-PEP generic objects

2004-12-03 Thread Nick Craig-Wood
eading to the critical > difference in this case: I think I finally understand now - thank you to you both! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Galois field

2004-12-03 Thread Nick Craig-Wood
orlds If someone did wrap PARI in python it would certainly be easier to use than GP which I found very unintuitive! In fact I just found this which looks like just the job! http://www.fermigier.com/fermigier/PariPython/readme.html -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://

Re: long number multiplication

2004-12-06 Thread Nick Craig-Wood
area of computer science! Its also rather big and expensive so you'll probably want to look at in the library... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive list comprehension

2004-12-08 Thread Nick Craig-Wood
e l l o ...and this works because str supports __getitem__ according to the docs. So there is some magic going on here! Is str defined to never have an __iter__ method? I see no reason why that it couldn't one day have an __iter__ method though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive list comprehension

2004-12-08 Thread Nick Craig-Wood
doesn't catch any exceptions it shouldn't) def flatten( i ): if hasattr(i, "__iter__"): for j in i: for k in flatten(j): yield k else: yield i -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: collaborative editing

2004-12-10 Thread Nick Craig-Wood
Robert Kern <[EMAIL PROTECTED]> wrote: > Personally, I loathe writing at any length inside a Web browser and > prefer to use a real editor at all times. Me too! You need mozex... http://mozex.mozdev.org/ Not sure about Mac support though /OT -- Nick Craig-Wood <[

Re: collaborative editing

2004-12-11 Thread Nick Craig-Wood
Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Robert Kern <[EMAIL PROTECTED]> wrote: > > Personally, I loathe writing at any length inside a Web browser and > > prefer to use a real editor at all times. > > Me too! You need mozex... > >http://mozex

Re: Python vs. Perl

2004-12-13 Thread Nick Craig-Wood
l(["ls", "-l"]) total 381896 -rw-r--r--1 ncw ncw 1542 Oct 12 17:55 1 [snip] -rw-r--r--1 ncw ncw 713 Nov 16 08:18 z~ >>> print rc 0 IMHO the new subprocess module is a very well thought out interface... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess vs. proctools

2004-12-15 Thread Nick Craig-Wood
Keith Dart <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > This sounds rather like the new subprocess module... > > > >>>>import subprocess > >>>>rc = subprocess.call(["ls", "-l"]) > > > > total 381896

Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-14 Thread Nick Craig-Wood
dvert for AMD ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for "syntax error": ++i, --i

2004-12-15 Thread Nick Craig-Wood
7;++', '--'. > > It does already. > > $ cat plusplus.py def main(): i = 1 return ++i $ pychecker plusplus Processing plusplus... Warnings... plusplus.py:4: Operator (++) doesn't exist, statement has no effect -- Nick Craig-Wood <[EMAIL PROTECTED]>

Re: expression form of one-to-many dict?

2004-12-18 Thread Nick Craig-Wood
in range(1000)])' 'map = {} for key, value in sequence: if map.has_key(key): map[key].append(value) else: map[key] = [ value ]' 1000 loops, best of 3: 1.11e+03 usec per loop Not that timing is everything of course ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Easy "here documents" ??

2004-12-19 Thread Nick Craig-Wood
ying around instead which is much more flexible than perl. You can even pass self.__dict__ if you are in a class method so you can access attributes. >>> class A: pass ... >>> a=A() >>> a.amount=10 >>> a.what="rutabaga" >>> a

Re: Easy "here documents" ??

2004-12-20 Thread Nick Craig-Wood
Jim Hill <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > >I prefer this > > > > ... I'll have %(amount)s %(what)s > > ... for $%(cost)s please""" % locals() > > Looks pretty slick. This might just be what I need. >

Re: regular expression: perl ==> python

2004-12-22 Thread Nick Craig-Wood
;float $1\n"; } else { print "unknown thing $line\n"; } Is there an easy way round this? AFAIK you can't assign a variable in a compound statement, so you can't use elif at all here and hence the problem? I suppose you could use a monstrosity like this, which relies on

Re: regular expression: perl ==> python

2004-12-23 Thread Nick Craig-Wood
. xml = re.compile(r""" <([/?!]?\w+) # 1. tags |&(\#?\w+); # 2. entities |([^<>&'\"=\s]+) # 3. text strings (no special characters) |(\s+) # 4. whitespace |(.) # 5. special characters ""&quo

Re: regular expression: perl ==> python

2004-12-23 Thread Nick Craig-Wood
mentation. This is probably what Windows people look at by default but Unix hackers like me expect everything (or at least a hint) to be in the man/pydoc pages. Just noticed in pydoc2.4 a new section MODULE DOCS http://www.python.org/doc/current/lib/module-sre.html Which is at least a hint that you are looking in the wrong place! ...however that page doesn't exist ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Queue.Queue-like class without the busy-wait

2005-04-01 Thread Nick Craig-Wood
. Processes can share this integer over mmap, via shared segments or because they share memory space, in which case the application is commonly called multithreaded. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Queue.Queue-like class without the busy-wait

2005-04-03 Thread Nick Craig-Wood
Paul Rubin wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > I believe futex is the thing you want for a modern linux. Not > > very portable though. > > That's really cool, but I don't see how it can be a pure userspace > operation if the futex

Re: Queue.Queue-like class without the busy-wait

2005-04-04 Thread Nick Craig-Wood
mode=thread&noheader=1&q=queue+timeout+python#doc_011f680b2dac320c Interesting thread. How about leaving the current threading alone, but adding a pthreads module for those OSes which can use or emulate posix threads? Which is windows and most unixes? -- Nick Craig-Wood <[EMAIL PROTECTED]&g

Re: Compute pi to base 12 using Python?

2005-04-14 Thread Nick Craig-Wood
172b1b50474351364749a33996a81ba8847347a8411b850b79a03018291672aa0945656a159aa6aa0a845531a592005b8a34366b882257107b190969a846474836a9800750778920ba797297a2791101b0685a86bb704b9baa17b055293679843b35215b0a8b1182b611953b080aa5431b219907a8448a81b1a9493245676b88013b470335240859594158621014216! 619553246570601967448b470174b9244892444817453865a4003b5aa7176451aab906 [EMAIL PROTECTED]' -- 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   >