Re: Top-posting &c. (was Re: [ANNC] pybotwar-0.8)

2012-08-21 Thread Steven D'Aprano
-mail to get to a (generally) 1 liner at the bottom. +1000 People with Hotmail accounts used to be known as "Metoobees" because of their tendency to reply to long posts with a single line at the very end, "Me too!". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Abuse of Big Oh notation

2012-08-21 Thread Steven D'Aprano
r than choosing between 2 and 4 bytes when you build the Python compiler. This is a big positive step forward with a pretty simple algorithm and will strongly help encourage the use of Unicode by taking much of the sting out of the perennial complaints that "Unicode wastes space". Not so wasteful any more. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Steven D'Aprano
then garbage collected, so: class B: '''a {} string'''.format('doc') is equivalent to: class B: __doc__ = None _tmp = '''a {} string'''.format('doc') del _tmp except that the name "_tmp" doesn't actually get used. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: asking

2012-08-22 Thread Steven D'Aprano
expect it to be more or less equally as efficient, and I find it easier to read: any(sub in string for sub in substrings) There's also an all() function that works similarly to any(), except that it stops as soon as it sees a false value. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Books?

2012-08-22 Thread Steven D'Aprano
would have adored as a newbie. (Your mileage may vary.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Methods versus functions [was Re: Objects in Python]

2012-08-22 Thread Steven D'Aprano
rties, and probably other things as well. You can do all sorts of funky things with descriptors -- google for "descriptor protocol", "data descriptor", "non-data descriptor" etc. if you are interested. Here's a trivial, but useful, one: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-22 Thread Steven D'Aprano
ugh I've already used it for something else, but there is still cost to re-using names (even if that cost is sometimes trivial). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-22 Thread Steven D'Aprano
of interfaces, over strict type testing, so users are also discouraged from writing excessively strongly-typed operations (if you just need something you can iterate over, why insist that it must be a list and nothing but a list?). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-23 Thread Steven D'Aprano
on, only the Ruby people call theirs "call by reference" and the Java people call theirs "call by value", *both of which are identical*, and NEITHER of which are the same thing that C and Pascal programmers will understand by call by value *or* call by reference. http://mail.python.org/pipermail/tutor/2010-December/080505.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-23 Thread Steven D'Aprano
ory locations as "the same sort of entity". Hence, if C variables are variables, then Python name bindings can't be. I used to agree with that reasoning. I no longer do, not entirely. While I see the differences between them -- for instance, C variables exist before they have a value assigned to them, Python name bindings do not -- I don't think the differences are important enough to *prohibit* use of the word "variable" to describe name bindings. Only to discourage it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: set and dict iteration

2012-08-23 Thread Steven D'Aprano
e > types such as strings and numbers, as well as container types. Counted > references could be used instead, but would be consistently wasted work > for the garbage collector, though the benefit to programmers' peace of > mind could be significant. The usual way to implement &qu

Re: Objects in Python

2012-08-24 Thread Steven D'Aprano
ldn't > tell what address a variable (or "variable instance", if you prefer) was > at -- would "int x;" cease to be a variable? Not at all. Just because the public interface of the language doesn't give you any way to view the fixed locations of variables, doesn't mean that variables cease to have fixed locations. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Identity function id() [was Re: Objects in Python]

2012-08-24 Thread Steven D'Aprano
on 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> id(x) 43 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Publish unittest results from test discovery

2012-08-24 Thread Steven D'Aprano
xmlrunner and unittest discovery, sorry. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Variables vs names [was: Objects in Python]

2012-08-24 Thread Steven D'Aprano
On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote: > On 08/23/2012 12:56 PM, Steven D'Aprano wrote: >> On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: >> >>> I definitely *wouldn't* say "Python >>> classes aren't really clas

Re: Objects in Python

2012-08-24 Thread Steven D'Aprano
On Fri, 24 Aug 2012 08:00:59 +1000, Chris Angelico wrote: > On Fri, Aug 24, 2012 at 3:56 AM, Steven D'Aprano > wrote: >> But name bindings are a kind of variable. Named memory locations are a >> *different* kind of variable. The behaviour of C variables and Python >>

Re: Computing win/loss records in Python

2012-08-25 Thread Steven D'Aprano
On Sat, 25 Aug 2012 22:42:59 -0400, Steven W. Orr wrote: > win_count = defaultdict(int) > loss_count = defaultdict(int) When I try that, I get "NameError: name 'defaultdict' is not defined." I think it is rather unfair on beginners to show them code that almost,

Re: Computing win/loss records in Python

2012-08-25 Thread Steven D'Aprano
) l = losses.get(name, 0) d = ties.get(name, 0) total = w+l+d print( "Team %s played %d games, won %d, lost %d and tied %d." % (name, total, w, l, d) ) If you want to store these results permanently, you need to write them out to file. You can roll your own, but a simpler way might

