Re: Py2.7/FreeBSD: maximum number of open files

2011-11-30 Thread Chris Torek
es of fd_set objects in select() calls.) You will want to redesign the code that finds or creates a free "FILE" object, and probably some of the things that work with line-buffered FILEs (specifically calls to _fwalk() when reading from a line-buffered stream). -- In-Real-Life: Chris T

Re: Best way to check that you are at the beginning (the end) of an iterable?

2011-09-08 Thread Chris Torek
istinguish between a valid -1 value and having encountered an EOF. The companion ferror() function tells you whether an earlier EOF value was due to an error.) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA

Re: Why do class methods always need 'self' as the first parameter?

2011-09-05 Thread Chris Torek
>Chris Torek writes: >[snip] >> when you have [an] instance and call [an] instance or class method: [note: I have changed the names very slightly here, and removed additional arguments, on purpose] >> black_knight = K() >> black_knight.spam() >> black

Re: Algorithms Library - Asking for Pointers

2011-09-02 Thread Chris Torek
lot of CPython interpreter overhead. Mileage in Jython, etc., may vary... -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out)

Re: Why doesn't threading.join() return a value?

2011-09-02 Thread Chris Torek
sion. :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.p

Re: Why doesn't threading.join() return a value?

2011-09-02 Thread Chris Torek
rget(*self.args, **self.kwargs) def join(self, timeout = None): "join, then return value set by target function" super(ValThread, self).join(timeout) return self.value -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Torek
r: print 'name "magic" is not available here, as desired' try: print rlevel except NameError: print 'name "rlevel" is not available here, as desired' class X(object): def __mrap(self, *args, **kwargs): def xset(arg): se

Re: Why no warnings when re-assigning builtin names?

2011-08-31 Thread Chris Torek
W0622: 2:func: Redefining built-in 'list' ... Your code has been rated at 6.67/10 If your shadowing is done on purpose, you can put in a pylint comment directive to suppress the warning. Pylint is the American Express Card of Python coding: "don't leave $HOME without

Re: try... except with unknown error types

2011-08-31 Thread Chris Torek
ure would be nice to have a static analysis tool that could answer questions about potential exceptions. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Torek
ot;@classmethod" or "@staticmethod", but the minor redundancy in the "def" statement seems, well, minor. Also, as a bonus, it lets you obfuscate the code by using a name other than "self" or "cls". :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Early binding as an option

