Re: Sudoku solver

2015-03-26 Thread Christian Gollwitzer

Am 26.03.15 um 00:04 schrieb Mark Lawrence:

On 25/03/2015 22:50, Steven D'Aprano wrote:

On Wed, 25 Mar 2015 10:39 pm, Marko Rauhamaa wrote:


I have yet to find practical use for fibonacci numbers.


Many people have failed to find practical uses for many things from
mathematics. Doesn't mean they don't exist:

http://en.wikipedia.org/wiki/Fibonacci_number#Applications



I've just read "Alan Turing: The Enigma".  Apparently he was fascinated
by the appearance of Fibonacci numbers in nature, as described here
http://en.wikipedia.org/wiki/Fibonacci_number#In_nature


https://xkcd.com/spiral/
--
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Marko Rauhamaa
Steven D'Aprano :

> You're arguing whether or not in the following line of code:
>
> spam = "abcd" "efgh"
> # implicitly concatenated to "abcdefgh" at compile time
>
> the right hand side pair of strings counts as a single token or two? Am I
> right, or am I missing something?
>
> If that's all it is, why don't you just run the tokenizer over it and
> see what it says?

Now, someone *could* write a tokenizer that took care of string
concatenation on the spot--as long as it dealt with comments as well:

   ("abc"
   # hello
"def")

It would be even possible to write a parser that didn't have a separate
lexical analyzer at all.

Arguing about terminology is pretty useless. Both sides in this fight
are correct, namely:

   * string literal concatenation is part of expression syntax

   * what goes on inside an atom stays inside an atom

For example, this expression is illegal:

   "abc" ("def")


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 01:21 pm, Rustom Mody wrote:

> Anyway my point is that in python (after 2.2??) saying something is an
> object is a bit of a tautology -- ie verbiage without information.


Er, it's *always* been a tautology. Every value in Python is an object,
including classes, and that has been always the case.

However, just because it's a tautology doesn't mean it isn't useful to know.
(Tautologies are also known as *facts* and knowing facts is usually a good
thing.) For the majority of programming languages, it is not the case that
all values are objects, and not all people reading the documentation should
be expected to know that this applies to Python.

Besides, "object" in Python circles is ambiguous. It can also mean:

* the Python type "object";

* an instance of the Python type "object";

* any non-class instance of any old-style class (Python 2 only) 
  or type (new-style class);

* "boxed" values in object-oriented languages;

and possibly others as well. Personally, I dislike using object as a synonym
for "instance", as it fails to account for classes which are instances. But
other than that, all those meanings are valid and have to be distinguished
from context.





-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 10:24:33 PM UTC-4, Mario Figueiredo wrote:
> On Thu, 26 Mar 2015 18:56:25 -0700 (PDT), 
> 
> >
> >How disappointing, I was expecting something worth opposing.
> >
> 
> And that's bad? Successfully opposing a troll is like getting a medal
> for winning an argument with Spencer Pratt.
> 
> Delusional pricks like you are only worth the 2 or 3 messages I care
> about writing for my own satisfaction. After that you just get as
> boring as the afore-mentioned idiot. Bye-bye!


All brawn no brain Mario lays down his confused rationale for leaving the field 
of battle after a couple of embarrassingly vulgar posts.  

Giving Mario an Internet connection just invites his reach to exceed his grasp. 



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Friday, March 27, 2015 at 7:56:16 AM UTC+5:30, Ian wrote:
> On Thu, Mar 26, 2015 at 7:56 PM, Chris Angelico  wrote:
> >> On a more specific note, its the 1st line:
> >>
> >> class filter(object)
> >>
> >> which knocks me off.
> >> If a more restricted type from the ABC was shown which exactly captures all
> >> the iterator-specific stuff like __iter__, __next__ it would sure help (me)
> >
> > But there's no point in subclassing for everything. In this case,
> > filter doesn't subclass anything but object, so there's no value in
> > stating anything else. You want to know if it's iterable? Check for an
> > __iter__ method. Etcetera.
> 
> Also, filter is a builtin, while collections.abc.Iterable is in a
> library module written in Python, so there's a bootstrapping problem
> with having the one inherit from the other.

As I said to Chris, I am not talking of the facts but of the docs
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Friday, March 27, 2015 at 7:26:54 AM UTC+5:30, Chris Angelico wrote:
> On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody  wrote:
> > On a more specific note, its the 1st line:
> >
> > class filter(object)
> >
> > which knocks me off.
> > If a more restricted type from the ABC was shown which exactly captures all
> > the iterator-specific stuff like __iter__, __next__ it would sure help (me)
> 
> But there's no point in subclassing for everything. In this case,
> filter doesn't subclass anything but object, so there's no value in
> stating anything else. You want to know if it's iterable? Check for an
> __iter__ method. Etcetera.

Well maybe... I dont the ABC thing very well in python.
[It does seem to be underutilized]

Anyway my point is that in python (after 2.2??) saying something is an object 
is a bit of a tautology -- ie verbiage without information.


Note: We are not talking of the *fact* that something -- in this case filter --
subclasses object, but the output of help(filter)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 7:56 PM, Chris Angelico  wrote:
>> On a more specific note, its the 1st line:
>>
>> class filter(object)
>>
>> which knocks me off.
>> If a more restricted type from the ABC was shown which exactly captures all
>> the iterator-specific stuff like __iter__, __next__ it would sure help (me)
>
> But there's no point in subclassing for everything. In this case,
> filter doesn't subclass anything but object, so there's no value in
> stating anything else. You want to know if it's iterable? Check for an
> __iter__ method. Etcetera.

Also, filter is a builtin, while collections.abc.Iterable is in a
library module written in Python, so there's a bootstrapping problem
with having the one inherit from the other.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Mario Figueiredo
On Thu, 26 Mar 2015 18:56:25 -0700 (PDT), Tiglath Suriol
 wrote:

>
>How disappointing, I was expecting something worth opposing.
>

And that's bad? Successfully opposing a troll is like getting a medal
for winning an argument with Spencer Pratt.

Delusional pricks like you are only worth the 2 or 3 messages I care
about writing for my own satisfaction. After that you just get as
boring as the afore-mentioned idiot. Bye-bye!
-- 
https://mail.python.org/mailman/listinfo/python-list


Test3

2015-03-26 Thread Tiglath Suriol

/*
 *  Only assholes need reply to this thread.  
 */

var Obj = (function() {
return function() {
var docRoot = '/as-qa23';
this.validateDocRoot = function(val) {
// throw Exception if not OK
};
this.setDocRoot = function(val) {
this.validateDocRoot(val);
docRoot = val;
};
this.getDocRoot = function() {
return docRoot;
};
Object.preventExtensions(this)
};
}());
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 9:55:08 PM UTC-4, Denis McMahon wrote:
> On Thu, 26 Mar 2015 14:06:28 -0700, marcuslom101 wrote:
> 
> > I posted two test messages containing code.  They are still there, are
> > you blind as well as dumb?
> 
> The message that you posted at the start of this thread may have 
> contained code, but it wasn't python code, 

Every post you made in this thread is off-topic.  Pot-kettle?  

Seriously folks, is this the best you can do?  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 6:41:15 PM UTC-4, Steven D'Aprano wrote:
> On Fri, 27 Mar 2015 07:00 am, BartC wrote:
> [...]
> 
> Don't give the troll the attention he craves. He reacted with hostility and
> scorn when we gave him some friendly good advice, don't imagine for a
> second you're going to reason with him. He's admitted that he's been
> trolling for years, so don't bother to engage with him.
> 
> The problem with wrestling a pig in the mud is that you get dirty and the
> pig enjoys it.
>  
> 
> -- 
> Steven

Steven exhorts you not to give me any attention, yet he posts three times to my 
thread. Go figure.

With enemies like this who needs friends...  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 6:36:57 PM UTC-4, Steven D'Aprano wrote:
> On Fri, 27 Mar 2015 02:33 am, Joel Goldstick wrote:
> [...]
> 
> Don't give the troll the attention he craves. He has as much told us that he
> is beyond reason -- he's been trolling for years, you don't need to justify
> your actions.
> 

I don't lie to you folks.  I told you from the outset that I did come here to 
provoke anyone, and I have asked you to ignore me repeatedly, something trolls 
are not known to do, but since YOU STARTED it, and you want more, I am having 
fun with you, and I can keep it up until the hell freezes, I assure you. 
Because one usually has to pay for a ticket to laugh like this.  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 5:24:10 PM UTC-4, sohca...@gmail.com wrote:
> On Tuesday, March 24, 2015 at 7:48:05 PM UTC-7, Tiglath Suriol wrote:
> > 
> > 

Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 5:20:08 PM UTC-4, Mario Figueiredo wrote:

> 
> Hush now, little baby troll. Don't get all teary on us. Calm down.
> Just a little while ago you were saying you didn't care about what
> people said.
> 
> So don't care about what people say.
> 
> BTW, you are as stupid as you are an ignorant little trapped troll.
> You purportedly spammed this place and now we are having fun telling
> you all about it. Boo hoo!
> 
> Now, remember what you said...

Mario repartee is going to be just plebeian invective, I see.  How 
disappointing, I was expecting something worth opposing.

Mario, boy. Sorry, but I don't usually engage victims of a bad education, it's 
too cruel. 

 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Chris Angelico
On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody  wrote:
> On Thursday, March 26, 2015 at 11:30:57 AM UTC+5:30, Chris Angelico wrote:
>> On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody  wrote:
>> > [And BTW
>> > help(filter) in python2 is much better documention than in python3
>> > ]
>>
>> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
>> [GCC 4.7.2] on linux2
>>
>> filter(...)
>> filter(function or None, sequence) -> list, tuple, or string
>>
>> Return those items of sequence for which function(item) is true.  If
>> function is None, return the items that are true.  If sequence is a tuple
>> or string, return the same type, else return a list.
>>
>> Python 3.5.0a0 (default:4709290253e3, Jan 20 2015, 21:48:07)
>> [GCC 4.7.2] on linux
>>
>> class filter(object)
>>  |  filter(function or None, iterable) --> filter object
>>  |
>>  |  Return an iterator yielding those items of iterable for which 
>> function(item)
>>  |  is true. If function is None, return the items that are true.
>>  |
>>  |  Methods defined here:
>> (chomp a handful of method details)
>
> Sackful may be more accurate :-)

Not really. Here's the entire help(filter) text:

Help on class filter in module builtins:

class filter(object)
 |  filter(function or None, iterable) --> filter object
 |
 |  Return an iterator yielding those items of iterable for which function(item)
 |  is true. If function is None, return the items that are true.
 |
 |  Methods defined here:
 |
 |  __getattribute__(self, name, /)
 |  Return getattr(self, name).
 |
 |  __iter__(self, /)
 |  Implement iter(self).
 |
 |  __new__(*args, **kwargs) from builtins.type
 |  Create and return a new object.  See help(type) for accurate signature.
 |
 |  __next__(self, /)
 |  Implement next(self).
 |
 |  __reduce__(...)
 |  Return state information for pickling.


> On a different note... I wonder how you do it:
> Look at 300 lines of code and notice exactly those 3 that... um... cause
> a lot of trouble :-)
> [My eyes just glaze over]

That's called experience. It's an intrinsic part of being a programmer.

> On a more specific note, its the 1st line:
>
> class filter(object)
>
> which knocks me off.
> If a more restricted type from the ABC was shown which exactly captures all
> the iterator-specific stuff like __iter__, __next__ it would sure help (me)

But there's no point in subclassing for everything. In this case,
filter doesn't subclass anything but object, so there's no value in
stating anything else. You want to know if it's iterable? Check for an
__iter__ method. Etcetera.

> On a 3rd note: I think Ive found a little buglet while trying to post this 
> message, can you confirm?
> [Linux Debian Xfce]
>
> After selecting the line above [inside python inside help(filter) ]for
> cut-pasting here, by mistake I pressed Ctrl-C rather than Ctrl-Shift-C
> An exception was thrown and the terminal remained in some sort of raw mode
> even after exiting python

Yes, confirmed. It'll be something to do with what happens when you
have 'less' and readline working together, probably.

Tip: Use Ctrl-Insert rather than Ctrl-Shift-C. It's the more standard
keystroke anyway.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Denis McMahon
On Thu, 26 Mar 2015 14:06:28 -0700, marcuslom101 wrote:

> I posted two test messages containing code.  They are still there, are
> you blind as well as dumb?

The message that you posted at the start of this thread may have 
contained code, but it wasn't python code, so it's off topic here. Hence 
its a pile of steaming excrement from a troll.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 5:12:00 PM UTC-4, Mario Figueiredo wrote:
> On Thu, 26 Mar 2015 13:58:36 -0700 (PDT), 
> wrote:
> 
> >I just needed to save some code and there was no email at hand  
> >
> 
> LOL. What an imbecile.
> 
> You gotta love trolls sometimes. They exist with the sole purpose to
> make you feel good about yourself.

And yet another clown joins circus.  This is great entertainment.  

Wassup Mario?   Wanna play?  Write more and see how good I can make you feel.  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 5:15 PM, Steven D'Aprano
 wrote:
> Looks to me that the two string literals each get their own token, and are
> concatenated at a later stage of compilation, not during parsing.

Thanks. The dispute was about expressions, though. I think we're all
in agreement that there are two tokens.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 4:56:41 PM UTC-4, Tim Chase wrote:
> On 2015-03-26 08:33, Tiglath Suriol wrote:
> > > Mark Lawrence  
> > 
> > I don't remember addressing his guy,  HE addressed me FIRST, as all
> > of you did,
> 
> Hmmm...To what then has he been replying?  *You* posted/broadcast the
> FIRST message which addressed every member of the list.  If you
> don't want to address every member of a list, try not posting. Or at
> least expect replies.
> 
> > now you complaint you don't like my replies.
> 
> Mostly it's your uncivil tone that people seem to be complaining
> about.  Reading over the messages in the thread, it's mostly *you*
> complaining about replies.  And you that keeps fanning the flame.
> 
> > I came here because I can and may.
> 
> And folks here replied.  Because they can and may.
> 
> And you're not kidding anybody: your bravado and insults against a
> plurality of respected community members only amplifies your own
> appearance of folly.
> 
> -tkc

It's never long before the semantic obfuscator makes an entrance... 

So for this guy the meaning of "to address" is now to post in newsgroups.  

If you actually post a question or anything that would amount to speaking to a 
person or a group, I could see how it could be considered "addressing" but I 
posted code titled 'test.'  So if that is addressing for you, it says that you 
need to run, not walk, to a library, and see a thing called a dictionary.  

Anything else?  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 5:04:21 PM UTC-4, Joel Goldstick wrote:
> post to yourself
> funny how you have a new email address
> 

