Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Ian Kelly
On Mon, Nov 28, 2011 at 7:42 PM, Travis Parks wrote: > I find that interesting. I also find it interesting that the common > functional methods (all, any, map, filter) are basically built into > Python core language. That is unusual for most imperative programming > languages early-on. all and an

Re: Pragmatics of the standard is() function

2011-11-28 Thread alex23
On Nov 29, 5:22 am, Den wrote: > On Nov 26, 3:01 pm, Steven D'Aprano > That is correct. You probably should rarely use `is`. Apart from testing > > for None, use of `is` should be rare. > > With respect, I disagree with advice that the use of a language > construct should be rare.  All constructs

Re: python 2.5 and ast

2011-11-28 Thread Dave Angel
On 11/28/2011 03:08 PM, Terry Reedy wrote: On 11/28/2011 6:45 AM, Andrea Crotti wrote: I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the sou

Re: Does py2app improves speed?

2011-11-28 Thread Dave Angel
On 11/28/2011 03:03 PM, Alan Meyer wrote: On 11/24/2011 9:27 AM, Dave Angel wrote: ... Several ways to speed up code. 1) use language features to best advantage 2) use 3rd party libraries that do certain things well 3) use best algorithms, subject to #1 and #2 4) have someone else review the co

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 28, 5:57 pm, Steven D'Aprano wrote: > On Mon, 28 Nov 2011 13:29:06 -0800, Travis Parks wrote: > > Exception handling is one of those subjects few understand and fewer can > > implement properly in modern code. Languages that don't support > > exceptions as part of their signature lead to ca

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 28, 8:49 pm, Chris Angelico wrote: > On Tue, Nov 29, 2011 at 11:54 AM, DevPlayer wrote: > > To me, I would think the interpreter finding the coder's intended > > indent wouldn't be that hard. And just make the need for consistant > > spaces or tabs irrevelent simply by reformatting the ind

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Chris Angelico
On Tue, Nov 29, 2011 at 1:42 PM, Travis Parks wrote: > A good example I have run into is recursion. When a local function > calls itself, the name of the function may not be part of scope (non- > local). Languages that support tail-end recursion optimization can't > optimize. In order to support t

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 28, 5:24 pm, Steven D'Aprano wrote: > On Mon, 28 Nov 2011 12:32:59 -0700, Ian Kelly wrote: > > On Sun, Nov 27, 2011 at 4:55 PM, Steven D'Aprano > > wrote: > [...] > >>> Lambdas and functions are the same thing in my language, so no need > >>> for a special keyword. > > >> That does not fol

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Chris Angelico
On Tue, Nov 29, 2011 at 11:54 AM, DevPlayer wrote: > To me, I would think the interpreter finding the coder's intended > indent wouldn't be that hard. And just make the need for consistant > spaces or tabs irrevelent simply by reformatting the indent as > expected. Pretty much all my text editors

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread DevPlayer
> I do not understand why the interpreter preprocesses each logical line > of source code using something as simple as this: correction: I do not understand why the interpreter - does not- preprocess each logical line of source code using something as simple as this: -- http://mail.python.org/m

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread DevPlayer
On Nov 27, 6:55 pm, Steven D'Aprano wrote: > On Sun, 27 Nov 2011 14:21:01 -0800, Travis Parks wrote: > > Personally, I find a lot of good things in Python. I thinking tabs are > > out-of-date. Even the MAKE community wishes that the need for tabs would > > go away and many implementations have don

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Steven D'Aprano
On Mon, 28 Nov 2011 13:29:06 -0800, Travis Parks wrote: > Exception handling is one of those subjects few understand and fewer can > implement properly in modern code. Languages that don't support > exceptions as part of their signature lead to capturing generic > Exception all throughout code. It

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Chris Angelico
On Tue, Nov 29, 2011 at 9:24 AM, Steven D'Aprano wrote: > Because the syntax is completely different. One is a statement, and > stands alone, the other is an expression. Even putting aside the fact > that lambda's body is an expression, and a def's body is a block, def > also requires a name. Usin

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Steven D'Aprano
On Mon, 28 Nov 2011 12:32:59 -0700, Ian Kelly wrote: > On Sun, Nov 27, 2011 at 4:55 PM, Steven D'Aprano > wrote: [...] >>> Lambdas and functions are the same thing in my language, so no need >>> for a special keyword. >> >> That does not follow. Lambdas and def functions are the same thing in >>

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Chris Angelico
On Tue, Nov 29, 2011 at 8:29 AM, Travis Parks wrote: > Languages that don't support > exceptions as part of their signature lead to capturing generic > Exception all throughout code. It is one of those features I wish .NET > had. At the same time, with my limited experience with Java, it has > bee