2011-08-04 Thread Chris Torek
ever here, by making those attributes "read-only" to whatever extent the snapshot operation is defined as fixing the binding (e.g., does it recurse into sub-attributes? does it bind only the name-and-type, or does it bind name-and-type-and-value, or name-and-type-and-function-address-if-fu

Re: How should I document exceptions thrown by a method?

2011-07-27 Thread Chris Torek
with Ben Finney though, and so does "import this": ... Simple is better than complex. ... Letting exceptions flow upward unchanged is (usually) simpler, hence "better". -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions a

Re: Use self.vars in class.method(parameters, self.vars)

2011-07-22 Thread Chris Torek
ist.append(Florg('fifth', 5)) for florg in flist: florg.zormonkle() if __name__ == '__main__': example() -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22&

Re: Python ++ Operator?

2011-07-19 Thread Chris Torek
mply writes: lst.append(val) (which also makes sure that there is *room* in the array-based list, something that requires a separate step in C). -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (

Re: Python ++ Operator?

2011-07-15 Thread Chris Torek
-) (Of course, +i followed by +i *also* increments i...) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: difflib-like library supporting moved blocks detection?

2011-07-13 Thread Chris Torek
perations, though, the problem becomes NP-complete. See http://pages.cs.brandeis.edu/~shapird/publications/JDAmoves.pdf for instance. (They give an algorithm that produces "usually acceptable" results in polynomial time.) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I

Re: Does hashlib support a file mode?

2011-07-06 Thread Chris Torek
#x27;big2')) you will get two md5sum values for your two files, but the md5sum value for big2 will not be the equivalent of "md5sum big2" but rather that of "cat big1 big2 | md5sum". The reason is that you are re-using the md5-sum-so-far on the second call (for file &

Re: subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread Chris Torek
ithout using import" but all you have to do is arrange for python to import this module before running any of your own code, e.g., with $PYTHONHOME and a modified site file. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Sa

Re: Safely modify a file in place -- am I doing it right?

2011-06-29 Thread Chris Torek
your own mkstemp() (this can be a bit of a challenge!). Finally, as I implied above in talking about the os.link()-then- os.rename() sequence, if the original file has multiple links to it, note that this "breaks the links". If this is not what you want, the problem has no fully general solut

Re: Significant figures calculation

2011-06-25 Thread Chris Torek
al for x in ( '1', '1.00', '1.23400e-8', '0.003' ): print 'sigdig(%s): %d' % (x, sigdig(D(x))) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City,

Re: Interpreting Left to right?

2011-06-25 Thread Chris Torek
ent (not expression) has the form: and the evaluation order is, in effect and using pseudo-Python: 1. -- the (single) RHS tmp = eval() 2. for in : # left-to-right = tmp When there is only one item in the (i.e., just one "x =" part in the whole stateme

Re: those darn exceptions

2011-06-24 Thread Chris Torek
>Chris Torek wrote: >> I can then check the now-valid >> pid via os.kill(). However, it turns out that one form of "trash" >> is a pid that does not fit within sys.maxint. This was a surprise >> that turned up only in testing, and even then, only because I &g

Re: writable iterators?

2011-06-23 Thread Chris Torek
the above into an iterator, and handling container classes that have an __iter__ callable that produces an iterator that defines an appropriate index-and-value-getter, is left as an exercise. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of W

Re: those darn exceptions

2011-06-23 Thread Chris Torek
In article <96gb36fc6...@mid.individual.net>, Gregory Ewing wrote: >Chris Torek wrote: > >> Oops! It turns out that os.kill() can raise OverflowError (at >> least in this version of Python, not sure what Python 3.x does). > >Seems to me that if this happens it ind

Re: writable iterators?

2011-06-23 Thread Chris Torek
== '__main__': d = {'one': 1, 'two': 2, 'three': 3} l = [9, 8, 7] print 'modify dict %r' % d for i in IndirectIter(d): i.set(-i.get()) print 'result: %r' % d print print 'modify list %r' % l

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Torek
while r == 0: yield p if q == 1: return num = q q, r = divmod(num, p) if __name__ == '__main__': for arg in (sys.argv[1:] if len(sys.argv) > 1 else ['600851475143']): try: arg = int(arg) ex

Re: those darn exceptions

2011-06-21 Thread Chris Torek
>On Tue, 21 Jun 2011 01:43:39 +0000, Chris Torek wrote: >> But how can I know a priori >> that os.kill() could raise OverflowError in the first place? In article <4e006912$0$29982$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano wrote: >You can't. Even i

Re: How to get return values of a forked process

2011-06-21 Thread Chris Torek
came from, but note that on Unix, the "os" module also provides os.WIFSIGNALED, os.WTERMSIG, os.WIFEXITED, and os.WEXITSTATUS for dissecting the "status" integer returned from the various os.wait* calls. Again, if you use the subprocess module, you are insulated from this sort of det

Re: those darn exceptions

2011-06-20 Thread Chris Torek
between child and parent here. However, it would suffice to set subprocess.__exceptions__ to some reasonable tuple, and leave the preexec_fn exceptions to the text documentation. [Of course, strictly speaking, the fact that the read cuts off at 1 MB means that even the pickle.loads() call might fail! B

those darn exceptions

2011-06-20 Thread Chris Torek
n classes that are only defined in user-provided code -- but to raise them, those functions have to include whatever code defines them, so I think this all just works.) The key thing needed to make this work, though, is the base cases for system-provided code written in C, which pylint by definitio

Re: Boolean result of divmod

2011-06-20 Thread Chris Torek
efore, you can subscript the return value to get either element: >>> divmod(99.6,30.1)[0] 3.0 Thus, you can call bool() on the subscripted value to convert this to True-if-not-zero False-if-zero: >>> bool(divmod(99.6,30.1)[0]) True -- In-Real-Life: Chris Torek,

Re: import from environment path

2011-06-18 Thread Chris Torek
ight also want to take a look at PEP 302: http://www.python.org/dev/peps/pep-0302/ If you use "subprocess" to run program B, it cannot affect program A in any way that program A does not allow. This gives you a lot more control, with the price you pay being that you need to open some

Re: Improper creating of logger instances or a Memory Leak?

2011-06-18 Thread Chris Torek
dler(filehandler) del logging.Logger.manager.loggerDict[self.logger.name] del self.logger # optional I am curious as to why you create a new logger for each thread. The logging module has thread synchronization in it, so that you can share one log (or several logs) amongst all threads

Re: Best way to insert sorted in a list

2011-06-17 Thread Chris Torek
ng trick if that is necessary: a[:] = merge_sorted(a, sorted(b), must_copy = False) If list b is already sorted, leave out the sorted() step. If list b is not sorted and is particularly long, use b.sort() to sort in place, rather than making a sorted copy. -- In-Real-Life: Chris Torek, Wind

Re: Best way to insert sorted in a list

2011-06-17 Thread Chris Torek
epending on your data and other needs, though, it might be best to use a red-black tree, an AVL tree, or a skip list. You might also investigate radix sort, radix trees, and ternary search trees (again depending on your data). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, U

Re: os.path and Path

2011-06-16 Thread Chris Torek
w.bitsavers.org/pdf/univac/1100/UE-637_1108execUG_1970.pdf (Those of you who have never had to deal with these machines, as I did in the early 1980s, should consider yourselves lucky. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Infinite recursion in __reduce__ when calling original base class reduce, why?

2011-06-13 Thread Chris Torek
; x.__reduce__() (, (, , None), {'name': 'janet', 'substitute': False}) which is of course the same as: >>> object.__reduce__(x) (, (, , None), {'name': 'janet', 'substitute': False}) which means that CPython&#x

Re: What is the most efficient way to compare similar contents in two lists?

2011-06-13 Thread Chris Torek
In article Chris Angelico wrote: >If order and duplicates matter, then you want a completely different >diff. I wrote one a while back, but not in Python. ... If order and duplicates matter, one might want to look into difflib. :-) -- In-Real-Life: Chris Torek, Wind River Systems Sal

Re: parallel computations: subprocess.Popen(...).communicate()[0] does not work with multiprocessing.Pool

2011-06-12 Thread Chris Torek
whatever the equivalent is for Windows) "eating" the wrong subprocess completion notifications, but that one is harder to solve in general :-) so if close_fds fixes things, it was just the pipes. If close_fds does not fix things, you will probably need to defer the pool.close() step until a