Re: Probability Algorithm

2012-08-25 Thread Steven D'Aprano
99: # + 19 return CLIST else: return DLIST the_list = select_list() the_item = random.choice(the_list) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Steven D'Aprano
e, to keep in memory this sequence according to the > *characers* composing this "array of code points". > > The message is even stronger. Use runes to work comfortably [*] with > unicode: > rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be better) Runes are not int32, and int32 is not UTF-32. Whether UTF-32 is the "perfect scheme" for Unicode is a matter of opinion. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-26 Thread Steven D'Aprano
pose you could. Then the parts of C that don't rely on fixed memory addresses could use the name bindings (with the corresponding loss of performance), and the parts of C which do require them could continue to do so, and we'll have one more language with a confusing, unclear and uncle

Re: Objects in Python

2012-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2012 00:45:55 -0500, Evan Driscoll wrote: > On 08/24/2012 05:00 AM, Steven D'Aprano wrote: >> No. The compiler remembers the address of 'a' by keeping notes about it >> somewhere in memory during the compilation process. When you run the >> comp

Re: Objects in Python

2012-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2012 23:58:31 +1000, Chris Angelico wrote: > On Sun, Aug 26, 2012 at 11:43 PM, Steven D'Aprano > wrote: >> It gets worse: Python has multiple namespaces that are searched. >> >> "Go to the Excelsior Hotel and ask the concierge for Mr Smith. If M

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Steven D'Aprano
?) But if rune is merely an alias for int32, why not just call it int32? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects in Python

2012-08-26 Thread Steven D'Aprano
On Mon, 27 Aug 2012 00:54:05 +1000, Chris Angelico wrote: > On Mon, Aug 27, 2012 at 12:18 AM, Steven D'Aprano > wrote: >> Also, built-ins require a name lookup too. As you point out, locals are >> special, but Python will search an arbitrarily deep set of nested >>

Re: Objects in Python

