Re: Convert '165.0' to int

2011-07-21 Thread Terry Reedy
On 7/21/2011 10:13 AM, Grant Edwards wrote: On 2011-07-21, Web Dreamer wrote: Leo Jay a ?crit ce jeudi 21 juillet 2011 11:47 dans int(x.split('.')[0]) But, the problem is the same as with int(float(x)), the integer number is still not as close as possible as the original float value. Nobo

Re: a little parsing challenge ☺

2011-07-21 Thread Terry Reedy
On 7/21/2011 2:53 PM, Xah Lee wrote: had hopes that parser expert would show some proper parser solutions… in particular i think such can be expressed in Parsing Expression Grammar in just a few lines… but so far no deity came forward to show the light. lol I am not a parser expert but 20 year

Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Terry Reedy
On 7/21/2011 2:46 PM, Andrew Berg wrote: -BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 On 2011.07.21 01:32 PM, Thomas Jollans wrote: So, the PEP says: do not align operators. End of story. I'm pretty sure that colons, commas and equals signs are not operators. Whether or not they are in

Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Terry Reedy
On 7/22/2011 12:48 AM, rantingrick wrote: On Jul 21, 11:13 pm, Corey Richardson wrote: Excerpts from rantingrick's message of Thu Jul 21 23:46:05 -0400 2011: I may have found the mother of all inconsitency warts when comparing the zipfile and tarfile modules. Not only are the API's different,

Re: Inconsistencies between zipfile and tarfile APIs

2011-07-22 Thread Terry Reedy
On 7/22/2011 2:40 AM, rantingrick wrote: On Jul 22, 12:45 am, Terry Reedy wrote: Let me give some overall comments rather than respond point by point. Python-dev is a volunteer *human* community, not a faceless corporation, with an ever-changing composition (a very mutable set;-). It is

