Clearing globals in CPython

2014-10-01 Thread Steven D'Aprano
portError: __import__ not found Oops. So, with no built-ins available, import no longer works. That makes things rather tricky. Obviously the easiest way to recover is to exit the current session and restart it, but as a challenge, can we recover from this state? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: how to parse standard algebraic notation

2014-10-01 Thread Steven D'Aprano
', '-1*x') if term.startswith('x'): term = term.replace('x', '1*x') if term.endswith('x'): term = term.replace('x', 'x^1') to each term, which will give us something like: ['4*x^3', '1*x^2', &#

Re: Obscuring Python source from end users

2014-10-02 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Dan Stromberg : > >> On Mon, Sep 29, 2014 at 4:47 AM, Steven D'Aprano >>> Yes. Distribute the pyc files only. >> >> Yes, this is the way it's usually done. > > Has the .pyc file format stabilized? A decade ago, my employ

Re: Function passed as an argument returns none

2014-10-02 Thread Steven D'Aprano
ll say that assignment is a third kind of return, because one can assign output to a global variable. (Since print does not actually exit the current sub-routine, it definitively is not a kind of return.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Clearing globals in CPython

2014-10-02 Thread Steven D'Aprano
Peter Otten wrote: > Steven D'Aprano wrote: >> Obviously the easiest way to recover is to exit the current session and >> restart it, but as a challenge, can we recover from this state? > > $ python3 > Python 3.4.0 (default, Apr 11 2014, 13:05:11) > [

Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread Steven D'Aprano
rning name is misleading, lambda is not deprecated. But stylistically, many people prefer to use a generator expression in place of map or filter: # instead of this map(lambda x: 2*x+1, values) # use this (2*x+1 for x in values) # instead of this filter(lambda x: x > 23, values) # use this (x for x in values if x > 23) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Function passed as an argument returns none

2014-10-02 Thread Steven D'Aprano
Rustom Mody wrote: > On Thursday, October 2, 2014 1:30:03 PM UTC+5:30, Steven D'Aprano wrote: >> Chris Angelico wrote: > Restoring the attribution line you removed: On Thu, Oct 2, 2014 at 12:29 PM, Rustom Mody wrote: >> >> So by now you know there are 2 kinds of r

Re: How to show a dictionary sorted on a value within its data?

2014-10-03 Thread Steven D'Aprano
On Fri, 03 Oct 2014 12:44:32 +1000, Chris Angelico wrote: > On Fri, Oct 3, 2014 at 9:16 AM, Steven D'Aprano > wrote: >>> Anyway, pylint doesn't complain about a bare use of lambda, but it >>> does complain about a map applied to a lambda or a filter applied

Re: "High water" Memory fragmentation still a thing?

2014-10-03 Thread Steven D'Aprano
cess periodically is likely to be orders of magnitude more expensive than that of moving a few blocks of memory around from time to time. Especially on Windows, where starting processes is expensive, but even on Linux you have to shut the running application down, then start it up again and rebuild all

Re: Python Basics

2014-10-03 Thread Steven D'Aprano
y how to solve a problem without giving them the answer. While I don't condone mindless parroting of work that others have done, remember that for tens of thousands of years, being shown how to do something, then imitating that, has been the most effective way for people to learn. Dropping hint

Re: "High water" Memory fragmentation still a thing?

2014-10-03 Thread Steven D'Aprano
Chris Angelico wrote: > On Sat, Oct 4, 2014 at 11:02 AM, Steven D'Aprano > wrote: >> Chris Angelico wrote: >> >>> In theory, a high >>> level language like Python would be allowed to move objects around to >>> compact memory, but CPython doesn&#x

Re: A little more: decimal_portion

2014-10-04 Thread Steven D'Aprano
returns 1. Given arguments 6 and 2, you want 0.0 == 0/2, and 6%2 returns 0. Given arguments 8 and 3, you want 0.... == 2/3, and 8%3 returns 2. P.S. the usual name for this function is "fraction part", sometimes "fp". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How donwnload youtube videos?

2014-10-05 Thread Steven D'Aprano
rstand the process for getting the URL of the actual video file. - You don't have Python installed. - Your script is buggy. - Or you simply forgot to press Enter and the script is just sitting there, waiting. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: "High water" Memory fragmentation still a thing?

2014-10-06 Thread Steven D'Aprano
On Sun, 05 Oct 2014 20:23:42 +0100, mm0fmf wrote: > On 04/10/2014 02:02, Steven D'Aprano wrote: >> Way back in the mid 1980s, Apple Macintoshes used a memory manager >> which could move memory around. > > But the memory manager didn't return a pointer to memory the

Re: Clearing globals in CPython

2014-10-06 Thread Steven D'Aprano
On Mon, 06 Oct 2014 09:05:17 +, jakubo wrote: > After invoking autocompletion (.__ and hitting tab), session has been > automagically healed. That's ... um ... I have no words. Can you confirm that autocompletion modifies globals()? I don't have 3.4 installed he

Re: ruby instance variable in python

2014-10-06 Thread Steven D'Aprano
es the "Offside Rule" (significant indentation). class MyClass(object): # subclass of object def __init__(self, arg): # Initialise the instance. self.ins_var = arg def method(self, arg): return self.ins_var == arg: instance = MyClass("some value&quo

Re: Practice question

2014-10-06 Thread Steven D'Aprano
a headache. You're obviously lying, acting, delusional, an insentient robot programmed to repeat the words 'I have a headache', a zombie (not the brain eating kind, the philosophical kind), a sophisticated bot (but not sophisticated enough to pass the Turing test), or otherwise faking it." I'm just sayin'... -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Practice question

2014-10-07 Thread Steven D'Aprano
case, imgur) is down or blocked. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Practice question

