;", line 5, in getMeasurement
NotImplementedError
>>> base.setPressure(14)
Traceback (most recent call last):
File "", line 1, in
File "", line 7, in setPressure
NotImplementedError
>>>
>>> real = RealDevice("/dev/ttyS1")
>>> real
RealDevice('/dev/ttyS1')
>>> real.getMeasurement()
0
>>> real.setPressure(14)
>>> real.getMeasurement()
14
>>>
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
callbacks or deferred objects).
To get your program to do something immediately after it is started,
use reactor.callLater() before calling reactor.run().
You can't mix and match programming styles with twisted - it is all
asynchronous callbacks or nothing in my experience! That takes a bit
of
if not out:
break
yield out
g = Grouper(5, xrange(20))
print list(g)
g = Grouper(4, xrange(19))
print list(g)
Which produces
[(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)]
[(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11), (12, 13, 14, 15), (16, 17,
plejson as json
Is more pythonic... You aren't relying on what came with particular
python versions which may not be true in jython/ironpython/etc.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
be even a bit
> easier.
I'd use pygame for a really clean full screen display.
Probably a bit more work, but you'll get something really cool at the
end of it!
here is how to use matplotlib on a pygame surface
http://www.pygame.org/wiki/MatplotlibPygame
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
=10**6 because I got bored of waiting ;-)
map
9.85280895233
pmap
28.4256689548
So the pmap took nearly 3 times as long. I expect this is because the
task was divided into 5 sections each competing madly for the GIL.
I ran the same script under the latest jython beta which was very
interesting! pmap showing a slight improvement, and faster than
cPython!
$ jython2.5rc2/jython pmap.py
map
6.242000103
pmap
5.8881144
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
nder.py\n'
(printed with a 1 second pause between each line)
----
If you want to interact with a subprocess (eg send, receive, send,
receive) then use the pexpect module - buffering in subprocess will
cause you nothing but pain otherwise!
> (Or, is there a way to create a subprocess.Popen object from what I assume =
> is the process handle integer ?)
Errr, not as far as I know.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
uld potentially note that function types don't have enough
references to them when passed in as arguments to C functions? It
might slow it down microscopically but it would fix this problem.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
David Bolen wrote:
> Nick Craig-Wood writes:
>
> > ctypes could potentially note that function types don't have enough
> > references to them when passed in as arguments to C functions? It
> > might slow it down microscopically but it would fix this problem.
&
ointers etc. If you want to dig into virtual classes with multiple
bases or the STL then you are probably into the territory you
describe.
That said I've used C++ with ctypes loads of times, but I always wrap
the exported stuff in extern "C" { } blocks.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
radius -= 1
screen.fill(background_colour)
for dot in dots:
pygame.draw.circle(screen, foreground_colour, dot, radius, 1)
dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in
dots ]
pygame.display.flip()
if __name__ == "__main__"
Enabled
According to the man page smartctl also runs under windows/mac/solaris
etc
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
, press Ctrl-C Ctrl-C and have the output shown in a
different window. If you messed up, clicking on the error will put
the cursor in the right place in the code).
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Ben Finney wrote:
> Emile van Sebille writes:
>
> > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said...
> > > In message , Nick Craig-
> > > Wood wrote:
> > >
> > >> You quit emacs with Ctrl-X Ctrl-C.
> > >
> > > That'
m concerned is that it is more of a port of CPython to a new
architecture than a complete re-invention of python (like PyPy /
IronPython / jython) so stands a chance of being merged back into
CPython.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
error_text = "".join(format_exception(type, value, traceback))
wx.MessageDialog(None, error_text, 'Custom Error:', wx.OK).ShowModal()
def OnClick(self, evt):
"Click with a deliberate mistake"
adsfsfsdf
if __name__ == "__main__":
a
rd with xmlrpc.
>
> I have looked at various solutions including:
>
> - PyOrbit - too heavy weight
> - Pyro - uses pickle, I do not trust it
It is possible to change the serialization used by Pyro
http://pyro.sourceforge.net/manual/9-security.html#pickle
to the the 'g
est.instances()
Which prints
[]
[<__main__.Test object at 0xb7d4eb6c>, <__main__.Test object at 0xb7d4eb4c>]
[<__main__.Test object at 0xb7d4eb6c>]
[]
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
hon with a bit of searching. Also
I believe twisted supports them directly or you could easily roll your
own.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
do more of those!" - as a battle scarred C programmer I'd agree ;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
be stored at an arbitrary
> > bit-position in the file
>
> Yes. I need arbitrary, 8bits, than 10 bits for something else, than
> sequence of bytes, than 10 bits again, etc.
You could try
http://construct.wikispaces.com/
which could well do exactly what you want.
--
Nick Cr
drummed into me to always use
parameters for user input and I was really suprised PHP didn't have
them.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
8.
8
2> X = 10.
** exception error: no match of right hand side value 10
3>
That error message is the erlang interpreter saying "Hey I know X is
8, and you've said it is 10 - that can't be right", which is pretty
much what math teachers say too...
--
Nick Craig-Wood <[EM
Mel <[EMAIL PROTECTED]> wrote:
> Mensanator wrote:
> > On May 22, 10:30??am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> >> Dave Parker <[EMAIL PROTECTED]> wrote:
> >> > But after getting input from children and teachers, etc, it started
> &g
L).
I think candygram is crying out to be married with stackless &or PyPy.
It also needs an IPC channel to compete with Erlang directly.
If you are interested in stackless python vs Erlang then take a look
at this...
http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-first-
nt call last):
File "", line 1, in
TypeError: 'int' object is not callable
>>> getattr(obj, 'f')(1)
False
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
y manipulation)...
So instead of f(a, *args) have f(a, list_of_args).
The f(*args) syntax is tempting to use for a function which takes a
variable number of arguments, but I usually find myself re-writing it
to take a list because of exactly these sort of problems. In fact I'd
be as bold to
4] OSCL_getCurrentStaticParams
[ 5] OSCL_getErrorString
[ 6] OSCL_getIdent
[snip]
This is a dll we used in a project, and those names exactly worked
with ctypes, eg some snips from the ctypes code
self.dll = cdll.LoadLibrary("OurSharedCodeLibrary")
self.dll.OSCL_getErrorString.restype = c_char_p
def getErrorString(self, status):
return self.dll.OSCL_getErrorString(c_int(status))
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
de("hex")
'400921fb54442d18'
>>> struct.unpack(">d", "400921FB54442D18".decode("hex"))
(3.1415926535897931,)
>>> struct.unpack(">d", "400921FB54442D19".decode("hex"))
(3.1415926535897936,)
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood a ?crit :
> > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> >>> Can someone suggest an efficient way of calling method whose name is
> >>> passed in a variable?
> >>>
t is hard to write tests for wx GUIs though
(but not impossible).
When you've finished you'll have 3 files full of classes. You may
have a few utility functions too.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
this...
from ctypes import *
Array = c_int64 * 100
a = Array()
for i in range(100):
a[i] = 2**63 - i
for i in range(100):
print a[i]
prints
-9223372036854775808
9223372036854775807
9223372036854775806
[snip]
9223372036854775710
9223372036854775709
ctypes arrays are fixed len
an "Invalid Parameter" errorcode. there's also no useful
> data whereas datainfo gets written correctly. I know that my cdStream
> can't work, facing the C-code, but what'd be the right cdStream class?
> What can I do? Any ideas?
I've noted some obvious problems above.
To get this to work will require some C knowledge. If they supply
some example C code I'd work through that translating it line by line
to python+ctypes.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
uint),
("open", cstreamopen),
("close", cstreamclose), # etc...
This will involve you re-ordering your definitions.
Or alternatively, you could cast the function pointer to a c_void_p
first, eg
data.u.pStream.open = c_void_p( c
call last):
File "", line 1, in
TypeError: expected LP_c_char instance, got _ctypes.PointerType
>>> databuftype = c_char * 10
>>> databuf = databuftype()
>>> cbuffer.cpBuffer = databuf
>>> databuf
<__main__.c_char_Array_10 o
> dwCreationDisposition,
> FILE_ATTRIBUTE_NORMAL,
> NULL );
use os.read os.write and os.open which will give you OS handles rather
than python file objects, ie I think these are a fairly direct
interface to CreatFile etc
L or Expect nor does it require C extensions to be
compiled. It should work on any platform that supports the standard
Python pty module. The Pexpect interface was designed to be easy to
use.
You'll never get it to work with subprocess like this because of the
buffering.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
com/ASPN/Cookbook/Python/Recipe/496960
and
http://sebulba.wikispaces.com/recipe+thread2
Read the caveats!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
ion layer (HAL). To specify processor
affinity for a thread, use the SetThreadAffinityMask function.
I would have said time.time is what you want to use anyway though
because under unix time.clock() returns the elapsed CPU time which is
not what you want at all!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Tim Roberts <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> >
> >time.clock() uses QueryPerformanceCounter under windows. There are
> >some known problems with that (eg with Dual core AMD processors).
> >
> >See http://m
Theo v. Werkhoven <[EMAIL PROTECTED]> wrote:
> The carbonbased lifeform Nick Craig-Wood inspired comp.lang.python with:
> > Theo v. Werkhoven <[EMAIL PROTECTED]> wrote:
> >> Output:
> >> Sample 1, at 0.0 seconds from start; Output power is: 8.967 dBm
>
but once you do you'll be writing a
killer crawler ;-)
As for Perl - once upon a time I would have done this with perl, but I
wouldn't go back now!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
SOURCE"
> redefined
>
> but if i do
>
> export C_INCLUDE_PATH=/usr/include/python2.4
>
> I do not face any compilation issues.
>
> I would like to know if there is anything i am missing on this.
Do it in your code with
#define _POSIX_C_SOURCE
instead of the Makefile
which was
from MSSQL->MySQL).
You'll find that different databases have subtly different ways of
doing things (eg autoincrement fields on mysql) so you'll most likely
need a custom script anyway.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
.mpq(123,1000)
>>> b = gmpy.mpq(12,100)
>>> a+b
mpq(243,1000)
>>> a*b
mpq(369,25000)
>>> a/b
mpq(41,40)
>>>
It is also *very* fast being written in C.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
'e']
> 2 : ['c']
> 3 : ['b', 'd']
> 4 : ['f']
>
Or use the little understood dict.setdefault method which has been
with us from time immemorial...
>>> d = {'a' : 1, 'b' : 3, 'c' : 2,'d' : 3,'e' : 1,'f' : 4}
>>> dd = {}
>>> for k, v in d.items():
... dd.setdefault(v, []).append(k)
...
>>> dd
{1: ['a', 'e'], 2: ['c'], 3: ['b', 'd'], 4: ['f']}
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
expensive than computer time,
> after all.
Good advice with one caveat: sorted() was only introduced in python
2.4 so if your code must run on earlier versions then use list.sort()
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
numerate(collatz(13)):
... last = x[:i+1]
... print x[:i+1]
... else:
... last.append(1)
... print last
...
[13]
[13, 40]
[13, 40, 20]
[13, 40, 20, 10]
[13, 40, 20, 10, 5]
[13, 40, 20, 10, 5, 16]
[13, 40, 20, 10, 5, 16, 8]
[13, 40, 20, 10, 5, 16, 8, 4]
[13, 40, 20, 10, 5, 16, 8,
vention.
I guess you've compiled your DLL with C++ and the above is a C++
mangled name.
Either compile it with C, or export the names in an extern "C" { }
block.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
if not os.path.exists('aaa'):
fd = open('aaa', 'w+')
else:
fd = open('aaa', 'r+')
fcntl.flock(fd,fcntl.LOCK_EX)
fd.truncate()
fd.write(data)
fd.close()
def check():
fd = open('aaa', 'r')
fcntl.flock(fd,fcntl.LOCK_EX)
data = fd.read()
fd.close()
if data not in ("sausage", "potato"):
raise AssertionError("Wrong data %r" % data)
if os.path.exists("aaa"):
os.unlink("aaa")
if len(sys.argv) < 2:
print "Syntax: %s " % sys.argv[0]
raise SystemExit(1)
method = globals()["method_"+sys.argv[1]]
if os.fork():
while 1:
method("sausage")
check()
else:
while 1:
method("potato")
check()
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
t;>> value
'\xc9\x11}\x8f?64\x83\xf3\xcaPz\x1d!\xddd'
>>> value.encode("hex")
'c9117d8f3f363483f3ca507a1d21dd64'
>>> long(value.encode("hex"), 16)
267265642849753964132104960801656397156L
>>>
> For unicode encoding, I can do, md5.update(value.encode('utf-8')) to
> give me ascii values.
Yes that would be fine
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
out.append(hex_to_binary[hex_digit])
... out = "".join(out).lstrip("0")
... if out == "":
... out = "0"
... return out
...
>>> to_binary(0)
'0'
>>> to_binary(10)
'1010'
>>> to_binary(100)
'1100100'
>>> to_binary(1000)
'101000'
>>> to_binary(1000)
'1000101011000111001000110100100010001000'
But don't try this ;-)
>>> to_binary(-1)
Traceback (most recent call last):
File "", line 1, in
File "", line 4, in to_binary
KeyError: '-'
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
)
Another VM to run python would be nice of course, but we already have
jython, ironpython and pypy.
Both jython and ironpython use JIT, pypy can compile to native code
and you can use psyco for JIT code also in normal python.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig
robably what you want is this...
from subprocess import call
rc = call(["mypath/myfile.exe",arg1,arg2])
rc will contain the exit status
See the subprocess module for more things you can do
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
t creates two lists
then joins them then throws the whole lot away!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
evidentemente.yo <[EMAIL PROTECTED]> wrote:
> On 24 jun, 14:32, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > Probably what you want is this...
> >
> > from subprocess import call
> >
> > rc = call(["mypath/myfile.exe",arg1,arg2])
add a bit of C/C++
if some part of it was running too slowly. If there were existing
C/C++ libraries then I'd use ctypes to interface with them.
I don't think I ever want to start another large C++ app - been there,
done that, got the (mental) scars to prove it ;-)
All my humble opinio
e here for a python memoize which makes the recursive algorithm run
fast...
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52201
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
passing len(x) arguments to zip.
So if x = [1,2,3,4]
zip(*x) == zip(1,2,3,4)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Rich Harkins <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood wrote:
> [snip]
> > By definition any function in a functional language will
> > always produce the same result if given the same arguments, so you can
> > memoize any function.
> >
>
> Ah, s
ll, but I haven't found any way of doing that. Can anyone offer
> my some suggestions? Or, am I S.O.L.?
You could try loading C explicitly with ctypes.LoadLibrary() before
loading A, then you'll have a handle to unload it before you load B.
I think I'd probably split the c
n the old site!
Mind telling us how it is implemented? I'm guessing python/django by
the url and the fact that you have python stuff on your home pages but
I could be wrong!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
a.x
0
>>> memmove(addressof(a), packet, sizeof(a))
3083811008L
>>> a.x
258
I think the second of those methods is promoted by the ctypes
documentation. I'm not sure about the lifetimes of the .contents in
the first method!
And the reverse
>>>
---
class Test(object):
def __init__(self):
self.foo = []
def goo(self):
self.foo.append(2)
def moo(self):
print self.foo
test = Test()
>>> from test2 import test
>>> test.foo
[]
>>> test.goo()
>>> test.foo
[2]
>>> test.moo()
[2]
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
c_char_p(136692916)
>>> s.value
'hello'
>>>
or use ctypes.memmove to copy the data out to somewhere else.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
to script that with python.
See here for some more info on dcop :-
http://www.ibm.com/developerworks/linux/library/l-dcop/
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
I spent weeks trying to get it to behave
when threading. I gave up in the end and changed to sqlite :-(
At least if you make a mistake with sqlite and use the wrong handle in
the wrong place when threading it gives you a very clear error.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://ww
function howMany(item,lst) which accepts
> an item and a lst of items and returns the number of times item occurs
> in lst. For example, howMany(3,[1,2,3,2,3]) should return 2.
Read section 4.1, 4.2 and 4.6 from here
http://docs.python.org/tut/node6.html
--
Nick Craig-Wood <[EMAIL
ying to use it in thread Y which won't work".
You can probably make bsddb work with threads, but I wasted too much
time trying without success!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
if not os.path.exists(link):
continue
open_files.setdefault(link, []).append(pid)
for link in sorted(open_files.keys()):
print "%s : %s" % (link, ", ".join(map(str, open_files[link])))
You m
dict unshareable, while immutable int
and str objects can still be shared. Further, mutable objects that
provide an explicit API for use between threads are also shareable.
----
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
if killpg:
os.killpg(pgid, signal.SIGKILL)
else:
os.kill(pid, signal.SIGKILL)
except OSError:
return
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Mark Wooding <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > Harishankar <[EMAIL PROTECTED]> wrote:
> >> 1. Create non-blocking pipes which can be read in a separate thread
> >> [...]
> >
> > You are correct o
uses pexpect fairly extensively to
> interface with all sorts of other systems. We recently received
> funding from Microsoft to do a native port of Sage (and all of its
> components to Windows. Part of this will most likely be a port of
> pexpect to Windows.
Hooray!
--
Nick Craig-Wood &
return v/len(x)
> >>
> >
> > think you want total/len(x) in return statement
> >
> Yes indeed, how glad I am I wrote "untested". I clearly wasn't pair
> programming when I wrote this post ;-)
Posting to comp.lang.python is pair programming wit
learning the
> language idioms).
When you are up to speed in python I suggest you check out gmpy for
number theory algorithms.
Eg :-
import gmpy
p = 2
while 1:
print p
p = gmpy.next_prime(p)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.co
o be put in and all the threads will have
to do is Queue.get() and be sure they've got a message they can deal
with.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
new = client.recv(256)
if not new:
break
data += new
>From the man page for recv
RETURN VALUE
These calls return the number of bytes received, or -1 if an
error occurred. The return value will be 0 when the peer has
performed an orderly shutd
impossible
to tell how much data has been sent.
There should really be a recvall for symmetry, but I don't think it
would get much use!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
7;, 'AUG', 'WWQWAWQWW', 'QWW', 'AGG')
>>>
> This way, I could scan for genes, remove the first letter, scan for
> more genes, remove the first letter again, and scan for more genes.
> This would hypothetically yield different genes, since the frame
> would be shifted.
Of you could just unconstrain the first match and it will do them all
at once :-
(AUG)((\w\w\w)*?)(AGG)
You could run this with re.findall, but beware that this will only
return non-overlapping matches which may not be what you want.
I'm not sure re's are the best tool for the job, but they should give
you a quick idea of what the answers might be.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood <[EMAIL PROTECTED]> writes:
>
> > What you are missing is that if the recv ever returns no bytes at all
> > then the other end has closed the connection. So something like this
> > is the corr
Terry <[EMAIL PROTECTED]> wrote:
> On Apr 28, 5:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > David <[EMAIL PROTECTED]> wrote:
> > > Another idea would be to have multiple queues, one per thread or per
> > > message type "group
lf.sock = None
raise ServerDisconnectedException()
self.rx_buf += rx
return message
Sorry I mis-understood your original post!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood <[EMAIL PROTECTED]> writes:
>
> >> Note that appending to a string is almost never a good idea, since it
> >> can result in quadratic allocation.
> >
> > My aim was clear exposition
= os.path.join(self.home, "."+self.NAME)
if not os.path.isdir(self.config_dir):
os.makedirs(self.config_dir, mode=0700)
self.config_file = os.path.join(self.config_dir, "config")
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
eceive output,
read exit code type jobs.
For jobs which require interactivity ie send input, receive output,
send input, receive output, ... it doesn't work well. There isn't a
good cross platform solution for this yet. pyexpect works well under
unix and is hopefully being ported to
ues since it's
> event-driven.
It took me a while but I found the documentation on this eventually
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorProcess.html
Looks interesting - I'll have to try it next time I'm reaching for
pexpect
Thanks
N
immediately after plugging the port in.
I do a lot of this sort of thing at work (not with cars though with
satellite equipment) and it is always the first packet and the first
response which is the hard part. After that it is usually plain
sailing!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
er idea ? Suggestions with
> reasoning would be very helpful.
Jython seems to be based off python 2.2 so you would be limited to 2.2
features in that case. No big deal in my opinion.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
y!
> I thought that it would be very nice if the built-in sum() function used
> this algorithm by default. Has this been brought up before? Would this
> have any disadvantages (apart from a slight performance impact, but
> Python is a high-level language anyway ...)?
sum() gets used for any numerical types not just floats...
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
SDK doing the same? As it is a hobby
> project, I don't like to spend money on the SDK.
Pick yourself up a cue-cat barcode reader, eg from here or ebay
http://www.librarything.com/cuecat
These appear as a keyboard and "type" the barcode in to your program.
Cheap and eff
gt; Is there a way to get it using pexpect ?
If I understand you correctly what you need to do is run "echo $$" on
the remote shell then "exec tunnel_command". The $$ will print the
pid and the exec will run tunnel_command without changing the pid.
--
Nick Craig-Wood <[EMA
file size...
> Are you sure the script runs to completion? Output a message at the
> end, to be sure.
Check the ownership of all the files too. Remember that the web
server (and hence your cgi) will likely run as nobody or www-data.
You are unlikely to be logging in as one of those users.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
vailable as a 3rd party
module for 2.3 and 2.4. As is sqlite3.
So in my opinion the real difference between the 2.2, 2.3, 2.4 and 2.5
are the built in modules. The actual language changes are very minor.
If you write your code for 2.5 which is probably a good idea, you'll
have no problem ba
inimize programming errors, simple code mistakes
> too.
And perl also
*ducks*
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
27;
> a.__argname__= new_value
Not quite sure what the above is supposed to achieve
> rather than :
>
> if arg == 'height':
>a.height = new_value
> elif arg == 'width';
>a.width = new_value
>
> Can I do this with python ? How ?
se
orting
it to python but looking at the regular expressions made me feel weak
at the knees ;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
#x27;d use select and run
asynchronously.
http://docs.python.org/lib/module-select.html
Actually if I really had to do this I'd use twisted. Right tool for
the job!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
= mydict['two']
v3 = mydict['two']
Either is only a couple more characters to type. It is completely
explicit and comprehensible to everyone, in comparison to
v1,v2,v3 = [ mydict[k] for k in ['one','two','two']] # 52 chars
v1,v2,v3 = [
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote:
>
> > As an ex-perl programmer and having used python for some years now, I'd
> > type the explicit
> >
> > v1,v2,v3 = mydict['one
701 - 800 of 861 matches
Mail list logo