Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-30 Thread Thomas Bellman
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message gvlppt$hk...@news.lysator.liu.se, Thomas Bellman wrote: Speaking as a sysadmin, running applications for production, programs not using SO_REUSEADDR should be taken out and shot. Not using SO_REUSEADDR means forcing

Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-28 Thread Thomas Bellman
, no matter what you do. Not using SO_REUSEADDR means forcing a service interruption of half an hour (IIRC) if for some reason the service must be restarted, or having to reboot the entire machine. No thanks. I have been in that situation. -- Thomas Bellman, Lysator Academic Computer Club

Re: named pipe and Linux

2009-04-08 Thread Thomas Bellman
. For example, a linefeed without a backslash before it (and you would probably want a way to escape the backslash, in case you want to end a message with a backslash). - Have small header of a fixed size at the start of each message, that includes the length of the message in octets. -- Thomas

Re: Hash of None varies per-machine

2009-04-04 Thread Thomas Bellman
Steven D'Aprano st...@remove-this-cybersource.com.au wrote: You can hash numbers no matter how big they are. hash(float('inf')) 314159 Cute. And hash(float('-inf')) is -271828... -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus

Re: Need help with os.system in linux

2009-01-17 Thread Thomas Bellman
. For example, you can avoid having to deal with quoting shell metacharacters, and interpreting the return values are easier. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se differently is selling something

Re: Security implications of using open() on untrusted strings.

2008-11-24 Thread Thomas Bellman
to pass that string unquoted to /bin/sh when the user thought he was just typing a filename.) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden I don't think [that word] means what you! bellman @ lysator.liu.se think it means. -- The Princess Bride! Make Love

Re: sorting list of complex numbers

2008-11-11 Thread Thomas Bellman
at all. The operator module is your friend: key=operator.attrgetter('real', 'imag') will create the required tuples for sorting. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus is an integer. ! bellman @ lysator.liu.se

Re: subprocess.Popen(..., cwd=...) and Makefile $(PWD) don't play nice

2008-10-14 Thread Thomas Bellman
shells, and hardly inside them either. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Adde parvum parvo magnus acervus erit ! bellman @ lysator.liu.se (From The Mythical Man-Month) ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman

Re: subprocess.Popen(..., cwd=...) and Makefile $(PWD) don't play nice

2008-10-07 Thread Thomas Bellman
by the shell he started the Python program from, but Python does *not* update to reflect changes to the working directory. Use '@pwd' instead of '@echo $(PWD)'. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Beware of bugs in the above code; I have! bellman

Re: max(), sum(), next()

2008-09-04 Thread Thomas Bellman
() function as well, but you can't argue that because a sum *involving* a NULL value returns NULL. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden This isn't right. This isn't even wrong. ! bellman @ lysator.liu.se -- Wolfgang Pauli ! Make

Re: max(), sum(), next()

2008-09-04 Thread Thomas Bellman
it might actually make sense to treat the empty sequence as an error, but just ignore non-numeric elements (i.e, treat them as if they were zero). And in some cases both should be an error, and in some neither should be an error. -- Thomas Bellman, Lysator Computer Club, Linköping University

Re: Exit from os.chroot()

2008-06-05 Thread Thomas Bellman
to point to things outside the chroot, you are at least guaranteed that you won't give the chroot:ed process to much information. Unfortunately, you won't be giving it the tools it needs to do its designed job, either, since symlinks can't escape a chroot. -- Thomas Bellman, Lysator Computer Club

Re: defaultdict.fromkeys returns a surprising defaultdict

2008-06-04 Thread Thomas Bellman
'list', {'y': 0, 'x': 0}) d['z'] [] d defaultdict(type 'list', {'y': 0, 'x': 0, 'z': []}) The keys you give to the fromkeys() method will all be set to the same object (the integer zero, in the case above), though, which might not be what you want. -- Thomas Bellman, Lysator

