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: results of division

2004-12-09 Thread Christopher A. Craig
. round(x,n) in (Python 2.4): multiplies x by 10**n adds .5 truncates divides by 10**n. Don't confuse this trick with giving us the correct result though, it's still floating point: >>> round(1.77499, 2) 1.78 -- Christopher A. Craig <[EMAIL PROTECTED]> &qu

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: A rational proposal

2004-12-20 Thread Christopher A. Craig
e are some very real performance reasons to do it in C rather than Python (i.e. I'm manipulating the internals of the numerator and denominator by hand for performance in the GCD function) -- Christopher A. Craig <[EMAIL PROTECTED]> "I affirm brethren by the boasting in you which

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

Re: Compute pi to base 12 using Python?

2005-04-18 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > I'm using GMPY (see code). > > [snip] > > > > If you are using gmpy you might as well do it like this. > >

Re: Nokia to speak at Python-UK next week

2005-04-18 Thread Nick Craig-Wood
ly on topic, but does anyone know if there is a series 80 python? Or if the series 60 python runs on a series 80 phone (eg communicator 9300/9500)? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Nokia to speak at Python-UK next week

2005-04-19 Thread Nick Craig-Wood
Ville Vainio <[EMAIL PROTECTED]> wrote: > >>>>> "Nick" == Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > Nick> Not entirely on topic, but does anyone know if there is a > Nick> series 80 python? Or if the series 60 python runs on a

Re: Memory leak in python

2005-04-19 Thread Nick Craig-Wood
t; anything. Are there any objects in gc.garbage? Are you writing objects with __del__ methods? If so then that is your problem probably. Have you written any extension modules in C? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster os.walk()

2005-04-20 Thread Nick Craig-Wood
of improvement given that decent OSes have a very good cache for stat results, and that parsing file names is very quick too, compared to python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting into Python, comming from Perl.

2005-04-25 Thread Nick Craig-Wood
if it is I'd recommend "Dive into Python" by Mark Pilgrim as a good first step. Its available for free in electronic form too. After that you could read Programming Python. Good luck! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python licence again

2005-04-25 Thread Nick Craig-Wood
has <[EMAIL PROTECTED]> wrote: > licence, practice = noun > license, practise = verb Tick ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing next/prev element while for looping

2005-12-18 Thread Nick Craig-Wood
other builtin somewhere that provides better functionality > that I'm missing? I suppose you could use itertools... >>> from itertools import * >>> L=range(10) >>> (L1, L2, L3) = tee(L, 3) >>> L2.next() 0 >>> L3.next() 0 >>> L3.next() 1 >

Re: [OT] How can I change Debian's default Python version?

2006-01-05 Thread Nick Craig-Wood
p you using ubuntu's python packages with careful use of apt preferences and sources.list. Or you can swap to ubuntu completely using apt-get! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Cross Compile Mips / Linux

2006-01-11 Thread Nick Craig-Wood
nique to cross build stuff for ARM. I found the debian ARM python quite sufficient for my needs so I didn't have to build that! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten a level one list

2006-01-12 Thread Nick Craig-Wood
"b","c"], "") Traceback (most recent call last): File "", line 1, in ? TypeError: sum() can't sum strings [use ''.join(seq) instead] >>> I've no idea why this limitation is here... perhaps it is because pre python2.4 cal

Re: flatten a level one list

