Re: Python WSDL Support

2009-06-16 Thread Piet van Oostrum
s/). And you may also look for soaplib (http://trac.optio.webfactional.com/) but it is probably also `dead'. There is a fork soaplib-lxml, however, that is being actively developed. SOAP is not very popular in the Python world, I think. SOAP is a mammoth and that fits better in the Java and M

Re: Newbie help for using multiprocessing and subprocess packages for creating child processes

2009-06-16 Thread Piet van Oostrum
a need for these threads. You could just use os.wait() to wait for a child to finish and then start a new process if necessary. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Input problem

2009-06-16 Thread Piet van Oostrum
>>>>> Lie Ryan (LR) wrote: >LR> Piet van Oostrum wrote: >>>>>>>> Prasoon (P) wrote: >>> >P> What is the difference between >P> z=int(raw_input()) and z=eval(raw_input())(I thought them to be >P> the same in case of in

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-18 Thread Piet van Oostrum
gt; memory management scheme of whatever language one uses. For code written >CY> for CPython only, as mine is, RAII is an appropriate idiom and not kludgy >CY> at all. Under your assumptions, its use would be wrong, of course. I dare to say that, even in CPython it is doomed to dis

Re: Newbie queue question

2009-06-18 Thread Piet van Oostrum
the self.q.join() will be processed and the thread finishes. In the mean time while t.isAlive() is constantly being tested, also wasting CPU time. IMHO a better way is to put a sentinel object in the queue: def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', re

Re: python tutorial

2009-06-18 Thread Piet van Oostrum
iles. I don't think >PB> that advances your case. And that was a bug apparently (euphemistically called a `problem'). >PB> If they had changed the Windows behaviour, yes, but >PB> Windows 7 seems to be compatible with NT 3.5 rather >PB> than with DOS. If that

Re: Help: Group based synchronize decorator

2009-06-19 Thread Piet van Oostrum
' >VS> - decorator passes this 'whatGroup' argument to my lock which is used in >acquire logic. >VS> Is it ok to make such assumptions in decorator? As long as you make sure that all decorated functions indeed adhere to that assumption there is nothing wrong wit

Re: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009

2009-06-19 Thread Piet van Oostrum
>>>>> John Machin (JM) wrote: >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnEBAJ Apart from these patents probably being silly, why don't they just write the code in Python? :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142B

Re: Newbie queue question

2009-06-19 Thread Piet van Oostrum
the Python language, but of the Python implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email:

Re: Integer Division

2009-06-19 Thread Piet van Oostrum
on >>>>> a = 1 >>>>> b = 25 >>>>> a / b >AL> 0.040001 >>>>> >AL> In what simple way can I get just 0.04 ? In addition to the answers others have given: >>> 0.04 0.040001 >>>

Re: Excel Formulae in Python ;-)

2009-06-19 Thread Piet van Oostrum
>>>>> Chris Withers (CW) wrote: >CW> Piet van Oostrum wrote: >>>>>>>> John Machin (JM) wrote: >>> >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnEBAJ >>> >>> Apart from these patents probably

Re: Newbie queue question

2009-06-19 Thread Piet van Oostrum
f the Python language, but of the *CPython* implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Privat

Re: multiprocessing and process run time

2009-06-19 Thread Piet van Oostrum
t the PID of the process, but I'm not sure >TR> where to go from there. Is there an easy way to do this? You could look at the psutil module: http://code.google.com/p/psutil/ -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: KeyboardInterrupt eats my error and then won't be caught

2009-06-20 Thread Piet van Oostrum
ceptions to be handled. I also added traceback printout in the outer exception handler and it points to the sem.acquire line. My conclusion is that if there are two exceptions at the same time, the inner exception handler is interrupted by the other exception even before the except clause can be entered. And only the outer one is really executed. This explains the behaviour that the OP described. I think you can only have two exceptions at the same time if at least one of them is a signal. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Piet van Oostrum
gram is running on could have atomic read/writes on 64-bit quantities but if you rely upon that your program may no longer be portable. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Piet van Oostrum
re comes in handy. Now usually these reads will not consume so much CPU so it will probably be hardly noticeable. But if you would have some kind of CPU-intensive User-space File System, for example with compression and/or encryption and the data is in memory you might notice it. In this example a

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Piet van Oostrum
thread is not I/O bound but CPU bound. See my other posting for an example. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: KeyboardInterrupt eats my error and then won't be caught