2014-10-07 Thread Steven D'Aprano
othing. But if they are unequal, assert will raise an exception and stop, and you know that the two cases are not equivalent and can go on to the next possibility. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: ruby instance variable in python

2014-10-07 Thread Steven D'Aprano
ing to say. Could you try explaining again please? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Another time question

2014-10-07 Thread Steven D'Aprano
considered a month supply. The would be 4 weeks instead of one month. Okay. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

operator module functions

2014-10-07 Thread Steven D'Aprano
; functions are actually: operator.__add__; operator.__sub__; operator.__mul__; etc., with the underscore-less versions being provided as a convenience. Was anyone aware of this? It came as a surprise to me. Is there anyone who uses or prefers the dunder versions? -- Steven -- https://mail.pyt

Re: operator module functions

2014-10-08 Thread Steven D'Aprano
official operator.__add__ function, and Terry Reedy says there are no tests for it. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Toggle

2014-10-08 Thread Steven D'Aprano
*string* "T r u e" with the constant True. It should be: assert isinstance(x, bool) if x: # don't write "if x == True" since that is redundant color = 'Red' else: color = 'Blue' x = not x > Others? color = ("Red", "Blue")[color == "Red"] color = {"Red": "Blue", "Blue": "Red"}[color] color = "Red" if color == "Blue" else "Blue" There may be even more complicated, obscure or obfuscated versions possible. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Toggle

2014-10-08 Thread Steven D'Aprano
which it suppresses), while print outputs the str() of them. py> class Test: ... def __repr__(self): return "repr" ... def __str__(self): return "str" ... py> x = Test() py> x repr py> print(x) str That's an old, old part of Python, going

Re: [OT] spelling colour / color was Re: Toggle

2014-10-09 Thread Steven D'Aprano
mm0fmf wrote: > On 09/10/2014 02:29, Steven D'Aprano wrote: >> Apart from the horrible spelling of colour :-) > > I've always spelt colour as "color" when programming and as "colour" > when writing language including documentation about softwar

Re: [OT] spelling colour / color was Re: Toggle

2014-10-10 Thread Steven D'Aprano
Terry Reedy wrote: > On 10/9/2014 1:43 PM, mm0fmf wrote: >> On 09/10/2014 02:29, Steven D'Aprano wrote: >>> Apart from the horrible spelling of colour :-) >> >> I've always spelt colour as "color" when programming and as "colour" >

