Re: How to safely maintain a status file

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 23:49:02 -0400, Gene Heskett wrote: > When I wanted to impress the visiting frogs, I often did something I > have never been able to do on any other operating system since, start > assembling a long assembly language file on one of the screens on the > color monitor, hit the cl

Re: lambda in list comprehension acting funny

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 21:33:40 -0700, rusi wrote: > On Jul 11, 11:41 am, Daniel Fetchinson > wrote: >> funcs = [ lambda x: x**i for i in range( 5 ) ] print funcs[0]( 2 ) >> print funcs[1]( 2 ) >> print funcs[2]( 2 ) >> >> This gives me >> >> 16 >> 16 >> 16 >> >> When I was excepting >> >> 1 >> 2 >>

Re: How to safely maintain a status file

2012-07-13 Thread Steven D'Aprano
On Thu, 12 Jul 2012 21:26:20 -0700, rantingrickjohnson wrote: > On Thursday, July 12, 2012 10:13:47 PM UTC-5, Steven D'Aprano wrote: >> Rick has obviously never tried to open a file for reading when somebody >> else has it opened, also for reading, and discovered that desp

Re: code review

2012-07-13 Thread Steven D'Aprano
On Fri, 13 Jul 2012 12:30:47 +, Albert van der Horst wrote: >>Apart from Python, Mathematica, Perl 6, CoffeeScript, Cobra and Clay >>give chained comparisons the standard meaning. It is, or was, a feature >>request for Boo, but I can't tell whether it has been implemented or >>not. > > Algol

Re: How to safely maintain a status file

2012-07-13 Thread Steven D'Aprano
On Fri, 13 Jul 2012 15:15:13 -0500, Chris Gonnerman wrote: > On 07/13/2012 12:59 PM, Prasad, Ramit wrote: >> I lean slightly towards the POSIX handling with the addition that any >> additional write should throw an error. You are now saving to a file >> that will not exist the moment you close it

Re: howto do a robust simple cross platform beep

2012-07-13 Thread Steven D'Aprano
On Sat, 14 Jul 2012 03:00:05 +0200, Gelonida N wrote: > How do others handle simple beeps? > > I just want to use them as alert, when certain events occur within a > very long running non GUI application. Why? Do you hate your users? > What I do at the moment is: > > For Windows I use winsoun

Re: lambda in list comprehension acting funny

2012-07-13 Thread Steven D'Aprano
On Fri, 13 Jul 2012 19:31:24 -0700, rusi wrote: > Consider the following > > def foo(x): > i = 100 > if x: > j = [i for i in range(10)] > return i > else: > return i A simpler example: def foo(): i = 100 j = [i for i in range(10)] return i In Pyt

Re: lambda in list comprehension acting funny

2012-07-14 Thread Steven D'Aprano
On Fri, 13 Jul 2012 21:53:10 -0700, rusi wrote: > On Jul 14, 8:43 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Fri, 13 Jul 2012 19:31:24 -0700, rusi wrote: >> > Consider the following >> >> > def foo(x): >> >     i = 100 &g

Re: lambda in list comprehension acting funny

2012-07-14 Thread Steven D'Aprano
On Fri, 13 Jul 2012 12:54:02 -0600, Ian Kelly wrote: > On Fri, Jul 13, 2012 at 11:53 AM, Hans Mulder wrote: >> The function `function` refers to a variable `VERBOSE` that isn't >> local. In some programming langauages, the interpreter would then scan >> the call stack at run-time, looking for a