Re: Exit from os.chroot()

2008-06-04 Thread Thomas Bellman
device files or setuid binaries. All this is of course assuming that the chroot is done for security reasons. There are other reasons one might want to run in chroot. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Life IS pain, highness. Anyone who tells

Re: Misuse of list comprehensions?

2008-05-20 Thread Thomas Bellman
not in new ] [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None] Yes, you do get a correct result in 'new', but you *also* create a 17 long list with all elements set to None, that is immediately thrown away. -- Thomas Bellman, Lysator

Re: Accumulating values in dictionary

2008-05-20 Thread Thomas Bellman
the first time a key is mentioned, and if the keys are mostly unique, that will be the majority of the times, and calling a pure Python function is fairly slow in CPython. (It probably won't matter unless you have many thousands of unique keys, though.) -- Thomas Bellman, Lysator Computer Club

Re: Misuse of list comprehensions?

2008-05-20 Thread Thomas Bellman
. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden What sane person could live in this world ! bellman @ lysator.liu.se and not be crazy? -- Ursula K LeGuin ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: Accumulating values in dictionary

2008-05-20 Thread Thomas Bellman
I gave about performance does not apply; my understanding is that calling built-in functions (like the int constructor) is fast. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Beware of bugs in the above code; I have! bellman @ lysator.liu.se only proved

Re: How to kill Python interpreter from the command line?

2008-05-10 Thread Thomas Bellman
Jean-Paul Calderone [EMAIL PROTECTED] wrote: (Ctrl+Z which sends SIGSTOP and _cannot_ be masked or otherwise ignored) Bzzt! Ctrl-Z causes a SIGTSTP to be sent, not SIGSTOP, and SIGTSTP can be both caught, ignored and masked. -- Thomas Bellman, Lysator Computer Club

Re: Python 2.5 adoption

2008-04-18 Thread Thomas Bellman
common, so if you want to reach a large customer base, make sure that your Python programs work with Python 2.3. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Don't tell me I'm burning the candle at both ! bellman @ lysator.liu.se ends -- tell me where to get more

Re: network programming: how does s.accept() work?

2008-02-25 Thread Thomas Bellman
that the four-tuple identifying the TCP connection will be unique. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden There are many causes worth dying for, but ! bellman @ lysator.liu.se none worth killing for. -- Gandhi ! Make Love -- Nicht Wahr! -- http

Re: Why does list have no 'get' method?

2008-02-07 Thread Thomas Bellman
, then no, in Scheme only #f is false, and the empty list () is considered true. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden When C++ is your hammer, everything ! bellman @ lysator.liu.se looks like a thumb.! Make Love -- Nicht Wahr! -- http

Re: polling for output from a subprocess module

2008-02-06 Thread Thomas Bellman
Ivo [EMAIL PROTECTED] wrote: Thomas Bellman wrote: However, the os.read() function will only read what is currently available. Note, though, that os.read() does not do line-based I/O, so depending on the timing you can get incomplete lines, or multiple lines in one read. be carefull

Re: polling for output from a subprocess module

2008-02-05 Thread Thomas Bellman
Christian Heimes [EMAIL PROTECTED] writes: Thomas Bellman wrote: The readlines() method will read until it reaches end of file (or an error occurs), not just what is available at the moment. You can see that for your self by running: Bad idea ;) Why is it a bad idea to see how

Re: polling for output from a subprocess module

2008-02-04 Thread Thomas Bellman
is currently available. Note, though, that os.read() does not do line-based I/O, so depending on the timing you can get incomplete lines, or multiple lines in one read. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Adde parvum parvo magnus acervus erit

Re: read and readline hanging