Re: Toggle

2014-10-10 Thread Steven D'Aprano
Rustom Mody wrote: > On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote: >> On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote: > >> >>>> Color.Red >> >>>> print (Color.Red) >> > Color.Red >> >

Re: Toggle

2014-10-10 Thread Steven D'Aprano
te much Python code, do you? *wink* It is not "rarely seen" in Python: some_string.strip().replace("x", "y").upper().split() sort of thing is extremely common in Python. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: while loop - multiple condition

2014-10-12 Thread Steven D'Aprano
x27;s the most readable version of all. One last note: if you are using Python 3.3 or better, you can support international text better by using the casefold() method rather than lower(). In this case, it won't make a difference, but the technically correct method for doing case-insensitive comparisons is to casefold both strings rather than lower- or upper-case them. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there an easy way to control indents in Python

2014-10-18 Thread Steven D'Aprano
ally think of three things: - excessively long one-liners; - excessive use of symbols and sigils ("line noise"); - "More Than One [Thousand] Ways To Do It" Are you suggesting that Perl functions tend to be too small? What do you consider "too small"? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Building lists

2014-10-20 Thread Steven D'Aprano
dom.random() < 0.5: ... alist.append("spam") ... py> print(alist) ['spam', 'spam'] Because this is random, if you try it you will get an unpredictable number of "spam" words in the list. About half the time it will contain no words at all, about

Re: When to use assert

2014-10-21 Thread Steven D'Aprano
rt isinstance(instance, Model) # Code that assumes that instance is an object of type Model That means that the logic for what is acceptable as a Model is all in one place, namely the Model.get method, and callers don't need to care about the pre-condition "argument is a Model or an integer ID", they only need to care about the post-condition "result of get() is a Model". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: my multi-download program can't finish

2011-09-07 Thread Steven D'Aprano
ch are bugs that need to be fixed, and which should be allowed through. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Create an index from a webpage

2011-09-08 Thread Steven D'Aprano
] Or better still, use a search engine that doesn't track and bubble your searches: https://duckduckgo.com/html/?q=python+sitemap You can even LMDDGTFY if you insist. http://lmddgtfy.com/ Completely-undermining-my-own-message-ly y'rs, -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Steven D'Aprano
en in Python, I'd say there is a strong likelihood that one that meets your needs and is publicly available under an appropriate licence is vanishingly small. If you do decide to write your own, please consider uploading it to PyPI under a FOSS licence. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Steven D'Aprano
Simon Cropper wrote: > Certainly doable but > considering the shear commonality of this task I don't understand why a > simple script does not already exist Perhaps it isn't as common or as simple as you believe. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: object.__init__() takes no parameters

2011-09-09 Thread Steven D'Aprano
7) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> object("two", "parameters") In Python 2.2, the default object constructor accepts, and ignores, any parameters. In Python 2.3 on up, that becomes an error. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: killing a script

2011-09-09 Thread Steven D'Aprano
Cameron Simpson wrote: > On 30Aug2011 14:13, Steven D'Aprano > wrote: > | On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: > | >> Yes, but if I am not mistaken, that will require me to put a line or > | >> two after each os.system call. That's almost

Re: killing a script

2011-09-09 Thread Steven D'Aprano
Hans Mulder wrote: > On 9/09/11 11:07:24, Steven D'Aprano wrote: >> Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of >> script.py. While script.py is running, it receives the Ctrl-C, the >> calling process does not. > > You misinterpret

Re: what's the command for (cd ..) in python

2011-09-09 Thread Steven D'Aprano
You may be better off staying in the same directory, and adjusting the path names to the files as you work with them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: object.__init__() takes no parameters

2011-09-09 Thread Steven D'Aprano
Duncan Booth wrote: > Steven D'Aprano wrote: >> In Python 2.2, the default object constructor accepts, and ignores, any >> parameters. In Python 2.3 on up, that becomes an error. >> > More recently than that. It only became an error in 2.6: For __init__, sure, bu

Re: can't generate list from iterator [was: can't generate iterator from list]