Re: [PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-22 Thread Terry Reedy
On 7/22/2011 4:26 AM, Lars Gustäbel wrote: On Thu, Jul 21, 2011 at 08:46:05PM -0700, rantingrick wrote: PS: I will be posting more warts very soon. This stdlib is a gawd awful mess! I do not agree. Although I come across one or two odd things myself from time to time, I think the stdlib as a

Re: Convert '165.0' to int

2011-07-22 Thread Terry Reedy
On 7/22/2011 1:55 AM, Frank Millman wrote: As the OP, I will clarify what *my* requirement is. This discussion has gone off at various tangents beyond what I was asking for. Typical. Don't worry about it ;-). As suggested above, I am only talking about a string containing int literals follow

Re: Inconsistencies between zipfile and tarfile APIs

2011-07-22 Thread Terry Reedy
On 7/22/2011 5:17 PM, Ned Deily wrote: In article, Terry Reedy wrote: This introduced the problem that upgrading to Python 3 is no longer a single thing. We really need 2to3.1 (the current 2to3), 2to3.2, 2to3.3, etc, but someone would have to make the new versions, but no one, currently, has

Re: learning another programing language

2011-07-24 Thread Terry Reedy
On 7/24/2011 4:59 AM, Benjamin Gregg wrote: Hi python was my first language but I need to learn C++ and java for a project (No there isn't an alternative) and I want to know is there any good tutorials or tips for learning C++/java after using python? Learn to meditate so you can deal with the

Re: Help with Latin Characters

2011-07-24 Thread Terry Reedy
On 7/24/2011 11:15 AM, Joao Jacome wrote: http://pastebin.com/aMrzczt4 list = os.listdir(dir) While somewhat natural, using 'list' as a local name and masking the builtin list function is a *very bad* idea. Someday you will do this and then use 'list(args)' expecting to call the list

python.org back up ?(was Re: python.org is down?)

2011-07-24 Thread Terry Reedy
On 7/24/2011 3:43 AM, Laszlo Nagy wrote: Can it be a problem on my side? I have tried from several different computers. I cannot even ping it. python.org, bugs.python.org, docs.python.org, pypi.python.org all work for me now. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/pytho

Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Terry Reedy
On 7/24/2011 8:51 PM, Michael Torrie wrote: Now replying to an existing thread to start an entirely new, unrelated thread is definitely rude. Rude or not, it tends to be unproductive. If someone posted "Help with threading internals" here, it could well not be seen by the appropriate people,

Re: Aw: Re: Aw: python.org back up ?(was Re: python.org is down?)

2011-07-25 Thread Terry Reedy
On 7/25/2011 7:25 AM, hackingKK wrote: Infact the first thing I ever did with documentation on Python was to download it. yes you are not uptodate but you can always do a download once in a while rather than putting load on the server every time you want to lookup a function reference. Happy hack

Re: Validating Entry in tkinter

2011-07-25 Thread Terry Reedy
On 7/25/2011 8:31 AM, Peter Otten wrote: Saul Spatz wrote: That doesn't work, I'm being stupid, The user might type anywhere in the string, not just at the end. I need return all([c in '1234567890abcdefABCDEF ' for c in after]) If one wants to validate keystrokes, rather than the entire fi

Re: Is this overuse a context manager?

2011-07-26 Thread Terry Reedy
On 7/26/2011 9:24 AM, Neil Cerutti wrote: I use them all the time now, even when the resource being managed is used for just one line, and never need be assigned an explicit name. Is it good style, or annoying? Annoying to you? or an actual or imagined audience? with open(in_fname, newli

Re: Only Bytecode, No .py Files

2011-07-26 Thread Terry Reedy
On 7/26/2011 3:32 PM, Dan Stromberg wrote: Another possibility: You could probably create a bunch of zero-length .py's that are older than the corresponding .pyc's. On Tue, Jul 26, 2011 at 8:19 AM, Eldon Ziegler mailto:eld...@atlanticdb.com>> wrote: Is there a way to have the Python proces

Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread Terry Reedy
On 7/26/2011 8:01 PM, rantingrick wrote: The "Fundamental Five" built-in functions There are quite a few helpful built in functions provided to the python programmer howev

Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Terry Reedy
On 7/26/2011 8:06 PM, llwa...@gmail.com wrote: Hello, I have been searching the example on C extension that works in python 3.1.x All the stdlib modules written in C. These are extension modules that come with Python. There are perhaps a hundred more on PyPI. Can any one who ever succeed

Re: Strings show as brackets with a 'u'.

2011-07-26 Thread Terry Reedy
On 7/26/2011 9:18 PM, goldtech wrote: Thank you. So what is happening? Is it that I'm in an environment that is not unicode and python is telling me the string (ie. n[0]) is unicode? Yes, n is a list and n[0] is a unicode string and you are using some 2.x, which is ascii/byte string based. Pyt

Re: NoneType and new instances

2011-07-28 Thread Terry Reedy
On 7/28/2011 5:03 PM, Ethan Furman wrote: I'm glad you asked! I'm using dictionaries to describe fields and what their return values should be. There happen to be two special cases: empty and Null. So a portion of the dictionary looks like: fielddef = { 'empty':some_func, 'null':some_func } De

Re: PyWart: os.path needs immediate attention!

2011-07-29 Thread Terry Reedy
On 7/29/2011 1:22 PM, rantingrick wrote: * Introduce a new method named "partition" which (along with string splitting methods) will replace the six methods "basename", "dirname", "split", "splitdrive", "splitunc", "splittext". The method will return a tuple of the path split into four parts:

Re: NoneType and new instances

2011-07-30 Thread Terry Reedy
Ethan's proposal was accepted on python-ideas. In Python 3.3, the classes for the singletons None, Ellipsis, and NotImplemented will be callables that return the singleton. It turns out that the reason an exception is now raised is that there currently is no .__new__ method, so an exception is

Re: PyWart: os.path needs immediate attention!

2011-07-30 Thread Terry Reedy
On 7/29/2011 8:50 PM, Steven D'Aprano wrote: Guido has a rule of thumb: "No constant arguments". Or another way to put it: if a function takes an argument which is nearly always a constant (usually, but not always, a flag) then it is usually better off as two functions. I do not really underst

Re: Wondering in the Python Forrest

2011-07-30 Thread Terry Reedy
On 7/30/2011 7:13 AM, ray wrote: I am new to Python and am learning for engineering and scientific use. For some reason, which I don’t remember, I went to Scipy.org downloaded the module. I am sure it had explained things but that was a couple weeks ago and it’s all a blur. So now I am working

Re: NoneType and new instances

2011-07-30 Thread Terry Reedy
On 7/30/2011 12:39 PM, bruno.desthuilli...@gmail.com wrote: On 28 juil, 17:39, Ethan Furman wrote: --> bool(0) is bool(0) True This test is not reliable It is in the sense that it will always work -- because False/True are doubletone constants and so documented. But expr is expr == Tr

Re: Early binding as an option

2011-08-02 Thread Terry Reedy
On 8/2/2011 12:55 PM, Chris Angelico wrote: As I understand it, Python exclusively late-binds names; when you define a function, nothing is ever pre-bound. By 'pre-bound' you presumably mean bound at definition time rather than call time. Default arg objects *are* pre-computed and pre-bound to

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Terry Reedy
On 8/3/2011 11:29 AM, Phlip wrote: This is either a code snippet, if you like it, or a request for a critique, if you don't. A learning exercise but pretty useless otherwise. As others pointed out, immediately stripping off \n is a bug relative to *your* function description. Also, you yours

Re: error compiling python, and "plat-linux2" versus "plat-linux3"

2011-08-04 Thread Terry Reedy
There has been some discussion about what to do with 'linux3'. See http://bugs.python.org/issue12326 for example. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Terry Reedy
On 8/5/2011 4:22 AM, Thomas Jollans wrote: On 05/08/11 09:20, Eric Snow wrote: Object available during code object execution: (M) no (C) no (F) no (F) yes. cf. recursion. Recursion only happens through runtime name resolution, not through direct access to the function or code object from wi

Re: Docstrings and class Attributes

2011-08-08 Thread Terry Reedy
On 8/8/2011 8:37 AM, Nick wrote: Is it possible to put a doc string on a class attribute? Class and function docstrings are generated from string expression statements at the beginning of a suite. class Test (object): '''classx''' fred = 10 '''attribute''' This is two stat

Re: Embedded python console and FILE* in python 3.2

2011-08-08 Thread Terry Reedy
On 8/8/2011 11:17 AM, Francis Labarre wrote: Hello everyone, I'm currentlytrying to port some embedded code from python 2.7 to python 3.2. The current code replicate the basic behavior of the python interpreter in an MFC application. When a command is entered in our embedded interpreter, we wri

Re: Docstrings and class Attributes

2011-08-08 Thread Terry Reedy
On 8/8/2011 2:26 PM, Steven D'Aprano wrote: Eric Snow wrote: On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: Is it possible to put a doc string on a class attribute? This really makes little sense. The purpose of docstrings is to give interactive help. The place to document data attributes of

Re: smtp

2011-08-08 Thread Terry Reedy
On 8/8/2011 12:26 PM, Chris Angelico wrote: As a side point: Does anyone else feel that it's potentially confusing to have a function whose parameter has the same name as the function itself? This is straight from the example. Yes. I might change it someday when I can. -- Terry Jan Reedy --

Re: smtp

2011-08-08 Thread Terry Reedy
On 8/8/2011 12:08 PM, Verde Denim wrote: I'm working on learning various aspects of Py coding, and happened to review the smtplib docs this morning. I entered the sample code from http://www.python.org/doc//current/library/smtplib.html When posting about error messages, please specify Python ve

Re: smtp

2011-08-08 Thread Terry Reedy
On 8/8/2011 12:45 PM, Verde Denim wrote: I'm running 2.6.5 on a debian base... It didn't seem to matter what is input - I tried using a single recipient as well as multiples (separated by comma). Output appears as - # python send_my_msg.py From: m...@me.com To: y...@you.com

Re: Object Diffs

2011-08-08 Thread Terry Reedy
On 8/8/2011 3:50 PM, Croepha wrote: Hello Python list: Hi I am doing research into doing network based propagation of python objects.In order to maintain network efficiency. I want to just send the differences of python objects, I was wondering if there was/is any other research or developmen

Re: just for fun: make a class (not its instances) iterable

2011-08-09 Thread Terry Reedy
On 8/9/2011 5:43 PM, Gelonida N wrote: Now I wondered whether there is any way to implement a class such, that I can write for val in MyClass: print val And what are the items in a class that you expect that to produce? I am pretty sure you can already do for val in MyClass.__dict__

Re: numpy/scipy: calculate definite integral of sampled data

2011-08-09 Thread Terry Reedy
numpy/scipy questions are best asked on the numpy/scipy user lists. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: just for fun: make a class (not its instances) iterable

2011-08-09 Thread Terry Reedy
On 8/9/2011 8:29 PM, Tim Chase wrote: On 08/09/2011 07:11 PM, Terry Reedy wrote: On 8/9/2011 5:43 PM, Gelonida N wrote: Now I wondered whether there is any way to implement a class such, that I can write for val in MyClass: print val And what are the items in a class that you expect that to

Re: Python 3.X: nonlocal support in eval/exec?

2011-08-11 Thread Terry Reedy
On 8/11/2011 3:19 AM, Paddy wrote: We can access nonlocal variables in a function, but if we were to eval/ exec the function we cannot set up a nested stack of evironment dicts. We are limited to just two: global and local. Right. That was and is Python's execution model. Note that when you exe

Re: allow line break at operators

2011-08-12 Thread Terry Reedy
On 8/12/2011 6:14 PM, Seebs wrote: I am responding to your whole line of posts. I have been indenting code neatly for at least 32 years whenever the language I used allowed it. Just over 14 years ago, when Python was an obscure little known or used languge, I adopted it *because* it dropped a

Re: generate and send mail with python: tutorial

2011-08-12 Thread Terry Reedy
On 8/12/2011 2:17 PM, aspineux wrote: On Aug 12, 3:38 pm, Steven D'Aprano wrote: aspineux wrote: Hi I have written a tutorial about how to generate and send emails with python. [...] Thank you, that is an extremely detailed tutorial. Thanks, It was my intention Have you considered cont

Re: pythonw.exe

2011-08-14 Thread Terry Reedy
On 8/14/2011 10:30 AM, Nobody wrote: The main use for pythonw.exe is if you write a GUI program in Python (using e.g. TkInter, wxPython, etc) and you want it to be able to run it from an icon (desktop, start menu) without it opening a console window (running a console executable from an icon wil

Re: Problem installing 3.2.1 on a Linux server

2011-08-14 Thread Terry Reedy
On 8/14/2011 8:56 PM, John S James wrote: Thanks, your reply helped. The problem seems to be the autoconfig -- I was using version 2.59 instead of 2.68. However, the host will not let users install 2.68. So I'm sending them feedback, suggesting a number of reasons for supporting 3.2 for their se

Re: allow line break at operators

2011-08-15 Thread Terry Reedy
On 8/15/2011 12:28 AM, Seebs wrote: To repeat again: you are free to put in explicit dedent markers that will let you re-indent code should all indents be removed. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: string to unicode

2011-08-15 Thread Terry Reedy
On 8/15/2011 11:29 AM, Adam Tauno Williams wrote: On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: if I am using the standard csv library to read contents of a csv file which contains Unicode strings (short example: '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such as de

Re: Idea for pure-python templates using AST.

2011-08-16 Thread Terry Reedy
On 8/16/2011 7:33 AM, Paul Wray wrote: Hello all Ive had what I think is a great idea for pure-python templates (I can almost hear the groans, bear with me...) For the impatient, proof of concept is at http://pastie.org/2379978 demonstrating simple substitution, balanced tags using context mana

Re: Linux : create a user if not exists

2011-08-16 Thread Terry Reedy
On 8/16/2011 10:57 AM, smain kahlouch wrote: Ok than you. You're right but it doesn't help me : I replaced it : >>> def finduser(user): ... if pwd.getpwnam(user): ... print user, "user exists" ... return True ... return False ... >>> finduser('realuser') realuse

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

2011-08-16 Thread Terry Reedy
On 8/16/2011 1:15 PM, Gerrat Rickert wrote: I think that best practices would suggest that one shouldn't use variable names that shadow builtins (except in specific, special circumstances), so I don't really think this would be an annoyance at all. The number of *unwanted* warnings they'd get w

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

2011-08-16 Thread Terry Reedy
On 8/16/2011 2:56 PM, Seebs wrote: I wonder whether there's a way to mitigate the cost of these things by messing with -W settings, such that runtime that wants to be fast can omit the checks, but the default could still be to, well, prevent likely errors. Warning messages have a cost even if

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

2011-08-16 Thread Terry Reedy
On 8/16/2011 7:49 PM, Seebs wrote: On 2011-08-16, Terry Reedy wrote: On 8/16/2011 2:56 PM, Seebs wrote: I wonder whether there's a way to mitigate the cost of these things by messing with -W settings, such that runtime that wants to be fast can omit the checks, but the default could sti

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

2011-08-16 Thread Terry Reedy
On 8/16/2011 8:18 PM, Philip Semanchuk wrote: Hi Terry, To generalize from your example, are you saying that there's a mild admonition > against shadowing builtins with unrelated variable names in standard lib code? I would expect that there might be. I would have to check PEP8. Here's an e

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-17 Thread Terry Reedy
The issue behind this thread is that for immutable objects, binding to n copies has the same effect as n bindings to one object (so one does not really have to know which one is doing), whereas the two are different for mutable objects (so one does have to know). In short, identity matters for

Re: Wait for a keypress before continuing?

2011-08-17 Thread Terry Reedy
On 8/17/2011 12:33 PM, Seebs wrote: On 2011-08-17, peter wrote: Is there an equivalent to msvcrt for Linux users? I haven't found one, and have resorted to some very clumsy code which turns off keyboard excho then reads stdin. Seems such an obvious thing to want to do I am surprised there is n

Re: List spam

2011-08-18 Thread Terry Reedy
I did check, though. I found a free, open news server with comp.lang.python after 6 that didn't work. Unfortunately, the one I found is read-only. I'll have to do some more looking if I want to participate in the newsgroup. I set it up in Thunderbird. I read and post to this and other Pyth

Re: List spam

2011-08-18 Thread Terry Reedy
On 8/18/2011 12:14 PM, gene heskett wrote: into a REAL mailing list. Subscribers only, or get past a GOOD captcha. I just had an idea. Ask 'What is python? __" or "What can you do with a python?' with a free-form fill in the blank answer. Look for 'computer', 'program' or 'l

Re: Word Perfect integration

2011-08-18 Thread Terry Reedy
On 8/18/2011 3:24 PM, Ethan Furman wrote: Alec Taylor wrote: wow, people still use WordPerfect? Them's fightin' words right there! :) Yes, we still use Word Perfect, and will as long as it is available. The ability to see the codes in use (bold, margins, columns, etc) has so far been unequale

Re: List spam

2011-08-18 Thread Terry Reedy
On 8/18/2011 10:10 PM, Steven D'Aprano wrote: Now, an ISP might not have the bandwidth to supply all the needs of their customers, that's a separate issue. But complaining that the problem is specifically because they use bittorrent, as if it would disappear if they changed to HTTP, is bogus.

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Terry Reedy
On 8/21/2011 1:27 PM, Andreas Löscher wrote: What the precise difference (semantics and speed) is between the BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source code or maybe someone knows it from memory :-) Irmen from Python/ceval.c: 1316case BINARY_ADD: 1317

Re: try... except with unknown error types

2011-08-21 Thread Terry Reedy
On 8/21/2011 2:26 PM, Paul Rubin wrote: Steven D'Aprano writes: But there's no way to know what that minimum is. Python libraries throw all sorts of exceptions that their documentation doesn't mention. Yes, you're absolutely correct. But it's also irrelevant. Most of those exceptions should

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Terry Reedy
On 8/21/2011 7:17 PM, Andreas Löscher wrote: Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: In article, Christian Heimes wrote: Am 21.08.2011 19:27, schrieb Andreas Lscher: As for using Integers, the first case (line 1319 and 1535) are true and there is no difference in Code. H

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Terry Reedy
On 8/21/2011 5:07 PM, Nobody wrote: If the value on the left has an __iadd__ method, that will be called; Correct the value will be updated in-place, Not necessarily correct. The target is rebound to the return from the __iadd__ method. Augmented *assignment* is always assignment. This tr

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Terry Reedy
On 8/21/2011 7:41 PM, Chris Angelico wrote: Agreed. If Python needed a faster alternative to "a=a+1", then I would recommend an "a.inc()" call or something But looking up the method name, creating a bound method wrapper, and making the call would probably be slower than the syntax;-). -- Te

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Terry Reedy
On 8/21/2011 7:49 PM, Laurent Payot wrote: I made Python my language of choice because of its readability and simpleness, and not because of its speed. But it's always good to know what is the fastest sometimes when you don't want to write a module in C. So I was just wondering if there was a dif

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Terry Reedy
On 8/22/2011 7:39 AM, Tomas Lidén wrote: On 22 Aug, 13:26, Roy Smith wrote: In article <356978ef-e9c1-48fd-bb87-849fe8e27...@p5g2000vbl.googlegroups.com>, Tomas Lidén wrote: In what order are the addresses returned by socket.gethostbyname_ex()? We know that gethostbyname() is indetermin

Re: is there any principle when writing python function

2011-08-23 Thread Terry Reedy
On 8/23/2011 7:59 AM, smith jack wrote: i have heard that function invocation in python is expensive, That comes into play when chosing between list2 = map(lambda x: 2*x, list1) # versus list2 = [2*x for x in list1] It also comes into play when choosing between looping with recursion (functi

Re: is there any principle when writing python function

2011-08-23 Thread Terry Reedy
On 8/23/2011 11:22 AM, Steven D'Aprano wrote: Even 7±2 is probably excessive: I find that I'm most comfortable with functions that perform 4±1 chunks of work. An example from one of my classes: def find(self, prefix): """Find the item that matches prefix.""" prefix = pref

Re: upgrade python

2011-08-23 Thread Terry Reedy
On 8/23/2011 6:09 PM, Ronald Reynolds wrote: What is recommended for upgrading python for windows? Do I just install the new version I put each version in its own Pythonxy directory, as the installer wants. x.y.z bug fix releases replace the previous x.y release. Do I edit my system path?

Re: Windows No-Install Distribution?

2011-08-23 Thread Terry Reedy
On 8/23/2011 5:56 PM, Eric Lemings wrote: On Aug 23, 1:52 pm, Stephen Hansen wrote: On 8/23/11 8:29 AM, Eric Lemings wrote: I would like to create/find a Python 3.x distribution that can be redeployed simply by copying a directory of required files; i.e. Just take the default installer, ins

Re: Announcing a new podcast: Radio Free Python

2011-08-24 Thread Terry Reedy
On 8/24/2011 12:15 AM, Larry Hastings wrote: Radio Free Python is a new monthly podcast focused on Python and its community. Episode 1 has just been released! It features a panel discussion with the PythonLabs team: * Barry Warsaw, * Fred Drake, * Guido van Rossum, * Roger Masse, * a

Re: [OT-ish] Design principles: no bool arguments

2011-08-25 Thread Terry Reedy
On 8/25/2011 3:13 AM, Steven D'Aprano wrote: One design principle often mentioned here (with a certain degree of disagreement[1]) is the idea that as a general rule, you shouldn't write functions that take a bool argument to switch between two slightly different behaviours. This is a principle o

Re: Record seperator

2011-08-27 Thread Terry Reedy
On 8/27/2011 1:45 PM, Roy Smith wrote: In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: open("file.txt") # opens the file .read() # reads the contents of the file .split("\n\n")# splits the text on double-newlines. The biggest prob

Re: typing question

2011-08-27 Thread Terry Reedy
On 8/27/2011 9:42 AM, Jason Swails wrote: P.S. I'll note that my "preferred" behavior is how python3.2 actually operates Python core developers agree. This is one of the reasons for breaking a bit from 2.x to make Python 3. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/py

Re: Understanding .pth in site-packages

2011-08-27 Thread Terry Reedy
On 8/27/2011 2:07 PM, Philip Semanchuk wrote: On Aug 27, 2011, at 1:57 PM, Josh English wrote: Philip, Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package developmen

Re: Record seperator

2011-08-27 Thread Terry Reedy
On 8/27/2011 5:07 PM, Roy Smith wrote: In article, Terry Reedy wrote: On 8/27/2011 1:45 PM, Roy Smith wrote: In article<4e592852$0$29965$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: open("file.txt") # opens the file .read() # read

Re: Why do closures do this?

2011-08-27 Thread Terry Reedy
On 8/27/2011 11:45 PM, John O'Hagan wrote: Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: funcs=[] for n in range(3): def f(): return n funcs.append(f) The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tel

Re: Why do closures do this?

2011-08-28 Thread Terry Reedy
On 8/28/2011 10:04 AM, Thomas Jollans wrote: This does not do what you'd like it to do. But let's assume that, it did, that Python, when encountering a function definition inside a function, "froze" the values of nonlocal variables used in the new function, from the point of view of that functio

Re: A question about class as an iterator

2011-08-28 Thread Terry Reedy
On 8/28/2011 1:22 PM, Yaşar Arabacı wrote: I got confused about classes as an iterator. I saw something like this: class foo(): __iter__(self): return self next(self): return something 2.x But then I saw a __next__ method on some code. 3.x This might work in 2.

Re: about if __name == '__main__':

2011-08-28 Thread Terry Reedy
On 8/28/2011 2:56 PM, woooee wrote: Two main routines, __main__ and main(), '__main__' in not a routine, it is the name of the initial module. is not the usual or the common way to do it. It is confusing and anyone looking at the end of the program for statements executed when the program is

Re: Why PyImport_ExecCodeModule takes char*?

2011-08-28 Thread Terry Reedy
On 8/28/2011 6:52 PM, Tim Roberts wrote: Mateusz Loskot wrote: I'm wondering, why PyImport_ExecCodeModule function takes char* instead of const char*? My guess is "history". I believe some const tags have been added over the last few years. Another factory than mere history for some thing

Re: Handling 2.7 and 3.0 Versions of Dict

2011-08-30 Thread Terry Reedy
On 8/30/2011 9:43 PM, Travis Parks wrote: I am writing a simple algorithms library that I want to work for both Python 2.7 and 3.x. I am writing some functions like distinct, which work with dictionaries under the hood. The problem I ran into is that I am calling itervalues or values depending on

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

2011-08-31 Thread Terry Reedy
On 8/31/2011 10:35 AM, T. Goodchild wrote: But one of the things that bugs me is the requirement that all class methods have 'self' as their first parameter. On a gut level, to me this seems to be at odds with Python’s dedication to simplicity. Actually, it is a consequence of Python's dedica

Re: Subclassing str object

2011-08-31 Thread Terry Reedy
On 8/31/2011 7:43 AM, Yaşar Arabacı wrote: Hİ, I originally posted my question to here: http://stackoverflow.com/q/7255655/886669 Could you people please look at it and enlighten me a little bit? I would appreciate an answer either from here or at stackoverflow. I believe two people already ga

Re: Closures and Partial Function Application

2011-08-31 Thread Terry Reedy
On 8/31/2011 12:45 PM, Travis Parks wrote: I was a little disappointed the other day when I realized that closures were read-only. 'Were', in 2.x. The standard 2.x workaround for a single nonlocal is to wrap it in a list. def f(): i = [0] def g(): i[0] += 1 for j in range(5): g()

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

2011-08-31 Thread Terry Reedy
On 8/31/2011 1:12 PM, Prasad, Ramit wrote: def double(obj): return 2*obj.value class C: def __init__(self, val): >> self.value = val c = C(3) >> C.double = double >> c.doub = double >> # not c.double as that would mask access to C.double in c.double() >> print(double(c), C.double(c)

Re: fun with nested loops

2011-09-01 Thread Terry Reedy
On 9/1/2011 10:05 AM, Daniel wrote: You seems to be requesting one of the options in http://python.org/dev/peps/pep-3136/ Labeled break and continue (The 'Other languages' section omits Fortran.) The rejection post is at http://mail.python.org/pipermail/python-3000/2007-July/008663.html I basica

Re: Optparse buggy?

2011-09-01 Thread Terry Reedy
On 9/1/2011 5:12 PM, Fulvio wrote: I'm on python3.2, trying some experiment with OptionParser but no success Do note "The optparse module is deprecated and will not be developed further; development will continue with the argparse module." -- Terry Jan Reedy -- http://mail.python.org/mailm

Re: Python thread

2011-09-01 Thread Terry Reedy
On 9/1/2011 5:14 PM, George wrote: Hi, Why doesn't python threads show an associated PID? On spawning python threads using the threading module I can only see the main thread's pid on using top or ps unix command, no subprocesses are displayed. In otherwords top or ps in not aware of any subpro

Re: Python thread

2011-09-01 Thread Terry Reedy
On 9/1/2011 6:08 PM, George wrote: So what exactly does threading module do, if it doesn't create a subprocess. Does each thread have its own stack and PC. What advantage would a threading module provide over sequential execution. https://secure.wikimedia.org/wikipedia/en/wiki/Thread_%28compute

Re: PythonThreading

2011-09-01 Thread Terry Reedy
Please do not repeatedly post the same thing. Doing so, with different titles, will only annoy people. It takes awhile for a post to show up with whatever news or mail reader you are using. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: Handling 2.7 and 3.0 Versions of Dict

2011-09-02 Thread Terry Reedy
On 9/2/2011 12:53 PM, Travis Parks wrote: On Sep 2, 12:36 pm, "Gabriel Genellina" Those if/else are at global scope. An 'if' statement does not introduce a new scope; so getDictValues, despite being "indented", is defined at global scope, and may be used anywhere in the module. Does that me

Re: [Python-ideas] allow line break at operators

2011-09-03 Thread Terry Reedy
On 9/3/2011 3:51 AM, Yingjie Lan wrote: I agree that long lines of code are not very common in many projects, though it might be the case with some heavily involved in math. For some reason, when the feature of free line breaking came about in computer languages, it is welcomed and generally well

Re: Functions vs OOP

2011-09-03 Thread Terry Reedy
On 9/3/2011 12:25 PM, Steven D'Aprano wrote: William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation Ours, or someone else's? that suggests that programming using functions, and programming using objects were somehow opposing techniqu

Re: IDLE from python 3.2 constantly crashes

2011-09-03 Thread Terry Reedy
On 9/3/2011 1:54 PM, Joshua Miller wrote: Ok i've been using IDLE on my home computer and everytime i try and open a file that i saved to my hdd instead of my flashdrive(because it's a school project) by accident, it opens for a second and i try to do something else like open another file and it

Re: SSL module needs issuer information

2011-09-03 Thread Terry Reedy
On 9/3/2011 2:10 PM, John Nagle wrote: The SSL module still doesn't return much information from the certificate. SSLSocket.getpeercert only returns a few basic items about the certificate subject. You can't retrieve issuer information, and you can't get the extensions needed to check if a cert i

Re: Functions vs OOP

2011-09-03 Thread Terry Reedy
On 9/3/2011 5:34 PM, William Gill wrote: On 9/3/2011 3:15 PM, Terry Reedy wrote: William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation Ours, or someone else's? Python. Since in Python, everything is an object, that would

Re: Functions vs OOP

2011-09-04 Thread Terry Reedy
On 9/4/2011 4:13 AM, tinn...@isbd.co.uk wrote: Ian Kelly wrote: Functional programming is about using functions in the *mathematical* sense. A mathematical function maps one value (or tuple of values) to another value. The mapped value never varies; if it did, it would be a different functi

Re: Need help with simple OOP Python question

2011-09-05 Thread Terry Reedy
On 9/5/2011 9:15 AM, Kristofer Tengström wrote: Thanks everyone, moving the declaration to the class's __init__ method did the trick. Now there's just one little problem left. I'm trying to create a list that holds the parents for each instance in the hierarchy. This is what my code looks like no

Re: One line command line filter

2011-09-05 Thread Terry Reedy
On 9/5/2011 4:38 PM, Jon Redgrave wrote: It seems unreasonably hard to write simple one-line unix command line filters in python: eg: ls | python -c " print x.upper()" to get at sys.stdin or similar needs an import, which makes a subsequent for-loop illegal. python -c "import sys; for x in sy

Re: Functions vs OOP

2011-09-05 Thread Terry Reedy
On 9/5/2011 1:45 PM, William Gill wrote: On 9/4/2011 9:13 AM, rusi wrote: On Sep 3, 9:15 pm, William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation that suggests that programming using functions, and programming using objects were someho

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