2006-01-13 Thread Nick Craig-Wood
Alex Martelli <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Except if you are trying to sum arrays of strings... > > > > >>> sum(["a","b","c"], "") > > Traceback (most recent

Re: Addressing a COM port from Python

2006-01-17 Thread Nick Craig-Wood
n my experience -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: add pexpect to the standard library, standard "install" mechanism.

2006-01-20 Thread Nick Craig-Wood
up.py install If on linux you can python setup.py bdist_rpm which builds an .rpm to install which you might prefer. If you want a .deb use alien to convert the rpm However in the case of this package apt-get install python-pexpect works for me on Debian and hence probably on ubuntu

Re: How to delete a Python package

2006-07-13 Thread Nick Craig-Wood
ays install python packages like this - it has worked every time so far! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: time.clock()

2006-07-17 Thread Nick Craig-Wood
0 1.77 1.77 1.77 1.77 time.clock() is elapsed cpu time of just that process. I think the precisions are the other way round on windows. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: range() is not the best way to check range?

2006-07-18 Thread Nick Craig-Wood
"set) That took %.3f seconds: result %s" % (dt, a) start = time.time() a = 1.0 mine = set(range(0, 1)) for i in range(0, 3): if 0 <= i < 1: a += 1 dt = time.time() - start print "comparison) That took %.3f seconds: result %s" % (dt, a) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Tkinter and exceptions

2006-07-25 Thread Nick Craig-Wood
ack(side=TOP, fill=X) Button(self.toolbar, text='Quit', command=self.quit).pack(side=TOP, fill=X) def make_exception(self): raise ValueError("Exception") def make_callback_exception(self): self.bang = 1 if __name__ == "__main__": AppDemo().mainloop() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter and exceptions

2006-07-26 Thread Nick Craig-Wood
Peter Otten <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > How do you catch general exceptions in a Tkinter program. > Overriding report_callback_exception() seems to work: Thank you. That is exactly what I needed to know! -- Nick Craig-Wood <[EMAIL PROTECTED]

Re: How to force a thread to stop

2006-07-27 Thread Nick Craig-Wood
ead %s running" % self.name _do_stuff(1.0) if __name__ == "__main__": thread1 = KillableThread(name="thread1") thread1.start() _do_stuff(0.5) thread2 = KillableThread(name="thread2") thread2.start() _do_stuff(2.0) thread1.kill() thread1.join() _do_stuff(2.0) thread2.kill() thread2.join() print "Done" -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Threads vs Processes

2006-07-27 Thread Nick Craig-Wood
ot;"" t = threading.Thread(target=do_child_stuff) t.start() # wait for child to finish t.join() def main(): print "Forking" timeit.main(["-s", "from __main__ import fork_test", "fork_test()"]) print "Threading&qu

Re: subprocess module

2006-07-27 Thread Nick Craig-Wood
;5', '-vframes', '1', '-s', '160x120', '-an', 'video.gif'] p = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE) If you mix the two styles then you are probably heading for trouble with argument quoting. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: PySNMP Thread unsafe?

2006-07-27 Thread Nick Craig-Wood
h. This is surely a job for twisted not threads? You'd be able to poll all 250 devices at once with twisted... This might be helpful (haven't tried it myself though) http://twistedsnmp.sourceforge.net/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick

Re: Subprocess confusion: how file-like must stdin be?

2006-08-18 Thread Nick Craig-Wood
t;abcdefgh\nabc\n") >>> p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 534, in __init__ (p2cread, p2cwrite, File &qu

Re: Py_BuildValue("I", ...) does not work