Re: lambda in list comprehension acting funny

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 10:49:48 +1000, Chris Angelico wrote: > On Sun, Jul 15, 2012 at 9:29 AM, Steven D'Aprano > wrote: >> Not necessarily *compile* time, but the distinction is between when the >> function is defined (which may at compile time, or it may be at run &

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 03:34:46 -0500, Andrew Berg wrote: > This has probably been discussed before, By the hoary hosts of Hoggoth, has it ever! > but why is there an implicit > conversion to a boolean in if and while statements? It's nothing to do with if and while. All Python objects are duck-t

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: > On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano > wrote: >> (For the record, I can only think of one trap for the unwary: time >> objects are false at *exactly* midnight.) > > Ugh, that's irritating. I c

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 12:02:37 -0500, Andrew Berg wrote: > On 7/15/2012 5:56 AM, Steven D'Aprano wrote: >> 3) Rather than distinguishing "true" from "false", a more useful >> dichotomy is between "something" and "nothing". Python include

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote: > If HOWEVER we want to "truth test" an object (as in: "if obj") we should > be FORCED to use the bool! Why? Because explicit is better than implicit And this is why Rick always writes code like: integer_value_three = int(1) + int(2) assert

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: > For example, instead of "if stack:" or "if bool(stack):", we could use > "if stack.isempty():". This line tells us explicitly that stack is a > container. isempty is not a container method. py> container = [] py> container.isempty()

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 22:03:52 -0700, Ranting Rick wrote: > But if you are going to argue that "if obj" is *explicit enough*, then > apply your argument consistently to "String"+1.75 also. Why must we be > explicit about string conversion BUT not boolean conversion? The problem with "String" + 1.75

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 19:41:34 -0700, Ranting Rick wrote: > Short circuitry is a powerful tool! But why the heck would your > sequences ever be None? Are you using None as a default? And if so, why > not use an empty sequence instead ([], {}, "")? Mostly for explicitness. I want to be able to say

Style question: metaclass self vs cls?

