interrupt. It may be possible - under unix you'd send a signal -
which python would act upon next time it got control back to the
interpreter, but I don't think it would buy us anything except a whole
host of problems!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote:
> > Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> > > But would be useful to be able to do without messing with
> > > threads and GUI
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote:
>
> > Well, yes there are different levels of potential reliability with
> > different implementation strategies for each!
>
> Gadzooks! F
lp you, as you are single-threaded here. The
> released lock won't prevent the called C-code from taking as long as it
> wants. |And there is nothing you can do about that.
I'm assuming that the timeout function is running in a thread...
--
Nick Craig-Wood <[EMAIL PROTECTED
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote:
>
> > I'd like there to be something which works well enough for day to day
> > use. Ie doesn't ever wreck the internals of python. It could ha
John Nagle <[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch wrote:
> > Nick Craig-Wood wrote:
> >
> >
> >>Did anyone write a contextmanager implementing a timeout for
> >>python2.5?
> >>
> >>And have it work reliably and in a c
ramming Perl" that Larry Wall said it was
a serious mistake to add this feature to perl.
If it is a feature too far for perl then it is *definitely* a feature
too far for python ;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
use of preexec_fn is
preexec_fn=os.setsid
You seem to be thinking it is pre-pending something to your command
line which isn't how it works.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
y.is_prime(2**607-1)
1
>>> gmpy.is_prime(2**608-1)
0
Cheating perhaps! Note is_prime will be a probabalistic test for
large numbers...
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
er qemu
and do native builds.
Cross compilers work well though - we build our app which has python
embedded for ARM using a cross compiler running under debian.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Gigs_ <[EMAIL PROTECTED]> wrote:
> does anyone know some good tutorial for unittest? (with examples
> how unit work)?
There is one in Dive into Python
http://www.diveintopython.org/unit_testing/index.html
Buy the book is my advice!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -
Unix Environment) needed to implement it is rather
disconcerting! A python module to do it would be great!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
ntry point to the local LAN, but would be harder to do
> if there are two points of entry, and packets could hit from
> outside on either..
It is all done in the kernel. The kernel has the state of the TCP
connection - it is just accessed from a different process.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
>>> mpq(1,3)+0.6
mpq(14,15)
>>> mpq(5,2)
mpq(5,2)
>>> mpq(1,3)*mpq(6,10)*mpq(4,10)+mpq(7,8)
mpq(191,200)
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
> processor families are truly multi-core, and which are HT.
On any unix/posix system (OSX and linux should both qualify) you can use
>>> import os
>>> os.sysconf('SC_NPROCESSORS_ONLN')
2
>>>
(From my Core 2 Duo laptop running linux)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
raise NotImplementedError
There is a bug in that code...
NotImplementedError will never be raised because num won't have been
set. It will raise "UnboundLocalError: local variable 'num'
referenced before assignment" instead
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
ode, plus a sequence of steps to be followed to
replicate the problem and you'll get some real help. The above is
just too vague.
The above code has a syntax error in it so obviously isn't from
working code.
PS I really doubt the problem is windows not seeing the created file...
--
Nick
've actually typed "f.close" rather
> > than "f.close()",
>
> You are right, I forgot the () in f.close() !
> thanks for pointing that out.
>
> VB programmer!? Thats really harsh..
I used to make that mistake a lot as an ex-perl programmer.
application in Qt on Mac, Win or Linux look like a
> native app.
I'd recommend wxPython over those becase
1) native look and feel on all platforms
2) doesn't require expensive licensing for non-commercial apps (QT)
3) Isn't a pain to install on windows (GTK)
That said, times change an
return math.exp(-n)*(n**(n-0.5))*math.sqrt(2*math.pi)*(1. + 1./12/n +
1./288/n**2 - 139./51840/n**3)
Works for non integer factorials also...
See here for background
http://mathworld.wolfram.com/StirlingsSeries.html
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.cr
e a program to demonstrate the problem?
You are best off reporting bugs here - then they won't get lost!
http://bugs.python.org/
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
etty
>
> Removing this (or just disabling it for the user who must run the
> cron job) should eliminate the error. Note that you will also need
> to disable authentication either via the NOPASSWD tag or the
> "authenticate" Defaults option.
Check the PATH in cron also
--
:
number = myNumer[:]
random.shuffle(number)
if number == myNumer:
count+=1
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
e written out if dirty
and then dropped.
The OS will try to keep hold of pages as long as possible just in case
you need them again. The pages dropped should be the least recently
used pages.
I wouldn't have expected a MemoryError though...
Did you do mmap.flush() after writing?
--
Nick C
a MemoryError. It is asking for
a new bit of memory and it is failing so it throws a MemoryError.
Could memory allocation under windows be affected by a large chunk of
mmap()ed file which is physically swapped in at the time of the
allocation?
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- h
r there is something
going on in your program that we don't know about or there is a bug
somewhere, either in the OS or in python.
Can you make a short program to replicate the problem? That will help
narrow down the problem.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-
under windows you get a quite different
result :-
>>> from time import clock, time
>>> print clock(), time()
7.54285810068e-006 1169574534.84
>>> print clock(), time()
3.32073322168 1169574538.16
>>> print clock(), time()
7.32428004118 1169574542.15
ot;
total = x
power = x
divisor = 1
old_delta = None
while 1:
power *= x
power *= x
power = -power
divisor += 2
old_total = total
total += power / divisor
delta = abs(total - old_total)
if old_delta is not None and
016001
>>> start = cpu_time(); f(); dt = cpu_time() - start; print dt
0.012001
>>> start = cpu_time(); f(); dt = cpu_time() - start; print dt
0.008001
You'll see the result is quantised to 4 ms (not sure what the .01
bits are about!)
4ms is the clock rate of this machine,
it would be more elegant...
>>> n = 1
>>> for i in range(16):
... print ("%X" % n).replace('0', ' ').replace('1', '*')
... n = n ^ (n << 4)
...
*
**
* *
* *
** **
* * * *
* *
** **
* * * *
* * * *
** ** ** **
* * * * * * * *
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
nd for this -- perhaps another way to
> access the values of those RTLD flags?
Read stuff out of /usr/include/bits/dlfcn.h ?
It seems to be a constant 1 anyway
#define RTLD_LAZY 0x1
You could try compiling the dl module by hand.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http
John Pye <[EMAIL PROTECTED]> wrote:
> On Feb 19, 6:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > John Pye <[EMAIL PROTECTED]> wrote:
> > > application from running on the Debian Etch AMD64 platform.
> > > It seems that the 'dl' mo
by a dummy request, which seems a bit awkward.
Can't you get SocketServer to timeout and return you control
regularly?
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
eError: can only concatenate list (not "tuple") to list
>>>
Ie
x += a
does not equal
x = x + a
which it really should for all types of x and a
(That is the kind of statement about which I'm sure someone will post
a perfectly reasonable counterexample ;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood wrote:
>
> > x += a
> >
> > does not equal
> >
> > x = x + a
> >
> > which it really should for all types of x and a
>
> Actually, this will *never* be t
see
that in a daemonize recipe before?
> else:
> # time for child to die
> os._exit(0)
> else:
> # wait for child to die and then bail
> os.wait()
> sys.exit()
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
r own GUI in pygame
to do exactly what you want for your embedded device.
> I'm not really sure what the differences are between those two. The
> latter seems to be a little more active.
Pygame is the way I've always done SDL stuff in python - never even
heard of PySDL!
-
p
I've used py2exe and nsis quite a few times - works well.
Note that py2exe can bundle your app into a single exe which you can
just run which may be good enough (no need for an installer).
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
instances (about 1,000,000 in our case) and adding __slots__
to it!
I'd guess that if you __slot__-ed the Domain class then you'll find
the overhead of a type attribute is minimal (4 bytes per instance I
think).
No idea about Hessian or Stomp (never heard of them!) but classes with
__s
, "credits" or "license" for more information.
>>> from sqlite3 import dbapi2
>>> import sqlite3
>>> set(dir(sqlite3)) ^ set(dir(dbapi2))
set(['__path__', 'dbapi2'])
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
python expect module to work around these
problems. Unfortunately there isn't a windows version :-(
You could try the non blocking subprocess modification here
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554
You could also try wx.Process and wx.Execute from wxPython.
--
Nic
ines += 1
total += len(line)
print "Received %d lines of %d bytes total" % (lines, total)
#
Which runs like this on my machine
$ python subprocess-shell-nb.py
waiting on child...
waiting on child...
waiting on child...
waiting
latform (using a shared QT) and see how much extra RAM it uses.
> is there an exaample of going thru a passworded proxy using twisted
> client classes? i have trouble understanding how to adapt the
> proxy example on page 58 in the twisted book to my needs.
I advise looking at
quot;"
print >>sys.stderr, globals()['__doc__']
print >>sys.stderr, error
sys.exit(1)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
at
> those few posted code lines.
Actually any number >= 2**31 won't fit in a python int.
>>> 2**31
2147483648L
According to my headers DWORD is defined like this
typedef unsigned long DWORD;
So you might see longs returned when you expected ints if the result
was >= 0x800.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
> "Nick Craig-Wood" wrote:
> > So you might see longs returned when you expected ints if the result
> > was >= 0x800.
>
> did you mean 0x8000 ?
>
> ;-)
Yes - well spotted!
--
Nick Crai
r stuff comes all after the stdout stuff.
> How can I get ahold of all the out and err joined synchronously in the
> order, it is created ?
You need to either
1) change myapp to fflush() more often
2) investigate the python pty module to fool the app into thinking it
is talking to a termi
t this:
>
> series = [x/2 for x in range(200, 1, -1)]
That should be
series = [x//2 for x in range(200, 1, -1)]
to be "from __future__ import division" safe
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
(spread)
This is simpler, easier to prove correct and most likely quicker.
def distribution(N=2):
L = [ random.uniform(0,1) for _ in xrange(N) ]
sumL = sum(L)
return [ l/sumL for l in L ]
spread = distribution(10)
print spread
print sum(spread)
--
Nick Craig-Wood <[EMAIL PROTECTED
i)
m = Matcher()
t = 'blue socks and red shoes'
if m.search(r'(blue|white|red)', t):
print "Colour:", m[1]
elif m.search(r'(socks|tights)', t):
print "Garment:", m[1]
elif m.search(r'(boot|shoe|trainer)', t):
print "
sn't look so scary as 5k-10k LOC in Python.
I bet your C code doesn't have unit tests either... Make sure you
write those as you are going along in Python. It will make more code,
but it will give you a wonderful feeling of confidence that your code
will actually work, and
esn't
matter!
> The following quote sums things up nicely I think:
>
> "In theory there is no difference between theory and practice, but in
> practice there is."
;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
You might want to show him this too...if you happen to need cnt in the
loop, this is what you write
files = [a,b,c,d]
for cnt, fi in enumerate(files):
do_something(cnt, fi)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
d I have to close it.
> I cannot find the reason. Can somebody give me a hint to let it work
> well? Thanks
I tried it but it doesn't work at all on linux.
I suggest you use wxPython and stop re-inventing the wheel!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wo
>>> print a, b
[5, 6, 7] [5, 6, 7]
Using keywords[:] stops the creation of another temporary list. The
other behaviour may or may not be what you want!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Nick Craig-Wood wrote:
>
> > Using keywords[:] stops the creation of another temporary list.
>
> in CPython, "list[:] = iter" actually creates a temporary list object on
> the inside, in case "iter"
0118 kb downloaded 21.304672.1 kBytes/s
Sleep for 0.497982025146
40 kb of 10118 kb downloaded 19.979510.1 kBytes/s
Sleep for 0.497948884964
48 kb of 10118 kb downloaded 19.184721.1 kBytes/s
Sleep for 0.498008966446
...
1416 kb of 10118 kb downloaded 16.090774.1 kBytes/s
Sleep for 0.499262094498
1424
ursion depth exceeded
16 16 maximum recursion depth exceeded
17 False
[snip]
89 False
90 90 maximum recursion depth exceeded
91 False
92 False
93 93 maximum recursion depth exceeded
94 False
95 False
96 96 maximum recursion depth exceeded
97 False
98 False
99 99 maximum recursion depth exceeded
--
N
which becomes
effectively part of the OS. The package manager tracks every file it
installes to ensure ovewrites can't happen etc...
/usr/local/bin is for stuff installed from source, not using the
package manager.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
bject
the ftphandler code relies on.
I see you attempt to kill the ftp server with ftpd.stop(). That is
good, but you don't wait for the thread to finish (it might take up to
a second in ftpd.server_forever if I understand correctly).
I expect if you put a self.join() at the end of the stop() method the
problem will go away.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
> production of Debian packages using distutils.
Looks interesting though!
> [1] http://stdeb.python-hosting.com/
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
n't
that hard).
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
ine)
This iterates over the lines of all files listed in sys.argv[1:],
defaulting to sys.stdin if the list is empty. If a filename is '-', it
is also replaced by sys.stdin. To specify an alternative list of
filenames, pass it as the first argument to input(). A single file
name is also allowed.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
or list size 1000
Read back 1000 items in 0.000352478027344 s
Written 50005 bytes for list size 1
Read back 1 items in 0.00165479183197 s
Written 55 bytes for list size 10
Read back 10 items in 0.0175776958466 s
Written 505 bytes for list size 100
Read back 100 i
'dummy' would both be OK.
As for me personally, I usually use '_' but sometimes use 'dummy'
depending on the surrounding code.
Note that this idiom is fairly common in python too
wanted, _, _, _, also_wanted = a_list
which looks quite neat to my eyes.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
tances.
The syntax isn't so great when you set things which aren't valid
keywords though...
eg
{ (1,2,3) : 'a', (4,5,6) : 'b' }
vs
dict([ ((1,2,3), 'a'), ((4,5,6), 'b') ])
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
n__.Y object at 0xb7d9fc2c>]
[<__main__.Y object at 0xb7d9fc8c>]
(It behaves slightly differently in the interactive interpreter for
reasons I don't understand - so save it to a file and try it!)
In fact I find most of the times I wanted __del__ can be fixed by
using a weakref.WeakValueDictionary or weakref.WeakKeyDictionary for a
much better result.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
20 job gets only 4%.
I think you are on to a loser here trying to normalise it across
OSes unfortunately :-(
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
this code? I looked
at the examples but I couldn't see one? Having a simple nameserver
written in python would be very useful indeed...
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
TimeHorse <[EMAIL PROTECTED]> wrote:
> On Feb 22, 4:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> > Interestingly enough this was changed in recent linux kernels.
> > Process levels in linus kernels are logarithmic now, whereas before
> > they weren'
sing the ptrace
interface.
Both those things will require the relevant rights and neither is
quite as easy as you might hope for!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
above and the original proposal
class InfiniteLoopError(Exception):
"""An 'infinite' loop has been detected"""
def infinite_loop(max=200):
for i in xrange(max):
yield i
raise InfiniteLoopError()
Use it like this
for i in infinite_loop():
if i > 10:
break
print "iteration", i
or
for i in infinite_loop(10):
print "iteration", i
> but I agree with Tim that a for ... else loop for the limit is
> clearer.
Probably yes
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
; Where is my fault?
You didn't (or you didn't show) defining the argument types of the
function.
myclib = CDLL("myclib.so") # or whatever
myclib.myfunction.argtypes = [ POINTER(INTERFACE) ]
myclib.myfunction.restype = c_int # or whatever
If you do that then you should be able to pass in myiface directly or
byref(myiface).
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
t):
cls.registry[cls.__name__] = cls
class ThingOne(BaseThing):
pass
class ThingTwo(BaseThing):
pass
class ThingThree(BaseThing):
pass
print BaseThing.registry["ThingOne"]
print BaseThing.registry["ThingTwo"]
print BaseThing.registry["ThingTh
Thread(target=test_lock_process,
args=(lock,i,queue,)))
for t in threads:
t.start()
for t in threads:
t.join()
if print_result:
try:
while True: print queue.get(block=False)
except Empty:
pass
if __name__ == "__
ossible to fix to me. I'd love to
be proved wrong though!
If you were thinking of passing time.time() /
clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll
want to know that it can differ by significant amounts on different
processors :-(
Good luck!
--
Nick Craig-Woo
t; raise Exception("Record not found")
>
>
> def changeRecord(self, record, type, target):
> """
> Changes a dns entry.
> @param record: which record to chance
> @param type: what type of record, A
flagg wrote:
> On Feb 3, 7:32?am, Nick Craig-Wood wrote:
> > flagg wrote:
> > > ?This xmlrpc server is designed to parse dns zone files and then
> > > ?perform various actions on said files. \
> > > ?It uses dnspython, and xmlrpclib
> > > ? I
t. It then uses that new
compiler to compile a gcc for the target architecture.
I could imagine a similar scheme for python, but it would involve lots
of fiddling about and some commitment from the python maintainers.
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
kurt.forrester@googlemail.com wrote:
> Any ideas on how to suppress the warning output:
> __main__:1: Warning: No data - zero rows fetched, selected, or
> processed
You can use the warnings module to suppress these I would have
thought.
--
Nick Craig-Wood -- http://www.craig
debian, ubuntu and centos packages for it if you
look!
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Jean-Paul Calderone wrote:
> On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood
> wrote:
> >r0g wrote:
> >> I'm writing a linux remastering script in python where I need to chroot
> >> into a folder, run some system commands and then come out and do some
moredata = "A"*4096
test = StringConcatTest()
t = time.time()
for i in range(1000):
test.feed(moredata)
print "%0.3f ms"%(1000*(time.time() - t))
Before it was 3748.012 ms on my PC, afterwards it was 52.737 ms
However that isn't a perfect solution - what if something had anot
est:$1$3nvOlOaw$vRWaitT8Ne4sMjf9NOrVZ.:13071:0:9:7:::
(not a real password line!)
You need to work out how to write that format.
>From memory: the "$1" bit means it is an md5 hash, the next
"$3nvOlOaw$" is the salt and the final "$vRWaitT8Ne4sMjf9NOrVZ." is
the m
all platforms. I used to use
> ctypes for wrapper but eventually I switched to Cython.
What sort of problems have you had?
I find as long as I use the same types as the C code actually uses it
all works fine. If on a 64 bit platform long is 64 bits then it will
be under ctypes too.
--
Nick
tly the same on all supported platforms and since it
usually runs full screen that is fine. I imagine this GUI toolkit
fits the same niche.
Presumably since it uses SDL then all the GUI will appear in one
window? So windows within windows in the MDI style?
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
ibrary atof()
does. Ie only converting as much as it can and returning 0.0 for
an error.
"""
match = _float_pattern.search(value)
if match:
return float(match.group(1))
return 0.0
>>> atof("15.5 Sausages")
15.5
>>> atof(" 17.2")
t;
return self._A
def _setA(self, value):
print "Setting A"
self._A = value
A = property(_getA, _setA)
def main(self):
print self.A
print self.B
# dosomething
self.A = "aValue"
self.B = "aValue"
print self.A
print self.B
>>> a = Stuff()
>>> a.main()
Getting A
None
None
Setting A
Getting A
aValue
aValue
>>>
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
fibonacci_noniterative(i)
t_noniterative = time() - t0
print "%10d, %10.6f, %10.6f" % (i, t_iterative, t_noniterative)
if f_iterative != f_noniterative:
print "Calculation error"
print "iterative", f_iterative
print "non iterative", f_noniterative
print "difference", f_iterative-f_noniterative
--
Nick Craig-Wood -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
is directory. I have a feeling that
> pdflatex is trying to generate files using some weird access
> credentials that dont have access to /tmp/pdfscratch{id}
Unlikely - it takes root to change user and I wouldn't have thought
any of the files would be setuid.
Try chdir to /tmp/pdfscrat
'm still waiting to hear that
>
> from __past__ import division
>
> will become a reality...
;-)
I think that is called using // instead of / which works without any
from __future__ import from python 2.2 onwards.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
opendir(".")
print "dir_p = %r" % dir_p
dir_fd = dirfd(dir_p)
print "dir_fd = %r" % dir_fd
print "closed (rc %r)" % closedir(dir_p)
Which prints on my linux machine
dir_p =
dir_fd = 3
closed (rc 0)
I don't know why os doesn't wrap - opendir, cl
e 'r' at 0xb7d03020> fd=0
STDOUT ', mode 'w' at 0xb7d03068> fd=1
os.O_NDELAY=0800
stdin: flag=0002
stdout: flag=8001
setting non blocking on stdin...
stdin: flag=0802
stdout: flag=8001
removing non blocking on stdin...
stdin: flag=0002
stdout: flag=8001
So I suspect your result is because stdin and stdout refer to the same
file (eg /dev/tty0 or /dev/pts/25).
No idea whether this is correct behaviour or not though!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
uot;
And here is the test again, actually calling something with the same
difference in execution speed :-
$ python -m timeit -s 'from os import nice' 'nice(0)'
100 loops, best of 3: 1.21 usec per loop
$ python -m timeit -s 'import os' 'os.nice(0)'
100 loops, best of 3: 1.48 usec per loop
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
im have all these features, don't
know about Eclipse.
In fact if I had to pick one feature that a programmer's editor must
have it would be keyboard macros.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
e
first time it will populate itself.
If None is a valid value for data then make a sentinel, eg
class PayloadOnDemand(object):
sentinel = object()
def __init__(self, a_file, a_file_position):
self._data = self.sentinel
self.f = a_file
self.file_position = a_file_position
@property
def data(self):
if self._data is self.sentinel:
self._data = self.really_read_the_data()
return self._data
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
bar.yourclass import YourClass
If this spelling causes local name clashes, then spell them
import myclass
import foo.bar.yourclass
and use "myclass.MyClass" and "foo.bar.yourclass.YourClass"
Ultimately it is a matter of taste I think!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Slaunger <[EMAIL PROTECTED]> wrote:
> On 2 Dec., 11:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>
> >
> > For 4 attributes I'd probably go with the __getattr__.
> >
> OK, I'll do that!
>
> > Or you could easily write
Slaunger <[EMAIL PROTECTED]> wrote:
> On 1 Dec., 16:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> >
> > I wouldn't use __getattr__ unless you've got lots of attributes to
> > overload. ?__getattr__ is a recipe for getting yourself into trouble
>
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Tue, 02 Dec 2008 11:12:31 +0000, Nick Craig-Wood wrote:
>
> > I prefer the "from module import function". That means that if "module"
> > doesn't supply "function" it raises an
301 - 400 of 641 matches
Mail list logo