Re: Cursor.fetchall

2011-11-28 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: PS : Try to code & document in English, it's much better especially when asking for help on this list, mixing spanish and english has few benefits since you may bother both spanish and english ppl :o) Actually it is english mixed with portuguese, sorry if I offende

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 28, 3:40 pm, Gregory Ewing wrote: > Travis Parks wrote: > > I thinking tabs are > > out-of-date. Even the MAKE community wishes that the need for tabs > > would go away > > The situation with make is a bit different, because it > *requires* tabs in certain places -- spaces won't do. > Pytho

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 28, 2:32 pm, Ian Kelly wrote: > On Sun, Nov 27, 2011 at 4:55 PM, Steven D'Aprano > > wrote: > >> My language combines generators and collection initializers, instead of > >> creating a whole new syntax for comprehensions. > > >> [| for i in 0..10: for j in 0.10: yield return i * j |] > > >

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Neil Cerutti
On 2011-11-28, Gregory Ewing wrote: > Neil Cerutti wrote: >> I've always held with the "anti-functional style conspiracy" >> interpretation of Python's lambda expressions. They were added >> but grudgingingly, made weak on purpose to discourage their >> use. > > Seems to me that Python's lambdas a

Re: remove characters before last occurance of "."

2011-11-28 Thread plsullivan1
Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: remove characters before last occurance of "."

2011-11-28 Thread Arnaud Delobelle
On 28 November 2011 20:45, Ethan Furman wrote: > plsulliv...@gmail.com wrote: >> >> s = GIS.GIS.Cadastral\GIS.GIS.Citylimit >> NeededValue = Citylimit > > NeededValue = s.rsplit('.', 1)[1] Also: >>> s[s.rfind(".") + 1:] 'Citylimit' >>> s.rpartition(".")[2] 'Citylimit' -- Arnaud -- http://mail

Re: remove characters before last occurance of "."

2011-11-28 Thread Ethan Furman
plsulliv...@gmail.com wrote: s = GIS.GIS.Cadastral\GIS.GIS.Citylimit NeededValue = Citylimit NeededValue = s.rsplit('.', 1)[1] ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Alemu mihretu
Hello all, My python runs and crashes after another run. I am getting errors like Microsoft Visual C++ Runtime Library program c:\Python27\pythonw.exe This application has requested the Runtime to terminate it in an usuak way. Please contact the application's support team for more information.

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Gregory Ewing
Neil Cerutti wrote: I've always held with the "anti-functional style conspiracy" interpretation of Python's lambda expressions. They were added but grudgingingly, made weak on purpose to discourage their use. Seems to me that Python's lambdas are about as powerful as they can be given the stat

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Gregory Ewing
Travis Parks wrote: I thinking tabs are out-of-date. Even the MAKE community wishes that the need for tabs would go away The situation with make is a bit different, because it *requires* tabs in certain places -- spaces won't do. Python lets you choose which to use as long as you don't mix them

Re: Pragmatics of the standard is() function

2011-11-28 Thread Ethan Furman
Den wrote: With respect, I disagree with advice that the use of a language construct should be rare. All constructs should be used *appropriately*. +1 ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

remove characters before last occurance of "."

2011-11-28 Thread plsullivan1
I need for GIS.GIS.Cadastral\GIS.GIS.Citylimit to be Citylimit. The "cadastral" and "citylimit" will be different as I readlines from a list. In other words, the above could be GIS.GIS.Restricted\GIS.GIS.Pipeline and I would need Pipeline. s = GIS.GIS.Cadastral\GIS.GIS.Citylimit NeededValue = C

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Neil Cerutti
On 2011-11-28, Ian Kelly wrote: > I think the implication is that Unit has only one syntax for > creating functions, which is lambda-style. In any case, why > does Python require a special keyword? def is only used in a > statement context, and lambda is only used in an expression > context. Wh

Re: python 2.5 and ast