2011-09-09 Thread Steven D'Aprano
you see clearly that they are the same array object. Try this: combos = list(balls_in_numbered_boxes(2, [3,3,3])) [id(a) for a in combos] I expect you will see something like [123456, 123456, 123456]. The simplest fix is to fix the next() method so that it returns a copy of self.distribution instead of the array itself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: IOError 35 when trying to read the result of call to urllib2.urlopen

2011-09-09 Thread Steven D'Aprano
url both using the same proxy? It may be that one is going direct and the other is using a proxy. Or perhaps the destination is just flaky, and the resource genuinely is temporarily unavailable. Or it doesn't like your useragent string and is lying. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: killing a script

2011-09-09 Thread Steven D'Aprano
Cameron Simpson wrote: > On 09Sep2011 22:16, Steven D'Aprano > wrote: > | Hans Mulder wrote: > | > On 9/09/11 11:07:24, Steven D'Aprano wrote: > | >> Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation > | >> of script.py. While script

Re: what's the command for (cd ..) in python

2011-09-10 Thread Steven D'Aprano
Waldek M. wrote: > On Fri, 09 Sep 2011 23:03:10 +1000, Steven D'Aprano wrote: >> But think carefully before doing this. Some functions may be confused if >> you change directories while they are running. You may be better off >> staying in the same directory, and adjus

Re: import packet.module without importing packet.__init__ ?

2011-09-10 Thread Steven D'Aprano
lone module outside the package directory, and be done. (Your installer can still treat cheese.py as a dependency of package, and ensure that they are both installed.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: import packet.module without importing packet.__init__ ?

2011-09-10 Thread Steven D'Aprano
init__.py # huge, imports my_app.module1, my_app.module2, etc. then point rpc4django at my_app.rpc instead of my_app. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: convert time

2011-09-10 Thread Steven D'Aprano
) Otherwise see the time and datetime modules: http://docs.python.org/library/time.html http://docs.python.org/library/datetime.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: killing a script

2011-09-10 Thread Steven D'Aprano
Cameron Simpson wrote: > On 10Sep2011 11:25, Steven D'Aprano > wrote: > | Cameron Simpson wrote: > | > My copy of the 2.7 docs says: > | > This is implemented by calling the Standard C function system(), and > | > has the same limitations. > | >

Re: Doctest failing

2011-09-11 Thread Steven D'Aprano
ly, tracebacks ignore the function.__name__ and print the code object name: >>> f >>> f("x") Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: cannot concatenate 'str' and 'int' objects

Re: PC locks up with list operations

2011-09-12 Thread Steven D'Aprano
On Wed, 31 Aug 2011 10:33 pm Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345

Re: How do I automate the removal of all non-ascii characters from my code?

2011-09-12 Thread Steven D'Aprano
e a quoted string literal, I would expect to get a SyntaxError. I have come across this myself. While I haven't really investigated in great detail, it appears to happen when copying and pasting code from a document (usually HTML) which uses non-breaking spaces instead of \x20 space characters. All

Re: Terminating an embedded interpreter

2011-09-12 Thread Steven D'Aprano
great. If you really fear rogue, or malicious, scripts, perhaps Python is not the right language for this task. Otherwise, just trust the script to be sane. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: strang thing:

2011-09-12 Thread Steven D'Aprano
n is to save a reference to the open built-in first: my_open = open open = "something" file = my_open("filename", "r") -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I automate the removal of all non-ascii characters from my code?

2011-09-13 Thread Steven D'Aprano
On Tue, 13 Sep 2011 05:49 pm jmfauth wrote: > On 12 sep, 23:39, "Rhodri James" wrote: > > >> Now read what Steven wrote again.  The issue is that the program contains >> characters that are syntactically illegal.  The "engine" can be perfectly >&g

Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-13 Thread Steven D'Aprano
t; interest: http://stackoverflow.com[...] > > I wonder why people ask this kind of question on stackoverflow, and then > come here asking people to go over there, read the question, and > (potentially) provide an answer. You should post that question on stackoverflow, and ask them to repl