Re: how to avoid leading white spaces

2011-06-08 Thread Chris Torek
>On 03/06/2011 03:58, Chris Torek wrote: >>> - >> This is a bit surprising, since both "s1 in s2" and re.search() >> could use a Boyer-Moore-based algorithm for a sufficiently-long >> fixed string, and the time

Re: Validating string for FDQN

2011-06-06 Thread Chris Torek
dot? I type them in this way sometimes, when poking at network issues. :-) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-06 Thread Chris Torek
rom what is written -- is useful. As an interesting aside, even without the re.VERBOSE flag, one can build complex, yet reasonably-understandable, REs in Python, by breaking them into individual parts and giving them appropriate names. (This is also possible in perl, although the perl syntax ma

Re: float("nan") in set or as key

2011-06-05 Thread Chris Torek
>> On Mon, Jun 6, 2011 at 8:54 AM, Chris Torek wrote: >>> A signalling NaN traps at (more or less -- details vary depending on >>> FPU architecture) load time. >On Mon, 06 Jun 2011 09:13:25 +1000, Chris Angelico wrote: >> Load. By this you mean the operation o

Re: float("nan") in set or as key

2011-06-05 Thread Chris Torek
ht or close-to-right per the (draft? final? I have not kept up with decimal FP standards) standard. Internal Python floating point, not quite so much. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-03 Thread Chris Torek
. In article <94svm4fe7...@mid.individual.net> Neil Cerutti wrote: [lots of snippage] >That is the opposite of my experience, but YMMV. I suspect it depends on how familiar the user is with regular expressions, their abilities, and their limitations. People relatively new to REs

Re: float("nan") in set or as key

2011-06-03 Thread Chris Torek
ere's a huge benefit to everybody following the rule. This analogy perhaps works better than expected. Whenever I swap between Oz or NZ and the US-of-A, I have a brief mental clash that, if I am not careful, could result in various bad things. :-) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiprocessing.connection magic

2011-06-03 Thread Chris Torek
llowing: Warning: The Connection.recv() method automatically unpickles the data it receives, which can be a security risk unless you can trust the process which sent the message. Therefore, unless the connection object was produced using Pipe() you should only use the recv() and send() methods after performing some sort of authentication. See Authentication keys. (i.e., do that :-) -- see the associated section on authentication) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-02 Thread Chris Torek
>In article , > Chris Torek wrote: >> Python might be penalized by its use of Unicode here, since a >> Boyer-Moore table for a full 16-bit Unicode string would need >> 65536 entries (one per possible ord() value). In article Roy Smith wrote: >I'm not sure what