2012-07-16 Thread Steven D'Aprano
Here's a style question for you: in a metaclass, what should I call the instance parameter of methods, "cls" or "self"? class ExampleMeta(type): def method(self, *args): ... I'm not quite sure if that feels right. On the one hand, self is the ExampleMeta instance alright... but on the other

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:54:32 -0700, Ethan Furman wrote: > Andrew Berg wrote: >> On 7/15/2012 9:38 PM, Steven D'Aprano wrote: >>>> I would expect None to mean "doesn't exist" or "unknown" or something >>>> like that - e.g., a valu

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Tue, 17 Jul 2012 01:12:47 +, Steven D'Aprano wrote: > It > looks like Firebird implements the variety of ternary logical called > "Keene logic". Oops, I meant "Kleene". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:28:14 -0400, Dennis Lee Bieber wrote: > On 16 Jul 2012 02:38:35 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > >> On Sun, 15 Jul 2012 12:02:37 -0500, Andrew Berg wrote: >> >> >> > Okay, I s

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:22:18 -0500, Andrew Berg wrote: > On 7/15/2012 3:28 PM, Terry Reedy wrote: >> Because everything does (or should). > I can see how truth testing for empty values is convenient, but perhaps > objects should only have a truth value if explicitly given one - > particularly in c

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:57:43 -0500, Andrew Berg wrote: > I have a better real example, but I opted not to use it before since it > requires some explanation - IRC messages. A client-to-server message has > the basic form of b'COMMAND arguments :message' (e.g. b'PRIVMSG #channel > :hi guys!'). Some

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 11:13:33 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: >>> On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: >>>> (For the record, I can only think of one trap for th

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Tue, 17 Jul 2012 00:18:28 -0400, Devin Jeanpierre wrote: > On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano > wrote: >> On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: >> >>> For example, instead of "if stack:" or "if bool(stack):

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Steven D'Aprano
On Tue, 17 Jul 2012 00:19:48 -0500, Andrew Berg wrote: > To put it in duck-typing terms, why should everything have to quack like > True or False? Sure, I can see why 1 quacks like True or [] quacks like > False, but I don't see why say, a Logger or function should quack like > either. The defaul

Re: Style question: metaclass self vs cls?

2012-07-17 Thread Steven D'Aprano
On Tue, 17 Jul 2012 05:23:22 -0700, Michele Simionato wrote: > The standard is to use `cls`. In the __new__ method you can use `mcl` or > `meta`. Thanks to everyone who answered. I think I will stick with "meta" and "cls". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Tue, 17 Jul 2012 12:01:21 +0100, Lipska the Kat wrote: > For the past 9 years I have been developing in Java [...] > Anyway, I'm looking at Python as a rapid prototyping language. I have an > idea and just want to get it down in basic outline code as quickly as > possible before it departs my a

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Tue, 17 Jul 2012 09:52:59 -0400, Roy Smith wrote: > you could write in Python: > > # Type matching will get checked at run-time > def my_function(mpf, ot): >assert isinstance(mpf, MassivelyParallelFrobinator) >assert isinstance(ot, OtherThing) Keep in mind that assertions are not gu

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2012 01:46:31 +0100, Andrew Cooper wrote: > Take for example a Linux system call handler. The general form looks a > little like (substituting C for python style pseudocode) > > if not (you are permitted to do this): > return -EPERM > if not (you've given me some valid data):

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2012 09:07:22 -0400, Roy Smith wrote: >> Keep in mind that assertions are not guaranteed to run. Code like the >> above is buggy, because if Python is run under the -O (optimize) flag, >> assertions will be stripped out. > > One could equally say that "code like the above is effici

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2012 15:48:28 +0100, Lipska the Kat wrote: > On 18/07/12 15:34, Grant Edwards wrote: >> Unless you're asking about the tabs vs. spaces argument. In that case, >> people who use 4 spaces per level are 'correct'; people who use a >> different number of spaces are a bit less correct;

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2012 12:33:01 -0400, Dave Angel wrote: > On 07/18/2012 08:58 AM, Steven D'Aprano wrote: >> >> For bonus points, can you see the mistake? [...] >> > There are actually two bugs in that function. One is in the assertion, > but more importantly, t

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Thu, 19 Jul 2012 01:04:50 +1000, Chris Angelico wrote: > Python isn't object oriented in the way Java is ("EVERYTHING has to be > in a class! Look, it's all OO now!"). Actually, Python is more object-oriented than Java. In Python, everything is an object. We have no distinction between boxed

Re: Encapsulation, inheritance and polymorphism

2012-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2012 15:40:00 +0100, Lipska the Kat wrote: [...] >> Even with a break, why bother continuing through the body of the >> function when you already have the result? When your calculation is >> done, it's done, just return for goodness sake. You wouldn't write a >> search that keeps goi

Re: Odd csv column-name truncation with only one column

2012-07-19 Thread Steven D'Aprano
On Thu, 19 Jul 2012 06:21:58 -0500, Tim Chase wrote: > tim@laptop:~/tmp$ python > Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. import csv from cStringIO import StringIO s = StringIO('E

Re: Encapsulation, inheritance and polymorphism

2012-07-19 Thread Steven D'Aprano
On Wed, 18 Jul 2012 23:09:13 -0700, rusi wrote: > Its not so much a question of language as in programming as language as > in layman-speak. > One characteristic with our field is that we take ordinary words and > then distort them so much the original meaning is completely lost. All technical fi

Re: Encapsulation, inheritance and polymorphism

2012-07-20 Thread Steven D'Aprano
On Thu, 19 Jul 2012 09:06:45 -0400, Roy Smith wrote: > Heh. This reminds me of one of my current pet peeves. I've run across > documentation for more than one Python project (django is the one that > comes to mind, but I'm sure there's others) which misuse words like > "set" and "list". They're

Re: Encapsulation, inheritance and polymorphism

2012-07-20 Thread Steven D'Aprano
On Thu, 19 Jul 2012 13:50:36 -0500, Tim Chase wrote: > On 07/19/12 13:28, Chris Angelico wrote: >> On Fri, Jul 20, 2012 at 4:20 AM, Tim Chase >> wrote: >>> Sure it terminates...If you don't run out of RAM to represent the >>> number "i" in question, there's also this "heat death of the universe"

Re: Encapsulation, inheritance and polymorphism

2012-07-20 Thread Steven D'Aprano
On Fri, 20 Jul 2012 08:20:57 +1000, Chris Angelico wrote: >>> Since the current evidence indicates the universe will just keep >>> expanding, it's more of a "deep freeze death..." >> >> Heat death means *lack* of heat. > > The second law of thermodynamics states that energy tends to go from

Re: Google the video blah blah jews blah blah 9/11 blah blah conspiracy blah cia blah blah blah zionist blah blah brainwashing blah blah blah

2012-07-20 Thread Steven D'Aprano
On Thu, 19 Jul 2012 10:27:02 -0400, Matty Sarro wrote: > I must be a Jew or a traitor as I keep deleting this email. You might be both. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Odd csv column-name truncation with only one column

2012-07-20 Thread Steven D'Aprano
On Thu, 19 Jul 2012 15:52:12 +0200, Hans Mulder wrote: > Perhaps it should be documented that the Sniffer doesn't work on > single-column data. > > If you really need to read a one-column csv file, you'll have to find > some other way to produce a Dialect object. Perhaps the predefined > 'cvs.ex

Re: ANN: dbf.py 0.94

2012-07-20 Thread Steven D'Aprano
On Fri, 20 Jul 2012 16:59:21 -0700, Ethan Furman wrote: > Getting closer to a stable release. Excellent! That's fantastic news! I've been waiting for a stable release of dbf for months! I just have one question. What is dbf? > Latest version has a simpler, cleaner API, and works on PyPy (and

Re: ANN: dbf.py 0.94

2012-07-20 Thread Steven D'Aprano
On Fri, 20 Jul 2012 19:56:59 -0700, Temia Eszteri wrote: >>I don't generally click on arbitrary links to find out whether or not >>the link is something that interests me enough to click on it. > > Can't really call a cheese shop link arbitrary. It's in the best place > it could be for providing

Re: ANN: dbf.py 0.94

2012-07-20 Thread Steven D'Aprano
On Sat, 21 Jul 2012 13:30:40 +1000, Simon Cropper wrote: > Works with PyPy, OK. > > Hopefully works with other implementations, Hm, what does this mean? I guess that Ethan means that his library definitely works with PyPy and CPython, because he has tested it on those, and that he expects that

Re: PyPy, is it a 1:1 replacement for CPython?

2012-07-20 Thread Steven D'Aprano
On Sat, 21 Jul 2012 13:35:21 +1000, Simon Cropper wrote: > Hi, > > Can you use PyPy as a direct replacement for the normal python or is it > a specialized compiler that can only work with libraries that are > manipulated to operate within its constraints (if it has any). PyPy should work perfect

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 10:33:27 +0300, Jan Riechers wrote: > Hello Pythonlist, > > I have one very basic question about speed,memory friendly coding, and > coding style of the following easy "if"-statement in Python 2.7, but Im > sure its also the same in Python 3.x I assume that the following is m

Re: Sudden doubling of nearly all messages

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 06:48:29 -0400, Dave Angel wrote: > Has anybody else noticed the sudden double-posting of nearly all > messages in the python mailing list? No I have not. It sounds like a problem with your Usenet provider. Remember that this news group is a mirror of the mailing list python

Re: Sudden doubling of nearly all messages

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 19:07:28 -0400, Devin Jeanpierre wrote: > People hold grudges against MS too strongly, and they believe too much > in Google's righteousness. They are both big companies that don't > necessarily care about you. +1 Google's motto "Don't be evil" should really be, "Don't b

Re: My first ever Python program, comments welcome

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 20:40:46 +0100, MRAB wrote: > On 21/07/2012 20:08, Lipska the Kat wrote: >> l=sorted(l, key=itemgetter(0)) > > Short is: > > l.sort(key=itemgetter(0)) Shorter, and the semantics are subtly different. The sorted function returns a copy of the input list. The list.s

Re: My first ever Python program, comments welcome

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 16:10:51 -0400, Dave Angel wrote: >> with fileinput.input(files=(filename)) as f: > > fileinput is much more general than you want for processing a single > file. That may be deliberate, if you're picturing somebody using > wildcards on their input. But if so, you should pro

Re: Converting a list of strings into a list of integers?

2012-07-22 Thread Steven D'Aprano
On Sun, 22 Jul 2012 19:20:18 +0300, Jan Riechers wrote: > "map" works on a list and does commandX (here "int" conversion, use > "str" for string.. et cetera) on sequenceY, returning a sequence. More > in the help file. > > And if I'm not completely mistaken, it's also the quicker way to do > perf

Re: default repr?

2012-07-22 Thread Steven D'Aprano
On Mon, 23 Jul 2012 08:54:00 +1000, Chris Angelico wrote: > On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg > wrote: >> If a class has defined its own __repr__ method, is there a way of >> getting the default repr output for that class anyway? If the class, call it C, is a subclass of some other

Re: default repr?

2012-07-22 Thread Steven D'Aprano
On Mon, 23 Jul 2012 10:29:33 +1000, Chris Angelico wrote: > On Mon, Jul 23, 2012 at 10:24 AM, Steven D'Aprano > wrote: >>> Methods are just functions, and you can call any method of any class >>> with any object as its first parameter. >> >> Not quite:

Re: the meaning of r’.......‘

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 17:59:42 +1000, Chris Angelico wrote: > On Fri, Jul 20, 2012 at 5:56 PM, levi nie wrote: >> the meaning of r’...‘? > > It's a raw string. Technically, no, it's a SyntaxError, because the Original Poster has used some sort of "Smart Quotes" characters r’‘ inste

Re: dict: keys() and values() order guaranteed to be same?

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 13:58:37 +0200, Stefan Behnel wrote: > Philipp Hagemeister, 23.07.2012 13:40: >> On 07/23/2012 01:23 PM, Henrik Faber wrote: >>> With an arbitrary dictionaty d, are d.keys() and d.values() guaraneed >>> to be in the same order? >> >> Yes. From the documentation[1]: >> >> If i

Re: the meaning of r.......ïŸ

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 08:55:22 -0400, Roy Smith wrote: > Some day, we're going to have programming languages that take advantage > of the full unicode character set. I don't know about the full Unicode character set, since there are many more than 1 characters, and few languages require that m

Re: the meaning of rユ.......�¾

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 23:06:45 +1000, Chris Angelico wrote: > On Mon, Jul 23, 2012 at 10:55 PM, Roy Smith wrote: >> Some day, we're going to have programming languages that take advantage >> of the full unicode character set. Right now, we're working in ASCII >> and creating silly digrams/trigrams

Re: the meaning of rユ.......ï¾

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 15:24:21 +0200, Henrik Faber wrote: > I disagree. Firstly, Python could already support the different types of > strings even with the ASCII character set. For example, the choice could > have made to treat the apostophe string 'foo' differently from the > double quote string "

Re: the meaning of rユ.......ï¾

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 15:52:32 +0200, Henrik Faber wrote: > If you allow for UTF-8 identifiers you'll have to be horribly careful > what to include and what to exclude. Is the non-breaking space a valid > character for a identifier? Technically it's a different character than > the normal space, so

Re: the meaning of rユ.......ï¾

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 16:29:33 +0100, Mark Lawrence wrote: > On 23/07/2012 15:43, Henrik Faber wrote: [...] >> I might wait until April 1st next year with that ;-) >> >> Best regards, >> Henrik >> >> > Sorry not with you is there something special about April 1st next year? As a Brit (or at least s

Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 17:44:27 -0400, Terry Reedy wrote: > On 7/23/2012 8:51 AM, Alexander Serebrenik wrote: >> Do you participate in StackOverflow discussions? >> >> As a part of a joint on-going research effort of the Brunel University >> (UK) and Eindhoven University of Technology (The Netherland

Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 22:51:07 -0400, Devin Jeanpierre wrote: > On Mon, Jul 23, 2012 at 9:30 PM, Steven D'Aprano > wrote: >>> Leaving aside the point that this is not directly related to Python, >>> my opinion is that if the authors will not make past and future pap

Re: python package confusion

2012-07-23 Thread Steven D'Aprano
On Mon, 23 Jul 2012 06:22:45 -0400, Devin Jeanpierre wrote: > Also adding . to the import search path is probably a bad diea. I don't know about a bad idea or not, but it is certainly redundant, because Python automatically adds '' (equivalent to '.') to the very start of the search path. --

Re: groveling over a file for Q:: and A:: stmts

2012-07-24 Thread Steven D'Aprano
On Tue, 24 Jul 2012 00:50:22 -0700, paul618 wrote: > #!/usr/bin/env python > # grep_for_QA.py I am only looking to isolate uniq Q:: and A:: stmts > from my daily files # > # note: This algorithm will fail if there are any blank lines within > the Q and A area of interest (a paragraph) > > # D.

Re: What's wrong with this code?

2012-07-24 Thread Steven D'Aprano
On Tue, 24 Jul 2012 09:47:38 +0200, Ulrich Eckhardt wrote: > [0] Note that in almost all cases, when referring to a tag, Python > implicitly operates on the object attached to it. One case (the only > one?) where it doesn't is the "del" statement. Name-binding: x = 1 operates on the name "x", n

Re: Gender, Representativeness and Reputation in StackOverflow

2012-07-24 Thread Steven D'Aprano
t; despite the reasons for the boycott, the product has some value. They >> > boycott it because by doing so, they can get something better than >> > or -- they can get > > badness>. (At least, in theory :) >> >> > On Jul 24, 10:34 am, Steven D'

Re: the meaning of rユ.......ï¾

2012-07-24 Thread Steven D'Aprano
On Wed, 25 Jul 2012 13:07:03 +1000, Ben Finney wrote: > Maarten writes: > >> You just missed it: >> 22/7 > > Which is appropriate, since 22/7 misses π by a wide margin. (355/113 is > my favourite approximation to π, and is far more accurate.) Approximation? Pffft. I use the exact value: π = 1

Re: from future import pass_function

2012-07-25 Thread Steven D'Aprano
On Wed, 25 Jul 2012 10:40:45 +0200, Ulrich Eckhardt wrote: > Hi! > > I just had an idea, it occurred to me that the pass statement is pretty > similar to the print statement, [...] > try: > do_something() > except: > pass() What's the point of this? If you intend to do n

Re: from future import pass_function

2012-07-26 Thread Steven D'Aprano
On Thu, 26 Jul 2012 08:39:25 +0200, Ulrich Eckhardt wrote: > I have seen code that just created a list comprehension to iterate over > something but was discarding the results. That could be a case for a "do > nothing" function. That would be a case for *not* using a list comprehension. Using a

Re: from future import pass_function

2012-07-26 Thread Steven D'Aprano
On Thu, 26 Jul 2012 08:59:30 +0200, Ulrich Eckhardt wrote: > Am 26.07.2012 04:38, schrieb Steven D'Aprano: >> The examples of pass-as-a-function shown by the Original Poster don't >> give any clue of what advantage there is to make pass a function. > > Just read

Re: from future import pass_function

2012-07-26 Thread Steven D'Aprano
On Thu, 26 Jul 2012 13:45:23 +0200, Ulrich Eckhardt wrote: > I didn't say "Pass should be a function!" but asked "What do you > think?". You are assuming lots of things about my goals and jumping to > conclusions like that I'm complaining about the stupid Python syntax, > that I'm a frustrated noo

Re: Generating valid identifiers

2012-07-26 Thread Steven D'Aprano
On Thu, 26 Jul 2012 14:26:16 +0200, Laszlo Nagy wrote: > I do not want this program to generate very long identifiers. It would > increase SQL parsing time, Will that increase in SQL parsing time be more, or less, than the time it takes to generate CRC32 or SHA hashsums and append them to a trun

Re: Generating valid identifiers

2012-07-26 Thread Steven D'Aprano
On Thu, 26 Jul 2012 13:28:26 -0600, Ian Kelly wrote: > The odds of a given pair of identifiers having the same digest to 10 hex > digits are 1 in 16^10, or approximately 1 in a trillion. Unless an attacker can select the field names, in which case they may be able to improve those odds significa

Re: dynamic setattr

2012-07-27 Thread Steven D'Aprano
On Fri, 27 Jul 2012 05:49:45 -0700, Mariano Di Felice wrote: > Hi, > I have a property file (.ini) that has multiple sections and relative > keys, as default structure. Have you looked at Python's standard INI file library? http://docs.python.org/library/configparser.html > Now, I would li

Re: Python Error

2012-07-29 Thread Steven D'Aprano
On Sun, 29 Jul 2012 05:30:15 -0700, subhabangalore wrote: > Dear Peter, > Thanks for the answer. But my list does not contain another list that is > the issue. Intriguing. That is not what the error message says. You said that this line of code: set1=set(list1) gives this error: TypeE

Extracting bit fields from an IEEE-784 float

2012-07-29 Thread Steven D'Aprano
I wish to extract the bit fields from a Python float, call it x. First I cast the float to 8-bytes: s = struct.pack('=d', x) i = struct.unpack('=q', s)[0] Then I extract the bit fields from the int, e.g. to grab the sign bit: (i & 0x8000) >> 63 Questions: 1) Are there any known i

Re: simplified Python parsing question

2012-07-29 Thread Steven D'Aprano
On Sun, 29 Jul 2012 19:21:49 -0400, Eric S. Johansson wrote: > When you are sitting on or in a name, you look to the left or look to > the right what would you see that would tell you that you have gone past > the end of that name. For example Have you read the docs? It gives full details of the

Re: simplified Python parsing question

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 11:40:50 -0400, Eric S. Johansson wrote: > If you have been reading the papers, you would understand what I'm > doing. That is the second time, at least, that you have made a comment like that. Understand that most people are not going to follow links to find out whether or

Re: ANN: visage (interfaces)

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 18:41:19 -0700, jwp wrote: >> BTW I think if you rename the ReStructured Text docs to .rst github >> will automatically render them. > > Did not know that. Gonna go do a lot of git mv's now. Do *one* and see if github actually does render it. Then do the rest. -- Steven --

Re: Is Python a commercial proposition ?

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 14:09:38 +, Grant Edwards wrote: > On 2012-07-30, Stefan Behnel wrote: > >> Still, you may still get away with the above statement by providing a >> sufficiently narrow definition of "standalone". By my definition, there >> isn't much "standalone" code out there. Most cod

Re: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 19:32:47 +, Prasad, Ramit wrote: >> >> I would suggest you change the theme -- using Firefox 3.6 the page >> >> is very difficult to read. >> > >> > Thanks for the report. Do you mind if I ask why you are using such an >> > old version? >> > (It looks fine with Firefox 14.0

Re: Is Python a commercial proposition ?

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 21:45:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> And at that level, you aren't going to write your app in Python anyway, >> and not because of the GIL. (These microcontrollers are unlikely to >> have multiple cores -- why the hel

Re: CRC-checksum failed in gzip

2012-08-01 Thread Steven D'Aprano
On Wed, 01 Aug 2012 14:01:45 +0100, andrea crotti wrote: > Full traceback: > > Exception in thread Thread-8: "DANGER DANGER DANGER WILL ROBINSON!!!" Why didn't you say that there were threads involved? That puts a completely different perspective on the problem. I *was* going to write back an

Re: Calling Values

2012-08-03 Thread Steven D'Aprano
On Fri, 03 Aug 2012 04:49:46 -0700, Subhabrata wrote: > I am preferring not to use argument passing It's not 1964 any more and you're not programming in BASIC. What you have just told us is that you prefer not to write good quality programs, and that you prefer to write buggy, hard to maintain

Re: Eclipse and the Python plugin

2012-08-03 Thread Steven D'Aprano
On Fri, 03 Aug 2012 16:51:26 +0100, lipska the kat wrote: > I can write a > Python class and call it Foo and save it in a file called Bar and it's > no big deal (at least Eclipse doesn't get excited) If I try that in Java > the sky falls in. :) Correct. Python does not require, or even encourage

Re: attribute is accessed from Nonetype

2012-08-03 Thread Steven D'Aprano
On Sat, 04 Aug 2012 08:41:20 +1000, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >> Python is case sensitive. > > There isn't a NoneType either. I get a NameError. Shame on you :-P Ramit Prasad

Re: Deciding inheritance at instantiation?

2012-08-03 Thread Steven D'Aprano
On Fri, 03 Aug 2012 13:48:08 -0700, Tobiah wrote: > I have a bunch of classes from another library (the html helpers from > web2py). There are certain methods that I'd like to add to every one of > them. So I'd like to put those methods in a class, and pass the parent > at the time of instantiat

Re: attribute is accessed from Nonetype

2012-08-03 Thread Steven D'Aprano
On Fri, 03 Aug 2012 19:03:20 -0400, Dave Angel wrote: > On 08/03/2012 06:41 PM, Chris Angelico wrote: >> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >>> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >>> Python is case sensitive. >> There isn't a NoneType either. I get

On-topic: alternate Python implementations

2012-08-03 Thread Steven D'Aprano
Most people are aware, if only vaguely, of the big Four Python implementations: CPython, or just Python, the reference implementation written in C. IronPython, written in .NET. Jython, written in Java. PyPy, the optimizing implementation written in Python (actually, it's written in a subset of P

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote: > And not to forget Cython, which is the only static Python compiler that > is widely used. Compiles and optimises Python to C code that uses the > CPython runtime and allows for easy manual optimisations to get C-like > performance out of i

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 16:34:17 +1000, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano > wrote: >> CLPython, an implementation of Python written in Common Lisp. >> >> Berp - a compiler which works by translating Python to Haskell and >

Re: when an iterable object is exhausted or not

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 12:44:07 -0700, Tim Roberts wrote: >>$$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') >>$$$ for x in i : print(x,end=' ') >>1 2 3 >>$$$ for x in i : print(x,end=' ')# i is exhausted >>$$$ >> >>IMHO, this should not happen in Py3k. > > It's interesting that it DOESN'T

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 08:59:18 -0700, Paul Rubin wrote: > C isn't so great for high-assurance stuff either, compared to (say) Ada. > People do use it in critical apps, but that's just because it is (or > anyway used to be) so ubiquitous. And then they are shocked, SHOCKED I say!, when their app has

Re: when an iterable object is exhausted or not

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 21:20:36 +0200, Franck Ditter wrote: > Two similar iterable objects but with a different behavior : [...] > IMHO, this should not happen in Py3k. What is the rationale of this (bad > ?) design, which forces the programmer to memorize which one is > exhaustable and which one is

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 18:38:33 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Runtime optimizations that target the common case, but fall back to >> unoptimized code in the rare cases that the optimization doesn't apply, >> offer the opportunity of big speedu

Re: conditional running of code portion

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 21:16:04 -0700, JW Huang wrote: > Hi, > > How can I implement something like C++'s conditional compile. > > if VERBOSE_MODE: print debug information else: do nothing > > But I don't want this condition to be checked during runtime as it will > slow down the code. You've pr

Re: Intermediate Python user needed help

2012-08-05 Thread Steven D'Aprano
On Sun, 05 Aug 2012 12:51:31 -0700, John Mordecai Dildy wrote: > Ive tried to delete the spaces in 75 and 76 to see if it made a change > but it has not made a difference to it. What made you think that the problem could be fixed by deleting *spaces*? In general, making random changes to code in

Re: Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
On Sun, 05 Aug 2012 18:45:47 -0400, Dennis Lee Bieber wrote: > Don't look for Object-Oriented Programming -- since the first widely > popular OOP language was C++ (Smalltalk was earlier, but rather > specialized, whereas C++ started as a preprocessor for C). > > Rather look for Object-Oriented An

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: > > Object Oriented programming is a mindset, a way of looking at that > particular part of our world that you are trying to encapsulate in > computer language. The language you use is (should be) irrelevant. That depends on how you defin

<    1   2   3   4   5   6   7   8   9   10   >