Re: [Tutor] Why define a function inside a function?

2016-01-29 Thread Steven D'Aprano
Oops, I screwed up! On Sat, Jan 30, 2016 at 02:31:09PM +1100, Steven D'Aprano wrote: > Complicated? Well, a bit. Here's a simpler demonstration of a closure: > > > def factory(num): > """Factory function that returns a new function that adds > num to whatever it is given.""" > def

Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-29 Thread Steven D'Aprano
On Fri, Jan 22, 2016 at 11:10:39PM -0600, boB Stepp wrote: > Am I understanding this correctly? It appears to me that you have > successfully added a method to class X from outside of class X! If > this is the case, then this clarifies some things I was wondering > about in my other thread. If

Re: [Tutor] Why define a function inside a function?

2016-01-29 Thread Steven D'Aprano
On Fri, Jan 29, 2016 at 04:29:14PM -0500, Ryan Smith wrote: > Hi all, > > I am new to programming and python and had a question. I hope I > articulate this well enough so here it goes... I was following along > on a thread on this mailing list discussing how to test file I/O > operations. In one o

Re: [Tutor] Why define a function inside a function?

2016-01-29 Thread Ben Finney
Ryan Smith writes: > In trying to understand the logic behind the code for my own > edification, I was wondering what is the reasoning of defining a > function in side another function (for lack of a better phrase)? Sometimes a function is so specific to the workings of another function that it

[Tutor] Why define a function inside a function?

2016-01-29 Thread Ryan Smith
Hi all, I am new to programming and python and had a question. I hope I articulate this well enough so here it goes... I was following along on a thread on this mailing list discussing how to test file I/O operations. In one of the suggested solutions the following code was used: def _open_as_st

Re: [Tutor] Noob: nested if-clauses

2016-01-29 Thread Alan Gauld
On 29/01/16 17:41, STF wrote: > what that gives. IDLE is indeed easier to use than the "DOS-style" Python > command-line window. One thing I'd say is that you can tweak the DOS CMD window quite a lot to make it better for IDLE(and other interpreters). But IDLE is probably still better for most

Re: [Tutor] Noob: nested if-clauses

2016-01-29 Thread John Wong
On Fri, Jan 29, 2016 at 3:13 PM, Alan Gauld wrote: > > When I first heard that python was white-space sensitive I > thought, oh no! But now I see it as a huge strength of the > language. Once you get used to it you will find it helps > far more than it hinders - just avoid tabs and/or map your >

Re: [Tutor] Noob: nested if-clauses

2016-01-29 Thread boB Stepp
On Fri, Jan 29, 2016 at 11:41 AM, STF wrote: > ...How do you call this thing, BTW? I'm unable to > understand how to navigate inside this thing. I mean, when I open it, in > which folder am I in? Suppose I have a Python file in > D:\mycode\abc\myfile.py. How to run it? IDLE presents itself i

Re: [Tutor] How do I test file operations (Such as opening, reading, writing, etc.)?

2016-01-29 Thread Ben Finney
Alan Gauld writes: > File simulation is faster and fine for unit testing functionality, > but not so good for testing the overall system. Yes, I'm only advocating fake files for unit tests which, more than all other kinds of tests, need to be fast and numerous. For testing larger parts of the s

Re: [Tutor] Noob: nested if-clauses

2016-01-29 Thread STF
On 25 January 2016 at 21:46, Alan Gauld wrote: > On 25/01/16 15:52, STF wrote: > > > It's a total fluke. I put the indentation like this to *visually* help > > myself understand what I was going to write. > > That's one of the good things about Python, if it looks right > it very often is right.

Re: [Tutor] Noob: nested if-clauses

2016-01-29 Thread Alan Gauld
On 29/01/16 17:41, STF wrote: > Personally, I don't find this as a "good thing". It rather recalls the > horrible dreams I have had when I was using Fortran! In Fortran, we have > to deal with position of first characters to make things work. IMO, making > a visual format an essential thing in

[Tutor] http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html

2016-01-29 Thread Albert-Jan Roskam
from sqlalchemy import * db = create_engine('sqlite:///joindemo.db') db.echo = True metadata = BoundMetaData(db) users = Table('users', metadata, autoload=True) emails = Table('emails', metadata, autoload=True) # These are the empty classes that will become our data classes class User(object

Re: [Tutor] lc_ctype and re.LOCALE

2016-01-29 Thread Oscar Benjamin
On 28 January 2016 at 20:23, Albert-Jan Roskam wrote: > > Out of curiosity, I wrote the throw-away script below to find a character > that is classified (--> LC_CTYPE) as digit in one locale, but not in another. > I ran it with 5000 locale combinations in Python 2 but did not find any > (somebod

Re: [Tutor] lc_ctype and re.LOCALE

2016-01-29 Thread eryk sun
On Thu, Jan 28, 2016 at 2:23 PM, Albert-Jan Roskam wrote: > Out of curiosity, I wrote the throw-away script below to find a character > that is classified > (--> LC_CTYPE) as digit in one locale, but not in another. The re module is the wrong tool for this. The re.LOCALE flag is only for byte st

Re: [Tutor] How do I test file operations (Such as opening, reading, writing, etc.)?

2016-01-29 Thread Alan Gauld
On 29/01/16 07:09, Ben Finney wrote: >> Create a directory and copy your pristine tree into the directory >> and make the base directory for the important data files >> configurable. Also known as parameterization. > > I consider that a poor option; real files complicate the test setup and

Re: [Tutor] How do I test file operations (Such as opening, reading, writing, etc.)?

2016-01-29 Thread Alan Gauld
On 29/01/16 04:58, boB Stepp wrote: > I'll ask you the same question that I asked Danny: Do you have a > favorite text which teaches OOP the way you feel it should be taught? > And if possible, Python-based? I have three; depending on your level of interest :-) 1) OO Design by Grady Booch. But

Re: [Tutor] How do I test file operations (Such as opening, reading, writing, etc.)?

2016-01-29 Thread Ben Finney
"Martin A. Brown" writes: > Option A (tempfile): > > Create a directory and copy your pristine tree into the directory > and make the base directory for the important data files > configurable. Also known as parameterization. I consider that a poor option; real files complicate the test se