The strange fascination you have with the email address of someone you don't 
know that d makes you write more and more, informs readers of how exciting your 
life must be.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Thursday, March 26, 2015 at 11:30:57 AM UTC+5:30, Chris Angelico wrote:
> On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody  wrote:
> > [And BTW
> > help(filter) in python2 is much better documention than in python3
> > ]
> 
> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
> [GCC 4.7.2] on linux2
> 
> filter(...)
> filter(function or None, sequence) -> list, tuple, or string
> 
> Return those items of sequence for which function(item) is true.  If
> function is None, return the items that are true.  If sequence is a tuple
> or string, return the same type, else return a list.
> 
> Python 3.5.0a0 (default:4709290253e3, Jan 20 2015, 21:48:07)
> [GCC 4.7.2] on linux
> 
> class filter(object)
>  |  filter(function or None, iterable) --> filter object
>  |
>  |  Return an iterator yielding those items of iterable for which 
> function(item)
>  |  is true. If function is None, return the items that are true.
>  |
>  |  Methods defined here:
> (chomp a handful of method details)

Sackful may be more accurate :-)

On a different note... I wonder how you do it:
Look at 300 lines of code and notice exactly those 3 that... um... cause 
a lot of trouble :-)
[My eyes just glaze over]

On a more specific note, its the 1st line:

class filter(object)

which knocks me off.
If a more restricted type from the ABC was shown which exactly captures all
the iterator-specific stuff like __iter__, __next__ it would sure help (me)

On a 3rd note: I think Ive found a little buglet while trying to post this 
message, can you confirm?
[Linux Debian Xfce]

After selecting the line above [inside python inside help(filter) ]for
cut-pasting here, by mistake I pressed Ctrl-C rather than Ctrl-Shift-C
An exception was thrown and the terminal remained in some sort of raw mode
even after exiting python
-- 
https://mail.python.org/mailman/listinfo/python-list


Save session Selenium PhantomJS

2015-03-26 Thread Juan C.
Objective: Save the browser session/cookies to share them in multiples
script execution.

I currently have this working using ChromeDriver:

chrome_options = Options()
chrome_options.add_argument("user-data-dir=" + os.path.dirname(sys.argv[0]))
browser = webdriver.Chrome(chrome_options=chrome_options)

This code tells Chrome to use a specific path, in my case the script path,
as "data" folder where it stores everything, and NOT use the default
approach where everything is temporary and deleted when the script exits.

This way, I can login in the site I need once and exit the script. If I
execute the script later everything is already saved and I don't have to
login anymore.

I need this approach because the site has a security measure where they
send a key to my email everytime I login in a "new" PC.


The issue: Now I need to use PhantomJS. I already tried this code:

cookie_path = os.path.join(os.getcwd(), 'cookie.txt')
driver = webdriver.WebDriver(service_args=['--cookies-file=cookies.txt'])

But it doesn't work. I looked at the PhantomJS doc and on Google but didn't
find anything. I hope someone knows better than me and could give me a
"hand" here.

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot Uninstall 3.4

2015-03-26 Thread Mario Figueiredo
On Thu, 26 Mar 2015 18:52:41 -0500, T Younger 
wrote:

>I have 3.4.1 (8/14) and replaced it with 3.4.2 (12/14)
>Neither of these uninstalled or I do not believe even had the option.
>
>I now wanted to update to 3.4.3 and the uninstall fails, provided the
>message that the installer is missing a program then backs off the changes.
>
>I loaded 3.5.0a2 and then uninstalled it OK.
>
>How do I get to 3.4.3 please?
>

What's your system?

There isn't usually any need to uninstall in order to upgrade minor
releases. You just install over the previous one, since Python34 will
still remain the main folder/directory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot Uninstall 3.4

2015-03-26 Thread Ben Finney
T Younger  writes:

> I have 3.4.1 (8/14) and replaced it with 3.4.2 (12/14)
> Neither of these uninstalled or I do not believe even had the option.

That's not so much a question about Python; it is rather a question of
how you install and uninstall applications on your operating system.
There's not enough information in your message to know what's wrong.

What did you use to install each of these? Does whatever did the
installation record un-install information?