2012-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2012 16:12:40 -0400, Dennis Lee Bieber wrote: > On 26 Aug 2012 13:43:33 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > >> (In some older versions of Python, wildcard imports are allowed, and >> the func

Re: Flexible string representation, unicode, typography, ...

2012-08-26 Thread Steven D'Aprano
On Sun, 26 Aug 2012 15:42:00 -0600, Ian Kelly wrote: > On Sun, Aug 26, 2012 at 2:13 PM, Steven D'Aprano > wrote: >> On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: >> >>> I think the documentation for those functions is simply badly worded. >>> T

Make error when installing Python 1.5

2012-08-26 Thread Steven D'Aprano
with it: wget http://www.python.org/ftp/python/src/py152.tgz tar xzf py152.tgz cd Python-1.5.2/ ./configure make sudo make altinstall -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Flexible string representation, unicode, typography, ...

2012-08-29 Thread Steven D'Aprano
get right, some might even say buggy. >> And it would give the python programmer a choice of efficiency >> profiles. > > So instead of having just one test for my Unicode-handling code, I'll > now have to run that same test *three times* -- once for each possible &g

Re: Flexible string representation, unicode, typography, ...

2012-08-30 Thread Steven D'Aprano
for each string as needed. So some strings will be stored internally as UCS-4, some as UCS-2, and some as ASCII (which is a standard, but not the Unicode consortium's standard). (And possibly some as UTF-8? I'm not entirely sure from reading the PEP.) There's nothing radical here,

Re: Flexible string representation, unicode, typography, ...

2012-08-30 Thread Steven D'Aprano
On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> The only thing which is innovative here is that instead of the Python >> compiler declaring that "all

Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Steven D'Aprano
On Thu, 30 Aug 2012 16:44:32 -0400, Terry Reedy wrote: > On 8/30/2012 12:00 PM, Steven D'Aprano wrote: >> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: [...] >>> Is the implementation smart enough to know that x == y is always False >>> if x an

Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Steven D'Aprano
On Fri, 31 Aug 2012 08:43:55 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: >> > Is the implementation smart enough to know that x

Re: Flexible string representation, unicode, typography, ...

2012-09-02 Thread Steven D'Aprano
re *seriously* interested in debugging why string code is slower for you, you can start by running the full suite of Python string benchmarks: see the stringbench benchmark in the Tools directory of source installations, or see here: http://hg.python.org/cpython/file/8ff2f4634ed8/Tools/stringbench -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Flexible string representation, unicode, typography, ...

2012-09-02 Thread Steven D'Aprano
On Sun, 02 Sep 2012 23:38:49 +0300, Serhiy Storchaka wrote: > On 30.08.12 09:55, Steven D'Aprano wrote: >> And Python's solution uses those: UCS-2, UCS-4, and UTF-8. > > I see that this misconception widely spread. I am not familiar enough with the C implementation

Re: Flexible string representation, unicode, typography, ...

2012-09-03 Thread Steven D'Aprano
On Mon, 03 Sep 2012 18:26:02 +0300, Serhiy Storchaka wrote: > On 03.09.12 04:42, Steven D'Aprano wrote: >> If you are *seriously* interested in debugging why string code is >> slower for you, you can start by running the full suite of Python >> string benchmarks: see th

Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Steven D'Aprano
more complex openers, just call the opener directly? What is the rationale for complicating open instead of telling people to just call their opener directly? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: set and dict iteration

2012-09-03 Thread Steven D'Aprano
restart the first iterator at which point some items returned by the iterator *may* be duplicated or skipped (depends on the nature of the modifications). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: set and dict iteration

2012-09-03 Thread Steven D'Aprano
On Mon, 03 Sep 2012 21:50:57 -0400, Dave Angel wrote: > On 09/03/2012 09:26 PM, Steven D'Aprano wrote: >> An unsigned C int can count up to 4,294,967,295. I propose that you say >> that is enough iterators for anyone, and use a single, simple, version >> counter in the

Re: Comparing strings from the back?

2012-09-03 Thread Steven D'Aprano
may require fewer, or more, than that, but whichever way you scan the string, some comparisons will take more and some will take fewer. With no general way of telling ahead of time which will be which, on average you can't do better than O(N/2) and no complexity justification for picking "start from the end" from "start from the start". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The opener parameter of Python 3 open() built-in

2012-09-03 Thread Steven D'Aprano
On Mon, 03 Sep 2012 23:19:51 -0400, Dennis Lee Bieber wrote: > On 04 Sep 2012 01:13:09 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > >> Why does the open builtin need this added complexity? Why not just call >> os

Re: Comparing strings from the back?

2012-09-04 Thread Steven D'Aprano
On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > On 04.09.2012 04:17, Steven D'Aprano wrote: > >> On average, string equality needs to check half the characters in the >> string. > > How do you arrive at that conclusion? Take two non-empty strings

Re: python docs search for 'print'

2012-09-04 Thread Steven D'Aprano
h fewer The second best thing for your friend to do is to learn to read the index to the docs, where the print statement is listed: http://docs.python.org/reference/index.html You can use your browser's Find command to search the page for "print". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: python docs search for 'print'

2012-09-04 Thread Steven D'Aprano
nation, although I understand it is much, much worse now. Blame Google for that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: python docs search for 'print'

2012-09-04 Thread Steven D'Aprano
On Tue, 04 Sep 2012 18:28:31 +, Steven D'Aprano wrote: > https://www.google.com.au/search?q=python+print > http://duckduckgo.com/html/?q=python+print > > In this case, google hits the right Python documentation on the first > link. Duckduckgo doesn't do nearly so wel

Re: Why derivated exception can not be pickled ?

2012-09-04 Thread Steven D'Aprano
ain that what you are seeing is expected behaviour. Exceptions should definitely be pickleable: http://bugs.python.org/issue1692335 so __getstate__ should be called. I think you should report this as a bug. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
) 44 CPython especially has the most complicated behaviour with IDs and object identity: >>> a = 99.99 >>> b = 99.99 >>> a is b False >>> a = 99.99; b = 99.99; a is b True In general, you almost never need to care about IDs and object identity. The main exception is testing for None, which should always be written as: if x is None -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
optimization -- something that makes code run slower, not faster). > and "a==True" should be automatically changed into memory comparison. Absolutely not. That would be a backward-incompatible change that would break existing programs: py> 1.0 == True True py> from de

Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
do with the ability of the timsort algorithm to exploit local order within a list and avoid performing comparisons. > In summary, let's please not debate "feelings" or such. I have no idea what feelings you are referring to. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
rent day computers at least, it is reasonable to say that "a is b" implies that a and b are the same object at a single location. The second half of the question is more complex: "id(a) == id(b)" *only* implies that a and b are the same object at the same location if the

Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 11:09:30 -0400, Dave Angel wrote: > On 09/05/2012 10:41 AM, Steven D'Aprano wrote: [...] >> So, for current day computers at least, it is reasonable to say that "a >> is b" implies that a and b are the same object at a single location. > >

Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
cted. So you are left with the highly non-random subset of 1 equality tests. But you haven't finished. Instead of checking all 1 equality tests, you then decide to only check the 2000 tests that happen to randomly occur when using the timsort algorithm to sort a list. So from the population of one million possible equality tests, you throw away the vast majority, then average the *strongly non-random* few that are remaining. Naturally the result you get is strongly biased, and it has nothing to do with the average Big Oh behaviour of equality on random strings. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The opener parameter of Python 3 open() built-in

