Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Selik
On Sun, Apr 24, 2016, 1:51 AM Steven D'Aprano wrote: > On Sun, 24 Apr 2016 12:34 pm, Michael Torrie wrote: > > > There are many aspects to Pythonic programming, not just OOP. For > > example using modules to store shared state for your program components > > is very pythonic, rather than using c

Optimizing Memory Allocation in a Simple, but Long Function

2016-04-23 Thread Derek Klinge
I have been writing a python script to explore Euler's Method of approximating Euler's Number. I was hoping there might be a way to make this process work faster, as for sufficiently large eulerSteps, the process below becomes quite slow and sometimes memory intensive. I'm hoping someone can give m

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Marko Rauhamaa
Steven D'Aprano : > On Sun, 24 Apr 2016 12:03 pm, Christopher Reimer wrote: > >> On 4/23/2016 2:33 PM, Matt Wheeler wrote: >>> This is still backwards to me. It prevents your classes from being >>> suitable for restoring a stored game state, not just custom starting >>> positions (which I think is

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Steven D'Aprano
On Sun, 24 Apr 2016 12:34 pm, Michael Torrie wrote: > There are many aspects to Pythonic programming, not just OOP. For > example using modules to store shared state for your program components > is very pythonic, rather than using classes. A module is kind of like a > singleton instance, and st

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Steven D'Aprano
On Sun, 24 Apr 2016 12:03 pm, Christopher Reimer wrote: > On 4/23/2016 2:33 PM, Matt Wheeler wrote: >> This is still backwards to me. It prevents your classes from being >> suitable for restoring a stored game state, not just custom starting >> positions (which I think is what Ethan means by custo

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Torrie
On 04/23/2016 09:41 PM, Christopher Reimer wrote: > I never wanted to learn Java in the first place. My community college > couldn't afford to renew the Microsoft site license, which local > employers required to learn C/C++ in MS Visual Studio, and all flavors > of Java got taught for the progr

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/23/2016 8:19 PM, Michael Torrie wrote: The reason you weren't taught beyond class inheritance is because Java implements organization only through a class hierarchy. Whole generations of Java programmers think that program organization is through classes (a static main method means your code

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Torrie
On 04/23/2016 08:32 PM, Christopher Reimer wrote: > That's the other problem I'm running into. Building a chess engine is a > big project. This is probably bigger than the Java XML parser I built > from scratch for a college project. I can't seem to find any information > on how to build bigger

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/23/2016 7:34 PM, Michael Torrie wrote Procedural programming does not necessarily mean BASIC-style goto hell. Not sure why you would think that. In fact that's not really what procedural programming is about. I mentioned several messages back that I spent two years writing procedural scr

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Torrie
On 04/23/2016 07:45 PM, Christopher Reimer wrote: > I had to confront all the bad habits I brought over Java and change my > code to be more Pythonic. This is where I started having fun, learning > the tricks and collapsing multi-line code into a single line code. I've > learned more about Pytho

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/23/2016 6:38 PM, Michael Selik wrote: Why so many files? Python can easily support thousands of lines in a file. If it's just one file any text editor can do a quick find-replace. That goes back to the Java convention of having one class per file. It took a while to convince myself that

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/23/2016 6:29 PM, Ian Kelly wrote: Python enums are great. Sadly, they're still not quite as awesome as Java enums. I remember enums more from C than Java. Although I haven't used them much in either language. I'm planning to immerse myself back into C via Cython. Depending on far I get i

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/23/2016 2:33 PM, Matt Wheeler wrote: This is still backwards to me. It prevents your classes from being suitable for restoring a stored game state, not just custom starting positions (which I think is what Ethan means by custom setups). I haven't thought that far about saving the game stat

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/22/2016 1:40 PM, Michael Selik wrote: Frankly, for someone coming from Java, the best advice is to not write any classes until you must. Of course classes in Python are very useful. It's just that your Java habits are unnecessary and often counter-productive. I disagree. I wrote procedural

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Selik
On Sat, Apr 23, 2016 at 9:31 PM Christopher Reimer < christopher_rei...@icloud.com> wrote: > On 4/21/2016 10:25 PM, Stephen Hansen wrote: > > > > Why not, 'color in ("black", "white")'? > > Checkers seems popular around here. What if I want to change "white" to > "red," as red and black is a commo

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Ian Kelly
On Sat, Apr 23, 2016 at 7:00 PM, Christopher Reimer wrote: > On 4/21/2016 9:46 PM, Ethan Furman wrote: >> >> Oh! and Enum!!! ;) > > > OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I > don't have to roll my own! > > Hmm... What do we use Enum for? :) Python enums are great

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/21/2016 10:25 PM, Stephen Hansen wrote: Why not, 'color in ("black", "white")'? Checkers seems popular around here. What if I want to change "white" to "red," as red and black is a common color scheme for checkers. Do I change a single constant variable or replace all the occurrences in

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Michael Selik
On Sat, Apr 23, 2016 at 9:01 PM Christopher Reimer < christopher_rei...@icloud.com> wrote: > On 4/21/2016 9:46 PM, Ethan Furman wrote: > > Oh! and Enum!!! ;) > > OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I > don't have to roll my own! > > Hmm... What do we use Enum for

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Christopher Reimer
On 4/21/2016 9:46 PM, Ethan Furman wrote: Oh! and Enum!!! ;) OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I don't have to roll my own! Hmm... What do we use Enum for? :) Thank you, Chris R. -- https://mail.python.org/mailman/listinfo/python-list

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Matt Wheeler
On 22 April 2016 at 04:11, Christopher Reimer wrote: > On 4/21/2016 7:10 PM, Ethan Furman wrote: >>> I do plan to incorporate a sanity test in each Piece class to validate >>> the initial position value. Pawns have 16 specific positions. Bishop, >>> Knight and Rook each have four specific position

