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

Re: os.mkdir and mode

2006-12-02 Thread Nick Craig-Wood
st' Size: 4096Blocks: 8 IO Block: 4096 directory Device: 806h/2054d Inode: 2453906 Links: 2 Access: (0770/drwxrwx---) Uid: ( 518/ ncw) Gid: ( 518/ ncw) Access: 2006-12-02 09:48:04.0 +0000 Modify: 2006-12-02 09:48:04.0 + Change: 2

Re: os.mkdir and mode

2006-12-04 Thread Nick Craig-Wood
os.mkdir() ? > > No, I didn't. What is the difference/advantage of that approach? If you use use os.umask(0) then the os.mkdir(dir, perms) will create the directory with exactly those permissions, no chmod needed. -- 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-04 Thread Nick Craig-Wood
Martin v. Löwis <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood schrieb: > > So it looks like python mkdir() is applying the umask where as > > /bin/mkdir doesn't. From man 2 mkdir > > Actually, mkdir(1) has no chance to not apply the umask: it also > has to us

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Nick Craig-Wood
or x in range(0,12): (x + 3) & ~0x3 Which prints 0,4,4,4,4,8,8,8,8,12... You could also consider the funky x>>2<<2 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Nick Craig-Wood
o read the return code of the command and its stderr both of which you'll need if you are programming defensively! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Subprocess with a Python Session?

2006-12-05 Thread Nick Craig-Wood
p://pexpect.sourceforge.net/ >>> import pexpect >>> p = pexpect.spawn("python") >>> p.expect(">>>") 0 >>> p.sendline("print 10\n") 10 >>> p.readline() ' print 10\r\n' >>> p.readline() '10\r\n&

Re: how to invoke the shell command and then get the result in python

2006-12-06 Thread Nick Craig-Wood
uages like Python when used in a web environment. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of factory pattern in Python?

2006-12-07 Thread Nick Craig-Wood
not > limited to use the generic *args and **kw. If you don't want to use a register() function on each class you could introspect like this (untested) to make the registry :- registry = {} for obj in sys.modules[__name__].__dict__.values(): try: if issubclass(obj, Base):

Re: shell command needs whitespace characters escaped

2006-12-08 Thread Nick Craig-Wood
): """Quote all the metacharacters in the args for the unix shell""" return " ".join([re.sub(r"([^A-Za-z0-9_])", r"\\\1", string) for string in args]) >>> print quotemeta(['a', "'b", 'c']) a \'b c > (or better, subprocess.call). A good idea! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Serial port failure

2006-12-15 Thread Nick Craig-Wood
ill tell you how to use it. I've broken a lot of serial port drivers with that program ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Serial port failure

2006-12-17 Thread Nick Craig-Wood
oes lock up it is a driver bug. Here you'll find a little program I wrote which, with the help of a loopback connector, you can check your serial port out http://www.craig-wood.com/nick/pub/cambert.exe Run the program from a cmd prompt and it will tell you how to use it. I've broken a lot

Re: How to replace a comma

2006-12-18 Thread Nick Craig-Wood
ent and accurate style - this matches the next character which gets added back into the string. >>> re.sub(r",([^\s])", r", \1", s) 'One, Two, Three, Four, File' >>> This shows a fundamental difference between the two methods >>> t

Re: Core dump revisited

2006-12-18 Thread Nick Craig-Wood
not post the output. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Core dump revisited

2006-12-19 Thread Nick Craig-Wood
as overwritten. Maybe it is a string you can identify... You'll also want to start reading the gdb manual on breakpoints and watchpoints at this moment! Find memory corruptions can be tricky and time consuming. Valgrind can help also. Good luck! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Core dump revisited

2006-12-19 Thread Nick Craig-Wood
oto err; } label[i] = xstrdup(item_cstr); Py_DECREF(item); item = 0; [snip] err:; PyErr_Print(); out:; if (value) Py_DECREF(value); if (item) Py_DECREF(item); return rc; -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating all permutations from a regexp

2006-12-22 Thread Nick Craig-Wood
achine generating all possible matches at each point. Luckily the python regexp matcher is written in python, so you have access to the state machine directly if you want. Take a look at sre*.py in the python library and you might be able to work out what to do! I had a brief look myself, and it looked

Re: Generating all permutations from a regexp

2006-12-22 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > A regular expression matcher uses a state machine to match strings. > > unless it's the kind of regular expression matcher that doesn't use a > state machine, like the one in Pyt

Re: Convert Perl to Python

2006-12-29 Thread Nick Craig-Wood
conversions by hand. It is a bit tedious but a good editor with macros will let you fly through the job. I used emacs. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I beat perl at grep-like processing speed?

2006-12-29 Thread Nick Craig-Wood
sys 0m0.068s > # I used python2.5 and perl 5.8.6 Playing for the other side temporarily, this is nearly twice as fast... $ time perl -lne 'print if m/destroy/oi' bigfile >pl.out real0m0.133s user 0m0.120s sys 0m0.012s vs $ time ./z.pl >pl.out.orig

<    1   2   3   4   5   6   7   >