2012-09-05 Thread Steven D'Aprano
ns in my module that call "open", and I monkey-patch the global (module-level) name "open" to intercept that call, I don't see that there is more risk of breakage just because one function is called from a thread. Obviously monkey-patching the builtin module itself

Re: is implemented with id ?

2012-09-05 Thread Steven D'Aprano
" should be special-cased by the interpreter as "a is True" instead of calling a.__eq__. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
hat from a computer science textbook, but I can't find that reference now, so possibly I was thinking of something else. (String searching perhaps?). In any case, the *worst* case for string equality testing is certainly O(N) (every character must be looked at), and the *best* case is O(1) obviously (the first character fails to match). But I'm not so sure about the average case. Further thought is required. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Steven D'Aprano
roven that's where the bottleneck is." — Rob Pike "The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet." — Michael A. Jackson -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Steven D'Aprano
e I don't know how it works. The internal details of how timeit works are complicated, but it is worth reading the comments and documentation, both in the Fine Manual and in the source code: http://docs.python.org/library/timeit.html http://hg.python.org/cpython/file/2.7/Lib/timeit.py -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.stat() distorts filenames that end with period (nt.stat())

2012-09-06 Thread Steven D'Aprano
append-a-period-to-a/4329b1f1-746e-4c45-9c32-75622b6ab526 http://support.microsoft.com/kb/115827 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
ing a lot of arguing in this thread > should take Python, find the string comparison routine, and hack in some > statistics-gathering. Then run *real code* on it. Where's the fun in that? :-P -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > On 09/06/2012 04:33 AM, Steven D'Aprano wrote: >> >> >> I may have been overly-conservative earlier when I said that on average >> string equality has to compare half the characters. I thought I had &g

Re: Comparing strings from the back?

2012-09-07 Thread Steven D'Aprano
On Fri, 07 Sep 2012 19:10:16 +, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano > wrote: >> >> >> After further thought, and giving consideration to the arguments given >> by people here, I'm now satisfied to say that for equal-length strings,

Re: Does os.getcwd() and os.curdir have the same effect ?

2012-09-09 Thread Steven D'Aprano
ir is a string which the operating system will understand to mean "this directory". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: where's the new python gone?

2012-09-09 Thread Steven D'Aprano
es Python 2.7, but when system tools call "python" they still see the version they are expecting. If your shell is something other than bash, you may need to use a different rc file. Did any of this make sense to you? If anything was unclear, please don't hesitate to ask. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Symbolic computations

2012-09-09 Thread Steven D'Aprano
ympy. See for example: http://www.sagemath.org/doc/reference/sage/calculus/test_sympy.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner Q: What does the double underscore __ mean?

2012-09-09 Thread Steven D'Aprano
one. http://mail.python.org/pipermail/tutor/2012-September/091388.html You can see the tutor archives, or subscribe to the list, from here: http://mail.python.org/mailman/listinfo/tutor -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Standard Asynchronous Python

2012-09-09 Thread Steven D'Aprano
bugs can be fixed, but we're stuck with "referer" forever :) At least, you should be prepared to justified why your library uthreads should be considered mature enough for the std lib despite the lack of real-world use. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Standard Asynchronous Python

2012-09-10 Thread Steven D'Aprano
On Mon, 10 Sep 2012 07:36:11 -0400, Dustin J. Mitchell wrote: > The responses have certainly highlighted some errors in emphasis in my > approach. > > * My idea is to propose a design PEP. (Steven, Dennis) I'm not at *all* > suggesting including uthreads in the standard