Re: stackoverflow and c.l.py

2011-09-14 Thread Steven D'Aprano
"someone is wrong on the Internet!". If you want to see a news group gone bad, go to something like sci.math. You can't move for the cranks "disproving" Cantor's Diagonal Theorem and Special Relativity and proving that 10**603 is the One True Actual Infinity (I'm not making that last one up!). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: cause __init__ to return a different class?

2011-09-14 Thread Steven D'Aprano
erClass are compatible. (If they're not compatible, you'll get an exception.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparisons of computation timing

2011-09-16 Thread Steven D'Aprano
reason i7 processes show > slower performance? Don't believe hardware manufacturer's advertising. These days, chip speed is not so important. Cache misses are MUCH more critical: a slow chip with a big cache will out-perform a fast chip with a small cache nearly always. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Turkic I and re

2011-09-16 Thread Steven D'Aprano
t; Turkish i-s" at separate codepoints. > > Then one could have the three pairs > I, i ("normal") > I (other one), ı > > and > > İ, i (the other one). And then people will say, "How can I match both sorts of dotless uppercase I but not dotted I when I'm doing comparisons?" -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why ps/fname of a python interpreter changes across platforms?

2011-09-16 Thread Steven D'Aprano
, they > are not launched with exec permissions. > > I don't know why the fname of the python interpreter changes across > platforms. Ask the person who built the system, or the people who made the distribution. They are free to name the Python executable anything they like. -- Steven

Re: way to calculate 2**1000 without expanding it?

2011-09-16 Thread Steven D'Aprano
-7): b = (b[0]+b[0], b[1]-3) while b > (0,9876): b = tuple((lambda a,b: map(lambda a,b:a+b, a,b)) ((lambda a,b: map(lambda a,b:a*b, a,b)) (b,(0,1)), (lambda a,b: map(lambda a,b:a-b, a,b)) (divmod(b[0],10),(0,64 print b[1] -- Steven -- http://mail.py

Re: What is wrong with this code?

2011-09-18 Thread Steven D'Aprano
ntax How about if you start off by explaining what you think "a cap for LaTeX" means, or provide a link to something that will explain it? This is a Python list, and we don't necessarily know much about LaTeX. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Operator commutativity

2011-09-19 Thread Steven D'Aprano
Westley Martínez wrote: > def __radd__(self, other): > return self.__add__(self, other) Which, inside a class, can be simplified to: __radd__ = __add__ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Operator commutativity

2011-09-20 Thread Steven D'Aprano
to me that the rule is: If the right-hand argument is a subclass of the left-hand argument, AND also defines __radd__ directly rather than inheriting it, then its __radd__ method is called before the left-hand argument's __add__ method. which strikes me as a strangely specific and not very useful rule. I suspect it might be an accident of implementation rather than a deliberate feature. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Odd behavior with imp.reload and logging

2011-09-21 Thread Steven D'Aprano
nsole_formatter) test_logger.addHandler(console_handler) test_logger.setLevel(logging.DEBUG) test_logger.info('Test info') -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Environment variables not visible from Python

2011-09-21 Thread Steven D'Aprano
ot;, "copyright", "credits" or "license" for more information. >>> import os >>> (os.getenv('LINES'), os.getenv('COLUMNS'), os.getenv('TERM')) (None, None, 'xterm') -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Odd behavior with imp.reload and logging

2011-09-22 Thread Steven D'Aprano
On Wed, 21 Sep 2011 23:47:55 -0500, Andrew Berg wrote: > On 2011.09.21 11:22 PM, Steven D'Aprano wrote: >> You could >> try something like this (untested): > That works. Thanks! > This makes me wonder what else stays around after a reload Practically everything. A relo

Re: Environment variables not visible from Python

2011-09-22 Thread Steven D'Aprano
Ben Finney wrote: > Steven D'Aprano writes: > >> I don't understand why some environment variables are not visible from >> Python. > > Not all variables are environment variables. Variables only become > environment variables if exported to the environment;

Re: Execute code after Shut Down command given --- How?

2011-09-22 Thread Steven D'Aprano
down sequence starts?" Find out how to do that, and then do it using Python instead of another language. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: python install on locked down windows box?

2011-09-22 Thread Steven D'Aprano
nstaller as a regular, unprivileged user, after selecting the option for a Non-Admin Install under Advanced Options first. You could also try the ActivePython installer. http://www.richarddooling.com/index.php/2006/03/14/python-on-xp-7-minutes-to-hello-world/ http://diveintopython.org/installing_pyth

Re: random.randint() slow, esp in Python 3

2011-09-22 Thread Steven D'Aprano
e@sylar ~]$ python3.2 -m timeit -s "from random import randint" "randint(0, 1000000)" 10 loops, best of 3: 4.98 usec per loop (The times are quite variable: the above are the best of three attempts.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.5 zlib trouble

2011-09-23 Thread Steven D'Aprano
Jesramz wrote: > Hello, > > I am trying to deploy an app on google app engine using bottle, a > micro-framework, similar to flask. [...] > ImportError: No module named zlib What happens if you explicitly launch Python2.5 and then try to import zlib? -- Steven -- http://

Re: extending class

2011-09-23 Thread Steven D'Aprano
ollowing attempt gives, however, a recursion error, but why? Here is an old recipe showing how to do automatic delegation correctly: http://code.activestate.com/recipes/52295/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Sep 23, 2011 at 4:14 AM, Steven D'Aprano > wrote: >> What makes you think it's in C? I don't have Python 3.3a, but in 3.2 the >> random module is mostly Python. There is an import of _random, which >> presumably is in

Re: Python Mixins

2011-09-24 Thread Steven D'Aprano
perclasses are reachable. In the case of injection, they aren't (at least not without more work). * Inheritance is late-binding, injection is early-binding: if you dynamically add a new method to Yamlafiable, Dog will see the change in the first case but not the second. That's n

Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
rors. Note that the 7th value is exact here, but not above. Is there a way to pick between methods #1 and #2 (or some combination of the two) without human intervention so as to minimise the rounding error? Or is there some other way to generate equally-spaced floats? My efforts at googling hav

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Mark Dickinson wrote: > On Sep 24, 2:53 pm, Steven D'Aprano [email protected]> wrote: >> I'm trying to generate a sequence of equally-spaced numbers between a >> lower and upper limit. Given arbitrary limits, what is the best way to >> generate a

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
2.2, 2.5, 2.8003, 3.1] >>> >>> start, stop, n = -1, 1.1, 7 >>> [float(F(start) + i*(F(stop)-F(start))/n) for i in range(n+1)] [-1.0, -0.7, -0.39997, -0.09996, 0.20004, 0.5001, 0.8, 1.1] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Arnaud Delobelle wrote: > On these examples, using fractions is no better than what I suggested > in my previous post. I'm sorry, I can't see your previous post. Perhaps it isn't available on my news provider? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggested coding style

2011-09-24 Thread Steven D'Aprano
o-format-integer-as-string-with-leading-zeros http://msdn.microsoft.com/en-us/library/dd260048.aspx http://www.ozgrid.com/forum/showthread.php?t=64193&page=1 http://www.google.com/codesearch#algXCqBNNP0/utils/zip2rep.py&q=lang:%5Epython$%20zfill%20case:yes&ct=rc&cd=7 http://www.goo

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Terry Reedy wrote: > On 9/24/2011 9:53 AM, Steven D'Aprano wrote: [...] >>>>> [0.0 + i*width for i in range(8)] >> [0.0, 0.3, 0.6, 0.8999, 1.2, 1.5, 1.7998, 2.1] >> >> The 4th and 7th values have rounding errors, the rest are exa

Re: Generating equally-spaced floats with least rounding error

2011-09-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Sun, Sep 25, 2011 at 3:01 AM, Steven D'Aprano > wrote: >> Mark Dickinson wrote: >> >>> Using Fraction for intermediate calculations actually works perfectly >>> for this, since conversions from float to Fraction are exact, whi

Re: Generating equally-spaced floats with least rounding error

2011-09-25 Thread Steven D'Aprano
actions module. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrote a new library - Comments and suggestions please!

2011-09-27 Thread Steven D'Aprano
so hard to show a couple of examples? Documentation like that really makes me appreciate the sterling work done on Python's docs. This tutorial: http://www2.sas.com/proceedings/sugi30/263-30.pdf is much clearer. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python 2.6.7 on Windows

2011-09-27 Thread Steven D'Aprano
skateboard desperately hanging onto the bumper trying not to be left behind.) You could try installing from source, if you have the appropriate Windows development environment. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Unittest testing assert*() calls rather than methods?

2011-09-28 Thread Steven D'Aprano
loops inside tests, you might find this anecdote useful: http://mail.python.org/pipermail/python-list/2011-April/1270640.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

[OT] Benefit and belief [was Re: Suggested coding style]

2011-09-28 Thread Steven D'Aprano
m. Forget money, or even the love of money. The idea that one mustn't criticise another person's beliefs is the root of all evil. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Python without a tty

2011-09-29 Thread Steven D'Aprano
I have a Python script which I would like to test without a tty attached to the process. I could run it as a cron job, but is there an easier way? I am running Linux. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggested coding style

2011-09-29 Thread Steven D'Aprano
Westley Martínez wrote: > Perhaps you should spend a little less time on the mailing list and a > little more time in church. Is that meant as punishment for Rick or for the churchgoers? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python without a tty

2011-09-29 Thread Steven D'Aprano
Alain Ketterlin wrote: > Steven D'Aprano writes: > >> I have a Python script which I would like to test without a tty attached >> to the process. I could run it as a cron job, but is there an easier way? >> >> I am running Linux. > > Isn't os.

Re: [OT] Off-Topic Posts and Threads on the Python Mailing List

2011-09-29 Thread Steven D'Aprano
Westley Martínez wrote: > On this mailing list, we're programmers, nothing else, Speak for yourself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Benefit and belief

2011-09-29 Thread Steven D'Aprano
Devin Jeanpierre wrote: > I also didn't reprimand anyone, except maybe Steven. If you are more upset at my describing the Catholic Church as protecting child molesters than you are at the Church for actually protecting child molesters, then your priorities are completely screwed up

Re: [OT] Off-Topic Posts and Threads on the Python Mailing List

2011-09-29 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Sep 30, 2011 at 12:38 PM, Steven D'Aprano > wrote: >> Westley Martínez wrote: >> >>> On this mailing list, we're programmers, nothing else, >> >> Speak for yourself. >> > > I don't think he meant

Hermeneutics and computer science [was off-topic, now back on]

2011-09-29 Thread Steven D'Aprano
alex23 wrote: > I'm slowly seeing more and more interest in applying > a discipline that arose out of the > study of religious texts. Tell us more, please. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: regexp compilation error

2011-09-30 Thread Steven D'Aprano
gt;>>> re.compile(r"""^(?: [^y]* )""", re.X) > <_sre.SRE_Pattern object at 0x7f4069cc3730> > > Is this a bug in python regex engine? Or maybe some incompatibility with > Perl? Before asking whether it is a bug, perhaps you should consider what (if anything) that regex is supposed to actually do. Perhaps you should post the Perl equivalent, and some examples of it in use. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

[OT] Chaos Theory [was Re: Benefit and belief]

2011-10-01 Thread Steven D'Aprano
n other words, "if this were true, it would be unfortunate, therefore it can't be true". The story of Mankind, really. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Chaos Theory [was Re: Benefit and belief]

2011-10-01 Thread Steven D'Aprano
Gregory Ewing wrote: > Steven D'Aprano wrote: >> By the way, who removed the OT label from the subject line? > > Probably nobody "removed" it, they just replied to some earlier > message that didn't have it. I started the "Benefit and belief&

Re: lower-case names for builtin types

2011-10-01 Thread Steven D'Aprano
thon just because they happen to be types. Maybe in Python 4000 there will be a push to rationalise the case of built-in types. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    81   82   83   84   85   86   87   88   89   90   >