2009-06-20 Thread Piet van Oostrum
custom error you will have to do some other stuff. I don't know what but maybe calling PyErr_SetString is sufficient as it might overwrite the KeyboardInterrupt stuff. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org --

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Piet van Oostrum
>SD> Class A only gets defined if you run the module as a script. What you need >SD> is to unconditionally define class A, outside of the if __name__ block: >SD> class A(BaseA): >SD> pass >SD> # A.__base__ = DebugA ## Uncomment this line for debugging. >>>A.__base__ = DebugA TypeError: readonly attribute Make that: A.__bases__ = DebugA, >SD> -- >SD> Steven -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y))

2009-06-21 Thread Piet van Oostrum
t sometimes only half of a discussion is visible. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Meta question: disappearing posts

2009-06-21 Thread Piet van Oostrum
>>>>> Chris Rebert (CR) wrote: >CR> On Sun, Jun 21, 2009 at 5:25 AM, Piet van Oostrum wrote: >>> I notice that I see several postings on news:comp.lang.python that are >>> replies to other postings that I don't see. Examples are the postings by >>

Re: UnicodeDecodeError: problem when path contain folder start with character 'u

2009-06-22 Thread Piet van Oostrum
mething wrong or this is as designed behavior >a> . >a> any help appreciated Calling unicode(fp, "unicode_escape") with these filenames is nonsense. unicode_escape is for transforming a string like \u20ac to a €-sign or vice versa: >>> fp="\\u20ac" >>> print unicode(fp,"unicode_escape") € So what are you trying to achieve? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter - non-ASCII characters in text widgets problem

2009-06-26 Thread Piet van Oostrum
his seems to cause other problems. See: http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862062 http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862807 -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: encoding problem

2009-06-27 Thread Piet van Oostrum
fig there and run my python server >n> script. >n> Now here is the problem, server is returning strange characters >n> although default encoding is the same on both development and server >n> machines. >n> Any hints? Yes, read http://catb.org/esr/faqs/sma

Re: change the first character of the line to uppercase in a text file

2009-06-27 Thread Piet van Oostrum
nes from a file there will >>> always be at least the newline character. Otherwise it would indeed fail: >TR> Except possibly for the last line. But then that line wouldn't be empty either. If there is an empty line not terminated by a newline after the last newline, then

Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Piet van Oostrum
IO module documentation, so >PM> I probably missed something obvious. Could you explain how I get the >PM> byte stream underlying sys.stdin? (That should give me enough to find >PM> what I was misunderstanding in the docs). http://docs.python.org/3.1/library/sys.html#sys.stdin

Re: Python Imaging Library download link broken?

2009-06-29 Thread Piet van Oostrum
>>>>> peter (p) wrote: >p> Whilst this is an interesting discussion about installers, I'm still >p> trying to find a copy of PIL. Any ideas? Pythonware is up again: http://pythonware.com/products/pil/index.htm -- Piet van Oostrum URL: http://pietvanoostrum.co

Re: Determining if a function is a method of a class within a decorator