Re: Comparing strings from the back?

2012-09-10 Thread Steven D'Aprano
On Mon, 10 Sep 2012 08:59:37 +, Duncan Booth wrote: > Gelonida N wrote: > >> On 09/07/2012 06:06 AM, Steven D'Aprano wrote: >>> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: >>> >>> >>> Also of some interest is the best case: O

Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

2012-09-10 Thread Steven D'Aprano
t you do NOT want the name filtered. > > Better said by Microsoft: > "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs > to disable all string parsing and to send the string that follows it > straight to the file system. That's not so much a

Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

2012-09-10 Thread Steven D'Aprano
On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote: > On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote: [...] > > That's not so much a workaround as the officially supported API for > > dealing with the situation you are in. Why don't you just pr

Re: Double sided double underscored variable names

2012-09-11 Thread Steven D'Aprano
score attributes like self.__spam. This can be a right PITA at times, and offers so little protection that it isn't worthwhile. __names only protect against *accidental* name collisions, and not all of those. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Double sided double underscored variable names

2012-09-11 Thread Steven D'Aprano
is idea. I tend to want them in pretty much > any language I write in. What do you mean by in-line functions? If you mean what you literally say, I would answer that Python has that with lambda. But I guess you probably mean something more like macros. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Which Version of Python?

2012-09-11 Thread Steven D'Aprano
ter choice. Everyone has to make that choice for themselves, based on what libraries they intend to use. For those who don't intend to use any libraries at all, I think the answer is simple: Learn the version of Python that comes installed on your computer, or if you have to install it yourself, learn Python 3. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Which Version of Python?

2012-09-11 Thread Steven D'Aprano
On Wed, 12 Sep 2012 02:11:22 +, Steven D'Aprano wrote: > On Tue, 11 Sep 2012 17:17:14 -0700, Peter wrote: > >> If your desire is to "learn" Python then I would stick to 2.7 >> >> My reasoning would be that there are still a significant number of >&

Re: Boolean function on variable-length lists

2012-09-12 Thread Steven D'Aprano
this sounds like homework, I won't give you the exact solution. If you still can't solve it, come back with your attempt and we'll give you a bit more help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime

2012-09-13 Thread Steven D'Aprano
lisecond precision -- why??? -- *and* expect to do it from a user-space application, you're going to have a bad time. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-13 Thread Steven D'Aprano
that your reply will be read a week after the post you replied to. Do you still expect the reader to understand what you're talking about? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Least-lossy string.encode to us-ascii?

2012-09-13 Thread Steven D'Aprano
ttp://code.activestate.com/recipes/251871 and especially the very many useful comments. In the case of 2), just binhex or uuencode your data for transport. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Least-lossy string.encode to us-ascii?

2012-09-13 Thread Steven D'Aprano
-cellphones-missing-dot-kills-two-people-puts-three-more-in-jail At least tell me that "ASCII only" is merely an *option* for your application, not the only choice, and that it defaults to UTF-8 which is the right standard to use for text. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-14 Thread Steven D'Aprano
On Fri, 14 Sep 2012 01:20:53 -0700, alex23 wrote: > On Sep 14, 6:04 pm, Dwight Hutto wrote: [snip] Please don't feed the trolls. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorators not worth the effort

2012-09-14 Thread Steven D'Aprano
logging, etc.) you're going to get a much more complex decorator. On the other hand, YAGNI. http://en.wikipedia.org/wiki/You_ain%27t_gonna_need_it -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorators not worth the effort

2012-09-14 Thread Steven D'Aprano
On Fri, 14 Sep 2012 15:22:26 +0200, Jean-Michel Pichavant wrote: > Here's Steven example: > > # Untested! > def timeout(t=15): > # Decorator factory. Return a decorator to actually do the work. if > FPGA: > t *= 3 > def decorator(func): &g

Re: AttributeError: 'list' object has no attribute 'lower'

2012-09-14 Thread Steven D'Aprano
#x27; object has no attribute 'lower' This tells you that you tried to access something.lower, but "something" is a list, and lists don't have an attribute or method "lower". Normally, Python will show you the line of source code with the error, so y

Re: Decorators not worth the effort

2012-09-14 Thread Steven D'Aprano
y that hard to grasp, so I prefer to see as much of the decorator logic to be in one place (a nested decorator function) rather than scattered across two separate decorators plus partial. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: want to show list of available options and arguments in my command line utility