2011-11-28 Thread Terry Reedy
On 11/28/2011 6:45 AM, Andrea Crotti wrote: I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the source from the ast helpers in my code base T

Re: Does py2app improves speed?

2011-11-28 Thread Alan Meyer
On 11/24/2011 9:27 AM, Dave Angel wrote: ... Several ways to speed up code. 1) use language features to best advantage 2) use 3rd party libraries that do certain things well 3) use best algorithms, subject to #1 and #2 4) have someone else review the code (perhaps on the list, perhaps within you

Re: Pragmatics of the standard is() function

2011-11-28 Thread Den
On Nov 26, 3:01 pm, Steven D'Aprano wrote: > On Sat, 26 Nov 2011 22:20:36 +0100, candide wrote: >>SNIP<< > > That is correct. You probably should rarely use `is`. Apart from testing > for None, use of `is` should be rare. > > -- > Steven With respect, I disagree with advice that the use of a lang

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Ian Kelly
On Sun, Nov 27, 2011 at 4:55 PM, Steven D'Aprano wrote: >> My language combines generators and collection initializers, instead of >> creating a whole new syntax for comprehensions. >> >> [| for i in 0..10: for j in 0.10: yield return i * j |] > > Are we supposed to intuit what that means? > > Is

Re: Return of an old friend

2011-11-28 Thread Den
On Nov 25, 2:13 am, Noah Hall wrote: > On Fri, Nov 25, 2011 at 5:08 AM, Matt Joiner wrote: > > I haven't heard of you before, but feel like I've missed out on something. > > > Do you (or someone else) care to link to some of your more contentious work? > > Ignore him, he's a troll with an unjustl

Re: correct usage of a generator?

2011-11-28 Thread Tim
thanks everyone. I thought blarg.next() looked a little strange--I'm just learning generators now and I'm glad too see that next(blarg) is the way to go. The example really was just a toy or I would use an iterator. I do need the two (well, the several) generators to not be coupled together so t

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread Travis Parks
On Nov 27, 6:55 pm, Steven D'Aprano wrote: > On Sun, 27 Nov 2011 14:21:01 -0800, Travis Parks wrote: > > Personally, I find a lot of good things in Python. I thinking tabs are > > out-of-date. Even the MAKE community wishes that the need for tabs would > > go away and many implementations have don

Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-11-28 Thread Stefan Behnel
Adam Funk, 25.11.2011 14:50: I'm converting JSON data to XML using the standard library's json and xml.dom.minidom modules. I get the input this way: input_source = codecs.open(input_file, 'rb', encoding='UTF-8', errors='replace') It doesn't make sense to use codecs.open() with a "b" mode.

Re: mailbox module difficulties

2011-11-28 Thread Eduardo Alvarez
On 2011-11-28, Peter Otten <__pete...@web.de> wrote: > Eduardo Alvarez wrote: > >> however, if I do the following: >> >> b = mailbox.Maildir("~/Maildir") >> b.items() >> >> I get an empty list. >> >> I don't understand why this is so, specially since the last example in >> the documentation show

Re: correct usage of a generator?

2011-11-28 Thread Mel Wilson
Tim wrote: > Hi, I need to generate a list of file names that increment, like this: > fname1 > fname2 > fname3 and so on. > > I don't know how many I'll need until runtime so I figure a generator is > called for. > > def fname_gen(stem): > i = 0 > while True: > i = i+1 >

Re: mailbox module difficulties

2011-11-28 Thread Peter Otten
Eduardo Alvarez wrote: > however, if I do the following: > > b = mailbox.Maildir("~/Maildir") > b.items() > > I get an empty list. > > I don't understand why this is so, specially since the last example in > the documentation shows a reference to a Maildir object being created. > Why does this

Re: mailbox module difficulties

2011-11-28 Thread Chris Angelico
On Tue, Nov 29, 2011 at 4:21 AM, Eduardo Alvarez wrote: > if I call a Maildir object directly, the module works perfectly. I can, > for example, call > > mailbox.Maildir("~/Maildir").items() > > and get the expected list of (key,Message) pairs. > > however, if I do the following: > > b = mailbox.M

mailbox module difficulties

2011-11-28 Thread Eduardo Alvarez
Hello, everyone, I'm in the process of learning how to use the mailbox module with python 3.2. I've noticed the following seemingly inconsistent behavior: if I call a Maildir object directly, the module works perfectly. I can, for example, call mailbox.Maildir("~/Maildir").items() and get the e