Re: how to avoid leading white spaces

2011-06-02 Thread Chris Torek
e values, a 256-element table suffices; re.compile(), at least, could scan the pattern and choose an appropriate underlying search algorithm. There is an interesting article here as well: http://effbot.org/zone/stringlib.htm -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Unshelving the data?

2011-06-01 Thread Chris Torek
key) ... Seems pretty straightforward. :-) Are you having some sort of problem with "del"? -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html --

Re: float("nan") in set or as key

2011-06-01 Thread Chris Torek
th 2**100 in each. (You will run out of memory first unless you have a machine with more than 64 bits of address space. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Updated blog post on how to use super()

2011-06-01 Thread Chris Torek
"NextClass.method", *your* class is definitely *not* ready for someone else to use in that MI situation. (I say "may" be ready for MI, because being "fully MI ready" requires several other code discipline steps. The point of super() -- at least when implemented nicely, as

Re: How to catch a line with Popen

2011-05-30 Thread Chris Torek
>Chris Torek wrote: >> In at least some versions of Python 2 [the "file"-type object iterators behave badly with pipes] (This may still be true in Python 3, I just have no experience with Py3k. "At least some version of Python 2" means "the ones I have acc

Re: float("nan") in set or as key

2011-05-30 Thread Chris Torek
imal, and complex, so that you do not need to worry about whether to use math.isnan() vs cmath.isnan()? (I almost never work with complex numbers so am not sure if the "or" behavior -- cmath.isinf and cmath.isnan return true if either real or complex part are Infinity or NaN respectivel

Re: float("nan") in set or as key

2011-05-29 Thread Chris Torek
quot;) (Of course, if something like this were adopted properly, it would all be in the base "float" type anyway.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.t

Re: float("nan") in set or as key

2011-05-29 Thread Chris Torek
o on, do not quite work right in all cases), with some performance penalty on non-conformant hardware. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: portable way of sending notifying a process

2011-05-29 Thread Chris Torek
e it as an actual client and server, i.e., the client connects to the server and writes the request directly (but then you have to decide about security considerations, which the OS's local file system may provide more directly). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake Cit

Re: How to catch a line with Popen

2011-05-29 Thread Chris Torek
pen(["ping", "-c5", "www.google.com"], stdout = subprocess.PIPE) for lineno, line in enumerate(line_at_a_time(p.stdout)): if 1 <= lineno <= 5: print line.split()[6] else: print line.rstrip('\n') p.wait() # disca

Re: float("nan") in set or as key

2011-05-29 Thread Chris Torek
special-case purposes at least) too. Of course a simple "classify this float as one of normal, subnormal, zero, infinity, or NaN" operator would suffice here (along with the usual "extract sign" and "differentiate between quiet and signalling NaN" operations). --

Re: Error: child process close a socket inherited from parent

2011-05-29 Thread Chris Torek
ion is to call accept() on the listening socket it closed just before it called self._talk_to_client(). If that socket is closed, you get an EBADF error raised. If not, the child and parent compete for the next incoming connection. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Code Review

2011-05-25 Thread Chris Torek
args.directory: clean_dir(dirname, args.days) def clean_dir(dirname, n_days): """ Clean one directory of files / subdirectories older than the given number of days. """ time_to_live = n_days * 86400 # 86400 = seconds-per-day current_time =

Re: Condition.wait(timeout) oddities

2011-05-23 Thread Chris Torek
ck. That *would* be a valid way to implement a timeout -- to return with the condition variable lock itself no longer held -- but that would require changing lots of other code structure. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a set into list

2011-05-16 Thread Chris Torek
>Chris Torek wrote: >> >>> x = [3, 1, 4, 1, 5, 9, 2, 6] >> >>> list(set(x)) >> This might not be the best example since the result is sorted >> "by accident", while other list(set(...)) results are not. In article , Duncan Booth

Re: Converting a set into list

2011-05-14 Thread Chris Torek
e', 'five'] >>> x ['three', 'one', 'four', 'one', 'five'] >>> list(set(x)) ['four', 'five', 'three', 'one'] >>> sorted(list(set(x))) ['five

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
turns the canonical bool >values: > >not returns False >not returns True > >Take note of the distinction between lower-case true/false, which are >adjectives, and True/False, which are objects of class bool. (At least as of current versions of Python -- in much older versions

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
here the result is defined as equivalent. (The biggest problem with answering that tends to be deciding what types x might take.) [% Chocolate with raspberry, or mint, or similar.] -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
called (if ever), and so on. As >with the Python-named-Monty, we have "rigidly defined areas of >doubt and uncertainty". These exist for good reasons: to allow >different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. -- In-R

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
is not promised, for instance, whether the "is" operator is always True for small integers that are equal (although it is in CPython), nor when __del__ is called (if ever), and so on. As with the Python-named-Monty, we have "rigidly defined areas of doubt and uncertainty". These

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
; be True rather than False. [% This is not at all obvious -- I have written an immutable class, and it is pretty easy to accidentally mutate an instance inside the class implementation. There is nothing to prevent this in CPython, at least. If there were a minor bug in the decimal.Decimal code suc

Re: Popen Question

2010-11-05 Thread Chris Torek
t; import subprocess >>> p = subprocess.Popen('/tmp/echo $MYVAR', stdout=subprocess.PIPE) >>> print p.communicate()[0] this is a self-printing file anything after the first line has NR > 1, so gets printed >>> p.returncode 0 >&g

Re: Interaction btw unittest.assertRaises and __getattr__. Bug?

2010-10-27 Thread Chris Torek
aluation just long enough: self.assertRaises(AttributeError, lambda: c.foo) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: merge list of tuples with list

2010-10-20 Thread Chris Torek
best of 3: 2.29 usec per loop (It is easy enough to move the assignments to a and b into the -s argument, but it makes relatively little difference since the list comprehension and two-zip methods both have the same setup overhead. The "import", however, is pretty slow, so it is not g

Re: ANN: stats 0.1a calculator statistics for Python

2010-10-19 Thread Chris Torek
instance, but then you run into the fact that math.isnan() is only in 2.6 and later :-) Workaround, assuming an earlier "from math import *": try: isnan(0.0) except NameError: def isnan(x): x != x Of course you are still stuck with float('nan') faili

Re: Simple logging example doesn't work!

2010-10-19 Thread Chris Torek
maxsize, backup_count) fh.setFormatter(logging.Formatter(g.log_format)) except IOError, e: logger.error('log to file: %s', e) errs = True fh = g.file_logger i

Re: Catching a SIGSEGV signal on an import

2010-10-19 Thread Chris Torek
an repeat the "import" else: print 'I am confused, maybe I got the wrong pid' --- The same kind of thing can be done on other OSes, but all the details will differ. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: How to implement retrying a lock tidily in Python?

2010-10-17 Thread Chris Torek
log and sleep here raise mailbox.ExternalClashError # or whatever and now instead of dest.lock() you just do a dest.retried_lock(). Plumbing (including fitting this in as a context manager so that you can just do "with dest" or some such) is left as an exercise, :-) --

Re: Spreadsheet-style dependency tracking

2010-10-16 Thread Chris Torek
s their dependencies. # By indexing by cell, we can find cells from dependencies in visit(). for row in sheet: for cell in row: if cell: r.S[cell] = cell cell.visited = False # Now simply (initial-)visit all the cells. for cell i

Re: what happens to Popen()'s parent-side file descriptors?

2010-10-15 Thread Chris Torek
the corresponding arguments were PIPE). In fact, thinking about it now, I *would* argue that. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Chris Torek
iple-quote, this trivial encoding technique will fail. (And of course, as others have noted, it fails on some systems that distinguish betwen text and binary file formats in the first place.) This is why using some "text-friendly" encoding scheme, such as base64, is a good idea. -- In-Real

Re: what happens to Popen()'s parent-side file descriptors?

2010-10-14 Thread Chris Torek
read = stdin else: # Assuming file-like object p2cread = stdin.fileno() (this is repeated for stdout and stderr) and the resulting integer file descriptors (or None if not applicable) are passed to os.fdopen() on the parent side. (On the child side, the code does the usual shell-like dance to move the appropriate descriptors to 0 through 2.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: what happens to Popen()'s parent-side file descriptors?

2010-10-13 Thread Chris Torek
to have _cleanup() read: if inst.poll(_deadstate=sys.maxint) is not None: (Note, this is python 2.5, which is what I have installed on my Mac laptop, where I am writing this at the moment). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: My first Python program

2010-10-13 Thread Chris Torek
finally: > fileobject.close() > >So you can sure `fileobject.close()` is called in *any* case. Unfortunately "with" is newish and this code currently has to support python 2.3 (if not even older versions). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City,

Re: My first Python program

2010-10-13 Thread Chris Torek
field: >>> x = SoLongAndThanksForAllTheFish('RIP DNA') >>> x.message 'RIP DNA' -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Class-level variables - a scoping issue

2010-10-10 Thread Chris Torek
think this is more a bug than a feature, you can always insert assert statements in key locations, e.g.: assert 'foo' not in inst.__class__.__dict__, \ 'overwriting class var "foo"' (you can even make that a function using introspection, although it could

Re: list parameter of a recursive function

2010-10-06 Thread Chris Torek
make copy of list and append something f(new_arg, some_list + [elem]) elif other_condition: # continue modifying same list f(new_arg, some_list) ... (Note: you can use also the fact that list1 + list2 produces a new list to make a copy by writ

Re: Inheritance and name clashes

2010-10-03 Thread Chris Torek
xy connection) to us, # which reaches our dispatcher above. By registering this in # our __init__, clients can do "if server:" to see if their # connection is up. It's a frill, I admit def __nonzero__(self): return True def register_admin_func

Re: partial sums problem

2010-09-29 Thread Chris Torek
uot;"" iterable = iter(vec) acc = iterable.next() yield acc for x in iterable: acc = op(acc, x) yield acc def cumsum(vec): """Return a list of the cumulative sums of a vector.""" import operator return list(iaccumulate(vec