2012-09-16 Thread Steven D'Aprano
process(arg, default_option) elif len(args) == 2: option, arg == args process(arg, option) elif len(args) > 2: do_error('too many arguments') else: do_error('not enough arguments') But as the argument checking code gets more extensive, it is time to just us

Re: want to show list of available options and arguments in my command line utility

2012-09-16 Thread Steven D'Aprano
process(arg, default_option) elif len(args) == 2: option, arg == args process(arg, option) elif len(args) > 2: do_error('too many arguments') else: do_error('not enough arguments') But as the argument checking code gets more extensive, it is time to just us

Re: unit test strategy

2012-09-16 Thread Steven D'Aprano
x27;nN' advances iterator N, an exception calls 'assertRaises', and the > rest are function calls. [...] You've proven that even in Python people can write obfuscated code. > Do you think the 2nd version is legible? Neither version is even close to legible. > Could it interfere with the accuracy of the test? Who knows? I have no clue what your code is doing, it could be doing *anything*. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime issue

2012-09-16 Thread Steven D'Aprano
the mailing list will be mirrored on the newsgroup automatically, there is no need to manually duplicate the post. Thank you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime issue

2012-09-16 Thread Steven D'Aprano
On Sun, 16 Sep 2012 03:15:11 -0700, Νικόλαος Κούρας wrote: > Whats a mailing list? > Can i get responses to my mail instead of constantly check the google > groups site? http://mail.python.org/mailman/listinfo/python-list -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: datetime issue

2012-09-16 Thread Steven D'Aprano
On Sun, 16 Sep 2012 03:54:45 -0700, Νικόλαος Κούρας wrote: > Τη Κυριακή, 16 Σεπτεμβρίου 2012 1:49:38 μ.μ. UTC+3, ο χρήστης Steven > D'Aprano έγραψε: >> On Sun, 16 Sep 2012 03:15:11 -0700, Νικόλαος Κούρας wrote: >> >> >> >> > Whats a mailing list? >

Re: Obnoxious postings from Google Groups (was: datetime issue)

2012-09-16 Thread Steven D'Aprano
news reader application". Or use Thunderbird. For the news server, you use your ISP's newserver, if they offer one, or Gmane, or any of dozens of commercial news providers who will give you access to one for a small fee. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Obnoxious postings from Google Groups (was: datetime issue)

2012-09-16 Thread Steven D'Aprano
he link before? It has instructions there. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python presentations

2012-09-16 Thread Steven D'Aprano
m, there will be 36 multiplications. If the algorithm is a bit smarter, there will be 19 multiplications. Either way, when the calculation is dominated by the cost of multiplication, powerlist3 is between two and four times as expensive as powerlist1. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: unit test strategy

2012-09-16 Thread Steven D'Aprano
modifications you like, with two requests: - I would appreciate a comment in the test file acknowledging my contribution; - I would like to be notified if you submit this to the bug tracker. Thanks again for tackling this project. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python garbage collector/memory manager behaving strangely

2012-09-17 Thread Steven D'Aprano
n caller's code that it's not the built-in one. > I'd replace that compound if statement with > if line.endswith("|\n": > I'd add a comment saying that partial lines at the end of file are > ignored. Or fix the generator so that it doesn't ignore partial lines, or raises an exception, whichever is more appropriate. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: gc.get_objects()

2012-09-17 Thread Steven D'Aprano
lows all of the objects to be deleted. But if you add a __del__ method to *even one* object, Python can no longer safely break the cycle, and so the objects will remain alive even when you can no longer reach them from your code. So, in general, avoid the __del__ method unless you absolutely need it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-18 Thread Steven D'Aprano
to call you David. Otherwise, people will continue to call you Dwight. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: User defined lexical scoping... can I do this?

2012-09-18 Thread Steven D'Aprano
'global' def test(): a = None locals()['a'] = 'local' locals()['b'] = 'local' print a, b test() steve@runes:~$ python test.py None global steve@runes:~$ jython test.py None global steve@runes:~$ ipy test.py local global Other Python implementations may do differently. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steven D'Aprano
nefficient. It depends on the details of the specific strings used, and the operating system's memory management. When it works, it can make string concatenation almost as efficient as ''.join(). When it doesn't work, repeated concatenation is PAINFULLY slow, hundreds or thousands of times slower than join. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steven D'Aprano
iven two incompatible arguments: raise an exception. And in fact, that's exactly what it does. py> sum ([1, 2, 'a']) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    3   4   5   6   7   8   9   10   11   12   >