-- 
 \ “To label any subject unsuitable for comedy is to admit |
  `\   defeat.” —Peter Sellers |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Tim Chase
On 2015-03-27 10:15, Steven D'Aprano wrote:
> If that's all it is, why don't you just run the tokenizer over it
> and see what it says?
> 
> py> from cStringIO import StringIO
> py> code = StringIO('spam = "abcd" "efgh"\n')
> py> import tokenize
> py> for item in tokenize.generate_tokens(code.readline):
> ... print item
> ...
> (1, 'spam', (1, 0), (1, 4), 'spam = "abcd" "efgh"\n')
> (51, '=', (1, 5), (1, 6), 'spam = "abcd" "efgh"\n')
> (3, '"abcd"', (1, 7), (1, 13), 'spam = "abcd" "efgh"\n')
> (3, '"efgh"', (1, 14), (1, 20), 'spam = "abcd" "efgh"\n')
> (4, '\n', (1, 20), (1, 21), 'spam = "abcd" "efgh"\n')
> (0, '', (2, 0), (2, 0), '')
> 
> 
> Looks to me that the two string literals each get their own token,

Nice.  I haven't played with the tokenize module before, but
resolving arguments on comp.lang.python is one of the best possible
uses.

It was interesting to try other feeders to generate_tokens(), my favorite being

>>> import tokenize
>>> i = iter(["spam = 'abc' 'def'"])
>>> for item in tokenize.generate_tokens(lambda: next(i)):
... print(item)
... 
TokenInfo(type=1 (NAME), string='spam', start=(1, 0), end=(1, 4), line="spam = 
'abc' 'def'")
TokenInfo(type=52 (OP), string='=', start=(1, 5), end=(1, 6), line="spam = 
'abc' 'def'")
TokenInfo(type=3 (STRING), string="'abc'", start=(1, 7), end=(1, 12), 
line="spam = 'abc' 'def'")
TokenInfo(type=3 (STRING), string="'def'", start=(1, 13), end=(1, 18), 
line="spam = 'abc' 'def'")
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')


It's also nice to have the translation from token-type to token-type-name in Py3

-tkc





-- 
https://mail.python.org/mailman/listinfo/python-list


Cannot Uninstall 3.4

2015-03-26 Thread T Younger
I have 3.4.1 (8/14) and replaced it with 3.4.2 (12/14)
Neither of these uninstalled or I do not believe even had the option.

I now wanted to update to 3.4.3 and the uninstall fails, provided the
message that the installer is missing a program then backs off the changes.

I loaded 3.5.0a2 and then uninstalled it OK.

How do I get to 3.4.3 please?

Thank you

Tom Younger
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 12:54 PM, Thomas 'PointedEars' Lahn
 wrote:
> Ian Kelly wrote:
>> What I mean is that if you construct a parse tree of "foo" "bar" using
>> that grammar, it looks like this:
>>
>>  expr
>>|
>> STRING+
>>  /   \
>> STRING  STRING
>> […]
>>
>> There is only one expr node, and it contains both STRING tokens.
>
> Prove it.

I'm not going to expend the effort that would be required to go
through the entire Python grammar step-by-step and exhaustively prove
that "foo" "bar" can unambiguously only be produced as a single expr.
If you believe otherwise, show a parse tree that parses these as
separate expressions.

> But be warned: Neither would prove that a string literal is not an
> expression.

I've not claimed that a string literal is not an expression. My claim
is that a literal consisting of the implicit concatenation of more
than one string token is can only be parsed as one expression, not
several. Parsing "foo" "bar"

>  Because you did not consider the most simple variant of an AST
> (or subtree) according to this grammar:
>
> expr
>  |
>STRING

Of course I did. This is again *exactly* what I was talking about in
reference to parsing the individual strings in isolation.

> Again, “STRING+” does _not_ mean “STRING STRING STRING*”; it means “STRING
> STRING*”.  The second and following STRINGs are *optional*.

Please stop speaking down to me. I'm quite familiar with basic concepts of EBNF.

>>> […] in the used flavour of EBNF the unquoted “+” following a goal symbol
>>> clearly means the occurrence of *at least one* of the immediately
>>> preceding symbol, meaning either one *or more than one*.
>>
>> It means one or more *tokens*, not one or more literals.
>
> Utter nonsense.  Have you ever written a parser?  (I have.)

Yes.

>  A literal *is*
> a token.  Whether two consecutive tokens end up as the same *node* in an AST
> is a *different* issue (that, again, was _not_ debated).

I was going to respond with a comment about how literals are a type of
expression, not token, using a literal tuple as an example of a
literal that is not a token. Then I checked the docs and noticed that
the language reference actually shies away from calling this a literal
and uses the phrase "container display" instead. Browsing through the
specifications of a few other languages (e.g. ECMAscript, which has
so-called "object literals"), they all seem to share the pattern of
using "literal" strictly to mean a type of token in their specs,
despite the word taking on a much broader meaning when writing
informally. So I'll have to concede that point as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 05:56 am, Thomas 'PointedEars' Lahn wrote:
[snip argument]


Hey guys, I'm trying to follow the argument but I must admit you've
completely lost me with the angels-on-the-head-of-a-pin nitpicking about
EBNF. I love a good pedant-brawl as much as you, so let me see if I've got
this straight, correct me if I'm wrong.

You're arguing whether or not in the following line of code:

spam = "abcd" "efgh"
# implicitly concatenated to "abcdefgh" at compile time

the right hand side pair of strings counts as a single token or two? Am I
right, or am I missing something?

If that's all it is, why don't you just run the tokenizer over it and see
what it says?

py> from cStringIO import StringIO
py> code = StringIO('spam = "abcd" "efgh"\n')
py> import tokenize
py> for item in tokenize.generate_tokens(code.readline):
... print item
...
(1, 'spam', (1, 0), (1, 4), 'spam = "abcd" "efgh"\n')
(51, '=', (1, 5), (1, 6), 'spam = "abcd" "efgh"\n')
(3, '"abcd"', (1, 7), (1, 13), 'spam = "abcd" "efgh"\n')
(3, '"efgh"', (1, 14), (1, 20), 'spam = "abcd" "efgh"\n')
(4, '\n', (1, 20), (1, 21), 'spam = "abcd" "efgh"\n')
(0, '', (2, 0), (2, 0), '')


Looks to me that the two string literals each get their own token, and are
concatenated at a later stage of compilation, not during parsing.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 04:11 am, Gregg Dotoli wrote:

>> Thanks for your help and patience. I'm new with Python.

No problems! If you hang around here, pay attention to the constructive
criticism you are given, and ignore the troll over on the "test1" thread,
you'll learn a lot.

Let's look at your code:


>> import os
>> import re
>> # From the Root
>> topdir = "."

Typically, "." is not considered the root, so that comment may be a bit
misleading. On Linux systems, "/" is the root. On Windows, each drive has
its own root, e.g. "C:/". You should consider a more descriptive comment.


>> # Regex Pattern
>> pattern="DECRYPT_I"
>> regexp=re.compile(pattern)

As given, using a regex to search for a fixed substring is rather like
firing up a nuclear-powered bulldozer to crack open a peanut. I will assume
that later you will add more complicated regexes with wildcards. If not,
you are literally wasting time here: substring matching with the "in"
operator will be significantly faster than matching using a regex.


>> for dirpath,dirnames, files in os.walk(topdir):
>> for name in files:
>> result=regexp.search(name)
>> print(os.path.join(dirpath,name))
>> print (result)


All this does is check with the string "DECRYPT_I" is in the file name.


> I posted this because I thought it may be of help to others. This does
> grep through all the files 

It absolutely does not.


> and is very fast because the regex is compiled 
> in Python , rather than sitting in some directory as an external command.
> That is where the optimization comes in.

Please take this with the intention I give it: constructive advice.

"More computing sins are committed in the name of efficiency 
(without necessarily achieving it) than for any other single
reason — including blind stupidity." — W.A. Wulf

This is a great example. You have been too focused on optimizing your code
and not focused enough on getting it to actually work correctly. It's fast,
*not* because "the regex is compiled in Python", but because it doesn't do
the work you think it does.

If you had tested this code, by creating a file called "FOUND IT" containing
the string "xDECRYPT_Ix" (for example), you would have discovered
for yourself that your search tool does not in fact search correctly.

Write your code first. Get it working. Make sure it is working. Then, and
only then, should you try to optimize it. Test your code: if you haven't
tested it, you don't know if it works or not.

Test means, does it work the way it needs to work with files containing the
string *as well as* files not containing the string? It's trivial to check
that the program doesn't find DECRYPT files when there are no DECRYPT
files, but if it fails to find them when they are actually there, that's a
pretty big bug.


And one more quote:

"The First Rule of Program Optimization: Don't do it. 
The Second Rule of Program Optimization (for experts only!): 
Don't do it yet." — Michael A. Jackson

(No, not Michael Jackson the dead pop singer.)



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Gregory Ewing

Ian Kelly wrote:

What I mean is that if you construct a parse tree of "foo" "bar" using
that grammar, it looks like this:

 expr
   |
STRING+
 /   \
STRING  STRING


Not quite -- STRING+ is not a symbol in the grammar, it's
a shorthand for a combination of symbols. The parse tree
is actually just

  expr
  /   \
 STRING  STRING


Not like this:

expr
 |
   STRING+
/  \
 expr  expr
  |  |
STRING  STRING


That would be

> expr
> /  \
>  expr  expr
>   |  |
> STRING  STRING

Thomas 'PointedEars' Lahn wrote:
> Prove it.

To get a parse tree like the above, there would need to be
a production like this in the grammar:

   expr ::= expr+

There is no such production, so that parse tree is impossible.
QED.

What you seem to be doing in your mind is taking this
production:

   expr ::= STRING

and using it "backwards" to justify expanding any occurrence
of STRING into expr. But grammars don't work that way. You're
committing a logical fallacy: just because some exprs are
STRINGs doesn't mean that all STRINGs are exprs.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 07:00 am, BartC wrote:
[...]

Don't give the troll the attention he craves. He reacted with hostility and
scorn when we gave him some friendly good advice, don't imagine for a
second you're going to reason with him. He's admitted that he's been
trolling for years, so don't bother to engage with him.

The problem with wrestling a pig in the mud is that you get dirty and the
pig enjoys it.
 

-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 02:33 am, Joel Goldstick wrote:
[...]

Don't give the troll the attention he craves. He has as much told us that he
is beyond reason -- he's been trolling for years, you don't need to justify
your actions.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 03:26 am, Tim Chase wrote:
[...]

Don't give the troll the attention he craves. He has as much told us that he
is beyond reason -- he's been trolling for years, you don't need to justify
your actions.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Pete Forman
Here's my Python sudoku solver which I wrote about 10 years ago.

http://petef.22web.org/sudoku/

It works by applying the solving techniques I came up with. No trial and
error or backtracking is used, so it is not up to cracking the very
hardest puzzles. Run time is 15 ms to 45 ms on a 2009 MacBook Pro using
Python 2.7.9.

There are verbose options to print the steps. Sizes and multiple grids
are flexible. IIRC it took a day or two to adapt the program when the
first samurai was published.

$ python sudoku.py -i sudoku2.sud
***|7**|***
1**|***|***
***|43*|2**
---+---+---
***|***|**6
***|5*9|***
***|***|418
---+---+---
***|*81|***
**2|***|*5*
*4*|***|3**
Solved, rating: dead easy
Calculation took 18.006 ms
264|715|839
137|892|645
598|436|271
---+---+---
423|178|596
816|549|723
759|623|418
---+---+---
375|281|964
982|364|157
641|957|382


-- 
Pete Forman
http://petef.22web.org/payg.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to calculate fraction part of x?

2015-03-26 Thread Russell Owen

On 3/24/15 6:39 PM, Jason Swails wrote:



On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille mailto:em...@fenx.com>> wrote:

On 3/23/2015 5:52 AM, Steven D'Aprano wrote:

Are there any other, possibly better, ways to calculate the
fractional part
of a number?


float (("%6.3f" % x)[-4:])


​In general you lose a lot of precision this way...​


I suggest modf in the math library:

math.modf(x)
Return the fractional and integer parts of x. Both results carry the 
sign of x and are floats.




--
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to calculate fraction part of x?

2015-03-26 Thread Oscar Benjamin
On 23 March 2015 at 12:52, Steven D'Aprano
 wrote:
> I have a numeric value, possibly a float, Decimal or (improper) Fraction,
> and I want the fractional part. E.g. fract(2.5) should give 0.5.
>
> Here are two ways to do it:
>
> py> x = 2.5
> py> x % 1
> 0.5
> py> x - int(x)
> 0.5
>
> x % 1 is significantly faster, but has the disadvantage of giving the
> complement of the fraction if x is negative:
>
> py> x = -2.75
> py> x % 1
> 0.25

The other version gives -0.75 in this case so I guess that's what you want.

> Are there any other, possibly better, ways to calculate the fractional part
> of a number?

What do you mean by better? Is it just faster?

To modify the % version so that it's equivalent you can do:

>>> x = -2.75
>>> (x % 1) - (x < 0)
-0.75

I'm not sure if that's faster than x - int(x) though. Obviously it
depends which numeric type you're primarily interested in.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sys.exec_prefix doesn't seem to reflect --exec-prefix path

2015-03-26 Thread Ned Deily
In article <548dcac1-fa00-4fc1-81d1-ccae28caf...@googlegroups.com>,
 Ralph Heinkel  wrote:
> on my linux box there is a python version 2.7.5 installed in /usr/local.
> 
> Now I want to install the newer version 2.7.9, but in a different directory 
> to avoid clashes with the current installation.
> 
> What I did was:
> 
> ./configure --prefix /usr/local/Python-2.7.9 --exec-prefix 
> /usr/local/Python-2.7.9
> make
> make install

Configure arguments need to be specified with '='.  Try instead:

./configure --prefix=/usr/local/Python-2.7.9

And --exec-prefix isn't needed in this case as it defaults to the value 
of --prefix.

-- 
 Ned Deily,
 n...@acm.org

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Cameron Simpson

On 26Mar2015 11:37, Peter Otten <__pete...@web.de> wrote:

You are right. [...]

By the way, in this case you don't need the list at all:

def vartuple(vars):
   return namedtuple("locals", vars)._make(vars.values())


Hmm. Neat. I had not realised that was available.

You'd need "vars.keys()", not "vars", for the first use of "vars", BTW:

 return namedtuple("locals", vars.keys())._make(vars.values())

A remark for the OP: a method name like "_make" would normally be something you 
would avoid as it is Python convenion that _* names are "private", which in 
Python usually means subject to arbitrary change and probably not documented; 
internal implementation mechanisms as opposed to published interfaces.


However, in namedtuple the word "_make" is chosen specificly to avoid clashes 
with the "named" tuple values (which would normally not start with "_"), and it 
is explicitly documented.


Thanks Peter!

Cheers,
Cameron Simpson 

Nothing is impossible for the man who doesn't have to do it.
--
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread sohcahtoa82
On Tuesday, March 24, 2015 at 7:48:05 PM UTC-7, Tiglath Suriol wrote:
> 
> 

Re: test1

2015-03-26 Thread Mario Figueiredo
On Thu, 26 Mar 2015 14:06:28 -0700 (PDT), marcuslom...@gmail.com
wrote:

>
>I posted two test messages containing code.  They are still there,
> are you blind as well as dumb? 
>
>Your post is also off-topic, so what are you whining about, girl?  
>
>You can ignore my posts almost effortlessly, the fact that you
>prefer to inveigh in your rant means that you want to be part of
>this.  I'll be happy to oblige, bozo.  Make my day.  
>

Hush now, little baby troll. Don't get all teary on us. Calm down.
Just a little while ago you were saying you didn't care about what
people said.

So don't care about what people say.

BTW, you are as stupid as you are an ignorant little trapped troll.
You purportedly spammed this place and now we are having fun telling
you all about it. Boo hoo!

Now, remember what you said...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Mario Figueiredo
On Thu, 26 Mar 2015 13:58:36 -0700 (PDT), marcuslom...@gmail.com
wrote:

>I just needed to save some code and there was no email at hand  
>

LOL. What an imbecile.

You gotta love trolls sometimes. They exist with the sole purpose to
make you feel good about yourself.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread marcuslom101
On Thursday, March 26, 2015 at 4:03:57 PM UTC-4, Denis McMahon wrote:
> On Thu, 26 Mar 2015 10:00:56 -0700, Tiglath Suriol wrote:
> 
> > I posted two test messages containing code.
> 
> No, you excreted a pile of steaming excrement and have continued to do 
> so. Your original post in this thread had no relevance to the newsgroup 
> or the gated mailing list, it was purely internet vandalism, and your 
> ongoing posts are simply trolling.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com


I posted two test messages containing code.  They are still there, are you 
blind as well as dumb? 

Your post is also off-topic, so what are you whining about, girl?  

You can ignore my posts almost effortlessly, the fact that you prefer to 
inveigh in your rant means that you want to be part of this.  I'll be happy to 
oblige, bozo.  Make my day.  

 


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Joel Goldstick
post to yourself
funny how you have a new email address

On Thu, Mar 26, 2015 at 4:58 PM,   wrote:
> On Thursday, March 26, 2015 at 4:01:08 PM UTC-4, BartC wrote:
>> On 26/03/2015 15:38, Tiglath Suriol wrote:
>>
>> > I did not spam anyone.  I posted to an open public newsgroup.  Just some 
>> > code, nothing offensive or even directed to anyone.  Then people started 
>> > to get cute, and now that returned fire is a bucket a drop they complaints 
>> > like bitches on the rag.  Not surprised, but not SPAM either.  If anyone 
>> > pull a newsgroup into his email that's his doing, not mine.
>>
>> There are 100,000 different public newsgroups for a reason: they are all
>> about different subjects.
>>
>> Your post had nothing to do with Python that I could see.
>
>
> A polite post at last. How refreshing.
>
> That would be two off-topic posts I submitted.  All the replies to it were 
> also off-topic, so it can't possibly be such a big crime.
>
>
>>
>> To post test messages, try alt.test. Otherwise the newsgroup would get
>> swamped if everyone posted irrelevant random stuff.
>
> Say that too to the imbeciles who jumped from the woodwork and made any 
> swamping I may have caused much worst.
>
> The reaction has been far worse than my action.  This stems from regular 
> posters of a newsgroup developing a sense of entitlement and turf, which is 
> purely imaginary.  This is a public place and everyone has the tools to 
> ignore posts and posters.  They just wanted to play and mock and got burned.
>
>
>>
>> BTW why /did/ you choose this newsgroup?
>>
>
> I just needed to save some code and there was no email at hand, I use this 
> because it's a group I am familiar with, alt.test sounds like a better option.
>
> Thanks
>
>
>> --
>> Bartc
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread marcuslom101
On Thursday, March 26, 2015 at 4:01:08 PM UTC-4, BartC wrote:
> On 26/03/2015 15:38, Tiglath Suriol wrote:
> 
> > I did not spam anyone.  I posted to an open public newsgroup.  Just some 
> > code, nothing offensive or even directed to anyone.  Then people started to 
> > get cute, and now that returned fire is a bucket a drop they complaints 
> > like bitches on the rag.  Not surprised, but not SPAM either.  If anyone 
> > pull a newsgroup into his email that's his doing, not mine.
> 
> There are 100,000 different public newsgroups for a reason: they are all 
> about different subjects.
> 
> Your post had nothing to do with Python that I could see.


A polite post at last. How refreshing.  

That would be two off-topic posts I submitted.  All the replies to it were also 
off-topic, so it can't possibly be such a big crime.  


> 
> To post test messages, try alt.test. Otherwise the newsgroup would get 
> swamped if everyone posted irrelevant random stuff.

Say that too to the imbeciles who jumped from the woodwork and made any 
swamping I may have caused much worst.  

The reaction has been far worse than my action.  This stems from regular 
posters of a newsgroup developing a sense of entitlement and turf, which is 
purely imaginary.  This is a public place and everyone has the tools to ignore 
posts and posters.  They just wanted to play and mock and got burned.  


> 
> BTW why /did/ you choose this newsgroup?
> 

I just needed to save some code and there was no email at hand, I use this 
because it's a group I am familiar with, alt.test sounds like a better option.  

Thanks


> -- 
> Bartc

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tim Chase
On 2015-03-26 08:33, Tiglath Suriol wrote:
> > Mark Lawrence  
> 
> I don't remember addressing his guy,  HE addressed me FIRST, as all
> of you did,

Hmmm...To what then has he been replying?  *You* posted/broadcast the
FIRST message which addressed every member of the list.  If you
don't want to address every member of a list, try not posting. Or at
least expect replies.

> now you complaint you don't like my replies.

Mostly it's your uncivil tone that people seem to be complaining
about.  Reading over the messages in the thread, it's mostly *you*
complaining about replies.  And you that keeps fanning the flame.

> I came here because I can and may.

And folks here replied.  Because they can and may.

And you're not kidding anybody: your bravado and insults against a
plurality of respected community members only amplifies your own
appearance of folly.

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best way to calculate fraction part of x?

2015-03-26 Thread Emile van Sebille

On 3/24/2015 6:39 PM, Jason Swails wrote:



On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille 




float (("%6.3f" % x)[-4:])


​In general you lose a lot of precision this way...​



Even more if you use %6.1 -- but feel free to flavor to taste.   :)

Emile



--
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Emile van Sebille

On 3/25/2015 12:49 PM, Tiglath Suriol wrote:

On Tuesday, March 24, 2015 at 11:04:48 PM UTC-4, Chris Angelico wrote:

On Wed, Mar 25, 2015 at 1:47 PM, Tiglath Suriol  wrote:



PLONK<



--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread BartC

On 26/03/2015 15:38, Tiglath Suriol wrote:


I did not spam anyone.  I posted to an open public newsgroup.  Just some code, 
nothing offensive or even directed to anyone.  Then people started to get cute, 
and now that returned fire is a bucket a drop they complaints like bitches on 
the rag.  Not surprised, but not SPAM either.  If anyone pull a newsgroup into 
his email that's his doing, not mine.


There are 100,000 different public newsgroups for a reason: they are all 
about different subjects.


Your post had nothing to do with Python that I could see.

To post test messages, try alt.test. Otherwise the newsgroup would get 
swamped if everyone posted irrelevant random stuff.


BTW why /did/ you choose this newsgroup?

--
Bartc


--
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Denis McMahon
On Thu, 26 Mar 2015 10:00:56 -0700, Tiglath Suriol wrote:

> I posted two test messages containing code.

No, you excreted a pile of steaming excrement and have continued to do 
so. Your original post in this thread had no relevance to the newsgroup 
or the gated mailing list, it was purely internet vandalism, and your 
ongoing posts are simply trolling.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Thomas 'PointedEars' Lahn
Ian Kelly wrote:

> […] Thomas 'PointedEars' Lahn […] wrote:
>> Ian Kelly wrote:
>>> What the grammar that you quoted from shows is that STRING+ is an
>>> expression. The individual STRINGs of a STRING+ are not expressions,
>>> except to the extent that they can be parsed in isolation as a
>>> STRING+.
>> How did you get that idea?  STRING+ means one or more consecutive STRING
>> tokens (ignoring whitespace in-between), which means one or more
>> consecutive string literals.  A (single) string literal definitely is an 
>> expression as it can be produced with the “expr” goal symbol of the 
>> Python grammar (given there in a flavor of EBNF).
> 
> Yes, that's what I was referring to in my parenthetical "except..." above.

Your “except” is contradictory to the rest of what you said, at best.

> What I mean is that if you construct a parse tree of "foo" "bar" using
> that grammar, it looks like this:
> 
>  expr
>|
> STRING+
>  /   \
> STRING  STRING
> […]
> 
> There is only one expr node, and it contains both STRING tokens.

Prove it.

But be warned: Neither would prove that a string literal is not an 
expression.  Because you did not consider the most simple variant of an AST 
(or subtree) according to this grammar:

expr
 |
   STRING

Again, “STRING+” does _not_ mean “STRING STRING STRING*”; it means “STRING 
STRING*”.  The second and following STRINGs are *optional*.

>> […] in the used flavour of EBNF the unquoted “+” following a goal symbol
>> clearly means the occurrence of *at least one* of the immediately
>> preceding symbol, meaning either one *or more than one*.
> 
> It means one or more *tokens*, not one or more literals.

Utter nonsense.  Have you ever written a parser?  (I have.)  A literal *is* 
a token.  Whether two consecutive tokens end up as the same *node* in an AST 
is a *different* issue (that, again, was _not_ debated).
 
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Thomas 'PointedEars' Lahn
Ian Kelly wrote:

> On Thu, Mar 26, 2015 at 12:29 PM, Ian Kelly  wrote:
>> On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn
>>> No, in the used flavour of EBNF the unquoted “+” following a goal symbol
>>> clearly means the occurrence of *at least one* of the immediately
>>> preceding symbol, meaning either one *or more than one*.
>>
>> It means one or more *tokens*, not one or more literals.
> 
> Although reading the documentation, it seems that it also conflates
> string literals with tokens,

There is nothing to conflate here.  String literals *are* tokens.

> so on that I'll have to concede the point.

Too late, the rebuttal is already underway :-p

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 12:29 PM, Ian Kelly  wrote:
> On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn
>> No, in the used flavour of EBNF the unquoted “+” following a goal symbol
>> clearly means the occurrence of *at least one* of the immediately preceding
>> symbol, meaning either one *or more than one*.
>
> It means one or more *tokens*, not one or more literals.

Although reading the documentation, it seems that it also conflates
string literals with tokens, so on that I'll have to concede the
point.

https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 10:45 AM, Thomas 'PointedEars' Lahn
 wrote:
> Ian Kelly wrote:
>> What the grammar that you quoted from shows is that STRING+ is an
>> expression. The individual STRINGs of a STRING+ are not expressions,
>> except to the extent that they can be parsed in isolation as a
>> STRING+.
>
> How did you get that idea?  STRING+ means one or more consecutive STRING
> tokens (ignoring whitespace in-between), which means one or more consecutive
> string literals.  A (single) string literal definitely is an expression as
> it can be produced with the “expr” goal symbol of the Python grammar (given
> there in a flavor of EBNF).

Yes, that's what I was referring to in my parenthetical "except..." above.

What I mean is that if you construct a parse tree of "foo" "bar" using
that grammar, it looks like this:

 expr
   |
STRING+
 /   \
STRING  STRING

Not like this:

expr
 |
   STRING+
/  \
 expr  expr
  |  |
STRING  STRING

There is only one expr node, and it contains both STRING tokens.

>> By the same token, a STRING+ is a single string literal, not
>> an aggregate of several.
>
> No, in the used flavour of EBNF the unquoted “+” following a goal symbol
> clearly means the occurrence of *at least one* of the immediately preceding
> symbol, meaning either one *or more than one*.

It means one or more *tokens*, not one or more literals.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote:

>   multiple-string = STRING *STRING
> […]
> in ABNF.

JFTR: ABNF allows for

  multiple-string = 1*STRING

to be equivalent to the above.

 pp.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Thomas 'PointedEars' Lahn
Dave Angel wrote:

[Fixed quotation]

> On 03/26/2015 01:09 AM, Ian Kelly wrote:
> Thomas 'PointedEars' Lahn wrote:
>> > 
>> literal-concatenation>
>>
>> What the grammar that you quoted from shows is that STRING+ is an
>> expression. The individual STRINGs of a STRING+ are not expressions,
>> except to the extent that they can be parsed in isolation as a
>> STRING+. By the same token, a STRING+ is a single string literal, not
>> an aggregate of several.
> 
> That's the way I also read the BNF.

Then I am afraid you need to refresh your knowledge of formal grammars.

> But something I cannot find in that chapter of the reference is the
> definition of STRING+

You *definitely* need to refresh your knowledge of formal grammars.

“STRING+” in this flavor of _E_BNF is – rather obviously – equivalent to

   ::=  *
::= '"' * '"'
  | "'" * "'"
  | '"""' * '"""'
  | "'''" * "'''"

in BNF and

  multiple-string = STRING *STRING
  STRING  = '"' *no-unescaped-doublequote '"'
  / "'" *no-unescaped-singlequote '"'
  / '"""' *no-unescaped-triple-doublequote '"""'
  / "'''" *no-unescaped-triple-singlequote "'''"

in ABNF.  I suspect that in this flavor of EBNF the definition of STRING 
looks similar to the following:

  STRING: ('"' no_unescaped_doublequote* '"'
 | "'" no_unescaped_singlequote* "'"
 | '"""' no_unescaped_triple_doublequote* '"""'
 | "'''" no_unescaped_triple_singlequote* "'''")

Definition of the still undefined goal symbols is left as an exercise to the 
reader.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread Dave Angel

On 03/26/2015 01:11 PM, Gregg Dotoli wrote:

On Wednesday, March 25, 2015 at 3:43:38 PM UTC-4, Gregg Dotoli wrote:

This basic script will help to find
evidence of CryptoWall on a slave drive. Although it is
just a string, more complex regex patterns can be
replaced with the string. It is incredible how fast Python is and
how easy it has helped in quickly assessing a pool of slave drives.
I'm improving it as we speak.


Thanks for your help and patience. I'm new with Python.


import os
import re
# From the Root
topdir = "."

# Regex Pattern
pattern="DECRYPT_I"
regexp=re.compile(pattern)
for dirpath,dirnames, files in os.walk(topdir):
 for name in files:
 result=regexp.search(name)
 print(os.path.join(dirpath,name))
 print (result)





Gregg Dotoli


I posted this because I thought it may be of help to others. This does grep 
through all the files and is very fast because the regex is compiled in Python 
, rather than sitting in some directory as an external command.
That is where the optimization comes in.

Let's close this thread.




It "grep"s through all the filenames, but there's no open() call or 
equivalent there at all.  it does not look inside a single file.


We can stop posting to the thread, but that won't fix the bug in the code.

--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread Gregg Dotoli
On Wednesday, March 25, 2015 at 3:43:38 PM UTC-4, Gregg Dotoli wrote:
> This basic script will help to find 
> evidence of CryptoWall on a slave drive. Although it is
> just a string, more complex regex patterns can be 
> replaced with the string. It is incredible how fast Python is and
> how easy it has helped in quickly assessing a pool of slave drives.
> I'm improving it as we speak.
> 
> 
> Thanks for your help and patience. I'm new with Python.
> 
> 
> import os
> import re
> # From the Root
> topdir = "."
> 
> # Regex Pattern
> pattern="DECRYPT_I"
> regexp=re.compile(pattern)
> for dirpath,dirnames, files in os.walk(topdir):
> for name in files:
> result=regexp.search(name)
> print(os.path.join(dirpath,name))
> print (result)
> 
> 
> 
> 
> 
> Gregg Dotoli

I posted this because I thought it may be of help to others. This does grep 
through all the files and is very fast because the regex is compiled in Python 
, rather than sitting in some directory as an external command.
That is where the optimization comes in.

Let's close this thread.



Gregg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 11:34:11 AM UTC-4, Joel Goldstick wrote:
> On Thu, Mar 26, 2015 at 11:25 AM, Tiglath Suriol
>  wrote:
> > On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote:
> >> Your first message was not python related.  Your subsequent messages
> >> were rude.  You've never been here before it seems.  This is an
> >> interesting group, open to all with interest in python.  How do you
> >> fit in?  Not
> >>
> >> On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol  wrote:
> >> > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote:
> >> >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote:
> >> >>
> >> >> > I've dealt with people like you in newsgroups for a long time
> >> >>
> >> >> So many years, so little learning. It's arseholes like you who make it 
> >> >> so
> >> >> important to invent a way to stab people through the internet. Just go
> >> >> away, you're not wanted here.
> >> >>
> >> >
> >> > I may stay a while just to poke you in the eye a little longer.  I am 
> >> > beginning to enjoy this.  People entering a battle of wits unarmed.  
> >> > It's a joy to watch.
> >> >
> >> >
> >> > You talk as if I wanted you to want me.  Pure delusion.  I posted at 
> >> > nobody, as I am free to do, and idiots come out of the woodwork as if I 
> >> > had committed some infraction.
> >> >
> >> > And you even want to stab me.  Sterling.  Who raised you. wolves?
> >> >
> >> >
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Steven
> >> >
> >> > --
> >> > https://mail.python.org/mailman/listinfo/python-list
> >>
> >>
> >>
> >> --
> >> Joel Goldstick
> >> http://joelgoldstick.com
> >
> > Rather...
> >
> > I came here because I can and may. but I did no provoke anyone.
> >
> > Then the Central Scrutinizer chimed in followed by his Seven Dwarves and 
> > his bitches.  Now you, in which group do you fit?
> >
> > Had you all minded your business I wouldn't be here.  Saving yourselves all 
> > those inane s, and even more inane retorts.
> >
> > Now be sincere, you write at me because this is like gawking at an accident 
> > on the road, it's a disturbance in your otherwise Pythonic, catatonic day.
> >
> > I did not intend to, but since you appeared, I don't mind kicking your 
> > asses for laughs. So please write more.
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> You came here to be on display since you have some sort of warped
> sense of self.  Show your mother what you write online.  Maybe she can
> get you help
> 

Look at the facts, Harpo.  

I posted two test messages containing code.  

I did not address anyone, I did not ask anything, I made no comment. Said 
nothing about me or anyone.  

Posts are still there. See them.  

All large groups have the type of lame people who like those on the road cause 
a jam to look at some disturbance.  Same here, it was just code, idiots. But 
you could not let it go.  Had to poke your long noses in it.  Now that you've 
found little pleasure in your endevour, you are plonking and whining like stuck 
pigs.  Serves you right.  

You are free to ignore any post you object to. You also have the power to 
killfile anyone, so if you are still here stinking my thread is because either 
you are as thick as a brick, or you want a pissing contest.  

Which one is it?  Bring it on or buzz off, but for fuck's sake stop whining.
  




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Ian Kelly :

> On Thu, Mar 26, 2015 at 9:48 AM, Marko Rauhamaa  wrote:
>> In fact, the "trial-and-error" technique is used in automated theorem
>> proving:
>>
>>   Lean provers are generally implemented in Prolog, and make proficient
>>   use of the backtracking engine and logic variables of that language.
>>
>>   http://en.wikipedia.org/wiki/Lean_theorem_prover>
>
> Sure, but what has this to do with the statement that *sudoku* should
> not require trial and error to solve?

Trial-and-error was presented in opposition to logical deduction, while
really trial-and-error *is* logical deduction.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-26 Thread Thomas 'PointedEars' Lahn
Ian Kelly wrote:

> […] Thomas 'PointedEars' Lahn […] wrote:
>> Chris Angelico wrote:
>>> […] Thomas 'PointedEars' Lahn […] wrote:
> Implicit concatenation is part of the syntax, not part of the
> expression evaluator.
 Reads like nonsense to me.
>>> What do you mean?
>> As I showed, string literals and consecutive tokens of string literals
>> (“STRING+”) so as to do implicit concatenation *are* expressions of the
>> Python grammar.  Expressions are *part of* the syntax of a programming
>> language.
>>
>> Perhaps you mean that the time when implicit concatenation is evaluated
>> (compile time) differs from the time when other expressions are evaluated
>> (runtime).  But a) whether that is true depends on the implementation and
>> b) there can be no doubt that either expression needs to be evaluated. 
>> So whatever you mean by “expression evaluator” has to be able to do those
>> things.
>>
>> Which makes the statement above read like nonsense to me.
> 
> What the grammar that you quoted from shows is that STRING+ is an
> expression. The individual STRINGs of a STRING+ are not expressions,
> except to the extent that they can be parsed in isolation as a
> STRING+.

How did you get that idea?  STRING+ means one or more consecutive STRING 
tokens (ignoring whitespace in-between), which means one or more consecutive 
string literals.  A (single) string literal definitely is an expression as 
it can be produced with the “expr” goal symbol of the Python grammar (given 
there in a flavor of EBNF).

> By the same token, a STRING+ is a single string literal, not
> an aggregate of several.

No, in the used flavour of EBNF the unquoted “+” following a goal symbol 
clearly means the occurrence of *at least one* of the immediately preceding 
symbol, meaning either one *or more than one*.

 pp.

> Ancillary data point:
> 
> >>> help(ast.literal_eval)
> Safely evaluate an expression node or a string containing a Python
> expression.  The string or node provided may only consist of the 
> following Python literal structures: strings, bytes, numbers, tuples, 
> lists, dicts, sets, booleans, and None.
> >>> ast.literal_eval('"foo" "bar"')
> 'foobar'
> 
> So the ast.literal_eval also treats this as one literal expression.

What do you mean?

ast.literal_eval() sees a single string value resulting from the evaluation 
of one string literal, by the Python compiler, that contains the 
representation of two consecutive string literals:

  '"foo" "bar"'

It then does exactly what the Python compiler would do in such a case: parse 
this as if it were one string literal (the “implicit concatenation” I am 
talking about).

  "foo" "bar" ≡ "foobar"

This was not debated.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 9:48 AM, Marko Rauhamaa  wrote:
> Ian Kelly :
>
>> On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa  wrote:
>>> That's trial and error, aka, reductio ad absurdum.
>>
>> Okay, I've probably used single-lookahead trial and error in my
>> reasoning at some point. But the example you give is equivalent to the
>> deductive process "That can't be a 5, so I remove it as a candidate.
>> The only place left for a 5 is here, so I remove the 2 as a candidate
>> and fill in the 5."
>
> In fact, the "trial-and-error" technique is used in automated theorem
> proving:
>
>   Lean provers are generally implemented in Prolog, and make proficient
>   use of the backtracking engine and logic variables of that language.
>
>   http://en.wikipedia.org/wiki/Lean_theorem_prover>

Sure, but what has this to do with the statement that *sudoku* should
not require trial and error to solve?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is elegant way to do configuration on server app

2015-03-26 Thread Grant Edwards
On 2015-03-26, Ben Finney  wrote:
> Jerry OELoo  writes:
>
>> Currently, I can just think out that I put status into a configure
>> file, and service schedule read this file and get status value,
>
> That sounds like a fine start. Some advice:
>
> * You may be tempted to make the configuration file executable (e.g.
>   Python code). Resist that temptation; keep it *much* simpler, a
>   non-executable data format.
>
>   Python's standard library has the ‘configparser’ module
>  https://docs.python.org/3/library/configparser.html> to parse and
>   provide the values from a very common configuration file format.
>   Use that unless you have a good reason not to.

I second the recommendation for configparser for stuff of simple to
moderate complexity.  If it gets too complex for configparser, you may
want to consider JSON, or for even more complex stuff just use plain
Python code in your config file (this can be very powerful and
expressive, but can also be diffucult to implement safely).

> * Your program can “poll” the configuration file to see whether it has
>   changed. At startup, read the config file's modification timestamp
>  https://docs.python.org/3/library/os.html#os.stat_result.st_mtime>.
>
>   Make a part of your event loop (assuming your server runs an event
>   loop) that wakes up every N seconds (e.g. every 60 seconds) and
>   checkes the file's modification timestamp again; if it's newer, record
>   that value for future comparisons, then re-read the file for its
>   values.

That sounds rather Windowsesque.  The more-or-less standard way to do
handle the situation on Unix is to reread the config file when you get
a SIGHUP.

-- 
Grant Edwards   grant.b.edwardsYow! ONE LIFE TO LIVE for
  at   ALL MY CHILDREN in ANOTHER
  gmail.comWORLD all THE DAYS OF
   OUR LIVES.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Ian Kelly :

> On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa  wrote:
>> That's trial and error, aka, reductio ad absurdum.
>
> Okay, I've probably used single-lookahead trial and error in my
> reasoning at some point. But the example you give is equivalent to the
> deductive process "That can't be a 5, so I remove it as a candidate.
> The only place left for a 5 is here, so I remove the 2 as a candidate
> and fill in the 5."

In fact, the "trial-and-error" technique is used in automated theorem
proving:

  Lean provers are generally implemented in Prolog, and make proficient
  use of the backtracking engine and logic variables of that language.

  http://en.wikipedia.org/wiki/Lean_theorem_prover>


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Dave Angel :

> When in a playful mood, I wonder if all the Sudoku puzzles out there
> are just permutations of a few hundred written by Will Shortz.

A sudoku solver can be trivially turned into a puzzle generator:


$ ./sudoku.py --generate >puzzle.dat
$ cat puzzle.dat
3 . 2 . 4 . . . .
4 5 . . . 6 . . .
6 . . . 9 . . 8 .
. . . . . . 5 . .
. 6 4 . . 9 . 3 .
. 7 3 5 . . . 4 8
. . . . . . 8 . .
. 8 . . 7 . . . 3
. . . . 1 . . . 2

$ ./sudoku.py  1 and sys.argv[1] == "--generate":
generate()
return
board = []
for n in sys.stdin.read().split():
try:
board.append(int(n))
except ValueError:
board.append(EMPTY)
for solution in solve(board):
report(solution)

def generate():
report(minimize(next(solve([ EMPTY ] * Q

def solve(board, slot=0):
if slot == Q:
yield board[:]
elif board[slot] is EMPTY:
shuffled = candidates[:]
random.shuffle(shuffled)
for candidate in shuffled:
for buddy in buddies[slot]:
if board[buddy] is candidate:
break
else:
board[slot] = candidate
yield from solve(board, slot + 1)
board[slot] = EMPTY
else:
yield from solve(board, slot + 1)

def minimize(board):
while True:
nonempty_slots = [ slot for slot in range(Q)
   if board[slot] is not EMPTY ]
random.shuffle(nonempty_slots)
for slot in nonempty_slots:
removed, board[slot] = board[slot], EMPTY
if uniquely_solvable(board):
break
board[slot] = removed
else:
return board

def uniquely_solvable(board):
it = solve(board[:])
next(it)
try:
next(it)
except StopIteration:
return True
return False

def report(board):
print("\n".join(
" ".join(str(board[row * N + col])
 for col in range(N))
for row in range(N)))
print()

if __name__ == '__main__':
main()



Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Grant Edwards
On 2015-03-25, Ian Kelly  wrote:
> On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards  
> wrote:
>> On 2015-03-25, Ian Kelly  wrote:
>>> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune  
>>> wrote:
>>>
 I'm looking for a way to supply a condition to an if-statement inside a
 function body when calling the function. I can sort of get what I want
 with using eval [...]
>>>
>>> Pass the condition as a function.
>>>
>>> def test1(a, b, condition=lambda i, j: True):
>>> for i,j in zip(a,b):
>>> c=i+j
>>> if condition(i, j):
>>> print("Foo")
>>>
>>> test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4)
>>> # etc.
>>
>> FWIW, back in the day such a function was referred to as a "thunk"
>> (particularly if it was auto-generated by a compiler that used
>> pass-by-name instead of pass-by-value or pass-by-reference):
>>
>>   http://en.wikipedia.org/wiki/Thunk
>>
>> Dunno if people still use that term or not.
>
> I've heard the term (though not since my college days, I think), but
> I've always understood thunks to be parameterless (hence the use as a
> form of pass-by-name).

You're right -- I misread the example. Somehow I skipped the "for i,j"
line completely, and was thinking that i and j were defined in the
caller's context. Thus the OP was trying to implment something akin to
call by name.

-- 
Grant Edwards   grant.b.edwardsYow! Here I am in the
  at   POSTERIOR OLFACTORY LOBULE
  gmail.combut I don't see CARL SAGAN
   anywhere!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 9:52:36 AM UTC-4, Ian wrote:
> On Mar 26, 2015 7:35 AM, "Igor Korot"  wrote:
> 
> >
> 
> >  On Thu, Mar 26, 2015 at 9:01 AM, alister
> 
> >  wrote:
> 
> > > i hope he has a good spam filter as I am about to sign him up for
> 
> > > everything :-)
> 
> >
> 
> > Well he did gave out his private key to the public in an ASCII format.
> 
> > I wonder what people can do with it? ;-)
> 
> Spamming someone as a response to being spammed is reasonable, in an 
> eye-for-an-eye kind of way (though a bit childish). Hacking their site is not.
> 
> Besides, it would be a lot more work for you to do anything untoward with it 
> than it would be for him to just change it.

Get your facts right, Sherlock.  

I did not spam anyone.  I posted to an open public newsgroup.  Just some code, 
nothing offensive or even directed to anyone.  Then people started to get cute, 
and now that returned fire is a bucket a drop they complaints like bitches on 
the rag.  Not surprised, but not SPAM either.  If anyone pull a newsgroup into 
his email that's his doing, not mine.  

Hack me all you want. I dare you.  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 11:14:06 AM UTC-4, Mark Lawrence wrote:
> On 26/03/2015 01:26, Tiglath Suriol wrote:
> > On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote:
> >>
> >> You might be used to dealing with other people in other newsgroups.
> >> This is the Python main mailing list/newsgroup.  There is a rather more
> >> civilised way of doing things around here.
> >
> > What arrogance,  So you think you are special.  I see the same busybodies 
> > here as in other newsgroups.  Same shit.  Why don't you write some Python 
> > instead of minding my business?
> >
> >
> >   As for ignoring you, why
> >> don't you simply stop posting, then we won't have to?
> >> e
> >
> > We? Is that the royal we or you speak for some group?
> >
> > You won't have to?  Hilarious!
> >
> > I've heard of the tail wagging the dog, but the knee jerking the jerk is 
> > quite an admission you just made.
> >
> > There is a good reason why I posted two test messages, but I don't owe you 
> > that explanation, so you will have to put up with that uncontrollable knee 
> > jerk for as long as I post spitballs at you, minus any explanation.  Feel 
> > free to mind your business.
> >
> >> --
> >> My fellow Pythonistas, ask not what our language can do for you, ask
> >> what you can do for our language.
> >>
> >> Mark Lawrence
> >
> 
> Everything reported as abuse on google groups 

How brave.  He starts an argument and not goes to tell the teacher because got 
a bloody nose.  Plonk and run to hide under the bed as fast as your little legs 
will carry you, Mark.  


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 11:14:06 AM UTC-4, Mark Lawrence wrote:
> On 26/03/2015 01:26, Tiglath Suriol wrote:
> > On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote:
> >>
> >> You might be used to dealing with other people in other newsgroups.
> >> This is the Python main mailing list/newsgroup.  There is a rather more
> >> civilised way of doing things around here.
> >
> > What arrogance,  So you think you are special.  I see the same busybodies 
> > here as in other newsgroups.  Same shit.  Why don't you write some Python 
> > instead of minding my business?
> >
> >
> >   As for ignoring you, why
> >> don't you simply stop posting, then we won't have to?
> >> e
> >
> > We? Is that the royal we or you speak for some group?
> >
> > You won't have to?  Hilarious!
> >
> > I've heard of the tail wagging the dog, but the knee jerking the jerk is 
> > quite an admission you just made.
> >
> > There is a good reason why I posted two test messages, but I don't owe you 
> > that explanation, so you will have to put up with that uncontrollable knee 
> > jerk for as long as I post spitballs at you, minus any explanation.  Feel 
> > free to mind your business.
> >
> >> --
> >> My fellow Pythonistas, ask not what our language can do for you, ask
> >> what you can do for our language.
> >>
> >> Mark Lawrence
> >
> 
> Everything reported as abuse on google groups and marked as spam on 
> gmane.  What else is there to do?  Ah yes.
> 
> *plonk*
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

I don't remember addressing his guy,  HE addressed me FIRST, as all of you did, 
now you complaint you don't like my replies.  That is what happens to nosy 
fishwives.  

The sooner you all "plonk" me the sooner you can go back to your ordinary 
lives. 



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Joel Goldstick
On Thu, Mar 26, 2015 at 11:25 AM, Tiglath Suriol
 wrote:
> On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote:
>> Your first message was not python related.  Your subsequent messages
>> were rude.  You've never been here before it seems.  This is an
>> interesting group, open to all with interest in python.  How do you
>> fit in?  Not
>>
>> On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol  wrote:
>> > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote:
>> >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote:
>> >>
>> >> > I've dealt with people like you in newsgroups for a long time
>> >>
>> >> So many years, so little learning. It's arseholes like you who make it so
>> >> important to invent a way to stab people through the internet. Just go
>> >> away, you're not wanted here.
>> >>
>> >
>> > I may stay a while just to poke you in the eye a little longer.  I am 
>> > beginning to enjoy this.  People entering a battle of wits unarmed.  It's 
>> > a joy to watch.
>> >
>> >
>> > You talk as if I wanted you to want me.  Pure delusion.  I posted at 
>> > nobody, as I am free to do, and idiots come out of the woodwork as if I 
>> > had committed some infraction.
>> >
>> > And you even want to stab me.  Sterling.  Who raised you. wolves?
>> >
>> >
>> >>
>> >>
>> >>
>> >> --
>> >> Steven
>> >
>> > --
>> > https://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>> --
>> Joel Goldstick
>> http://joelgoldstick.com
>
> Rather...
>
> I came here because I can and may. but I did no provoke anyone.
>
> Then the Central Scrutinizer chimed in followed by his Seven Dwarves and his 
> bitches.  Now you, in which group do you fit?
>
> Had you all minded your business I wouldn't be here.  Saving yourselves all 
> those inane s, and even more inane retorts.
>
> Now be sincere, you write at me because this is like gawking at an accident 
> on the road, it's a disturbance in your otherwise Pythonic, catatonic day.
>
> I did not intend to, but since you appeared, I don't mind kicking your asses 
> for laughs. So please write more.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

You came here to be on display since you have some sort of warped
sense of self.  Show your mother what you write online.  Maybe she can
get you help

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 9:53:48 AM UTC-4, Joel Goldstick wrote:
> Your first message was not python related.  Your subsequent messages
> were rude.  You've never been here before it seems.  This is an
> interesting group, open to all with interest in python.  How do you
> fit in?  Not
> 
> On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol  wrote:
> > On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote:
> >> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote:
> >>
> >> > I've dealt with people like you in newsgroups for a long time
> >>
> >> So many years, so little learning. It's arseholes like you who make it so
> >> important to invent a way to stab people through the internet. Just go
> >> away, you're not wanted here.
> >>
> >
> > I may stay a while just to poke you in the eye a little longer.  I am 
> > beginning to enjoy this.  People entering a battle of wits unarmed.  It's a 
> > joy to watch.
> >
> >
> > You talk as if I wanted you to want me.  Pure delusion.  I posted at 
> > nobody, as I am free to do, and idiots come out of the woodwork as if I had 
> > committed some infraction.
> >
> > And you even want to stab me.  Sterling.  Who raised you. wolves?
> >
> >
> >>
> >>
> >>
> >> --
> >> Steven
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com

Rather... 

I came here because I can and may. but I did no provoke anyone. 

Then the Central Scrutinizer chimed in followed by his Seven Dwarves and his 
bitches.  Now you, in which group do you fit?  

Had you all minded your business I wouldn't be here.  Saving yourselves all 
those inane s, and even more inane retorts. 

Now be sincere, you write at me because this is like gawking at an accident on 
the road, it's a disturbance in your otherwise Pythonic, catatonic day.  

I did not intend to, but since you appeared, I don't mind kicking your asses 
for laughs. So please write more.  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Chris Angelico
On Fri, Mar 27, 2015 at 2:03 AM, Dave Angel  wrote:
> On 03/26/2015 10:41 AM, Chris Angelico wrote:
>  that's already been proven. So, that's why I would avoid guessing.
>>
>>
>> I've written a lot of solvers for various puzzles. Minesweeper,
>> Sudoku, a binary Sudoku-like puzzle that I don't really have a good
>> name for, several others. Every time, I've tried to prove the puzzles
>> solvable by humans, and sometimes that means rejecting ones that could
>> technically be solved by brute force.
>
>
> OK, we're on the same page.  I would use different terminology for some of
> it, but that's okay.

Good, I thought we were in agreement. And yeah, terminology is tricky.

> The purist in me would like to write a solver which (within a few seconds)
> could solve any unique puzzle, and identify puzzles which don't have a
> unique solution.  One reason I never got back to writing one was I also
> wanted a difficulty-ranker, which would identify how hard a human was likely
> to consider the puzzle.

It'd be pretty straight-forward. You simply define a number of
rule-difficulty-categories, something like this:

EASY
* If eight digits are "locked off" from a cell by already existing in
its neighbours, the remaining digit must be the one.
* If eight cells in a {row, column, square} have a given digit locked
off, then the remaining cell must contain that digit.

MEDIUM
* Construct "possibility regions" for digits in squares (ie all the
possible cells that that digit could be in). Any such region which
sits within a single row/column is equivalent to an actual digit in
that row/column for the purposes of exclusions.
* Likewise the converse - if both possible places for the 7 in this
row are in this square, we can depend on the 7 being in one of those,
and not anywhere else in the square.

HARD
* Any complex rule that you feel like coding up. There are plenty of
"Sudoku help" web sites out there that can provide rule definitions.

IMPOSSIBLE
* Brute force. Attempt to put a digit in a cell, then see if you can
solve the puzzle thereafter. If you prove the puzzle to have no
solutions, that digit cannot be in that cell.

Then, in your solver, you use EASY rules until they provide you with
no more material, and only then move on to MEDIUM rules, etc. The
highest difficulty class that you had to use in solving the puzzle is
the puzzle's difficulty class.

This isn't a perfect system, of course, but it's a decent start. It
also deals with the terminology problem: you can declare a puzzle
"solvable, but IMPOSSIBLE class difficulty", which means you have to
guess. Though I would strongly suggest disabling brute-forcing most of
the time, as it'll kill your CPU... especially if you have a puzzle
generation algorithm that looks like this:

Start with a blank grid.
While puzzle not solvable:
Add random clue digit
For each clue digit:
Remove clue
If puzzle not solvable: Reinstate clue

With IMPOSSIBLE deactivated, this is a reasonably straight-forward way
to generate puzzles (and you can deactivate HARD to require a
medium-difficulty puzzle, etc). Otherwise... kerchug, kerchug,
kerchug

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 9:33:43 AM UTC-4, Igor Korot wrote:
> On Thu, Mar 26, 2015 at 9:01 AM, alister
>  wrote:
> > On Thu, 26 Mar 2015 00:36:49 +, Mark Lawrence wrote:
> >
> >> On 26/03/2015 00:17, MRAB wrote:
> >>> On 2015-03-25 22:36, Chris Angelico wrote:
>  On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol
>   wrote:
> > Two possibilities:
> >
> >You are a moderator. If you are a moderator you are welcome to
> > delete my tests posts. This is of course improbably because this
> > newsgroup is not moderated.
> 
>  You misunderstand newsgroups and mailing lists. Posts do not get
>  deleted after the event. Even on a web forum, where an administrator
>  can delete posts, the information is already out there; the instant
>  any one person has seen your post, you've lost control of it. So think
>  about what you post - especially when (as in your other thread) it
>  contains private information.
> 
> > The other possibility is that you are just a guy, who despite the
> > fact that my posts cost you nothing, and you are absolutely free to
> > ignore them, your life is so dull that that you just must intervene
> > and comment on anything you do not comprehend, because appointing
> > yourself net cop is about as exciting as it gets.
> >
> > It's a free country, I know.  You have every right to engage in
> > pathetic speech.
> 
>  You also misunderstand freedom. I suggest you explore all three
>  concepts (freedom, newsgroups, and mailing lists), and learn what
>  you're actually dealing with. You may find the results rewarding.
> 
>  ChrisA
> 
> >>> A quick search suggests that he has prior form.
> >>
> >> How many years did he get?  Was it PHP or C++ ? :)
> >
> > i hope he has a good spam filter as I am about to sign him up for
> > everything :-)
> 
> Well he did gave out his private key to the public in an ASCII format.
> I wonder what people can do with it? ;-)

You got me there. Dang!  



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Tiglath Suriol
On Thursday, March 26, 2015 at 9:01:23 AM UTC-4, alister wrote:
> On Thu, 26 Mar 2015 00:36:49 +, Mark Lawrence wrote:
> 
> > On 26/03/2015 00:17, MRAB wrote:
> >> On 2015-03-25 22:36, Chris Angelico wrote:
> >>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol
> >>>  wrote:
>  Two possibilities:
> 
> You are a moderator. If you are a moderator you are welcome to
>  delete my tests posts. This is of course improbably because this
>  newsgroup is not moderated.
> >>>
> >>> You misunderstand newsgroups and mailing lists. Posts do not get
> >>> deleted after the event. Even on a web forum, where an administrator
> >>> can delete posts, the information is already out there; the instant
> >>> any one person has seen your post, you've lost control of it. So think
> >>> about what you post - especially when (as in your other thread) it
> >>> contains private information.
> >>>
>  The other possibility is that you are just a guy, who despite the
>  fact that my posts cost you nothing, and you are absolutely free to
>  ignore them, your life is so dull that that you just must intervene
>  and comment on anything you do not comprehend, because appointing
>  yourself net cop is about as exciting as it gets.
> 
>  It's a free country, I know.  You have every right to engage in
>  pathetic speech.
> >>>
> >>> You also misunderstand freedom. I suggest you explore all three
> >>> concepts (freedom, newsgroups, and mailing lists), and learn what
> >>> you're actually dealing with. You may find the results rewarding.
> >>>
> >>> ChrisA
> >>>
> >> A quick search suggests that he has prior form.
> > 
> > How many years did he get?  Was it PHP or C++ ? :)
> 
> i hope he has a good spam filter as I am about to sign him up for 
> everything :-)
> 

You are all booster and no warhead, mental midgets.  

As if I would use my regular email to visit this place.  


> 
> 
> 
> -- 
> Violence in reality is quite different from theory.
>   -- Spock, "The Cloud Minders", stardate 5818.4

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Mark Lawrence

On 26/03/2015 01:26, Tiglath Suriol wrote:

On Wednesday, March 25, 2015 at 7:58:11 PM UTC-4, Mark Lawrence wrote:


You might be used to dealing with other people in other newsgroups.
This is the Python main mailing list/newsgroup.  There is a rather more
civilised way of doing things around here.


What arrogance,  So you think you are special.  I see the same busybodies here 
as in other newsgroups.  Same shit.  Why don't you write some Python instead of 
minding my business?


  As for ignoring you, why

don't you simply stop posting, then we won't have to?
e


We? Is that the royal we or you speak for some group?

You won't have to?  Hilarious!

I've heard of the tail wagging the dog, but the knee jerking the jerk is quite 
an admission you just made.

There is a good reason why I posted two test messages, but I don't owe you that 
explanation, so you will have to put up with that uncontrollable knee jerk for 
as long as I post spitballs at you, minus any explanation.  Feel free to mind 
your business.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




Everything reported as abuse on google groups and marked as spam on 
gmane.  What else is there to do?  Ah yes.


*plonk*

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 8:23 AM, Marko Rauhamaa  wrote:
> Ian Kelly :
>
>> I don't think that I have used trial and error, in my head or
>> otherwise, in any sudoku I have ever solved.
>
> Of course you have. "This here can't be a 2 because if it were a 2, that
> there would have to be a 5, which is impossible. Thus, the only
> remaining alternative is 3, so I mark that down."
>
> That's trial and error, aka, reductio ad absurdum.
>
> (Additionally, sudoku solvers are known to pencil all kinds of markings
> on the sudoku sheets to help the deduction work.)

Okay, I've probably used single-lookahead trial and error in my
reasoning at some point. But the example you give is equivalent to the
deductive process "That can't be a 5, so I remove it as a candidate.
The only place left for a 5 is here, so I remove the 2 as a candidate
and fill in the 5."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Dave Angel

On 03/26/2015 10:41 AM, Chris Angelico wrote:
 that's already been proven. So, that's why I would avoid guessing.


I've written a lot of solvers for various puzzles. Minesweeper,
Sudoku, a binary Sudoku-like puzzle that I don't really have a good
name for, several others. Every time, I've tried to prove the puzzles
solvable by humans, and sometimes that means rejecting ones that could
technically be solved by brute force.


OK, we're on the same page.  I would use different terminology for some 
of it, but that's okay.


The purist in me would like to write a solver which (within a few 
seconds) could solve any unique puzzle, and identify puzzles which don't 
have a unique solution.  One reason I never got back to writing one was 
I also wanted a difficulty-ranker, which would identify how hard a human 
was likely to consider the puzzle.


Had I been writing it in Python, I'd probably have pursued adding brute 
force, and then used some of the code to write a puzzle-generator.  But 
even then, the problem of ranking was one that had me buffaloed.  It's 
clearly not enough to count the starting clues


(eg. easyness = (clues - 17) * pi )

And writing an efficient program that generates a non-trivial puzzle 
would seem to be quite hard.  I've heard it said that Sudoku puzzles 
generated by machines are much less satisfying than those generated by a 
human.


When in a playful mood, I wonder if all the Sudoku puzzles out there are 
just permutations of a few hundred written by Will Shortz.  Swap around 
rows, columns, boxes, and cryptogram the digit mapping.  Voila, a new 
puzzle.i read a short story about the purpose of jokes, in which 
it said there were only a few hundred of them, the rest were just minor 
variants, and that they were an experiment being run on human beings. 
And once we realized it, they'd shut off our sense of humor.


--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Chris Angelico
On Fri, Mar 27, 2015 at 1:14 AM, Dave Angel  wrote:
> On 03/26/2015 08:37 AM, Chris Angelico wrote:
>> Nothing. And solving a Sudoku puzzle - or any other puzzle - should
>> require no guessing. It should be possible to solve purely by logic.
>> Same goes for every other kind of puzzle out there; it's highly
>> unsatisfying to play Minesweeper and get to the end with a block of
>> four squares in a corner, two mines left, and no way of knowing which
>> diagonal has the mines and which is clear.
>>
>> No trial-and-error, thanks.
>
>
> I think you're making an unwarranted assumption here.  Your Minesweeper
> example has two solutions, so there's no way of telling which is the
> "correct" one.  But I'd claim that there are puzzles which have exactly one
> solution, but which need trial and error at some point to find that
> solution.

Only one can possibly be correct; if you dig one cell, you'll die, and
if you dig the other, you'll win. But you have no way of knowing which
is which, without dying, using some kind of "undo" feature (orange
smoke comes to mind), and trying the other. Or, of course, guessing
right, in which case you win.

> I'm not sure how to prove it, since somebody could claim that I just haven't
> tried all the non-trial-and-error rules.

With Sudoku, there are some pretty complicated rules and patterns.
Minesweeper is much simpler to prove. But there are still rules and
patterns, and at some point, you simply have to say that a puzzle is
"beyond the logic of this set of rules". It might not be beyond a more
comprehensive set of rules, but that doesn't matter; you've proven the
puzzle to be unsolvable *with your (program's) skill set*.

> I did write a Sudoku-solver many years ago, in C++, and it solved the
> typical Sudoku I fed it in about 2ms.  But it was deliberately written to
> apply only rules that humans could readily apply.  No backtracking. I did
> not at that time have any electronic source for puzzles, and I got bored
> with manually entering them in from puzzle books.  So I never actually
> encountered a puzzle it couldn't solve.  I mostly used it to determine that
> a puzzle I couldn't manually solve was in fact uniquely solvable, and that
> I'd just messed up somehow.
>
> I wish I still had that source code, as it probably sounds like I'm blowing
> smoke here.
>
> The general approach I used was to make objects of each of the cells, which
> tracked its neighbors to decide whether its value was determined.  And when
> it was determined, it notified its other neighbors.  In turn, if that
> decided a value for any of the neighbors, that cell notified its neighbors.
> Likewise each row or column or box kept track of its state and notified the
> appropriate cells whenever something interesting was discovered.  Then the
> outer loop just tickled each cell in turn, and the solution rippled out.

Not entirely sure I have this correct, but it sounds like you have a
basic solver that uses one rule: If there is no other value that can
be in this cell, you can write this one down. It's certainly possible
to add a lot more sophistication to a solver; for instance, in this
grid, it's possible to place a 4 with certainty:

. . . | . . . | . . .
. . . | 4 . . | . . .
. . . | . . . | . . 4
--+---+--
. . . | . . . | . . .
. . . | . . . | . . .
. . . | . . . | . 4 .
--+---+--
. . . | . . . | . . .
. . . | . 1 2 | . . .
4 . . | . . . | . . .

An examination of the bottom-center block shows that the 4 in it must
be on its top row (even though you don't know which of two
possibilities has it), ergo the bottom-right block must have its 4 on
the center row. The more of these kinds of rules you have, the more
puzzles you can solve - but I would still code the solver to avoid
guessing.

> Maybe I'm misinterpreting your phrase "No trial and error, thanks". Perhaps
> you're saying that puzzles that require trial and error are no fun to solve
> for humans.  And that's a different matter entirely.  I do the daily KenKen
> puzzles in my local paper, and they're just hard enough to be fun, seldom
> taking longer than I'm willing to take in the mornings.

I agree that they're no fun for humans. That's part of the point, but
not the whole point. Since we're talking about puzzles, here, the
primary purpose of a machine solver is (or should be!) to prove that a
puzzle is solvable, and thus worthy of being given to a human. So the
solver should restrict itself to what's considered worth working with
- and in some cases, might restrict itself even further ("generate an
easy puzzle, please"), by cutting out some forms of logic. Now, if
your humans are happy with puzzles that they have to guess, then sure,
incorporate guessing in your solver. But if the humans aren't, then
what do you prove by having an electronic solver that can do the
puzzle? There's a small mathematical curiosity to finding out just how
few clues can carry sufficient information to uniquely define a grid,
but that's alrea

Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Ian Kelly :

> I don't think that I have used trial and error, in my head or
> otherwise, in any sudoku I have ever solved.

Of course you have. "This here can't be a 2 because if it were a 2, that
there would have to be a 5, which is impossible. Thus, the only
remaining alternative is 3, so I mark that down."

That's trial and error, aka, reductio ad absurdum.

(Additionally, sudoku solvers are known to pencil all kinds of markings
on the sudoku sheets to help the deduction work.)


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Marko Rauhamaa :

> I have optimized my solution slightly:
>
>   1. precalculated integer division operations (big savings)
>
>   2. interned integers (little savings)
>
> The example above now finishes in 41 minutes on my computer. (The C
> version finishes in 13 seconds).

Any considered harmfull.

Changing an "any" test to a loop shortens the solving time from 41
minutes to 14 minutes.

Object creation overhead seems to be the killer. The program still has a
prominent integer incrementation...


#!/usr/bin/env python3

import sys

M = 3
N = M * M
P = M * N
Q = M * P

buddies = [ [ buddy
  for buddy in range(Q)
  if buddy != slot and
  (buddy % N == slot % N or
   buddy // N == slot // N or
   buddy // P == slot // P and
   buddy % N // M == slot % N // M) ]
for slot in range(Q) ]
interned = { n : n for n in range(1, N + 1) }
candidates = list(interned.values())

def main():
board = []
for n in sys.stdin.read().split():
try:
board.append(int(n))
except ValueError:
board.append(None)
solve(board)

def solve(board, slot=0):
if slot == Q:
report(board)
elif board[slot] is None:
for candidate in candidates:
for buddy in buddies[slot]:
if board[buddy] is candidate:
break
else:
board[slot] = candidate
solve(board, slot + 1)
board[slot] = None
else:
solve(board, slot + 1)

def report(board):
print("\n".join(
" ".join(str(board[row * N + col])
 for col in range(N))
for row in range(N)))
print()

if __name__ == '__main__':
main()



Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Dave Angel

On 03/26/2015 08:37 AM, Chris Angelico wrote:

On Thu, Mar 26, 2015 at 11:26 PM, Marko Rauhamaa  wrote:

"Frank Millman" :


Here is another python-based sudoku solver -

http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py

>From its docstring -

"A proper Sudoku puzzle must have a unique solution, and it should be
possible to reach that solution by a sequence of logical deductions
without trial and error.


I don't think that statement holds water. Trial-and-error is at the
basis of deduction (reductio ad absurdum). The human solver employs it
in their head. The question is, what is the difference between
pen-and-paper and in-your-head for a computer program?


Nothing. And solving a Sudoku puzzle - or any other puzzle - should
require no guessing. It should be possible to solve purely by logic.
Same goes for every other kind of puzzle out there; it's highly
unsatisfying to play Minesweeper and get to the end with a block of
four squares in a corner, two mines left, and no way of knowing which
diagonal has the mines and which is clear.

No trial-and-error, thanks.


I think you're making an unwarranted assumption here.  Your Minesweeper 
example has two solutions, so there's no way of telling which is the 
"correct" one.  But I'd claim that there are puzzles which have exactly 
one solution, but which need trial and error at some point to find that 
solution.


I'm not sure how to prove it, since somebody could claim that I just 
haven't tried all the non-trial-and-error rules.


I did write a Sudoku-solver many years ago, in C++, and it solved the 
typical Sudoku I fed it in about 2ms.  But it was deliberately written 
to apply only rules that humans could readily apply.  No backtracking. 
I did not at that time have any electronic source for puzzles, and I got 
bored with manually entering them in from puzzle books.  So I never 
actually encountered a puzzle it couldn't solve.  I mostly used it to 
determine that a puzzle I couldn't manually solve was in fact uniquely 
solvable, and that I'd just messed up somehow.


I wish I still had that source code, as it probably sounds like I'm 
blowing smoke here.


The general approach I used was to make objects of each of the cells, 
which tracked its neighbors to decide whether its value was determined. 
 And when it was determined, it notified its other neighbors.  In turn, 
if that decided a value for any of the neighbors, that cell notified its 
neighbors.  Likewise each row or column or box kept track of its state 
and notified the appropriate cells whenever something interesting was 
discovered.  Then the outer loop just tickled each cell in turn, and the 
solution rippled out.



Maybe I'm misinterpreting your phrase "No trial and error, thanks". 
Perhaps you're saying that puzzles that require trial and error are no 
fun to solve for humans.  And that's a different matter entirely.  I do 
the daily KenKen puzzles in my local paper, and they're just hard enough 
to be fun, seldom taking longer than I'm willing to take in the mornings.


--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Joel Goldstick
Apparently Tiglath is a troll:  see this:
http://www.science-bbs.com/121-math/6b7f8c793e31402e.htm

On Thu, Mar 26, 2015 at 9:51 AM, Ian Kelly  wrote:
> On Mar 26, 2015 7:35 AM, "Igor Korot"  wrote:
>>
>>  On Thu, Mar 26, 2015 at 9:01 AM, alister
>>  wrote:
>> > i hope he has a good spam filter as I am about to sign him up for
>> > everything :-)
>>
>> Well he did gave out his private key to the public in an ASCII format.
>> I wonder what people can do with it? ;-)
>
> Spamming someone as a response to being spammed is reasonable, in an
> eye-for-an-eye kind of way (though a bit childish). Hacking their site is
> not.
>
> Besides, it would be a lot more work for you to do anything untoward with it
> than it would be for him to just change it.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread Joel Goldstick
Your first message was not python related.  Your subsequent messages
were rude.  You've never been here before it seems.  This is an
interesting group, open to all with interest in python.  How do you
fit in?  Not

On Wed, Mar 25, 2015 at 9:34 PM, Tiglath Suriol  wrote:
> On Wednesday, March 25, 2015 at 7:59:34 PM UTC-4, Steven D'Aprano wrote:
>> On Thu, 26 Mar 2015 10:43 am, Tiglath Suriol wrote:
>>
>> > I've dealt with people like you in newsgroups for a long time
>>
>> So many years, so little learning. It's arseholes like you who make it so
>> important to invent a way to stab people through the internet. Just go
>> away, you're not wanted here.
>>
>
> I may stay a while just to poke you in the eye a little longer.  I am 
> beginning to enjoy this.  People entering a battle of wits unarmed.  It's a 
> joy to watch.
>
>
> You talk as if I wanted you to want me.  Pure delusion.  I posted at nobody, 
> as I am free to do, and idiots come out of the woodwork as if I had committed 
> some infraction.
>
> And you even want to stab me.  Sterling.  Who raised you. wolves?
>
>
>>
>>
>>
>> --
>> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: test1

2015-03-26 Thread Ian Kelly
On Mar 26, 2015 7:35 AM, "Igor Korot"  wrote:
>
>  On Thu, Mar 26, 2015 at 9:01 AM, alister
>  wrote:
> > i hope he has a good spam filter as I am about to sign him up for
> > everything :-)
>
> Well he did gave out his private key to the public in an ASCII format.
> I wonder what people can do with it? ;-)

Spamming someone as a response to being spammed is reasonable, in an
eye-for-an-eye kind of way (though a bit childish). Hacking their site is
not.

Besides, it would be a lot more work for you to do anything untoward with
it than it would be for him to just change it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: test1

2015-03-26 Thread Igor Korot
 On Thu, Mar 26, 2015 at 9:01 AM, alister
 wrote:
> On Thu, 26 Mar 2015 00:36:49 +, Mark Lawrence wrote:
>
>> On 26/03/2015 00:17, MRAB wrote:
>>> On 2015-03-25 22:36, Chris Angelico wrote:
 On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol
  wrote:
> Two possibilities:
>
>You are a moderator. If you are a moderator you are welcome to
> delete my tests posts. This is of course improbably because this
> newsgroup is not moderated.

 You misunderstand newsgroups and mailing lists. Posts do not get
 deleted after the event. Even on a web forum, where an administrator
 can delete posts, the information is already out there; the instant
 any one person has seen your post, you've lost control of it. So think
 about what you post - especially when (as in your other thread) it
 contains private information.

> The other possibility is that you are just a guy, who despite the
> fact that my posts cost you nothing, and you are absolutely free to
> ignore them, your life is so dull that that you just must intervene
> and comment on anything you do not comprehend, because appointing
> yourself net cop is about as exciting as it gets.
>
> It's a free country, I know.  You have every right to engage in
> pathetic speech.

 You also misunderstand freedom. I suggest you explore all three
 concepts (freedom, newsgroups, and mailing lists), and learn what
 you're actually dealing with. You may find the results rewarding.

 ChrisA

>>> A quick search suggests that he has prior form.
>>
>> How many years did he get?  Was it PHP or C++ ? :)
>
> i hope he has a good spam filter as I am about to sign him up for
> everything :-)

Well he did gave out his private key to the public in an ASCII format.
I wonder what people can do with it? ;-)
>
>
>
>
> --
> Violence in reality is quite different from theory.
> -- Spock, "The Cloud Minders", stardate 5818.4
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Ian Kelly
On Mar 26, 2015 6:31 AM, "Marko Rauhamaa"  wrote:
>
> "Frank Millman" :
>
> > Here is another python-based sudoku solver -
> >
> > http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py
> >
> >>From its docstring -
> >
> > "A proper Sudoku puzzle must have a unique solution, and it should be
> > possible to reach that solution by a sequence of logical deductions
> > without trial and error.
>
> I don't think that statement holds water. Trial-and-error is at the
> basis of deduction (reductio ad absurdum). The human solver employs it
> in their head. The question is, what is the difference between
> pen-and-paper and in-your-head for a computer program?

It's an accurate characterization of the sort of puzzles that are typically
presented as sudoku. I don't think that I have used trial and error, in my
head or otherwise, in any sudoku I have ever solved.

> > It solved Marko's original puzzle and Ian's puzzle in less than a
> > second. It could not solve Marko's second one, returning "impossible"
> > immediately.

Perhaps this is why that puzzle was described as being so difficult: it
required steps that human solvers don't usually take.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test1

2015-03-26 Thread alister
On Thu, 26 Mar 2015 00:36:49 +, Mark Lawrence wrote:

> On 26/03/2015 00:17, MRAB wrote:
>> On 2015-03-25 22:36, Chris Angelico wrote:
>>> On Thu, Mar 26, 2015 at 6:49 AM, Tiglath Suriol
>>>  wrote:
 Two possibilities:

You are a moderator. If you are a moderator you are welcome to
 delete my tests posts. This is of course improbably because this
 newsgroup is not moderated.
>>>
>>> You misunderstand newsgroups and mailing lists. Posts do not get
>>> deleted after the event. Even on a web forum, where an administrator
>>> can delete posts, the information is already out there; the instant
>>> any one person has seen your post, you've lost control of it. So think
>>> about what you post - especially when (as in your other thread) it
>>> contains private information.
>>>
 The other possibility is that you are just a guy, who despite the
 fact that my posts cost you nothing, and you are absolutely free to
 ignore them, your life is so dull that that you just must intervene
 and comment on anything you do not comprehend, because appointing
 yourself net cop is about as exciting as it gets.

 It's a free country, I know.  You have every right to engage in
 pathetic speech.
>>>
>>> You also misunderstand freedom. I suggest you explore all three
>>> concepts (freedom, newsgroups, and mailing lists), and learn what
>>> you're actually dealing with. You may find the results rewarding.
>>>
>>> ChrisA
>>>
>> A quick search suggests that he has prior form.
> 
> How many years did he get?  Was it PHP or C++ ? :)

i hope he has a good spam filter as I am about to sign him up for 
everything :-)




-- 
Violence in reality is quite different from theory.
-- Spock, "The Cloud Minders", stardate 5818.4
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread CHIN Dihedral
> Gregg Dotoli

Are you reminding everyone who had a PC running DOS2.X-3X in 1990. 

It was really a pain at that time 
that a hard disk of an intel-MS based PC was sold hundreds of dollars, and 
another pain was that the buyer had to use the disabled 
dir in DOS after buying a HD.


-- 
https://mail.python.org/mailman/listinfo/python-list


sys.exec_prefix doesn't seem to reflect --exec-prefix path

2015-03-26 Thread Ralph Heinkel
Hi,

on my linux box there is a python version 2.7.5 installed in /usr/local.

Now I want to install the newer version 2.7.9, but in a different directory to 
avoid clashes with the current installation.

What I did was:

./configure --prefix /usr/local/Python-2.7.9 --exec-prefix 
/usr/local/Python-2.7.9
make
make install

Everything looks fine, Python is installed in the proper directory.

BUT: When I run /usr/local/Python-2.7.9/bin/python and do 'print 
sys.exec_prefix' it prints '/usr/local' instead of '/usr/local/Python-2.7.9'.

This has the effect that the old libraries of version 2.7.5 are used instead of 
the 2.7.9 ones.

The docs in https://docs.python.org/2/library/sys.html state that 
sys.exec_prefix will reflect the value given to option --exec-prefix at 
configuration time. Any idea what I did wrong? 

Thanks for your help,

Ralph
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Chris Angelico
On Thu, Mar 26, 2015 at 11:26 PM, Marko Rauhamaa  wrote:
> "Frank Millman" :
>
>> Here is another python-based sudoku solver -
>>
>> http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py
>>
>>>From its docstring -
>>
>> "A proper Sudoku puzzle must have a unique solution, and it should be
>> possible to reach that solution by a sequence of logical deductions
>> without trial and error.
>
> I don't think that statement holds water. Trial-and-error is at the
> basis of deduction (reductio ad absurdum). The human solver employs it
> in their head. The question is, what is the difference between
> pen-and-paper and in-your-head for a computer program?

Nothing. And solving a Sudoku puzzle - or any other puzzle - should
require no guessing. It should be possible to solve purely by logic.
Same goes for every other kind of puzzle out there; it's highly
unsatisfying to play Minesweeper and get to the end with a block of
four squares in a corner, two mines left, and no way of knowing which
diagonal has the mines and which is clear.

No trial-and-error, thanks.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
"Frank Millman" :

> Here is another python-based sudoku solver -
>
> http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py
>
>>From its docstring -
>
> "A proper Sudoku puzzle must have a unique solution, and it should be
> possible to reach that solution by a sequence of logical deductions
> without trial and error.

I don't think that statement holds water. Trial-and-error is at the
basis of deduction (reductio ad absurdum). The human solver employs it
in their head. The question is, what is the difference between
pen-and-paper and in-your-head for a computer program?

(Question: Are computers good at blindfold chess?)

> To the extent possible, we strive to keep the same ethic in our
> automated solver, by mimicking human rule-based reasoning, rather than
> resorting to brute force backtracking search."

That's cool...

> A neat feature is that, having printed the solution, it then lists
> every step it took in its reasoning process to arrive at the solution.
>
> It solved Marko's original puzzle and Ian's puzzle in less than a
> second. It could not solve Marko's second one, returning "impossible"
> immediately.

... but that realization greatly reduces the value of the solver.

I brought up sudoku solving as a "real-world" example of the usefulness
of exhaustive recursion. The concerns on astronomical execution times
must be considered but at the same time, one should realize things
aren't as bad as they would seem: exhaustion is a practical way to solve
sudoku puzzles and analogous programming challenges.

The compactness of a working sudoku solver should demonstrate something
about (1) the usefulness of recursion and (2) the expressive power of
Python.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-26 Thread Marko Rauhamaa
Abhiram R :

> On Thu, Mar 26, 2015 at 8:54 AM, Ian Kelly  wrote:
>> On Wed, Mar 25, 2015 at 8:56 PM, Abhiram R  wrote:
>>> On Mar 26, 2015 5:39 AM, "Ian Kelly"  wrote:
 $ cat sudoku2.dat
 . . . 7 . . . . .
 1 . . . . . . . .
 . . . 4 3 . 2 . .
 . . . . . . . . 6
 . . . 5 . 9 . . .
 . . . . . . 4 1 8
 . . . . 8 1 . . .
 . . 2 . . . . 5 .
 . 4 . . . . 3 . .

 I tried the first puzzle you posted, and it took about a second. I
 then started running it on this one before I started typing up this
 post, and it hasn't finished yet.
>>>
>>> So... Is it done yet? And if yes, how long did it take?
>>
>> I don't know, I killed it at about 16 minutes.
>
> :( Too bad. I'll give it a go myself. And then try implementing my own
> solution. Have a lot of time on my hands today :D

Early optimization and so on and so forth...

I have optimized my solution slightly:

  1. precalculated integer division operations (big savings)

  2. interned integers (little savings)

The example above now finishes in 41 minutes on my computer. (The C
version finishes in 13 seconds).

The program runs single-threaded. Taking the trouble to parallelize the
algorithm is out of scope for the purposes of this discussion; it would
necessarily destroy the compactness of the solution.


#!/usr/bin/env python3

import sys

M = 3
N = M * M
P = M * N
Q = M * P

buddies = [ [ buddy
  for buddy in range(Q)
  if buddy != slot and
  (buddy % N == slot % N or
   buddy // N == slot // N or
   buddy // P == slot // P and
   buddy % N // M == slot % N // M) ]
for slot in range(Q) ]
interned = { n : n for n in range(1, N + 1) }
candidates = list(interned.values())

def main():
board = []
for n in sys.stdin.read().split():
try:
board.append(int(n))
except ValueError:
board.append(None)
solve(board)

def solve(board, slot=0):
if slot == Q:
report(board)
elif board[slot] is None:
for candidate in candidates:
if not any(board[buddy] is candidate for buddy in buddies[slot]):
board[slot] = candidate
solve(board, slot + 1)
board[slot] = None
else:
solve(board, slot + 1)

def report(board):
print("\n".join(
" ".join(str(board[row * N + col])
 for col in range(N))
for row in range(N)))
print()

if __name__ == '__main__':
main()



Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-26 Thread Denis McMahon
On Wed, 25 Mar 2015 14:19:39 -0700, Gregg Dotoli wrote:

> On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote:
>> On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote:
>> 
>> > I am creating a tool to search a filesystem for one simple string.
>> 
>> man grep
>> 
>> STOP! REINVENTING! THE! WHEEL!
>> 
>> Your new wheel will invariably be slower and less efficient than the
>> old one.

> Grep is regular expressions. If I'm using Python, I'll use the Python
> modules.
> Silly

1. Please don't top post, this is usenet, we don't top post, comments go 
after the text they comment on soi we can read down the page and it makes 
sense.

2. You gave the thread the title of "regex python help".

3. Your initial comment was "I am creating a tool to search a filesystem 
for one simple string."

4. The tool (see 3) already exists, it's called grep, it uses regular 
expressions (see 2). It's also going to be a lot faster than using python.

5. According to your post, grep seems to be the tool you are looking for.

6. Reinventing grep in python seems much more silly to me, by the time 
you've finished writing and testing the python code (especially if you 
need to seek help from a newsgroup in the process) grep would have found 
and identified every file containing your "one simple string".

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Function Defaults - avoiding unneccerary combinations of arguments at input

2015-03-26 Thread Steven D'Aprano
On Thu, 26 Mar 2015 08:47 pm, Ivan Evstegneev wrote:

> 
> 
>> -Original Message-
>> From: Python-list [mailto:python-list-
>> bounces+webmailgroups=gmail@python.org] On Behalf Of Steven
>> D'Aprano
>> Sent: Thursday, March 26, 2015 01:49
>> To: python-list@python.org
>> Subject: Re: Function Defaults - avoiding unneccerary combinations of
>> arguments at input
>> 
>> On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote:
>> 
>> > Hello all ,
>> >
>> >
>> > Just a little question about function's default arguments.
>> >
>> > Let's say I have this function:
>> >
>> > def  my_fun(history=False, built=False, current=False, topo=None,
>> > full=False, file=None):
>> > if currnet and full:
>> > do something_1
>> > elif current and file:
>> > do something_2
>> > elif history and full and file:
>> > do something_3

[...]

> As I said in a previous mail, main purpose of this arguments is to define
> what path should be chose. It is actually one xls file that could be
> placed into various placed within my folder tree.
> 
> For instance, I have following folder tree:
> 
> data_lib/
> current/
> history/
> built/
> 
> Say  I have "test.xls" that could be in one of those three folders.
> I wrote a function that reads it out, and its input arguments just define
> where it should be read. So  all those "ifs" related to path definition.

Perhaps something like this?

def my_func(subdir):
if subdir not in ("current", "history", "built"):
raise ValueError("invalid sub-directory")
# Better to use os.path.join, but I'm feeling lazy.
path = "path/to/data_lib/" + subdir + "/test.xls"
process(path)




-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Peter Otten
Cameron Simpson wrote:

> On 26Mar2015 10:03, Peter Otten <__pete...@web.de> wrote:
>>Cameron Simpson wrote:
>>>   vars = locals()
>>>   varnames = list(vars.keys())
>>
>>That leaves varnames in undefined order. Consider
>>
>>varnames = sorted(vars)
> 
> Actually, not necessary.
> 
> I started with sorted, but it is irrelevant, so I backed off to "list" to
> avoid introducing an unwarranted implication, in fact precisely the
> implicaion you are making.
> 
> The only requirement, which I mentioned, is that the values used to
> initialise the namedtuple are supplied in the same order as the tuple
> field names, so all that is needed is to suck the .keys() out once and use
> them in the same order when we construct the namedtuple. Hence just a
> list.

You are right. 

Once I spotted the "error" I failed to notice that you pass the named tuple 
as a single argument, i. e. condition(nt), not condition(*nt) :(

By the way, in this case you don't need the list at all:

def vartuple(vars):
return namedtuple("locals", vars)._make(vars.values())


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module attributes and docstrings

2015-03-26 Thread Chris Angelico
On Thu, Mar 26, 2015 at 8:53 PM, Mario Figueiredo  wrote:
> However, lambda functions do read well in my mind and I find it hard
> to spot where they obscure the code more than a function. So the
> explicit vs. implicit part of the argument doesn't translate well with
> me. I however agree that a function declaration brings other benefits,
> like the ability to decorate or document.

A function is a function is a function, so really, it's just a
question of whether you create them with a statement (def) or an
expression (lambda). Two basic rules of thumb:

1) If you're assigning a lambda function to a simple name, then you
don't need it to be an expression, so use def.
2) If you're warping your function body to make it an expression, use def.

Basically, look at the outside and look at the inside. In some cases,
it's obvious that it's all expressions:

# Sort a list of widget objects by name
widgets.sort(key=lambda w: w.name)

Other times, it's pretty obvious that you should be using statements:

delete_name_if_blank = lambda w: delattr(w, "name") if w.name == "" else None
list(map(delete_name_if_blank, widgets))

In between, there's a lot of room to call it either way.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Cameron Simpson

On 26Mar2015 10:03, Peter Otten <__pete...@web.de> wrote:

Cameron Simpson wrote:

  vars = locals()
  varnames = list(vars.keys())


That leaves varnames in undefined order. Consider

varnames = sorted(vars)


Actually, not necessary.

I started with sorted, but it is irrelevant, so I backed off to "list" to avoid 
introducing an unwarranted implication, in fact precisely the implicaion you 
are making.


The only requirement, which I mentioned, is that the values used to initialise 
the namedtuple are supplied in the same order as the tuple field names, so all 
that is needed is to suck the .keys() out once and use them in the same order 
when we construct the namedtuple. Hence just a list.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: module attributes and docstrings

2015-03-26 Thread Mario Figueiredo
On Tue, 24 Mar 2015 15:33:41 -0400, Terry Reedy 
wrote:

>
>You have discovered one of advantages of a def statement over a 
>name=lambda assignment statement.  In Python, there is no good reason to 
>use the latter form and PEP 8 specifically discourages it: "Always use a 
>def statement instead of an assignment statement that binds a lambda 
>expression directly to an identifier."

Chris also suggested me this. And frankly, I don't see why I shouldn't
follow that advise. It's good advice.

However, lambda functions do read well in my mind and I find it hard
to spot where they obscure the code more than a function. So the
explicit vs. implicit part of the argument doesn't translate well with
me. I however agree that a function declaration brings other benefits,
like the ability to decorate or document.

I will reserve the use of lambdas to only where they are necessary.
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module attributes and docstrings

2015-03-26 Thread Mario Figueiredo
Sorry for the late reply. We experienced a 3 day blackout following
one of the most amazing thunderstorms I've witnessed in my life.

On Tue, 24 Mar 2015 22:49:49 +1100, Steven D'Aprano
 wrote:

>On Tue, 24 Mar 2015 07:55 pm, Mario Figueiredo wrote:
>
>> Reading PEP 257 and 258 I got the impression that I could document
>> module attributes and these would be available in the __doc__
>> attribute of the object.
>
>PEP 258 is rejected, so you can't take that as definitive.

Ah! That explains it then. Thank you.

(Also learned to start paying more attention to the status field).

>
>PEP 257 has this definition very early in the document:
>
>A docstring is a string literal that occurs as the first 
>statement in a module, function, class, or method definition.
>
>
>Nothing there about documenting arbitrary attributes.

That did get me a little confused. But since PEP 258 required PEP 257,
I just assumed the former would redefine the latter and didn't make
much of the apparent contradiction.

>
>Even if there was support from the compiler to extract the docstring, where
>would it be stored? Consider:
>
>spam = None
>"""Spammy goodness."""
>eggs = None
>"""Scrambled, not fried."""
>
>There's only one None object, and even if it could take a docstring (and it
>can't), which docstring would it get? Presumably the second, which would
>make help(spam) confusing, but when we say eggs = 23 the docstring would
>disappear too.

This is a byproduct of me still thinking in terms of C variables. When
I first read that paragraph of yours, it didn't make sense to me --
"What is he talking about? I'm documenting the spam and eggs
identifiers, not the None object".

But when I was trying to reply to you by mounting a case around
writing directly to the __doc__ attribute of the spam and eggs
identifiers, the python shell was quick to make me realized my
foolishness, and I remembered about Python variables not being the
same as C variables.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Function Defaults - avoiding unneccerary combinations of arguments at input

2015-03-26 Thread Ivan Evstegneev


> -Original Message-
> From: Python-list [mailto:python-list-
> bounces+webmailgroups=gmail@python.org] On Behalf Of Steven
> D'Aprano
> Sent: Thursday, March 26, 2015 01:49
> To: python-list@python.org
> Subject: Re: Function Defaults - avoiding unneccerary combinations of
> arguments at input
> 
> On Thu, 26 Mar 2015 04:43 am, Ivan Evstegneev wrote:
> 
> > Hello all ,
> >
> >
> > Just a little question about function's default arguments.
> >
> > Let's say I have this function:
> >
> > def  my_fun(history=False, built=False, current=False, topo=None,
> > full=False, file=None):
> > if currnet and full:
> > do something_1
> > elif current and file:
> > do something_2
> > elif history and full and file:
> > do something_3
> 
> 
> This is an extreme example that shows why Guido's Law "No constant
> arguments" is a good design principle. (Well, it's not really so much a
law as a
> guideline.)
> 
> If you have a function that looks like this:
> 
> def spam(arg, flag=True):
> if flag:
> return do_this(arg)
> else:
> return do_that(arg)
> 
> 
> then you should just use do_this and do_that directly and get rid of spam.
> 
> In your case, its hard to say *exactly* what you should do, since you are
only
> showing a small sketch of "my_fun", but it looks to me that it tries to do
too
> much. You can probably split it into two or four smaller functions, and
avoid
> needing so many (or any!) flags.
> 
> That will avoid (or at least reduce) the need to check for mutually
> incompatible sets of arguments.
> 
> Another useful design principle: if dealing with the combinations of
> arguments is too hard, that's a sign that you have too many combinations
of
> arguments.
> 
> If there are combinations which are impossible, there are three basic ways
to
> deal with that. In order from best to worst:
> 
> 
> (1) Don't let those combinations occur at all. Redesign your function, or
split
> it into multiple functions, so the impossible combinations no longer
exist.
> 
> (2) Raise an error when an impossible combination occurs.
> 
> (3) Just ignore one or more argument so that what was impossible is now
> possible.
> 
> 
> 
> 
> --
> Steven
> 
> --
> https://mail.python.org/mailman/listinfo/python-list



Hello Steven,

As I said in a previous mail, main purpose of this arguments is to define
what path should be chose. It is actually one xls file that could be placed
into various placed within my folder tree. 

For instance, I have following folder tree:

data_lib/
current/
history/
built/

Say  I have "test.xls" that could be in one of those three folders. 
I wrote a function that reads it out, and its input arguments just define
where it should be read. So  all those "ifs" related to path definition.



Still now I'm thinking to really split it out...  I'll have a separate
function for path definition and then it will call a common reader_fun() in
order to read this file.


Sincerely,

Ivan



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Supply condition in function call

2015-03-26 Thread Peter Otten
Cameron Simpson wrote:

> On 26Mar2015 07:27, Manuel Graune  wrote:
>>Gary Herron  writes:
>>> On 03/25/2015 10:29 AM, Manuel Graune wrote:
 def test1(a, b, condition="True"):
  for i,j in zip(a,b):
  c=i+j
  if eval(condition):
 print("Foo")

 test1([0,1,2,3],[1,2,3,4],"i+j >4")
 print("Bar")
 test1([0,1,2,3],[1,2,3,4],"c >4")
 print("Bar")
 test1([0,1,2,3],[1,2,3,4],"a[i] >2")
>>>
>>> This is nicely done with lambda expressions:
>>>
>>> To pass in a condition as a function:
>>>test1([0,1,2,3],[1,2,3,4], lambda i,j: i+j<4)
>>>
>>> To check the condition in the function:
>>> if condition(i,j):
>>
>>This seems to be the right direction and a good solution for simple
>>cases. Unfortunately this:
>>
>>> To get the full range of conditions, you will need to include all the
>>> variables needed by any condition you can imagine.  So the above
>>> suggestions may need to be expanded to:
>>>  ... lambda i,j,a,b: ... or whatever
>>>
>>> and
>>>   ... condition(i,j,a,b) ... or whatever
>>>
>>
>>is not as concise as I had hoped for. Is there a possibility to do
>>(maybe with a helper function inside the main function's body) solve
>>this more elegantly? I'm thinking of some combination of e. g. **kwargs,
>>dir() and introspection.
> 
> Yes.
> 
> Consider locals():
> 
>   https://docs.python.org/3/library/functions.html#locals
> 
> which is a built in function returning a copy of the current local
> variables in a dict. Example:
> 
>   condition_test = lambda vars: vars['i'] + vars[j'] > 4
> 
>   def test1(a, b, condition):
> for i, j in zip(a,b):
>   c = i + j
>   if condition(locals()):
> print("Foo")
> 
>   test1([0,1,2,3], [1,2,3,4], condition_test)
> 
> This passes the local variables inside test1() to "condition" as a single
> parameter. Now, I grant that vars['i'] is a miracle of tediousness. So
> consider this elaboration:
> 
>   from collections import namedtuple
> 
>   condition_test = lambda vars: vars.i + vars.j > 4
> 
>   def test1(a, b, condition):
> for i, j in zip(a,b):
>   c = i + j
>   vars = locals()
>   varnames = list(vars.keys())

That leaves varnames in undefined order. Consider

varnames = sorted(vars)

instead or pass the list of arguments explicitly, optionally with some 
inspect fallback:

$ cat pass_condition_inspect.py
import inspect

def test3(a, b, condition, args=None):
if args is None:
args = inspect.getargspec(condition).args

for i, j in zip(a,b):
c = i + j
_locals = locals()
if condition(*[_locals[name] for name in args]):
print("Foo", i, j)

def condition(c, i):
return i * i > c

test3([1, 2, 3], [2, 3, 4], condition)
print("---")
# note reverse order of argument names
test3([1, 2, 3], [2, 3, 4], condition, ["i", "c"]) 
$ python3 pass_condition_inspect.py
Foo 3 4
---
Foo 1 2
Foo 2 3
Foo 3 4

A simpler alternative is changing the signature of condition() and passing 
keyword arguments:

$ cat pass_condition.py
def test2(a, b, condition):
for i, j in zip(a,b):
c = i + j
if condition(**locals()):
print("Foo", i, j)

def condition(c, i, **unused):
return i * i > c

test2([1, 2, 3], [2, 3, 4], condition)
$ python3 pass_condition.py 
Foo 3 4

Creating a locals() dict on every iteration is still costly, and personally 
I would prefer the tighter interface where you pass a limited set of 
arguments explicitly.

>   varstupletype = namedtuple("locals", varnames)
>   varstuple = varstupletype(*[ vars[k] for k in varnames ])
>   if condition(varstuple):
> print("Foo")
> 
> Here, the condition_test function/lambda uses "vars.i" and "vars.j", which
> i think you'll agree is easier to read and write. The price is the
> construction of a "namedtuple" to hold the variable name values. See:
> 
>   
https://docs.python.org/3/library/collections.html#collections.namedtuple
> 
> So the (untested) code above:
> 
>   - get the locals() as before
>   - get the names of the variables; it is important to have this in a
>   array because we need to access the values in the same order when we
>   make the tuple - make a new namedtuple class "varstupletype", which is
>   used to make the named tuple - make the named tuple itself with the
>   values of the variables in order
> 
> If you're writing a lot of test functions like test1 you can push the
> namedtuple stuff off into a helper function:
> 
>   def vartuple(vars):
> varnames = list(vars.keys())
> varstupletype = namedtuple("locals", varnames)
> varstuple = varstupletype(*[ vars[k] for k in varnames ])
> return varstuple
> 
> and then "test1()" can look like this:
> 
>   def test1(a, b, condition):
> for i, j in zip(a,b):
>   c = i + j
>   if condition(vartuple(locals())):
> print("Foo")
> 
> which makes it much easier to write test2 and so on later.


-- 
https://mail.python.org/mailman/lis

  1   2   >