Re: Remove directory tree without following symlinks

2016-04-23 Thread Random832
On Sat, Apr 23, 2016, at 12:29, Nobody wrote: > On Linux, an alternative is to use fchdir() rather than chdir(), which > changes to a directory specified by an open file descriptor Of course, then there's also the risk of running out of open file descriptors. High-quality implementations of rm wi

Re: Remove directory tree without following symlinks

2016-04-23 Thread Random832
On Sat, Apr 23, 2016, at 06:24, Steven D'Aprano wrote: > "rm -r" gives me a NameError when I run it in my Python script :-) > > But seriously, where is that documented? I've read the man page for > rm, and it doesn't say anything about treatment of symlinks, nor is > there an option to follow/not

Re: Remove directory tree without following symlinks

2016-04-23 Thread eryk sun
On Sat, Apr 23, 2016 at 4:34 AM, Albert-Jan Roskam wrote: > >> From: eryk...@gmail.com >> Date: Fri, 22 Apr 2016 13:28:01 -0500 >> On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam >> wrote: >> > FYI, Just today I found out that shutil.rmtree raises a WindowsError if >> > the dir is read-only (

Re: Remove directory tree without following symlinks

2016-04-23 Thread Nobody
On Sat, 23 Apr 2016 00:56:33 +1000, Steven D'Aprano wrote: > I want to remove a directory, including all files and subdirectories under > it, but without following symlinks. I want the symlinks to be deleted, not > the files pointed to by those symlinks. Note that this is non-trivial to do secure

Re: Remove directory tree without following symlinks

2016-04-23 Thread Gregory Ewing
Steven D'Aprano wrote: But seriously, where is that documented? I've read the man page for rm, and it doesn't say anything about treatment of symlinks The Linux man page seems to be a bit deficient on this. The BSD version contains this sentence: The rm utility removes symbolic links, not

Re: Remove directory tree without following symlinks

2016-04-23 Thread Steven D'Aprano
On Sat, 23 Apr 2016 06:13 pm, Paul Rubin wrote: > Steven D'Aprano writes: >> I want to remove a directory, including all files and subdirectories >> under it, but without following symlinks. I want the symlinks to be >> deleted, not the files pointed to by those symlinks. > > rm -r shouldn't fol

RE: Remove directory tree without following symlinks

2016-04-23 Thread Albert-Jan Roskam
> From: eryk...@gmail.com > Date: Fri, 22 Apr 2016 13:28:01 -0500 > Subject: Re: Remove directory tree without following symlinks > To: python-list@python.org > > On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam > wrote: > > FYI, Just today I found out that shutil.rmtree raises a WindowsErro

Re: Remove directory tree without following symlinks

2016-04-23 Thread Paul Rubin
Steven D'Aprano writes: > I want to remove a directory, including all files and subdirectories under > it, but without following symlinks. I want the symlinks to be deleted, not > the files pointed to by those symlinks. rm -r shouldn't follow symlinks like you mention. -- https://mail.python.org