Re: correct usage of a generator?

2011-11-28 Thread Neil Cerutti
On 2011-11-28, Steven D'Aprano wrote: > On Mon, 28 Nov 2011 07:36:17 -0800, Tim wrote: >> Hi, I need to generate a list of file names that increment, like this: >> fname1 >> fname2 >> fname3 and so on. >> >> I don't know how many I'll need until runtime so I figure a >> generator is called for. >

Re: correct usage of a generator?

2011-11-28 Thread Peter Otten
Tim wrote: > Hi, I need to generate a list of file names that increment, like this: > fname1 > fname2 > fname3 and so on. > > I don't know how many I'll need until runtime so I figure a generator is > called for. > > def fname_gen(stem): > i = 0 > while True: > i = i+1 >

Re: correct usage of a generator?

2011-11-28 Thread Steven D'Aprano
On Mon, 28 Nov 2011 07:36:17 -0800, Tim wrote: > Hi, I need to generate a list of file names that increment, like this: > fname1 > fname2 > fname3 and so on. > > I don't know how many I'll need until runtime so I figure a generator is > called for. > > def fname_gen(stem): > i = 0 > whil

Re: Proper way to delete/kill a logger?

2011-11-28 Thread cassiope
Thanks Chris and JM, I will explore how much work it's going to take to change the various scripts to _always_ starting the logger from main(). As further explanation - this code predates the logging module, and many of the functions/classes had an optional argument for the home- made logger - and

correct usage of a generator?

2011-11-28 Thread Tim
Hi, I need to generate a list of file names that increment, like this: fname1 fname2 fname3 and so on. I don't know how many I'll need until runtime so I figure a generator is called for. def fname_gen(stem): i = 0 while True: i = i+1 yield '%s%d' % (stem,i) blarg = fnam

Re: Proper way to delete/kill a logger?

2011-11-28 Thread Roy Smith
In article , Jean-Michel Pichavant wrote: > Loggers are static objects managed by the module itself. For reasons I can't quite explain, that sentence makes me want to sing The Lumberjack Song. "I'm a logger(*) and I'm OK..." (*) Yes, I know that's not right. -- http://mail.python.org/mailma

Re: sick of distribute, setup, and all the rest...

2011-11-28 Thread Andreas Perstinger
On 2011-11-28 14:14, rusi wrote: On Nov 28, 4:42 pm, Steven D'Aprano wrote: We don't chase people down on the street and lecture them about the problems we think they are having, we answer questions about ACTUAL problems that they have experienced and asking about. ... ever question gets

Re: sick of distribute, setup, and all the rest...

2011-11-28 Thread Steven D'Aprano
On Mon, 28 Nov 2011 05:14:27 -0800, rusi wrote: > On Nov 28, 4:42 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> We don't chase people down on the street and lecture them about the >> problems we think they are having, we answer questions about ACTUAL >> problems that they have ex

Re: Proper way to delete/kill a logger?

2011-11-28 Thread Jean-Michel Pichavant
cassiope wrote: I've been trying to migrate some code to using the standard python logging classes/objects. And they seem quite capable of doing what I need them to do. Unfortunately there's a problem in my unit tests. It's fairly common to have to create quite a few entities in the course of a

Re: Cursor.fetchall

2011-11-28 Thread Jean-Michel Pichavant
Jayron Soares wrote: Hi Felipe, I did, however I got this error: Traceback (most recent call last): File "/home/jayron/Downloads/grafos.py", line 48, in g, e = ministro_lei() File "/home/jayron/Downloads/grafos.py", line 34, in ministro_lei for i in G.degree(): TypeError: 'int' obj

Re: sick of distribute, setup, and all the rest...

2011-11-28 Thread rusi
On Nov 28, 4:42 pm, Steven D'Aprano wrote: > We don't chase people down on the street and lecture them about the > problems we think they are having, we answer questions about ACTUAL > problems that they have experienced and asking about. > ... ever question gets an answer, and we're discussing >

Re: Pragmatics of the standard is() function

2011-11-28 Thread Jean-Michel Pichavant
candide wrote: In which cases should we use the is() function ? The is() function compares identity of objects rather than values so I was wondering in which circumstances comparing identities of objects is really vital. Examining well reputated Python source code, I realize that is() functio