2009-07-05 Thread Piet van Oostrum
ce of the subclass, not the name of the class that the method was defined in: class D(C): pass D().f(1, 2) will talk about class D, not class C. So if you would like to do something special for bound methods the __get__ might be the proper place to do it. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
: factorise(6) will return [2, 2] (the powers are returned one higher than the actual value) as in, 2^1 * 3^1 = 6.""" powers = [] power = 0 for factor in sieve(): power = 0 while num % factor == 0: power += 1 num /

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
lobal Dlist for q in Dlist: yield q while True: q += 2 p = D.pop(q, 0) if p: x = q + p while x in D: x += p D[x] = p else: Dlist.append(q) D[q*q] = 2*q yield q -- Piet van Oostrum URL:

Re: try -> except -> else -> except?

2009-07-06 Thread Piet van Oostrum
> this exception from the one that may be generated from the DH> amount of code that may raise a KeyError> line. >DH> (ii) it moves the error handler for the DH> raise a KeyError> bit miles away from the line that might generate the >DH> error, making it unclear which code the

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
>>>>> Scott David Daniels (SDD) wrote: >SDD> # No need for global declarations, we alter, not replace Yes, I know, but I find it neater to do the global declarations, if only for documentation. And they don't affect the run time, only the compile time. -- P

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
is one, which is >DA> usually sooner than the square root. And no need to precalculate the >DA> square root. That's right. I thought of doing the sqrt trick by testing for num < factor, i.e." if num < factor: break but found out that it is useles

Re: Catching control-C

2009-07-06 Thread Piet van Oostrum
use a try/except to catch a KeyboardInterrupt exception, or you >PS> can trap it using the signal module: >PS> http://docs.python.org/library/signal.html >PS> You want to trap SIGINT. And make sure threads don't mess up the signal handling. -- Piet van Oostrum UR

Re: Semi-Newbie needs a little help

2009-07-07 Thread Piet van Oostrum
n k which = 11/14/2008 >N> here is the value that was returned 11/14/2008 >N> here is a list of the dictionary values [5] >N> the length of the dictionary is 1 >>> Exit code: 0 Now in your code there is a 1-1 relation between printing "here is the value that

Re: Creating alot of class instances?

2009-07-07 Thread Piet van Oostrum
ightly. Unless the screw >SD> has been specifically designed to be hammered, hammering screws is pretty >SD> much the definition of incompetence and/or laziness! In our language (Dutch, i.e. Guido's mother tongue) `American screwdriver' is an expression meaning `hammer' :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Python/pyobjC Apps on iPhone now a possibility?

2009-07-07 Thread Piet van Oostrum
1.5.2. My first Python experience at home was on a 40MHz 80486 (Python 1.5.2 I think). It was a bit slow :=( -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: ISO library ref in printed form

2009-07-07 Thread Piet van Oostrum
at lulu.com. It would even be nicer if the PSF would offer them at lulu. They could even make some money from it if enough copies would be sold.. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-07 Thread Piet van Oostrum
en tries to assign the result of it to spam[0], which is not allowed. That the item it tries to assign is the same as the item that was already there doesn't matter. So dont't forget += is a real assignment, even when it is an in-place modification. Your example just proves that. The language ref manual says: With the exception of assigning to tuples and multiple targets in a single statement, the assignment done by augmented assignment statements is handled the same way as normal assignments. But I think that your example isn't for beginners either. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-08 Thread Piet van Oostrum
se "x = x + y" until they have enough knowledge to >SF> understand "augmented" assignment. And *then* you can tell them that "x += y" can be subtly different from "x = x + y", which is what happened in the example that the OP gave. -- Piet van Oostru

Re: IP Address Function

2009-07-08 Thread Piet van Oostrum
CGI script. Something like: #! /usr/bin/env python import cgi from os import getenv print "Content-type: text/html" print ipaddr = (getenv("HTTP_CLIENT_IP") or getenv("HTTP_X_FORWARDED_FOR") or getenv("HTTP_X_FORWARDED_FOR") or getenv("REMOTE_ADDR") or "UNKNOWN") print ipaddr -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Emacs Python-mode. Newbie problem.

2009-07-08 Thread Piet van Oostrum
python code what command C-c RET is bound to? With C-h k C-c RET Shell command succeeded with no output suggests that is has a different binding than the standard one in python-mode. Did you happen to name your file 'test' or 'test.py? C-c RET does an import and 'import test&

Re: ISO library ref in printed form

2009-07-08 Thread Piet van Oostrum
>>>>> kj (k) wrote: >k> In Piet van Oostrum writes: >>>>>>>> kj (kj) wrote: >kj> Does anyone know where I can buy the Python library reference in >kj> printed form? (I'd rather not print the whole 1200+-page tome >kj> mys

Re: IP Address Function

2009-07-09 Thread Piet van Oostrum
>>>>> Fred Atkinson (FA) wrote: >FA> On Wed, 08 Jul 2009 12:29:54 +0200, Piet van Oostrum >FA> wrote: >>> Something like: >>> >>> #! /usr/bin/env python >>> >>> import cgi >>> from os import getenv >>>

Re: Emacs Python-mode. Newbie problem.

2009-07-09 Thread Piet van Oostrum
your python file is located, otherwise the import statement will not find your file. Unless it is somewhere in the python path. Also the *Python* buffer will not automatically pop up if it is not visible, in contrast with the *Python Output* buffer. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Emacs Python-mode. Newbie problem.

2009-07-09 Thread Piet van Oostrum
age. >L> Then I run python shell with C-c ! command. And: >L> a) C-c RET opens *Python* buffer and prints 'hello world' in the >L> python shell >L> b) C-c C-c gives the same result. Which version of python-mode.el do you have? (Variable py-version) -- Piet van

Re: Automate rsync w/ authentication

2009-07-10 Thread Piet van Oostrum
i /home/bry/keys/brybackup.key"' >CR> args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest] >CR> Note that the -e switch and its operand are separate arguments for the >CR> purposes of POSIX shell tokenization. I think you should have only one kind of quotes in rshArg: rshArg = "/usr/bin/ssh -i /home/bry/keys/brybackup.key" I haven't tried it, however, but this is just how Unix works. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Automate rsync w/ authentication

2009-07-10 Thread Piet van Oostrum
system. #! /usr/bin/env python from subprocess import Popen, PIPE rsyncExec = '/usr/local/bin/rsync' source = 'xxx.cs.uu.nl:/users/piet/yy' dest = '/Users/piet/TEMP/test.rsync' rshArg = &#

Re: tough-to-explain Python

2009-07-11 Thread Piet van Oostrum
anyway (supposing int is 32 bits) but longs and then the same reasoning shows that there are no overflows. Only when you have an array of shorts or bytes (chars) you get the problem. In that case the alternative formulation l + (u-l)/2 is more robust and therefore preferable. -- Piet van Oostrum

Re: Threading.Condition problem

2009-07-11 Thread Piet van Oostrum
lso saves you the hassle of doing your own synchronisation like above. If you are not familiar with synchronising multithreaded applications it is very easy to make errors and even if you are it is quite easy to do them wrong. I have been involved in distributed programming c

Re: how to run the "main" section of another module ?

2009-07-12 Thread Piet van Oostrum
section and uses the >SM> library under construction) >SM> if __name__ == '__main__': >SM>import db_test >SM>new_globals = {} >SM>new_globals [ '__name__' ] = '__main__' >SM>new_globals [ '__file__' ] = 'not really valuable' >SM>execfile ( 'db_test.py', new_globals ) Why not: import db_test db_test.main() I think that is what Aahz meant. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about generators

2009-07-12 Thread Piet van Oostrum
generator I wrote so that I don't need two for >CP> loops that do the same thing? >CP> I tried writing a primes function using yield statements, but it didn't >CP> work like I thought it would. See the recent thread `Why is my code faster with append() in a loop tha

Re: Sockets and threading

2009-07-12 Thread Piet van Oostrum
srvr.vlock.acquire() >z> srvr.v += k >z> srvr.vlock.release() >z> self.myclntsock.send(srvr.v) >z> self.myclntsock.close() The last line is wrongly indented. It should be outside the loop. Shift it left so that it line

Re: multiprocessing and dictionaries

2009-07-13 Thread Piet van Oostrum
. Try to make a *minimal* program that shows the problem and include it in your posting or supply a download link. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about generators

2009-07-13 Thread Piet van Oostrum
y looking at it there are some interesting >CP> patterns I might be able to extend into a generator that would >CP> yield only correct sets of numbers for the 6x + n pattern. As I wrote in my previous reply, in your use case the non-primes are harmless. But it is useful to reflect tha

Re: Infinite loops and synchronization

2009-07-13 Thread Piet van Oostrum
eful: I haven't tested this code (not even syntax checked). So consider it pseudo code.* -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: The meaning of "="

2009-07-13 Thread Piet van Oostrum
ute 'x' >LD> Nope, still doesn't work... Of course you need c = AttrDict() And to get c.x = 4 working you also need a __setitem__. And to get c["x"] working AtrrDict should subclass dict: >>> class AttrDict(dict): but these are only minor details :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Automate rsync w/ authentication

2009-07-13 Thread Piet van Oostrum
', '-v', '--dry-run'] +  rshArgs + [ source, dest] >>> >>>                                         Gary Duzan >>>                                         Motorola H&NM >B> Separating the argument parts worked. Strangely though, I don

Re: Threading.Condition problem

2009-07-13 Thread Piet van Oostrum
>>>>> Gabriel Rossetti (GR) wrote: >GR> Piet van Oostrum wrote: ... >GR> I wrote a small example that listens for xmpp msgs in a thread. The main >GR> program calls a function that blocks (using Condition.wait) until a msg >GR> has been received and then

Re: multiprocessing and dictionaries

2009-07-13 Thread Piet van Oostrum
ata1,data2, mydict): print name, data1, data2 for nam in name: for num in range(0,3): mydict.setdefault(nam, []) mydict[nam] += [data1[num]] mydict[nam] += [data2[num]] print 'Multiprocess test dic:',mydict If you have more than one process operating on the dictionary simultaneously you have to beware of race conditions!! -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Piet van Oostrum
related to ftp. Do you want to catch an exception like a misspelling in one of the variables? from ftplib import FTP, all_errors try: ftp = FTP(ftp_host) ftp.login(ftp_user, ftp_pass) except all_errors, err: print err -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Piet van Oostrum
is kind of strange, since it >DA> seems to me like an obvious question to ask. Of course you can take any BST algorithm and replace pointers by indices in the array and allocate new elements in the array. But then you need array elements to contain the indices for the children explicitely. -- Pie

Re: explode()

2009-07-14 Thread Piet van Oostrum
>>> That is a server configuration and has nothing to do with Python directly. >FA> Agreed, it doesn't. But if my hosting provider won't change it, I'm >FA> stuck with it. That's a good reason to dislike your hosting provider, not a good reason to dislike

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Piet van Oostrum
configuring MTAs >CB> 4. Even if all this works, you might just want to do your logging >CB> directly in Python anyway Even then, I think the program would get structured better if the FTP code would only catch FTP-specific errors, including socket errors (which is what all_errors do

Re: The meaning of "="

2009-07-14 Thread Piet van Oostrum
>>>>> a...@pythoncraft.com (Aahz) (A) wrote: >A> In article , Piet van Oostrum >A> wrote: >>> And to get c.x = 4 working you also need a __setitem__. >A> Nope. You do need __setitem__ so that this works: >A> c['x'] = 4 Sorry, I m

Re: Efficient binary search tree stored in a flat array?

2009-07-15 Thread Piet van Oostrum
>>>>> Douglas Alan (DA) wrote: >DA> I wrote: >>> On Jul 14, 8:10 am, Piet van Oostrum wrote: >>> >>> > Of course you can take any BST algorithm and replace pointers by indices >>> > in the array and allocate new elements in t

Re: The meaning of "="

2009-07-15 Thread Piet van Oostrum
>>>>> a...@pythoncraft.com (Aahz) (A) wrote: >A> In article , Piet van Oostrum >wrote: >>>>>>>> a...@pythoncraft.com (Aahz) (A) wrote: >>> >A> In article , Piet van Oostrum >A> wrote: >>> >>>&

Re: promlems with threading and print

2009-07-15 Thread Piet van Oostrum
read): def __init__(self, t, s, lock): self.lock = lock self.threadmarker = t self.sleeptime = s threading.Thread.__init__(self) def run(self): with lock: print("Thread", self.threadmarker, "is going to sleep for

Re: promlems with threading and print

2009-07-15 Thread Piet van Oostrum
>>>>> Piet van Oostrum (PvO) wrote: >PvO> def run(self): >PvO> with lock: All the 'with lock:' lines should have been 'with self.lock:' but as lock is also a global variable, it did work. Of course you can decide to use only t

Re: How to Force exiting from program/script

2009-07-16 Thread Piet van Oostrum
mand lasts too long" signal.signal(signalcode, handler) def interrupt(): os.kill(os.getpid(), signalcode) def execute(function, timeout): Timer(timeout, interrupt).start() try: function() except AlarmError, e: print e print 'Execution aborted'

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-16 Thread Piet van Oostrum
fore the line.encode('utf-8'), but after the decode('utf-8'). It might be better to use different variables for Unicode strings and byte code strings to prevent confusion, like: 'line' is read as bytes from a stream uline = line.decode('utf-8') uline = uline.replace('<<', u'«').replace('>>', u'»') line = uline.encode('utf-8') -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Why aren't OrderedDicts comparable with < etc?

2009-07-16 Thread Piet van Oostrum
> Mark (M) wrote: >M> You are right that it doesn't make sense to compare two dicts. >M> But OrderedDicts can be viewed logically as lists of (key,value) >M> tuples so they are much more like lists or tuples when it comes to >M> comparisons. >M> For example: > l = [("a", 1), ("z", 2),

Re: Persistent variable in subprocess using multiprocessing?

2009-07-16 Thread Piet van Oostrum
range(self.number * 10, (self.number + 1) * 10) self.doit() def doit(self): for i in range(5): sleep(3 * random()) self.data[i] += i print self.data[i] processes = [] for k in range(10): p = MyProcess(k) p.start() proce

Re: Persistent variable in subprocess using multiprocessing?

2009-07-16 Thread Piet van Oostrum
%s'%str(p2.getPid()) >m> else: >m> p2.run() >m> . >m> . >m> . >m> So I'd like to load that data into memory once and keep there as long >m> as th

Re: Persistent variable in subprocess using multiprocessing?

2009-07-16 Thread Piet van Oostrum
, so you would have a loop in the run(0 method getting work from the queue. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: This is a mess...

2009-07-16 Thread Piet van Oostrum
vect = e_vect def length(self): return len(self.e_vect) def __getitem__(self, indx): return self.e_vect[indx] I hope I did not make a mistake, I didn't check it because I don't want to make test input files. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: no return value for threading.Condition.wait(timeout)?

2009-07-16 Thread Piet van Oostrum
hing is inserted in the queue, another thread may sneak in while you are waiting and snatch the inserted item just before your thread continues after the wait. In that case you can't distinguish between a timeout and a snatcher. So it all depends on what your use case is. (Java's wait

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-16 Thread Piet van Oostrum
Unicode string. You can only decode encoded things which are byte strings. So you are mixing up byte strings and Unicode strings. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: question of style

2009-07-17 Thread Piet van Oostrum
False, everything else True (with a slight preference for 1 as True). Same as in C. Nowadays this is reflected in bool being a subtype of int with False == 0 and True == 1. Actually it is even closer: False and True are just 0 and 1 cast to bool, so to say. -- Piet van Oostrum URL: http://pietvanoos

Re: Persistent variable in subprocess using multiprocessing?

2009-07-17 Thread Piet van Oostrum
e subprocess makes changes in its copy 2. Each subprocess has a seperate data structure not equal to the others 3. Something else. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Piet van Oostrum
imeout >GR> as to not block forever, so the idea is to check if I returned because of a >GR> timeout or not. So that case is easy I think. After the wait just check if the answer has arrived. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email:

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-17 Thread Piet van Oostrum
7;t decode bytes in position 0-2: invalid >a> data >a> for this line: >a> â Your Python assumes stdin uses utf-8 encoding, probably because your locale says so. But it seems the input is not really utf-8 but some other encoding. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Piet van Oostrum
>>>>> Gabriel Rossetti (GR) wrote: >GR> Piet van Oostrum wrote: >>>>>>>> Gabriel Rossetti (GR) wrote: >>>>>>>> >>> >>> >GR> I have a 1-1 relation, I have a thread reading msgs from a network sock

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Piet van Oostrum
I should add that *if the wait times out* it still could be the case that your answer has arrived but that the notify occured a microsecond after the timeout. So knowing if the timeout occurred really doesn't tell you much. It's just a way to prevent infinite waiting. -- Piet van Oo

Re: How to receive a data file of unknown length using a python socket?

2009-07-19 Thread Piet van Oostrum
e XMLRPC. By the way if the image file is the only thing you send, the client should close the socket after sending and then the receiver will detect end of file which will be detected by your `if len(data) == 0:' -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: invoke method on many instances

2009-07-19 Thread Piet van Oostrum
gt;> a=A() >>>>> b=B() >>>>> c=C() >>>>> a.hello() >RG> 'hello: A' >>>>> b.hello() >RG> 'hello: B' >>>>> c.hello() >RG> 'hello: C' >>>>> >>>>> ma

Re: A little help with pexpect

2009-07-19 Thread Piet van Oostrum
gt;> t.connect(username=username, password=password) Open a channel for a command >>> chan = t.open_session() >>> chan.exec_command('ls -l') >>> chan.recv(99) 'total 0\ndrwxr-xr-x 2 user group 60 Apr 2 2009 Mail\ndrwx-- 2 user group

Re: A little help with pexpect

2009-07-19 Thread Piet van Oostrum
>>>>> Piet van Oostrum (PvO) wrote: [snip] >PvO> You can also consider using paramiko instead of pexpect. [snip] >>>>> chan = t.open_session() >>>>> chan.exec_command('cat') >>>>> chan.send('abcdefghijklmn\n'

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Piet van Oostrum
gt;>>>> x = [2,1,3] >>>>>> print x.sort()[0] >>> 3 >>>>>> print x >>> [2,1,3] >DB> You already have a way to do what you want: >>>>> x = [2,1,3] >>>>> print sorted(x)[0] >DB> 3 What kind

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Piet van Oostrum
>>>>> Paul Moore (PM) wrote: >PM> 2009/7/20 Chris Rebert : >>> On Mon, Jul 20, 2009 at 2:23 PM, Piet van Oostrum wrote: >>>>>>>>> x = [2,1,3] >>>>>>>>> print sorted(x)[0] >DB> 3 >>>> >>

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Piet van Oostrum
int in the cartesian plane with >HvR> an associated attribute like colour. There are numerous other examples. Anytime you need a key that is not a single object but composed of more than one: Name + birthday Street + number + City Student + Course etc. -- Piet van Oostrum URL: http://pietv

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Piet van Oostrum
>>>>> David Smith (DS) wrote: >DS> Piet van Oostrum wrote: >>>>>>>> Hendrik van Rooyen (HvR) wrote: >>> >HvR> On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: >>>>>> On Jul 20, 6:08 pm, Duncan Booth wro

Re: python function for retrieving key and encryption

2009-07-21 Thread Piet van Oostrum
ur answer. Please: 1. Type your python code with newlines and proper indentation. 2. Show the error messages that your code gives when you run it. 3. Use proper capital letters at the beginning of your sentences. 4. Don't fire so many questions in rapid succession. The recipient_public_key.p

Re: Issue combining gzip and subprocess

2009-07-21 Thread Piet van Oostrum
stdout (and the others) must be None, PIPE or a real file object or file descriptor, not a file like object. In your case the solution would be to use PIPE, and then read the output and write in to the GzipFile yourself. f = gzip.open(filename, 'w') proc = subprocess.Popen(['ls',

Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-21 Thread Piet van Oostrum
gt;d> 16:07:56 >d> 16:07:16 >d> 16:07:36 >d> 16:07:56 >d> 16:07:16 >d> 16:07:36 >d> 16:07:56 You probably meant: print time.strftime('%m-%d-%Y %H:%M:%S') -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: Balanced binary tree implementation

2009-07-21 Thread Piet van Oostrum
e. >LPM> [1] Ex: 1 2 3 4 5 6 are elements of the bbt. If I use this operation given >LPM> 4 as the parameter, the value returned would be 5. http://newcenturycomputers.net/projects/rbtree.html (warning: see end of page!) http://pypi.python.org/pypi/rbtree/ http://pyavl.sou

Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-21 Thread Piet van Oostrum
st all relevant stuff (preferably a minimal example that shows the problem). *DO NOT RETYPE THE CODE* 2. Copy and paste the output. *DO NOT RETYPE THE OUTPUT* 3. Tell what the expected or desired output is. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list

Re: doted filenames in import statements

2009-07-21 Thread Piet van Oostrum
e path? Is that 4.6.0.0? >JP> example: >JP> file = "/home/dsp/test.py" >JP> test = __import__(file) >JP> works like a charm That's not supposed to work. In older pythons it did work but that's a bug. In newer pythons it doesn't. __import__ wo

Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order

2009-07-22 Thread Piet van Oostrum
>>>>> davidj411 (d) wrote: >d> i never heard of the logging module, but this function seemed simple >d> enough. >d> i assume this link is what you refering to: >d> http://docs.python.org/library/logging.html >d> thanks for the helpful info. i think

Re: Issue combining gzip and subprocess

2009-07-22 Thread Piet van Oostrum
>>>>> Scott David Daniels (SDD) schreef: >SDD> Piet van Oostrum wrote: >>> ... >>> f = gzip.open(filename, 'w') >>> proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE) >>> while True: >>>

<    1   2   3   4   5   6   7   8   >