2008-01-27 Thread Thomas Bellman
` module suggested by the other poster. I think you would be better off looking into the correctly spelled 'threading' module rather than the misspelled 'trheading' module. :-) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus is an integer

Re: read and readline hanging

2008-01-25 Thread Thomas Bellman
that there won't be any more lines in response to its command. If you can't get the program you are calling to follow some protocol like this, then you can only make guesses. Sometimes you can make fairly good guesses, and sometimes it will be more or less impossible... -- Thomas Bellman, Lysator

Re: spawning a process with subprocess

2007-11-27 Thread Thomas Bellman
. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus is an integer. ! bellman @ lysator.liu.se ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Thomas Bellman
or terminals, you would have major problems, since suddenly calling the eof() method would block the process. Probably not what you were expecting. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Thomas Bellman
to recognize a character rendered in the Taiwanese or mainland Chinese way. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Adde parvum parvo magnus acervus erit ! bellman @ lysator.liu.se (From The Mythical Man-Month) ! Make Love -- Nicht Wahr! -- http

Re: An expression that rebinds a variable?

2007-05-18 Thread Thomas Bellman
comprehensions: c Traceback (most recent call last): File stdin, line 1, in module NameError: name 'c' is not defined eval('[ord(c) for c in parrot]') [112, 97, 114, 114, 111, 116] c 't' This is supposed to be changed in Python 3.0. -- Thomas Bellman, Lysator

Re: Get Shift + TAB in ncurses.

2007-04-12 Thread Thomas Bellman
to your terminal, not to anyone else's. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Don't tell me I'm burning the candle at both ! bellman @ lysator.liu.se ends -- tell me where to get more wax!! ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman

Re: Prevent Modification of Script?

2007-04-05 Thread Thomas Bellman
, but after many years working with computer security I have managed to learn not to do *that* particular error again; I hope...) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se differently

Re: How to suppress DeprecationWarning: Old style callback, use cb_func(ok, store) instead

2007-02-06 Thread Thomas Bellman
as arguments, and thus passed the four words foo, bar, gazonk and del as arguments for the above #! line, but I don't remember what Unix that was. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Adde parvum parvo magnus acervus erit ! bellman @ lysator.liu.se

Re: Need help with an array problem.

2006-10-03 Thread Thomas Bellman
* of the variables, not the actual contents of them. It is the *dereferencing* of those casted pointers that interpret the bit patterns in the variables as if they were another type, not the casting itself. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden I don't think [that word

Re: simplexmlrpcserver and allow_none

2006-06-08 Thread Thomas Bellman
) return self.__dumps[0](*args, **kwargs) xmlrpclib.dumps = _xmldumps(xmlrpclib.dumps) import SimpleXMLRPCServer -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden This isn't right. This isn't even wrong. ! bellman @ lysator.liu.se

Re: Problem calling math.cos()

2006-04-23 Thread Thomas Bellman
Alex Martelli [EMAIL PROTECTED] wrote: C has no stand on complex numbers. If by that you mean that C does not have complex numbers, then you are wrong. C99 defines the three types float _Complex, double _Complex, and long double _Complex, and also the header complex.h. -- Thomas Bellman

Re: how relevant is C today?

2006-04-10 Thread Thomas Bellman
Lawrence D'Oliveiro [EMAIL PROTECTED] writes: const is in C89/C90. Although with slightly different semantics from in C++... For instance: static const int n = 5; double a[n]; is valid C++, but not valid C. -- Thomas Bellman, Lysator Computer Club, Linköping University

Re: How do I use the subprocess module with mswindows?

2006-03-19 Thread Thomas Bellman
download from http://www.lysator.liu.se/~bellman/download/asyncproc.py I suspect that it only works on Unix, though. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Beware of bugs in the above code; I have! bellman @ lysator.liu.se only proved it correct

Re: writing large files quickly

2006-01-29 Thread Thomas Bellman
size of 4 Kbyte.) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden There are many causes worth dying for, but ! bellman @ lysator.liu.se none worth killing for. -- Gandhi ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: Testing for the presence of input from stdin.

2006-01-24 Thread Thomas Bellman
| myprogram.py' will stop at some random point, when the OS happens to decide that myprogram.py should be scheduled twice without dd getting the chance to fill the pipe buffer inbetween. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden We don't understand the software

Re: append to non-existing list

2005-11-09 Thread Thomas Bellman
much more fragile; think for example about what happens if your SQL statement (I assume that's what sqlsth is) yields zero rows, and you then try to look at pkcolumns after that loop. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden God is real, but Jesus is an integer

Re: process and spinning slash

2005-10-30 Thread Thomas Bellman
use the poll() methods on the Popen object to check if the process has terminated. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden You are in a twisty little passage of ! bellman @ lysator.liu.se standards, all conflicting.! Make Love -- Nicht

Re: Python Doc Error: os.makedirs

2005-10-19 Thread Thomas Bellman
: os.makedirs(/tmp/trh/spam/norwegian/blue/parrot/cheese) except os.error, e: if e.errno != errno.EEXIST: raise -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden I refuse to have a battle of wits with an ! bellman @ lysator.liu.se unarmed person

Re: Python Doc Error: os.makedirs

2005-10-19 Thread Thomas Bellman
/blue/parrot/cheese) except os.error, e: if ( e.errno != errno.EEXIST or not os.path.isdir(/tmp/trh/spam/norwegian/blue/parrot/cheese)): raise -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Beware of bugs in the above code; I have

Re: subprocess and non-blocking IO (again)

2005-10-11 Thread Thomas Bellman
test it. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Beware of bugs in the above code; I have! bellman @ lysator.liu.se only proved it correct, not tried it. ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: determine if os.system() is done

2005-09-07 Thread Thomas Bellman
? You just *might* find the answer to your question if you look at what you can do with Popen objects. Actually, just learning about the exact semantics of the communicate() method might be enought to solve your problem. -- Thomas Bellman, Lysator Computer Club, Linköping University

Re: dual processor

2005-09-06 Thread Thomas Bellman
' is waiting for I/O even on a single-CPU system. And I'm fairly certain that 'sort' won't start spending CPU time until it has collected all its input, so you won't gain much there either. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden We don't understand the software

Re: Trouble saving unicode text to file

2005-05-11 Thread Thomas Bellman
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= [EMAIL PROTECTED] wrote: Thomas Bellman wrote: Fixed-with characters *do* have advantages, even in the external representation. With fixed-with characters you don't have to parse the entire file or stream in order to read the Nth character; instead

Re: Trouble saving unicode text to file

2005-05-10 Thread Thomas Bellman
(the way UTF-8 is), nor uses fixed-with characters (like UTF-32 does)? -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden You are in a twisty little passage of ! bellman @ lysator.liu.se standards, all conflicting.! Make Love -- Nicht Wahr! -- http

Re: Trouble saving unicode text to file

2005-05-10 Thread Thomas Bellman
efficient. The codec for UTF-32 is extremely simple. There are no illegal sequences to care about, like there are in UTF-8 and UTF-16, just illegal single 32-bit values (those that are larger than 0x10). And not the least, UTF-32 is *beautiful* compared to UTF-16. -- Thomas Bellman

Re: How to use subprocess

2005-03-23 Thread Thomas Bellman
use it as inspiration for doing it yourself. It requires the subprocess module, but I have successfully used it under Python 2.3.2 with subprocess installed locally. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Adde parvum parvo magnus acervus erit ! bellman

Re: Python becoming less Lisp-like

2005-03-17 Thread Thomas Bellman
be ignored away. There is a local cost with it, for learning Python, but I'm not sure there really is a global cost, when you look at the entire situation. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Too much of a good thing is WONDERFUL. ! bellman

Re: Python becoming less Lisp-like

2005-03-15 Thread Thomas Bellman
the English language for allowing them to write such books, or do you blame the writers for using English in a bad way? -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden We don't understand the software, and! bellman @ lysator.liu.se sometimes we don't