2006-08-21 Thread Nick Craig-Wood
cd build/lib.linux-i686-2.4 $ python2.4 Python 2.4.4c0 (#2, Jun 14 2006, 22:35:41) [GCC 4.1.2 20060613 (prerelease) (Debian 4.1.1-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mi

Re: Sending binary pickled data through TCP

2006-10-13 Thread Nick Craig-Wood
\\n, \\t and \\any_char into CR, LF, TAB and any_char""" def _translate(m): return m.group(1).translate(_unescape_mapping) return _unescape_re.sub(_translate, s) (These functions have been through the optimisation mill which is why they may not look immediately like how you might first think of writing them!) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: building extensions for Windows Python

2006-10-13 Thread Nick Craig-Wood
ensions with mingw under linux, using -lpython2.4 which will run under windows. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: building extensions for Windows Python

2006-10-13 Thread Nick Craig-Wood
-the-box'. Neither of those statements are true. It is fairly easy to build python extensions using mingw hosted on linux which work with the standard python.org install - see my other post in this thread. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://

Re: Thread termination

2006-10-14 Thread Nick Craig-Wood
ing to search for... ctypes.pythonapi.PyThreadState_SetAsyncExc -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: IDE that uses an external editor?

2006-10-16 Thread Nick Craig-Wood
major-mode. Syntax colouring, indentation that sort of thing. There is also IM-Python for code navigation, and bycycle repair man for refactoring support. You can run stuff at the interactive python prompt from within emacs. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: wx.grid question (trying to use code from Grid_Example.py)

2006-10-16 Thread Nick Craig-Wood
7;m just learning!). http://www.wxpython.org/maillist.php -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Ok. This IS homework ...

2006-10-16 Thread Nick Craig-Wood
appropriate maps for the modern computing language territory. I was born and bred on flow charts and I admit they were useful back in the days when I wrote 1000s of lines of assembler code a week. Now-a-days a much better map for the the territory is pseudo-code. Python is pretty much executable pseudo-

Re: __div__ not recognized automatically

2006-11-02 Thread Nick Craig-Wood
def __str__(self): return "%s(%s)" % (self.__class__.__name__, self.value) a = NumX(4) b = NumX(2) print a,b print a+b print (a+b)/2 This prints ---- Nu

Re: Sorted and reversed on huge dict ?

2006-11-04 Thread Nick Craig-Wood
* resource.getpagesize() ... >>> print memory_used() 4575232 >>> a=1000*"x" >>> print memory_used() 14577664 >>> If anyone knows a (unix) portable way of doing this I'd be interested! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: assigning values in __init__

2006-11-07 Thread Nick Craig-Wood
>>> You can then add to attributes in the subclasses class MagicCharacter(Character): attributes = Character.attributes | set(['spells', 'wand']) >>> MagicCharacter('name', strength=10, dexterity=5, intelligence=3, luck=0, spells=1)

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Nick Craig-Wood
QT licence, but we decided we didn't want to have to incurr the additional expense of renewing it. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorted list - how to change it

2006-11-09 Thread Nick Craig-Wood
7;hello') >>> random.shuffle(L) >>> L array('c', 'elohl') >>> L.tostring() 'elohl' Which is some way towards a mutable string... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Nick Craig-Wood
Christophe <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood a écrit : > > There is also PyQT which we wrote off as we wanted to write commercial > > applications too. As it happens we have a commercial QT licence, but > > we decided we didn't want to have to

Re: How to choose the right GUI toolkit ?

2006-11-10 Thread Nick Craig-Wood
look a lot nicer Eg debian ii gtk2-engines-gtk-qt 0.7-1 theme engine using Qt for GTK+ 2.x You get a control panel for GTK apps in the KDE control center also. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using signal.alarm to terminate a thread

2006-11-13 Thread Nick Craig-Wood
pexpect has a timeout parameter exactly for this case import os, pexpect, threading def runyes(): print "Running yes command..." pexpect.run('yes', timeout=5) t = threading.Thread(target=runyes) t.start() t.join() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using signal.alarm to terminate a thread

2006-11-14 Thread Nick Craig-Wood
ogram can then either poll the global flag, or use sem_wait() and sem_trywait() on the semaphore. Another option is to do nothing in the signal handler, and dedicate one thread (preferably the initial thread) to wait synchronously for signals, using sigwait(), and send messages to the other t

Re: Using signal.alarm to terminate a thread

2006-11-14 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > The only sensible things you can do from a signal handler is set a > > global flag, or call sem_post on a semaphore, to record the delivery > > of the signal. The remainder of the pr

Re: Using signal.alarm to terminate a thread

2006-11-15 Thread Nick Craig-Wood
es(): ... print "Running yes command..." ... pexpect.run('yes', timeout=5) ... >>> t = threading.Thread(target=runyes) >>> t.start() >>> Running yes command... t.join() [never returns] I'd guess at differences between the pexpect versions. You could try the pexpect from debian/testing easily enough I expect. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python-2.5.exe?

2006-11-15 Thread Nick Craig-Wood
helpful, eg @echo off set DEMOHOME=%CD% set PYTHONHOME=%DEMOHOME%\Python24 set PYTHONPATH=%PYTHONHOME%;%DEMOHOME%\Demo\Python set PYTHON=%PYTHONHOME%\python.exe set PYTHONW=%PYTHONHOME%\pythonw.exe set PATH=%PYTHONHOME%;%PATH% start "Demo" "%PYTHONW%" "demo.pyw"

Re: Best way to check that a process is running on a Unix system?

2006-06-05 Thread Nick Craig-Wood
, []).append(process) for process in self.by_pid.values(): try: parent = self.by_pid[process.parent_pid] #print "child",process #print "parent",parent parent.children.append(process)

Re: how to switch from os.tmpnam to os.tmpfile

2006-06-08 Thread Nick Craig-Wood
ect Create a temporary file with no directory entries. Have a look at the functions in the tempfile module, mkstemp() in particular (the posix way), or NamedTemporaryFile() http://docs.python.org/lib/module-tempfile.html -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://

Re: os.link makes a copy, not a link

2006-06-10 Thread Nick Craig-Wood
tell whether you have a copy or a hardlink. >>> import os >>> file("z", "w").write("test") >>> os.link("z", "z2") >>> os.stat("z").st_ino 1685186L >>> os.stat("z2").st_ino 1685186

Re: os.link makes a copy, not a link

2006-06-10 Thread Nick Craig-Wood
our system, might copy the > file. The link(2) system call on linux never does that. Eg >>> import os >>> file("z", "w").write("test") >>> os.link("z", "/dev/shm/z") Traceback (most recent call last): File "", line 1, in ? OSError: [Errno 18] Invalid cross-device link >> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: help() on stdout.closed

2006-06-21 Thread Nick Craig-Wood
closed' bool indicating the current state of the file object. This is a read-only attribute; the `close()' method changes the value. It may not be available on all file-like objects. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Time out question

2006-07-03 Thread Nick Craig-Wood
ested #9a", True, 4, _test_time_limit, "nested #9b", True, 5, _spin, 10) _test_time_limit("nested #10", False, 7, _test_time_limit, "nested #10a",False, 6, _test_time_limit, "nested #10b",True, 5, _spin, 10) #_test_time_limit("nested #11", False, 7, _test_time_limit, # "nested #11a",True, 4, _test_time_limit, # "nested #11b",False, 10, _spin, 5) _test_time_limit("nested #12", False, 7, _test_time_limit, "nested #12a",False, 6, _test_time_limit, "nested #12b",False, 10, _spin, 5) print "All tests OK" test() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem when import C model

2006-07-03 Thread Nick Craig-Wood
.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Time out question

2006-07-04 Thread Nick Craig-Wood
Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2006-07-03, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Alex Martelli <[EMAIL PROTECTED]> wrote: > >> DarkBlue <[EMAIL PROTECTED]> wrote: > >> > try for 10 seconds > >> >if d

Re: defining multi dimensional array

2006-07-05 Thread Nick Craig-Wood
for y in range(3): ... a[x][y] = i ... i = i + 1 ... >>> print a[1][1] 5 >>> a[2][1] = 'hello' >>> print a [[1, 2, 3], [4, 5, 6], [7, 'hello', 9], [10, 11, 12]] Numeric/scipy/numpy/whatever-it-is-called-today supports multidimensional arrays too I think and that may be more appropriate if you are doing heavy numerical work. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Fork You.. Forking and threading..

2006-07-05 Thread Nick Craig-Wood
p://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 That releases the controlling terminal from your job and it exits from the process group. You could probably close / redirect stdin/out/err too. Search for daemonize.py and you'll find a module which does all this. --

Re: Tkinter problem

2006-07-08 Thread Nick Craig-Wood
o.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7aa9000) libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7aa5000) /lib/ld-linux.so.2 (0x8000) If there are any missing things then you need to re-install those packages. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-woo

Re: Can Python do Perl's print <

2006-08-24 Thread Nick Craig-Wood
this using stdin >>> cmds="""read A ... read B ... read C ... echo $C $B $A""" >>> out = Popen(cmds, shell=True, stdin=PIPE) >>> out.communicate("""one ... two ... three""") three two one (None, None) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Best Practices for Python Script Development?

2006-08-25 Thread Nick Craig-Wood
es of the language, but otherwise it is a solid book with lots of good stuff in. The section on programming with TK is very good too - I keep coming back to that section. ... I'd recommend the first and the last from your list to start with, "Dive into Python" and "Progr

Re: IronPython on Mono howto

2006-09-07 Thread Nick Craig-Wood
user0m1.000s sys 0m0.036s $ time python2.4 -c pass real0m0.015s user0m0.008s sys 0m0.007s Over all I'm very impressed - it is great to have a new implemention of Python. I'm not sure mono is showing it off to its full extent though! -- Nick Crai

Re: xmingw and f2py

2006-09-08 Thread Nick Craig-Wood
svc/bin/dlltool --dllname python24.dll --def python24.def --output-lib libpython2.4.a # Move the files into the correct place mv -i python24.dll python24.def libpython2.4.a /usr/i586-mingw32msvc/lib/ After that lot you can build python extensions with mingw under linux, using -lpython2.4 -- Nick Cra

Re: xmingw and f2py

2006-09-08 Thread Nick Craig-Wood
27;t help you there. You want to tell distutils that the compiler is just gcc somehow and takes the same options. Not sure how you do that. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
d like someone to tell me that PyQT, tkinter or PyGTK does it all for me, but from my searching on the subject I doubt it is going to be that easy! Thanks -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
TheSeeker <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Does anyone have some hints / tips / experience with making a cross > > platform systray icon? It should work on Windows, Gnome and KDE at > > minimum. > You might do a search for TaskBarIcon in th

Re: A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
N/Cookbook/Python/Recipe/475155 Thanks anyway -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
Tim Golden <[EMAIL PROTECTED]> wrote: > if os.path.isfile (filepath): >print filepath You might get a more accurate result using os.access(filepath, os.X_OK) instead of os.path.isfile(filepath) Which checks the file is executable -- Nick Craig-Wood <[

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
Tim Golden <[EMAIL PROTECTED]> wrote: > [Nick Craig-Wood] > > | Tim Golden <[EMAIL PROTECTED]> wrote: > | > if os.path.isfile (filepath): > | >print filepath > | > | You might get a more accurate result using > | > | os.

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
s return False for X_OK under > Win32. I'm happy to submit the patch, but is it worth it? Wouldn't returning X_OK as true if the file exists be more sensible? Ie the file might be executable, you'll have to try it, rather than, no this file is definitely not executable... -

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
on-dev about what you've done Thats what I've done in the past anyway! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: R.S.I. solutions?

2006-09-26 Thread Nick Craig-Wood
ds just fine. RSI is a complicated disease - there are lots of different forms of it all caused by different things. You'll need some professional advice to sort it out. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ruby %w equivalent

2006-09-27 Thread Nick Craig-Wood
) which is nearly as neat as qw//, but not quite since the split() bit comes at the end so it doesn't notify you that you have an array of strings rather than a string. I don't expect a replacement for %w{}, qw// to ever be added to python, it is not the python way. And the python way is why I am now a python programmer not a perl programmer! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ruby %w equivalent

2006-09-27 Thread Nick Craig-Wood
Duncan Booth <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > In python when making __slots__ or module.__all__ you end up typing > > lists of objects or methods and they turn out like this which is quite > > a lot of extra typ

Re: builtin regular expressions?

2006-10-02 Thread Nick Craig-Wood
Moreover match becomes a string method. No need for extra importing > re and applying re.compile(). Both can be done in str.match() if > necessary. I'm happy with the re module. Having transitioned from perl to python some time ago now, I find myself using many fewer regexps due to the much better built in string methods of python. This is a good thing, because regexps should be used sparingly and they do degenerate into line noise quite quickly... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: DAT file compilation

2006-10-02 Thread Nick Craig-Wood
and .jar, and openoffice and all of its many extensions. If you are feeling really paranoid then encrypt it. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python to use a non open source bug tracker?

2006-10-04 Thread Nick Craig-Wood
n python. http://svn.mythtv.org/trac/ A nice extra is that 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: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Nick Craig-Wood
late to ''. None is the traditional value to use for value not present, then you'd get this for the function def mainFunction(var, template=None): if template is None: template = 'base' And this for the calling bit if not_set_properly(template): template = None return mainFunction(var, template) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Nick Craig-Wood
urn var * 2 > But yes, defining a sentinel like this is a good idea. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pyserial port connection problem

2006-11-17 Thread Nick Craig-Wood
-th port? Also are you running as adminstrator? You may need admin rights to open a serial port under windows (I'm not sure). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: "fork and exit" needed?

2006-11-28 Thread Nick Craig-Wood
eamonisation under unix. I'm not sure how you do open stdout to /dev/null in python though! I suspect something like this... import posix posix.close(1) posix.open("/dev/null", posix.O_WRONLY) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: "fork and exit" needed?

2006-11-28 Thread Nick Craig-Wood
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Tue, 28 Nov 2006 04:30:09 -0600, Nick Craig-Wood > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > > > If you run this > > > > import os,sys,time > > print

Re: Really closing stdout (was: "fork and exit" needed?)

2006-11-29 Thread Nick Craig-Wood
Mitja Trampus <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > I'm not sure how you do open stdout to /dev/null in python though! > > I suspect something like this... > > import posix > > posix.close(1) > > posix.open("/dev/null",

Re: Wrapping A Shell

2006-11-29 Thread Nick Craig-Wood
quot;" end_time = time() + timeout output = "" while time() < end_time: try: output += p.stdout.read(1024) except IOError, e: if e.errno != EAGAIN: raise return output p.stdin.write("ls\n") print read_output(p) p.stdin.write("uname -a\n") print read_output(p) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: os.mkdir and mode

2006-12-02 Thread Nick Craig-Wood
mkdir() works just like its C equivalent, see > http://docs.python.org/dev/lib/os-file-dir.html: > > "Where it is used, the current umask value is first masked out." > > Use os.chmod() after os.mkdir() to get the desired permissions. I think you meant use os.umask(0) befor

<    1   2   3   4   5   6   7   8   9   >