Re: Cursor.fetchall

2011-11-28 Thread Jayron Soares
Hi Felipe, I did, however I got this error: Traceback (most recent call last): File "/home/jayron/Downloads/grafos.py", line 48, in g, e = ministro_lei() File "/home/jayron/Downloads/grafos.py", line 34, in ministro_lei for i in G.degree(): TypeError: 'int' object is not iterable I

Re: cmd.Cmd asking questions?

2011-11-28 Thread Robert Kern
On 11/28/11 12:12 PM, Tim Chase wrote: Are there best-practices for creating wizards or asking various questions (whether yes/no or text/numeric entry) in a cmd.Cmd class? Something like the imaginary confirm() and get_string() methods here: class MyCmd(cmd.Cmd): def do_name(self,line): s = get_

Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-11-28 Thread Steven D'Aprano
On Fri, 25 Nov 2011 13:50:01 +, Adam Funk wrote: > I'm converting JSON data to XML using the standard library's json and > xml.dom.minidom modules. I get the input this way: > > input_source = codecs.open(input_file, 'rb', encoding='UTF-8', > errors='replace') big_json = json.load(input_sour

cmd.Cmd asking questions?

2011-11-28 Thread Tim Chase
Are there best-practices for creating wizards or asking various questions (whether yes/no or text/numeric entry) in a cmd.Cmd class? Something like the imaginary confirm() and get_string() methods here: class MyCmd(cmd.Cmd): def do_name(self,line): s = get_string(prompt=line, defa

Re: Cursor.fetchall

2011-11-28 Thread Felipe Vinturini
Hi Jayron, Instead of using "Q" to loop over the result, use: "dbcursor". resp = dbcursor.fetchall() I hope it helps. Regards, Felipe. On Mon, Nov 28, 2011 at 9:54 AM, Jayron Soares wrote: > Hi guys! > > I'm stuck at a problem, when I run the follow code: > > http://pastebin.com/4Gd9V325 > >

Cursor.fetchall

2011-11-28 Thread Jayron Soares
Hi guys! I'm stuck at a problem, when I run the follow code: http://pastebin.com/4Gd9V325 I get this error: Traceback (most recent call last): File "/home/jayron/Downloads/grafos.py", line 49, in g, e = ministro_lei() File "/home/jayron/Downloads/grafos.py", line 24, in ministro_lei

python 2.5 and ast

2011-11-28 Thread Andrea Crotti
I'm happily using the ast module to analyze some code, but my scripts need also to run unfortunately on python 2.5 The _ast was there already, but the ast helpers not yet. Is it ok if I just copy over the source from the ast helpers in my code base or is there a smarter way? (I don't even need al

Re: sick of distribute, setup, and all the rest...

2011-11-28 Thread Steven D'Aprano
On Sun, 27 Nov 2011 23:18:15 -0800, rusi wrote: > On Nov 28, 9:37 am, alex23 wrote: > >> With that approach in mind, I've never had any real issues using pip, >> virtualenv etc for managing my development environment. > > Yes that is in a way my point also: we discuss (things like) pip, > virtu

Re: lxml precaching DTD for document verification.

2011-11-28 Thread Gelonida N
Thanks Stefan, On 11/28/2011 08:38 AM, Stefan Behnel wrote: > Gelonida N, 27.11.2011 18:57: >> I'd like to verify some (x)html / / html5 / xml documents from a server. >> >> These documents have a very limited number of different doc types / DTDs. >> >> So what I would like to do is to build a sm

Re: my new project, is this the right way?

2011-11-28 Thread 88888 Dihedral
On Sunday, November 27, 2011 4:49:14 PM UTC+8, 8 Dihedral wrote: > On Sunday, November 27, 2011 4:29:52 PM UTC+8, 8 Dihedral wrote: > > On Sunday, November 27, 2011 12:03:26 PM UTC+8, Matt Joiner wrote: > > > Sounds like you want a key-value store. If it's a lot of data, you may > > > still

Re: Proper way to delete/kill a logger?

2011-11-28 Thread Chris Withers
On 28/11/2011 04:16, cassiope wrote: I've been trying to migrate some code to using the standard python logging classes/objects. And they seem quite capable of doing what I need them to do. Unfortunately there's a problem in my unit tests. It's fairly common to have to create quite a few entiti