Re: Lawrence D'Oliveiro

2016-09-30 Thread Paul Rubin
Chris Angelico  writes:
>> Why can't you block "PEDOFILO"?
> I've no idea who you're talking about

That's the weird Italian spam that the newsgroup has been getting for a
while.  I've been wondering for a while if anyone knows what the story
is, i.e. why it's on comp.lang.python but not on other newsgroups that
I've noticed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lawrence D'Oliveiro

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 3:19 PM, Bob Martin  wrote:
> in 765690 20160930 181552 Ethan Furman  wrote:
>>Lawrence D'Oliveiro is banned from Python List until the new year.
>>
>>If his posts show up somewhere else (e.g. Usenet), please ignore them.  If 
>>you must respond to him p
>>lease trim out his text so the rest of us don't have to deal with him.
>>
>>--
>>Python List Moderators
>
> Why can't you block "PEDOFILO"?

I've no idea who you're talking about, so my guess is that those posts
already aren't making the leap to the mailing list. The newsgroup
isn't under the same governance, so if you're reading netnews, you
have to manually killfile people.

<<<
"Excellent. What is a killfile?"

"Uh. It's a list of usernames/topics/news items etc that you wish the
news- reader to automatically skip so you don't have to wade through
rubbish"

"Uh No. Remember I said pertaining to Operations. A killfile is in fact
a file with a list of names of people you are going to have killed."

"Oh. Of course."
>>>
-- The BSMFH, formerly and subsequently known as the BOFH

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


Re: Lawrence D'Oliveiro

2016-09-30 Thread Bob Martin
in 765690 20160930 181552 Ethan Furman  wrote:
>Lawrence D'Oliveiro is banned from Python List until the new year.
>
>If his posts show up somewhere else (e.g. Usenet), please ignore them.  If you 
>must respond to him p
>lease trim out his text so the rest of us don't have to deal with him.
>
>--
>Python List Moderators

Why can't you block "PEDOFILO"?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
On Saturday, 1 October 2016 14:17:06 UTC+10, Rustom Mody  wrote:
> On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> > I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if 
> > there are better non list comprehension options I would like to know as 
> > generally I find then confusing.
> 
> Two points here — best taken independently:
> 1. List comprehensions are confusing
> 2. When to want/not want them
> 
> 
> For 1 I suggest you (privately) rewrite them with '|' for 'for' and '∈' for 
> 'in'
> Once you do that they will start looking much more like the origin that 
> inspires
> them — set builder notation:
> https://en.wikipedia.org/wiki/Set-builder_notation
> 
> From there I suggest you play with replacing '[]' with '{}' ie actually try
> out set comprehensions and then others like dict-comprehensions — very nifty
> and oft-neglected. And the mother of all — generator comprehensions.
> 
> Of course to check it out in python you will need to invert the translation:
> '|' for 'for' and '∈' for 'in'
> the point of which is to use python as a kind of math assembly language
> *into* which you *code* but not in which you *think*
> 
> For 2 its important that you always keep in front of you whether you want to
> approach a problem declaratively (the buzzword FP!) or imperatively.
> Python is rather unique in the extent to which it allows both
> This also makes it uniquely difficult because its all too easy to garble the 
> two styles as John's .append inside a LC illustrates.
> 
> And the way to ungarble your head is by asking yourself the meta-question:
> Should I be asking "How to solve this (sub)problem?" or more simply
> "What is the (sub)problem I wish to solve?"
> 
> How questions naturally lead to imperative answers; whats to declarative
> 
> You may be helped with [plug!] my writings on FP:
> http://blog.languager.org/search/label/FP
> 
> Particularly the tables in:
> http://blog.languager.org/2016/01/primacy.html

Your insight has helped. May lack elegance but I have got it working.

from lxml import etree
import csv
import re


def clean(attr):
p = re.compile('\d+')
myList = p.findall(attr)
if len(myList) < 5:
myList.append('0')
return myList[0], myList[1], myList[2], myList[3], myList[4]


with open("20161001RAND0.xml", 'rb') as f, open(
"output/310916RABD.csv", 'w', newline='') as csvf:
tree = etree.parse(f)
root = tree.getroot()
race_writer = csv.writer(csvf, delimiter=',')

for meet in root.iter("meeting"):
for race in root.iter("race"):
for nom in root.iter("nomination"):
meetattr = meet.attrib
raceattr = race.attrib
nomattr = nom.attrib
if nomattr['number'] != '0':
print(clean(nomattr['firstup']))

Cheers

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


Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
On Saturday, 1 October 2016 14:17:06 UTC+10, Rustom Mody  wrote:
> On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> > I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if 
> > there are better non list comprehension options I would like to know as 
> > generally I find then confusing.
> 
> Two points here — best taken independently:
> 1. List comprehensions are confusing
> 2. When to want/not want them
> 
> 
> For 1 I suggest you (privately) rewrite them with '|' for 'for' and '∈' for 
> 'in'
> Once you do that they will start looking much more like the origin that 
> inspires
> them — set builder notation:
> https://en.wikipedia.org/wiki/Set-builder_notation
> 
> From there I suggest you play with replacing '[]' with '{}' ie actually try
> out set comprehensions and then others like dict-comprehensions — very nifty
> and oft-neglected. And the mother of all — generator comprehensions.
> 
> Of course to check it out in python you will need to invert the translation:
> '|' for 'for' and '∈' for 'in'
> the point of which is to use python as a kind of math assembly language
> *into* which you *code* but not in which you *think*
> 
> For 2 its important that you always keep in front of you whether you want to
> approach a problem declaratively (the buzzword FP!) or imperatively.
> Python is rather unique in the extent to which it allows both
> This also makes it uniquely difficult because its all too easy to garble the 
> two styles as John's .append inside a LC illustrates.
> 
> And the way to ungarble your head is by asking yourself the meta-question:
> Should I be asking "How to solve this (sub)problem?" or more simply
> "What is the (sub)problem I wish to solve?"
> 
> How questions naturally lead to imperative answers; whats to declarative
> 
> You may be helped with [plug!] my writings on FP:
> http://blog.languager.org/search/label/FP
> 
> Particularly the tables in:
> http://blog.languager.org/2016/01/primacy.html

Thank You Rustom
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Rustom Mody
On Saturday, October 1, 2016 at 8:55:19 AM UTC+5:30, Random832 wrote:
> On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote:
> > What *is* necessary and sufficient is to make each iteration
> > of the for-loop create a new binding of the loop variable
> > (and not any other variable!).
> 
> I don't think that's true. I think this is logic that is excessively
> tied to the toy examples that are used to illustrate the problem.
> 
> You don't think it's common [at least, as far as defining a lambda
> inside a loop at all is common] to do something like this?
> 
> for a in collection:
> b = some_calculation_of(a)
> do_something_with(lambda: ... b ...)

Common? — Dunno
What I know — Yuck!

[Yeah… someone brought up on Lisp and APL and who finds C++ terrifying!]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lawrence D'Oliveiro

2016-09-30 Thread Rustom Mody
On Saturday, October 1, 2016 at 10:04:01 AM UTC+5:30, Rustom Mody wrote:
> On Friday, September 30, 2016 at 10:45:03 PM UTC+5:30, Ethan Furman wrote:
> > Lawrence D'Oliveiro is banned from Python List until the new year.
> > 
> > If his posts show up somewhere else (e.g. Usenet), please ignore them.  If 
> > you must respond to him please trim out his text so the rest of us don't 
> > have to deal with him.
> > 
> > --
> > Python List Moderators
> 
> Sure Lawrence was/is being rude/difficult/whatever but does it warrant that 
> much
> severity?
> 
> If we consider the 4 cases (I know in recent times) that have been banned
> 1. Mark Lawrence
> 2. Thomas Lahn
> 3. jmf
> 4. and now Lawrence d'Oliveiro
> 
> that is also the (my subjective) order of rudeness (jmf is never rude but
> highly troublesome)

I meant to say “in decreasing order”
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lawrence D'Oliveiro

2016-09-30 Thread Rustom Mody
On Friday, September 30, 2016 at 10:45:03 PM UTC+5:30, Ethan Furman wrote:
> Lawrence D'Oliveiro is banned from Python List until the new year.
> 
> If his posts show up somewhere else (e.g. Usenet), please ignore them.  If 
> you must respond to him please trim out his text so the rest of us don't have 
> to deal with him.
> 
> --
> Python List Moderators

Sure Lawrence was/is being rude/difficult/whatever but does it warrant that much
severity?

If we consider the 4 cases (I know in recent times) that have been banned
1. Mark Lawrence
2. Thomas Lahn
3. jmf
4. and now Lawrence d'Oliveiro

that is also the (my subjective) order of rudeness (jmf is never rude but
highly troublesome)

Of course you/other-mods will have your own metrics
But please run your own abuse-metric-eval on this case again
And there is found a bug therein consider toning down 2 months to (say) 2 weeks

None of the above gainsays the fact that you folks — list-mods — do a onerous
splendid, mostly invisible job. For which thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to append to list in list comprehension

2016-09-30 Thread Rustom Mody
On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if there 
> are better non list comprehension options I would like to know as generally I 
> find then confusing.

Two points here — best taken independently:
1. List comprehensions are confusing
2. When to want/not want them


For 1 I suggest you (privately) rewrite them with '|' for 'for' and '∈' for 'in'
Once you do that they will start looking much more like the origin that inspires
them — set builder notation:
https://en.wikipedia.org/wiki/Set-builder_notation

From there I suggest you play with replacing '[]' with '{}' ie actually try
out set comprehensions and then others like dict-comprehensions — very nifty
and oft-neglected. And the mother of all — generator comprehensions.

Of course to check it out in python you will need to invert the translation:
'|' for 'for' and '∈' for 'in'
the point of which is to use python as a kind of math assembly language
*into* which you *code* but not in which you *think*

For 2 its important that you always keep in front of you whether you want to
approach a problem declaratively (the buzzword FP!) or imperatively.
Python is rather unique in the extent to which it allows both
This also makes it uniquely difficult because its all too easy to garble the 
two styles as John's .append inside a LC illustrates.

And the way to ungarble your head is by asking yourself the meta-question:
Should I be asking "How to solve this (sub)problem?" or more simply
"What is the (sub)problem I wish to solve?"

How questions naturally lead to imperative answers; whats to declarative

You may be helped with [plug!] my writings on FP:
http://blog.languager.org/search/label/FP

Particularly the tables in:
http://blog.languager.org/2016/01/primacy.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Sat, 1 Oct 2016 10:46 am, Gregory Ewing wrote:

> Steve D'Aprano wrote:
>> Giving for-loops their own namespace is a grossly unintuitive and a very
>> weird thing to do.
>> 
>> It would be terribly inconvenient and surprising for if...else blocks to
>> be separate namespaces:
> 
> There's an important difference between a for-loop and an
> if-statement that's relevant here: a for-loop binds a name,
> whereas an if-statement doesn't.

That's incorrect: either can bind any number of names:

if condition:
a = 1
b = 2
else:
a = 222
b = 111


for i in seq:
x = i + 1
y = x**2
z = 3*y



> Whenever there's binding going on, it's necessary to decide
> whether it should be creating a new binding or updating an
> existing one.

Right.


> This is actually a *different* issue from one of scope.
> List comprehensions were changed so that the loop variable
> lives in a different scope from the containing function.
> However, they still have the same unintuitive behaviour
> with regard to capture of the loop variable by a lambda.
> 
>  >> l = [lambda: i for i in range(3)]
>  >>> for f in l: print(f())
> ...
> 2
> 2
> 2
> 
> Most people consider *this* behaviour to be far weirder
> than anything that would result from giving for-loop
> variables their own scope.
> 
> Even if you don't think it's weird, it's hard to argue
> that it's *useful* in any significant number of cases.

Firstly, let's agree (or perhaps we don't?) that loop variables are the same
kind of variable as any other. It would be strange and confusing to have
different kinds of variables with different binding and lookup rules based
on where they came from.

The whole list comprehension and lambda syntax is a red herring. Let's write
it like this:

alist = []
for i in (0, 1, 2):
def func():
return i
alist.append(func)

for f in alist:
print(f())



And the output is the same:

2
2
2


Okay, that's inconvenient and not what I wanted. Obviously. But as they say
about computers, "this damn machine won't do what I want, only what I tell
it to do". It did *exactly what I told it to do*, and, yes, that is a good
thing. Let's remember that the variable i is no more special than any other
variable:

alist = []
x = 0
for i in (0, 1, 2):
def func():
return x
alist.append(func)

x = 999
# What do you predict the functions will return?
for f in alist:
print(f())



Are you surprised that each of the func()'s return the same value, the
current value of x instead of whatever accidental value of x happened to
exist when the function was defined? I should hope not. I would expect that
most people would agree that variable lookups should return the value of
the variable *as it is now*, not as it was when the function was defined.
Let's call that Rule 1, and I say it is fundamental to being able to reason
about code. If I say:

x = 1
spam(x)

then spam() MUST see the current value of x, namely 1, not some mysterious
value of x that happened to exist long ago in the mists of time when spam()
was first defined. And Rule 1 needs to apply to ALL variable look ups, not
just arguments to functions.


Closures, of course, are a special case of Rule 1, not an exception:

def make(arg):
x = arg
def func():
   return x
return func

f = make(0)
print(f())


*Without* closures, that would lead to a NameError (unless there happened to
be a global called "x"): the local variables of make() no longer exist, so
you cannot refer to them. That was the behaviour in Python 1.5, for
example.

But *with* closures, the local variables still exist: the inner function
grabs the surrounding environment (or at least as much as it needs) and
keeps it alive, so that it can look up names in that surrounding scope.

What do you expect should happen here?

def make(arg):
x = arg
def func():
   return x
x = 999
return func

f = make(0)
print(f())


By Rule 1, the only sensible behaviour is for f() to return 999, regardless
of whether it is convenient or not, regardless of whether that is what I
intended or not. The interpreter shouldn't try to guess what I mean, it
shouldn't cache variable look-ups, and it shouldn't try to give x special
behaviour different from all other variables just so this special case is
more convenient.

But wait, I hear you say, what about closures? They cache the value of the
surrounding variables don't they? Perhaps in a sense, but only a weak
sense. Each call to make() creates a *new* local environment (its a
function, each time you call a function it starts completely afresh) so
each of the inner functions returned is independent of the others, with its
own independent closure. And each inner function still looks up the current
value of *their own* closed-over x, not a snapshot of x as it was when the
inner function was defined.

Final step: let's unroll that original loop.

l = [lambda: i for i in range(3)]
for f in l: print(f())


becomes:

l = []
i = 0
l.append(lambda:

Re: unintuitive for-loop behavior

2016-09-30 Thread Rustom Mody
For the most part you've taken the words out of my mouth!
Some more details...

On Saturday, October 1, 2016 at 6:16:32 AM UTC+5:30, Gregory Ewing wrote:
> Steve D'Aprano wrote:
> > Giving for-loops their own namespace is a grossly unintuitive and a very
> > weird thing to do.
> > 
> > It would be terribly inconvenient and surprising for if...else blocks to be
> > separate namespaces:
> 
> There's an important difference between a for-loop and an
> if-statement that's relevant here: a for-loop binds a name,
> whereas an if-statement doesn't.
> 
> Whenever there's binding going on, it's necessary to decide
> whether it should be creating a new binding or updating an
> existing one.
> 
> This is actually a *different* issue from one of scope.
> List comprehensions were changed so that the loop variable
> lives in a different scope from the containing function.
> However, they still have the same unintuitive behaviour
> with regard to capture of the loop variable by a lambda.
> 
>  >> l = [lambda: i for i in range(3)]
>  >>> for f in l: print(f())
> ...
> 2
> 2
> 2
> 
> Most people consider *this* behaviour to be far weirder
> than anything that would result from giving for-loop
> variables their own scope.
> 
> Even if you don't think it's weird, it's hard to argue
> that it's *useful* in any significant number of cases.
> 
> > To me, "make for-loops be their own scope" sounds like a joke feature out of
> > joke languages like INTERCAL.
> 
> Which is a straw man, since that's not actually what we're
> talking about doing. It's neither necessary nor sufficient
> to solve the problem.
> 
> What *is* necessary and sufficient is to make each iteration
> of the for-loop create a new binding of the loop variable
> (and not any other variable!).


Yes one basic problem with comprehensions in python is that they are 
defined by assignment not binding to the comprehension variable

> 
> > I'm not aware of any sensible language that
> > does anything like this.
> 
> Scheme and Ruby come to mind as examples of languages in
> which the equivalent of a for-loop results in each iteration
> getting a new binding of the control variable. Although
> you could argue that these languages are not "sensible". :-)

Python copied comprehensions from haskell and copied them wrong

Here are all the things (that I can think of) that are wrong:
1. Scope leakage from inside to outside the comprehension
2. Scope leakage from one value to the next
3. The name 'for' misleadingly associates for-loops and comprehensions
4. The for-loop based implementation strategy made into definitional semantics
5. The absence of simple binding inside comprehensions:
   [f(newvar) for v in l newvar = rhs]

1 was considered sufficiently important to make a breaking change from python2 
to 3
2 is what causes the lambda gotcha
3 is what makes noobs to take longer than necessary to grok them
4 is what causes a useless distinction between 1 and 2 — scope leakage is scope
leakage. The explanatory mechanisms of why/whither/what etc should at best be 
secondary
5. is workaroundable with a [... for newvar in [rhs]]
   Possible and clunky
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw

> > I want to go threw and for each index error at [4] append a 0.
> 
> You want to append 0 if the list does not have at least 5 items?
> 
> > p = re.compile('\d+')
> > fups = p.findall(nomattr['firstup'])
> > [x[4] for x in fups if IndexError fups.append(0)]
> > print(fups)
> 
> > Unsure why I cannot use append in this instance
> 
> Because that's incorrect syntax.
> 
> > how can I modify to acheive desired output?
> 
> for f in fups:
> if len(f) < 5:
> f.append(0)
> 
> Or, if you really want to use a list comprehension:
> 
>   [f.append(0) for f in fups if len(f) < 5]
> 
> However there's no reason to use a list comprehension here.  The whole
> point of list comprehensions is to create a *new* list, which you don't
> appear to need; you just need to modify the existing fups list.
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
 B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

You are right John in that I don't want a new list I just wish to modify 
in-place to acheive the desired output.

I had no direct desire to use list comprehension just seemed an option.

Ultimately once it works I will abstract it into a function for other lists 
that will have a similar issue.

def listClean(fups)
holder = [(f + ['0'] if len(f) < 5 else f) for f in fups ] 
return holder[0], holder[1], holder[2], holder[3], holder[4]

and then call it in my csv.writer that I have, which currently errors quite 
correctly that it cannot write index[4] as some of my lists fail it.


I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if there 
are better non list comprehension options I would like to know as generally I 
find then confusing.
Cheers

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


Re: how to append to list in list comprehension

2016-09-30 Thread Rustom Mody
On Saturday, October 1, 2016 at 7:48:19 AM UTC+5:30, John Gordon wrote:
> In Sayth Renshaw  writes:
> 
> > I want to go threw and for each index error at [4] append a 0.
> 
> You want to append 0 if the list does not have at least 5 items?
> 
> > p = re.compile('\d+')
> > fups = p.findall(nomattr['firstup'])
> > [x[4] for x in fups if IndexError fups.append(0)]
> > print(fups)
> 
> > Unsure why I cannot use append in this instance
> 
> Because that's incorrect syntax.
> 
> > how can I modify to acheive desired output?
> 
> for f in fups:
> if len(f) < 5:
> f.append(0)
> 
> Or, if you really want to use a list comprehension:
> 
>   [f.append(0) for f in fups if len(f) < 5]

Wrong

fups = [['0', '0', '0', '0'],
['0', '0', '0', '0'],
['0', '0', '0', '0'],
['0', '0', '0', '0'],
['0', '0', '0', '0'],
['0', '0', '0', '0'],
['7', '2', '1', '0', '142647', '00'],
['7', '2', '0', '1', '87080', '00'],
['6', '1', '1', '1', '51700', '00'],
['4', '1', '1', '0', '36396', '00'] ]

>>> [f.append(0) for f in fups if len(f) < 5] 
[None, None, None, None, None, None]

Or right if you re-squint:

>>> fups
[['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], 
['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], ['0', '0', '0', '0', 0], 
['7', '2', '1', '0', '142647', '00'], ['7', '2', '0', '1', '87080', '00'], 
['6', '1', '1', '1', '51700', '00'], ['4', '1', '1', '0', '36396', '00']]
>>> 

Which is to say that imperative code — .append — inside a comprehension 
is a bad idea

One comprehension way to do it would be:

>>> [(f + ['0'] if len(f) < 5 else f) for f in fups ]
[['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', 
'0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0'], ['0', '0', '0', 
'0', '0'], ['7', '2', '1', '0', '142647', '00'], ['7', '2', '0', '1', '87080', 
'00'], ['6', '1', '1', '1', '51700', '00'], ['4', '1', '1', '0', '36396', '00']]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Random832
On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote:
> What *is* necessary and sufficient is to make each iteration
> of the for-loop create a new binding of the loop variable
> (and not any other variable!).

I don't think that's true. I think this is logic that is excessively
tied to the toy examples that are used to illustrate the problem.

You don't think it's common [at least, as far as defining a lambda
inside a loop at all is common] to do something like this?

for a in collection:
b = some_calculation_of(a)
do_something_with(lambda: ... b ...)

There's a reason that C++'s solution to this problem is an explicit list
of what names are captured as references vs values inside the lambda.

I think what we really need is an explicit expression/block that gives a
list of names and says that all uses of that name in any function
defined inside the expression/block refer to the value that that
expression had when the expression/block was entered.

Suppose:

[final exponent: lambda base: (base ** exponent) for exponent in
range(9)]

for exponent in range: 9
   final exponent:
   def pwr(base):
   return base ** exponent
   result.append(pwr)

for a in collection:
b = some_calculation_of(a)
final b: do_something_with(lambda: ... b ...)

Maybe do stuff like "for final var in ..." for both loops and
comprehensions, or "final var = expr:", depending on if we can make the
intuitive-looking syntax well-defined. "final" is a placeholder for
whatever new keyword is chosen, though I will note that even though IIRC
Guido doesn't like this sort of thing, it would only appear next to
identifiers in the proposed syntax and two identifiers not joined by an
operator is meaningless.

An alternative would be, considering that the problem only applies to
nested functions, to expand the "keyword argument" hack into a
less-"hacky" and less verbose solution, e.g. "lambda base, $exponent:
base ** exponent" - creating, in effect, a keyword argument with the
name 'exponent' that can't actually be passed in to the function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a foreign function run as fast as possible in Windows?

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 11:27 AM,   wrote:
> At this moment my interest is how to make it runs at 100% core usage. Windows 
> task manager shows this function takes only ~70% usage, and the number varies 
> during its execution, sometimes even drop to 50%.
>

What's it doing? Not every task can saturate the CPU - sometimes they
need the disk or network more.

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


Re: Could find libpython.so after succesfull compilation.

2016-09-30 Thread Steven Truppe
Damn i'm so stupid... the files where in fron on of my eyes and i was 
just not able to find then ..



On 2016-10-01 02:23, Steven Truppe wrote:

Hi all,


i've compiled python3.5 and all went fine, i find ./python and it 
works, most of the make test stuff is working my only problem is that 
i'm not able to find libpython.so 



am i missing somehting ?


Thianks in advance



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


Re: how to append to list in list comprehension

2016-09-30 Thread John Gordon
In <534d5506-1810-4a79-ac8f-95a664d17...@googlegroups.com> Sayth Renshaw 
 writes:

> I want to go threw and for each index error at [4] append a 0.

You want to append 0 if the list does not have at least 5 items?

> p = re.compile('\d+')
> fups = p.findall(nomattr['firstup'])
> [x[4] for x in fups if IndexError fups.append(0)]
> print(fups)

> Unsure why I cannot use append in this instance

Because that's incorrect syntax.

> how can I modify to acheive desired output?

for f in fups:
if len(f) < 5:
f.append(0)

Or, if you really want to use a list comprehension:

  [f.append(0) for f in fups if len(f) < 5]

However there's no reason to use a list comprehension here.  The whole
point of list comprehensions is to create a *new* list, which you don't
appear to need; you just need to modify the existing fups list.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Could find libpython.so after succesfull compilation.

2016-09-30 Thread Steven Truppe

I fond this in the ./configuration help:

*  --enable-shared disable/enable building shared python library*

so i tried:

$configure --enabled-shard

but i can't still find a library inside my build directory.



On 2016-10-01 02:23, Steven Truppe wrote:

Hi all,


i've compiled python3.5 and all went fine, i find ./python and it 
works, most of the make test stuff is working my only problem is that 
i'm not able to find libpython.so 



am i missing somehting ?


Thianks in advance



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


how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
I have a list of lists of numbers like this excerpt.

['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['7', '2', '1', '0', '142647', '00']
['7', '2', '0', '1', '87080', '00']
['6', '1', '1', '1', '51700', '00']
['4', '1', '1', '0', '36396', '00']

I want to go threw and for each index error at [4] append a 0.

I have called the lists fups.

p = re.compile('\d+')
fups = p.findall(nomattr['firstup'])
[x[4] for x in fups if IndexError fups.append(0)]
print(fups)

Unsure why I cannot use append in this instance, how can I modify to acheive 
desired output?

Desired Output
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '0']
['0', '0', '0', '0', '0']
['7', '2', '1', '0', '142647', '00']
['7', '2', '0', '1', '87080', '00']
['6', '1', '1', '1', '51700', '00']
['4', '1', '1', '0', '36396', '00']

Thanks

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


Re: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread Terry Reedy

On 9/30/2016 2:23 PM, Les Cargill wrote:


A really interesting design approach in Tcl is to install a callback
when a variable is written to. This affords highly event-driven
programming.

Example ( sorry; it's Tcl  ) :


namespace eval events {
set preRPM -1
proc handleRPM { args } {
# do stuff to handle an RPM change here
variable ::motor::RPM
variable preRPM
puts "RPM changed from $preRPM to $RPM
set preRPM $RPM
}
}

...

trace variable ::motor::RPM w ::events::handleRPM


'trace variable' and the corresponding 'trace vdelete' and trace vinfo' 
have been deprecated in favor of the newer 'trace add variable', 'trace 
remove variable', and 'trace info variable.  In 3.6, the tkinter 
Variable class has corresponding new trace_add, trace_remove, and 
trace_info methods.



...

set ::motor::RPM 33.33


The cost of being able to trace variables is having to set them through 
a method that can check for the existence of callbacks.  The are used in 
tk to connect the values of widgets.



What is an equivalent mechanism in Python?


Python has a trace module for functions and lines, rather than 
variables.  I believe the primary intended use is for debugging.


The Variable class in tkinter.__init__, currently about line 290, wraps 
the tcl mechanism so it literally is the 'equivalent mechanism' in 
Python.  It could be rewritten to do everything in Python instead of 
calling into tk.  However, it can also be used as it without displaying 
a gui window.  Use what you already know.


import tkinter as tk
root = tk.Tk()  # Only needed to create Vars.
root.withdraw()  # So keep it invisible.

avar = tk.StringVar(root)
avar.trace_add('write', lambda tk_id, unknown, mode:
   print(avar.get(), tk_id, unknown, mode))
# See >>> help(tk.Variable.trace_add) for more.
avar.set('abc')
avar.set('def')

* prints
abc PY_VAR0  write  # 'unknown' == ''
def PY_VAR0  write

Since you are familiar with tcl, you could potentially use root.call() 
to call into tcl yourself.


There are other packages in Python that implement the idea of 
broadcasting a change to a set of reistered listeners.


--
Terry Jan Reedy

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


Re: How to make a foreign function run as fast as possible in Windows?

2016-09-30 Thread jfong
Paul  Moore at 2016/9/30 7:07:35PM wrote:
> OK. So if your Python code only calls the function once, the problem needs to 
> be fixed in the external code (the assembly routine). But if you can split up 
> the task at the Python level to make multiple calls to the function, each to 
> do a part of the task, then you could set up multiple threads in your Python 
> code, each of which handles part of the task, then Python merges the results 
> of the sub-parts to give you the final answer. Does that make sense to you? 
> Without any explicit code, it's hard to be sure I'm explaining myself clearly.
> 

That's what I will do later, to split the task into multiple cores by passing a 
range parameter (such as 0~14, 15~29, ..) to each instance. Right now, I just 
embedded the range in the function to make it simple on testing.

At this moment my interest is how to make it runs at 100% core usage. Windows 
task manager shows this function takes only ~70% usage, and the number varies 
during its execution, sometimes even drop to 50%.

I also had test a batch file (copied from another discussion forum):
@echo off
:loop
goto loop
It takes ~85% usage, and the number is stable.

The result is obviously different. My question is how to control it:-)

--Jach

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Gregory Ewing

Steve D'Aprano wrote:

What happens if it is *not* a misfeature? Gotchas are not always
misfeatures -- sometimes gotchas are gotchas because people's expectations
are simply wrong, and pandering to their confused expectations does not
actually help them.

I haven't made up my mind about *this* specific (mis)feature itself.


Here's my analysis of it.

First, some definitions:

Current behaviour: The way for-loop variables currently
interact with nested functions.

Alternative behaviour: A nested function captures a
different instance of the for-loop variable on each
iteration. (But *nothing* else changes; in particular,
the body of the loop is *not* a separate scope.)

The current behaviour is completely useless (or at least it's
useful in in only a vanishingly small proportion of cases).
The alternative behaviour would sometimes be useful.

Nothing would need to change except in the rare case where
the loop variable is referenced by a nested function. You
would only pay for the feature if you used it.

There would be no need for ugly workarounds such as default
argument abuse or introducing another level of nested
function.

As a bonus, the alternative behaviour would be more in
line with people's intuitions.

There are some sharp contrasts here with the default
argument situation. There, the alternative behaviour would
be very wasteful in the majority of cases, and there is
a clean workaround for cases where a mutable default is
needed.

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


Could find libpython.so after succesfull compilation.

2016-09-30 Thread Steven Truppe

Hi all,


i've compiled python3.5 and all went fine, i find ./python and it works, 
most of the make test stuff is working my only problem is that i'm not 
able to find libpython.so 



am i missing somehting ?


Thianks in advance

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Gregory Ewing

Steve D'Aprano wrote:

Giving for-loops their own namespace is a grossly unintuitive and a very
weird thing to do.

It would be terribly inconvenient and surprising for if...else blocks to be
separate namespaces:


There's an important difference between a for-loop and an
if-statement that's relevant here: a for-loop binds a name,
whereas an if-statement doesn't.

Whenever there's binding going on, it's necessary to decide
whether it should be creating a new binding or updating an
existing one.

This is actually a *different* issue from one of scope.
List comprehensions were changed so that the loop variable
lives in a different scope from the containing function.
However, they still have the same unintuitive behaviour
with regard to capture of the loop variable by a lambda.

>> l = [lambda: i for i in range(3)]
>>> for f in l: print(f())
...
2
2
2

Most people consider *this* behaviour to be far weirder
than anything that would result from giving for-loop
variables their own scope.

Even if you don't think it's weird, it's hard to argue
that it's *useful* in any significant number of cases.


To me, "make for-loops be their own scope" sounds like a joke feature out of
joke languages like INTERCAL.


Which is a straw man, since that's not actually what we're
talking about doing. It's neither necessary nor sufficient
to solve the problem.

What *is* necessary and sufficient is to make each iteration
of the for-loop create a new binding of the loop variable
(and not any other variable!).


I'm not aware of any sensible language that
does anything like this.


Scheme and Ruby come to mind as examples of languages in
which the equivalent of a for-loop results in each iteration
getting a new binding of the control variable. Although
you could argue that these languages are not "sensible". :-)

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


rocket simulation game with just using tkinter

2016-09-30 Thread Irmen de Jong
Hi,

I've made a very simple rocket simulation game, inspired by the recent success 
of SpaceX
where they managed to land the Falcon-9 rocket back on a platform.

I was curious if you can make a simple graphics animation game with just using 
Tkinter,
instead of using other game libraries such as PyGame.
As it turns out, that works pretty well and it was quite easy to write. 
Granted, there's
not much going on on the screen, but still the game runs very smoothly and I 
think it is
fun for a little while where you try to learn to control the rocket and attempt 
to
successfully land it on the other launchpad!

The physics simulation is tied to the game's frame rate boohoo, but the upside 
is that
you can change the framerate to control the game's difficulty. It's easy at 
<=20, fun at
30 and impossible at 60 :)  It's running on 30 by default.


You can get the code here if you want to give it a try:
https://github.com/irmen/rocketsimulator

So you just need python 2/3 with tkinter to play this!


Have fun
Irmen
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Counting words in a string??

2016-09-30 Thread breamoreboy
On Friday, September 30, 2016 at 8:12:47 PM UTC+1, Jake wrote:
> On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki  wrote:
> > On Oct 1, 2016 12:10 AM, "Jake" wrote:
> > >
> > > Hi, I need a program which:
> > > 1) Asks the user for a sentence of their choice (not including
> > punctuation)
> > > 2) Ask the user which word they would like to know is repeated
> > > 3) Print out to the user how many times the word came up which they chose
> > from their sentence.
> > >
> > 
> > typical home work assignment, even though stop asking for programs and
> > start asking how to make the same.
> > 
> > anyway if you ever try to write code for this you have to split you
> > sentence and use a dict for counting
> > 
> > Python has Counter from collections but it is a little bit slower when
> > compared to defaultdict for this kind of purpose.
> > 
> > Regards
> > Srinivas Devaki
> > Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad
> > Computer Science and Engineering Department
> > ph: +91 9491 383 249
> > telegram_id: @eightnoteight
> 
> --
> Could you make the program for me or provide an outline?

We'll start work as soon as your cheque made payable to the Python Software 
Foundation has been cashed.  It works a bit like the Monty Python "Blackmail" 
sketch, the higher the grade you want, the more you have to pay.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread breamoreboy
On Friday, September 30, 2016 at 7:16:10 PM UTC+1, Les Cargill wrote:
> A really interesting design approach in Tcl is to install a callback
> when a variable is written to. This affords highly event-driven 
> programming.
> 
> Example ( sorry; it's Tcl  ) :
> 
> 
> namespace eval events {
>   set preRPM -1
>   proc handleRPM { args } {
>   # do stuff to handle an RPM change here
>   variable ::motor::RPM
>  variable preRPM
>   puts "RPM changed from $preRPM to $RPM
>   set preRPM $RPM
>  }
> }
> 
> ...
> 
> trace variable ::motor::RPM w ::events::handleRPM
> 
> ...
> 
> set ::motor::RPM 33.33
> 
> What is an equivalent mechanism in Python?
> 
> Thanks in advance.
> 
> -- 
> Les Cargill

Perhaps you could pinch the idea, or even the code, from tkinter?  E.g. see the 
section "Variable tracing" at 
http://stupidpythonideas.blogspot.co.uk/2013/12/tkinter-validation.html

Kindest regards.

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


Re: Counting words in a string??

2016-09-30 Thread mm0fmf

On 30/09/2016 20:12, Jake wrote:

On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki  wrote:

On Oct 1, 2016 12:10 AM, "Jake"  wrote:


Hi, I need a program which:
1) Asks the user for a sentence of their choice (not including

punctuation)

2) Ask the user which word they would like to know is repeated
3) Print out to the user how many times the word came up which they chose

from their sentence.




typical home work assignment, even though stop asking for programs and
start asking how to make the same.

anyway if you ever try to write code for this you have to split you
sentence and use a dict for counting

Python has Counter from collections but it is a little bit slower when
compared to defaultdict for this kind of purpose.

Regards
Srinivas Devaki
Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight


--
Could you make the program for me or provide an outline?


How much will you pay for a commented program or an outline?
--
https://mail.python.org/mailman/listinfo/python-list


Re: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread Random832
On Fri, Sep 30, 2016, at 14:42, Ned Batchelder wrote:
> On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote:
> > What is an equivalent mechanism in Python?
> 
> There's no way* to hook into "x = 2", but you could hook into "x.a = 2"
> if you wanted do, by defining __setattr__ on x's class.

That or set cls.a to be a descriptor (using either @property or a
custom-made descriptor class)

class motor:
@property
def RPM(self): return self._RPM
@RPM.setter
def RPM(self, value):
print("RPM changed from", self._RPM, "to", value)
self._RPM = value

If you really wanted to get crazy, you could use self.__dict__['RPM']
instead of self._RPM, which would allow you to inject the descriptor
separately after the class has already been defined and used. Making it
work right if the definition of motor already has an RPM descriptor [for
example, if it uses __slots__] is an exercise for the reader.

> *OK, there might be some crazy hack involving your own class as the
> globals for a module or something, but it sounds ill-advised.

You can make your own class to be *the module itself* to support
external code's "mod.x = 2", but AIUI that won't apply to plain
assignment, which bypasses most of the relevant machinery.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Counting words in a string??

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 5:12 AM, Jake  wrote:
> Could you make the program for me or provide an outline?

No. In case you didn't read any of the other responses, this community
is not a plagiarism source. If you want to learn to be a programmer,
you're going to have to learn some key skills, one of which (possibly
the most important) is figuring out how to break a problem down into
its parts. Start work. If you don't have any clue how to start, ask
your professor - that way, it's not cheating.

Or if you don't HAVE a professor (if this is a coding challenge from a
self-paced online course, for instance), then you may need to consider
a pay-for course. A good few of these exist (check the Python Wiki for
some), and in some cases, you can get one-on-one tuition, which can
help you out enormously. But whether it's freely-given help on a
mailing list, group lectures, or personal tutoring, you won't get
people just giving you the code - not if they care about you becoming
a competent programmer, anyway.

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


Re: Counting words in a string??

2016-09-30 Thread Peter Pearson
On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake  wrote:
> Hi, I need a program which:
> 1) Asks the user for a sentence of their choice (not including punctuation)
> 2) Ask the user which word they would like to know is repeated
> 3) Print out to the user how many times the word came up which they chose
>from their sentence.
>
> It would help if you could comment the code. 
> Thankyou in advance!!

Welcome to the Python newsgroup.  Many helpful, capable, and polite
people frequent this newsgroup, but doing someone's homework assignment
is not viewed as helpful.  If you write the code and run into a problem,
then you can post the code here (if it's short) with a specific question,
and will probably get a prompt and very helpful response.


-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Counting words in a string??

2016-09-30 Thread Jake
On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki  wrote:
> On Oct 1, 2016 12:10 AM, "Jake"  wrote:
> >
> > Hi, I need a program which:
> > 1) Asks the user for a sentence of their choice (not including
> punctuation)
> > 2) Ask the user which word they would like to know is repeated
> > 3) Print out to the user how many times the word came up which they chose
> from their sentence.
> >
> 
> typical home work assignment, even though stop asking for programs and
> start asking how to make the same.
> 
> anyway if you ever try to write code for this you have to split you
> sentence and use a dict for counting
> 
> Python has Counter from collections but it is a little bit slower when
> compared to defaultdict for this kind of purpose.
> 
> Regards
> Srinivas Devaki
> Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad
> Computer Science and Engineering Department
> ph: +91 9491 383 249
> telegram_id: @eightnoteight

--
Could you make the program for me or provide an outline?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Counting words in a string??

2016-09-30 Thread Rob Gaddi
Jake wrote:

> Hi, I need a program which:
> 1) Asks the user for a sentence of their choice (not including punctuation)
> 2) Ask the user which word they would like to know is repeated
> 3) Print out to the user how many times the word came up which they chose 
> from their sentence.
>
> It would help if you could comment the code. 
> Thankyou in advance!!

I'm sure it would help; your professor will probably take points off
otherwise.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Counting words in a string??

2016-09-30 Thread srinivas devaki
On Oct 1, 2016 12:10 AM, "Jake"  wrote:
>
> Hi, I need a program which:
> 1) Asks the user for a sentence of their choice (not including
punctuation)
> 2) Ask the user which word they would like to know is repeated
> 3) Print out to the user how many times the word came up which they chose
from their sentence.
>

typical home work assignment, even though stop asking for programs and
start asking how to make the same.

anyway if you ever try to write code for this you have to split you
sentence and use a dict for counting

Python has Counter from collections but it is a little bit slower when
compared to defaultdict for this kind of purpose.

Regards
Srinivas Devaki
Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread Ned Batchelder
On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote:
> A really interesting design approach in Tcl is to install a callback
> when a variable is written to. This affords highly event-driven 
> programming.
> 
> Example ( sorry; it's Tcl  ) :
> 
> 

(I can't read Tcl, sorry)

> 
> What is an equivalent mechanism in Python?

There's no way* to hook into "x = 2", but you could hook into "x.a = 2"
if you wanted do, by defining __setattr__ on x's class.

*OK, there might be some crazy hack involving your own class as the
globals for a module or something, but it sounds ill-advised.

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


Counting words in a string??

2016-09-30 Thread Jake
Hi, I need a program which:
1) Asks the user for a sentence of their choice (not including punctuation)
2) Ask the user which word they would like to know is repeated
3) Print out to the user how many times the word came up which they chose from 
their sentence.

It would help if you could comment the code. 
Thankyou in advance!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 11:43 pm, BartC wrote:

> It can make sense for 'x' to be local to this for-loop block (everything
> else is at it works now), and independent of any x's in outer blocks. It
> means being able to do stuff like this:
> 
> for x in a:
>   for x in b:
>  pass
>   pass # outer x still has its value

If you're (generic you) not using the loop variables, as in your example,
why do you care if one overwrites the other? You're not using either of
them.

And if you are using them, then surely you need them to be different names
so you can use them *both*. So why does it matter if they are in different
scopes?

I can't think of an example of where I would want two nested for-loops,
where *both* loop variables need to be the same name, but I only want to
access the inner variable inside the inner loop and the outer variable in
the outer loop.

And if I was in that position, why couldn't I just relax the "must be the
same name" condition and give them different names? Its not like there is a
shortage of possible names.


> And any even more outer x's are not affected. With 'for', especially one
> inside a list-comp, often you just need some throwaway index variable
> without worrying if it will clash with an existing local.
> 
> But it's not useful enough I think to bother changing now. Or even when
> the language was designed.

Indeed.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 03:06 pm, Rustom Mody wrote:

> On Friday, September 30, 2016 at 10:23:31 AM UTC+5:30, Gregory Ewing
> wrote:
>> namenobodywants wrote:
>>  > can anyone help to reconcile me to this semantics?
>> 
>> Not really. Most people agree that it's not desirable
>> behaviour, but we've ended up here due to a convoluted
>> history, and there doesn't seem to be a good way to
>> fix it without breaking a lot of existing code.
> 
> Thanks for an unusually helpful answer.
> 
> In my experience telling a beginner:
> «This» is a misfeature/gotcha
> And «this» is its workaround
> 
> greatly shortens the learning curve as compared to long-winded
> justificatory explanations

What happens if it is *not* a misfeature? Gotchas are not always
misfeatures -- sometimes gotchas are gotchas because people's expectations
are simply wrong, and pandering to their confused expectations does not
actually help them.

I haven't made up my mind about *this* specific (mis)feature itself. I know
I don't want for-loops to introduce their own scope, but that doesn't mean
that the binding behaviour inside for-loops is necessarily the best way of
doing it. I'm still thinking about it.

But *in general*, people often don't think the logical consequences through
before deciding what behaviour is "obviously" right. They insist that
whatever behaviour would be convenient for them *now* is the one and only
correct way of doing things -- even if, an hour later, the *opposite*
behaviour is convenient and therefore the correct way of doing things.

Obviously late binding is the one and only correct way of setting function
parameter defaults -- until we need early binding, then it is the one and
only correct way of doing it.

Gotchas usually exist for a reason. Very few programming languages design
gotchas into them to deliberately trip people up[1], or even through
carelessness. More often, they're the unexpected consequences of a series
of sensible, or even unavoidable, decisions.






[1] "When I design my killer language, the identifiers `foo` and `bar` will
be reserved words, never used, and not even mentioned in the reference
manual. Any program using one will simply dump core without comment.
Multitudes will rejoice."  -  Tim Peters


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?

2016-09-30 Thread Les Cargill


A really interesting design approach in Tcl is to install a callback
when a variable is written to. This affords highly event-driven 
programming.


Example ( sorry; it's Tcl  ) :


namespace eval events {
set preRPM -1
proc handleRPM { args } {
# do stuff to handle an RPM change here
variable ::motor::RPM
variable preRPM
puts "RPM changed from $preRPM to $RPM
set preRPM $RPM
}
}

...

trace variable ::motor::RPM w ::events::handleRPM

...

set ::motor::RPM 33.33

What is an equivalent mechanism in Python?

Thanks in advance.

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


Re: Regarding Job Opportunity for the position Python Developer in Mc Lean, VA

2016-09-30 Thread gowri
On Friday, September 30, 2016 at 10:56:14 AM UTC-5, go...@spsolinc.com wrote:
> Hi,
> 
> Here we have an immediate opening. Location will be Mc Lean, VA.
> Please revert back to us if you are interested.
> Need good Python experience. SAS or AWS knowledge is added advantage.
> 
> Thanks,
> Gowri Shekar
> 972-983-3467

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


Re: Save Idle Options

2016-09-30 Thread Terry Reedy

On 9/29/2016 9:33 PM, tce...@comcast.net wrote:

Win 10 pro 32, Python 3.6
I’m new to Python and installed Python with Idle, which I like as an IDE. But 
I’m mystified as to how to make interface options stick. Opened Options, 
Configure Idle. Changed font to Consolas Bold. And stopped dead. There doesn’t 
seem to be a way to save the changes. Tried reloading my file but had to exit 
the Options to do so. So lost the changes. Same issue with  highlighting 
colors. Google is hopeless. How can I do this?


Options are saved automatically when you close the dialog with OK rather 
than Cancel (or [X])  I just retested with Win 10 Pro 64 3.6.0b1.



--
Terry Jan Reedy


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


Lawrence D'Oliveiro

2016-09-30 Thread Ethan Furman

Lawrence D'Oliveiro is banned from Python List until the new year.

If his posts show up somewhere else (e.g. Usenet), please ignore them.  If you 
must respond to him please trim out his text so the rest of us don't have to 
deal with him.

--
Python List Moderators
--
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 3:03 AM, Brendan Abel <007bren...@gmail.com> wrote:
>> a = 1
> if condition:
> print(a)  # UnboundLocalError: local 'a' referenced before assignment
> a += 1
>
>
> For-loops are no different. Making them their own namespace is a very
> strange thing to do, it would mean you couldn't re-bind a value inside a
> for-loop:
>
> count = 0
> for x in sequence:
> count += 1
> # raises UnboundLocalError: local 'count' referenced before assignment
>
> --
>
> That's generally not how nested scopes work, you could still reference
> objects in the outer scope from the inner scope, but the outer scope
> couldn't reference objects in the inner scope

The trouble is that, absent some sort of declaration, there's no way
for the compiler to know whether 'count' and 'a' are supposed to be
new variables in the inner scope, or the same variable as the one in
the next scope out. In Python, declarations are used when you rebind
nonlocal or global names, so these examples would have to be written
thus:

a = 1
if condition:
nonlocal a
print(a)
a += 1

count = 0
for x in sequence:
nonlocal count
count += 1

I don't think we want that. :)

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Brendan Abel
> a = 1
if condition:
print(a)  # UnboundLocalError: local 'a' referenced before assignment
a += 1


For-loops are no different. Making them their own namespace is a very
strange thing to do, it would mean you couldn't re-bind a value inside a
for-loop:

count = 0
for x in sequence:
count += 1
# raises UnboundLocalError: local 'count' referenced before assignment

--

That's generally not how nested scopes work, you could still reference
objects in the outer scope from the inner scope, but the outer scope
couldn't reference objects in the inner scope

a = 1
if condition:
b = a + 2

print b # UnboundLocalError: local 'b' referenced before assignment


for x in sequence:
print x

print x  # UnboundLocalError: local 'x' referenced before assignment.


--

I wouldn't call either behavior intuitive or unintuitive.  They're just
different behaviors of different languages.


On Fri, Sep 30, 2016 at 5:33 AM, Steve D'Aprano 
wrote:

> On Fri, 30 Sep 2016 05:29 am, namenobodywa...@gmail.com wrote:
>
> > hello pythonistas
> >
> > i've had a nodding acquaintance with python for some time, and all along
> i
> > assumed that for-loops got a namespace of their own;
>
> Giving for-loops their own namespace is a grossly unintuitive and a very
> weird thing to do. Modules, classes and functions are obviously namespaces.
> Why should arbitrary syntactic structures create their own namespace?
>
> It would be terribly inconvenient and surprising for if...else blocks to be
> separate namespaces:
>
> a = 1
> if condition:
> print(a)  # UnboundLocalError: local 'a' referenced before assignment
> a += 1
>
>
> For-loops are no different. Making them their own namespace is a very
> strange thing to do, it would mean you couldn't re-bind a value inside a
> for-loop:
>
> count = 0
> for x in sequence:
> count += 1
> # raises UnboundLocalError: local 'count' referenced before assignment
>
>
> unless you declared it nonlocal or global, depending on whether your for
> loop was inside a function or not.
>
> To me, "make for-loops be their own scope" sounds like a joke feature out
> of
> joke languages like INTERCAL. I'm not aware of any sensible language that
> does anything like this.
>
> No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that
> one
> of his favourite languages, Pike or REXX, does it. I forget which.
>
>
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Grant Edwards
On 2016-09-30, Grant Edwards  wrote:
> On 2016-09-30, Steve D'Aprano  wrote:
>
>> To me, "make for-loops be their own scope" sounds like a joke
>> feature out of joke languages like INTERCAL. I'm not aware of any
>> sensible language that does anything like this.
>
> In C99 a for loop has its own namespac:
[...]
> I think that's an absolutely brilliant feature, and I use it a _lot_
> when writing C code.  I'm a big fan of minimizing the lifetime/scope
> of variables. I wish if/then/else did the same thing:
>
>   if ((r=some_function()) != R_SUCCESS)
> printf("some_function() failed with status %d\n",r);

The example of what I wished C did should have been this:

   if ((int r=some_function()) != R_SUCCESS)
 printf("some_function() failed with status %d\n",r);


-- 
Grant Edwards   grant.b.edwardsYow! If I pull this SWITCH
  at   I'll be RITA HAYWORTH!!
  gmail.comOr a SCIENTOLOGIST!

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 12:36 AM, Grant Edwards
 wrote:
> On 2016-09-30, Steve D'Aprano  wrote:
>
>> To me, "make for-loops be their own scope" sounds like a joke feature out of
>> joke languages like INTERCAL. I'm not aware of any sensible language that
>> does anything like this.
>
> In C99 a for loop has its own namespac:
>
>   int main(void)
>   {
> for (int i=0; i<5; ++i)
>   printf("i=%d\n",i);
>   }
>
> If you try to access 'i' outside the for loop, it's an error, because
> it doesn't exist in the file, global or 'main' namespace.  It only
> exists in the for-loop's namespace.

I believe that's the same semantics as C++ uses, and I agree, it's
very convenient. Among other things, it means that nested loops behave
more like they do in Python, with independent iterators:

int main(void)
{
for (int i=0; i<5; ++i)
{
printf("%d:", i);
for (int i=0; i<3; ++i)
printf(" %d", i);
printf("\n");
}
}

Now, granted, this is not something I would ever actually recommend
doing, and code review is absolutely justified in rejecting this...
but it's a lot better than pure function-scope variables, where you'd
get stuck in an infinite loop. Obviously the inner 'i' shadows the
outer 'i', but that's the only actual conflict between them.

> I think that's an absolutely brilliant feature, and I use it a _lot_
> when writing C code.  I'm a big fan of minimizing the lifetime/scope
> of variables. I wish if/then/else did the same thing:
>
>   if ((r=some_function()) != R_SUCCESS)
> printf("some_function() failed with status %d\n",r);

No particular reason not to. Ditto 'while' loops:

while (int r=some_function())
..

I agree with minimizing scope, but only where it's practical to do so.
In Python, it simply isn't. Like C, Python has infinitely nested
scopes; unlike C, Python requires explicit 'nonlocal' declarations in
order to assign to something in an outer scope, ergo the convenience
of not declaring local variables translates into extreme inconvenience
of working with overly-narrow scopes. To put it more simply: Scope is
cheap in C, but expensive in Python.

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


Regarding Job Opportunity for the position Python Developer in Mc Lean, VA

2016-09-30 Thread gowri
Hi,

Here we have an immediate opening. Location will be Mc Lean, VA.
Please revert back to us if you are interested.
Need good Python experience. SAS or AWS knowledge is added advantage.

Thanks,
Gowri Shekar
972-983-3467
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread BartC

On 30/09/2016 15:01, Chris Angelico wrote:

On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano
 wrote:

To me, "make for-loops be their own scope" sounds like a joke feature out of
joke languages like INTERCAL. I'm not aware of any sensible language that
does anything like this.

No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one
of his favourite languages, Pike or REXX, does it. I forget which.


In C-like languages (including Pike), you can legally define a
variable at any point, making it visible at that point and all inner
locations - effectively, every brace becomes a new subscope. It makes
sense ONLY because variables are declared, no matter where they are
(globals are declared at module scope, locals at some kind of inner
scope). So, it's not strictly true that Pike has for loops as their
own scope, just that C-like languages have a lot of nested scopes.


C likes to make things a bit more complicated:

 int A;
 { A;   // this is the outer A
   int A;
   A;   // this is the inner A
   goto A;
   A:   // this is yet another A
 }

Labels live in a different name-space from other names. I've left out 
struct tags which also have their own name-space, and would allow five 
different A's in that block (an outer and inner 'struct A') rather than 
the three I've shown.


So a single pair of {-} can enclose three (sometimes five) versions of 
the same identifier.


Personally I think function-scope is plenty. Only one possible top-level 
'A' in a function instead of an unlimited number.


(Python allows extra 'A's inside nested functions and classes within 
that function, but that's a bit different.)


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


Re: unintuitive for-loop behavior

2016-09-30 Thread Grant Edwards
On 2016-09-30, Steve D'Aprano  wrote:

> To me, "make for-loops be their own scope" sounds like a joke feature out of
> joke languages like INTERCAL. I'm not aware of any sensible language that
> does anything like this.

In C99 a for loop has its own namespac:

  int main(void)
  {
for (int i=0; i<5; ++i)
  printf("i=%d\n",i);
  }

If you try to access 'i' outside the for loop, it's an error, because
it doesn't exist in the file, global or 'main' namespace.  It only
exists in the for-loop's namespace.

I think that's an absolutely brilliant feature, and I use it a _lot_
when writing C code.  I'm a big fan of minimizing the lifetime/scope
of variables. I wish if/then/else did the same thing:

  if ((r=some_function()) != R_SUCCESS)
printf("some_function() failed with status %d\n",r);

-- 
Grant Edwards   grant.b.edwardsYow! I don't know WHY I
  at   said that ... I think it
  gmail.comcame from the FILLINGS in
   my rear molars ...

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


Re: unintuitive for-loop behavior

2016-09-30 Thread Chris Angelico
On Fri, Sep 30, 2016 at 10:33 PM, Steve D'Aprano
 wrote:
> To me, "make for-loops be their own scope" sounds like a joke feature out of
> joke languages like INTERCAL. I'm not aware of any sensible language that
> does anything like this.
>
> No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one
> of his favourite languages, Pike or REXX, does it. I forget which.

In C-like languages (including Pike), you can legally define a
variable at any point, making it visible at that point and all inner
locations - effectively, every brace becomes a new subscope. It makes
sense ONLY because variables are declared, no matter where they are
(globals are declared at module scope, locals at some kind of inner
scope). So, it's not strictly true that Pike has for loops as their
own scope, just that C-like languages have a lot of nested scopes.

(REXX has nothing like this.)

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


ANN: distlib 0.2.4 released on PyPI

2016-09-30 Thread Vinay Sajip via Python-list
I've just released version 0.2.4 of distlib on PyPI [1]. For newcomers,
distlib is a library of packaging functionality which is intended to be
usable as the basis for third-party packaging tools.

The main changes in this release are as follows:

* Updated to not fail during import if SSL is not available.
* Changed project name comparisons to follow PEP 503.
* Changed manifest and resources logic to work correctly under (upcoming) 
Python 3.6.
* Updated Windows launchers with fixes to bugs related to argument-passing in 
shebang lines.

A more detailed change log is available at [2].

Please try it out, and if you find any problems or have any suggestions for
improvements, please give some feedback using the issue tracker! [3]

Regards,

Vinay Sajip

[1] https://pypi.python.org/pypi/distlib/0.2.4
[2] https://goo.gl/M3kQzR
[3] https://bitbucket.org/pypa/distlib/issues/new
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyicloud: TypeError: 'dict_values' object does not support indexing

2016-09-30 Thread Peter Otten
Adam Funk wrote:

> I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu).
> 
> 
> 
> The basic stuff works, but access to photos (following the
> instructions) fails:
> 
> 
 photos = api.photos.all
 for photo in photos:
> print(photo.filename)
> 
> 
> Traceback (most recent call last):
>   File "", line 2, in 
>   print(photo.filename)
> File
>   "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
>   line 242, in filename
>   return self.data['details'].get('filename')
> File
>   "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
>   line 237, in data
>   self._data = self.album._fetch_asset_data_for(self)
> File
>   "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
>   line 203, in _fetch_asset_data_for
>   client_ids.append(self._photo_assets[index].client_id)
>   TypeError: 'dict_values' object does not support indexing
> 
> which points at this bit of the source code
> 
> 240@property
> 241def filename(self):
> 242return self.data['details'].get('filename')
> 
> And I get the same exception trying to do anything with a single
> photo.  Is this code not really Python 3 compatible?  Or am I doing
> something stupid?

I don't think you are. Try wrapping the return value of

 def _parse_binary_feed(self, feed):
  ...
  return list(assets.values())

in services/photos.py to convert the view into a list.

Of course when there's one problem there will likely be more...

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


Save Idle Options

2016-09-30 Thread tcebob
Win 10 pro 32, Python 3.6
I’m new to Python and installed Python with Idle, which I like as an IDE. But 
I’m mystified as to how to make interface options stick. Opened Options, 
Configure Idle. Changed font to Consolas Bold. And stopped dead. There doesn’t 
seem to be a way to save the changes. Tried reloading my file but had to exit 
the Options to do so. So lost the changes. Same issue with  highlighting 
colors. Google is hopeless. How can I do this?

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


Re: unintuitive for-loop behavior

2016-09-30 Thread BartC

On 30/09/2016 13:33, Steve D'Aprano wrote:

On Fri, 30 Sep 2016 05:29 am, namenobodywa...@gmail.com wrote:



i've had a nodding acquaintance with python for some time, and all along i
assumed that for-loops got a namespace of their own;



It would be terribly inconvenient and surprising for if...else blocks to be
separate namespaces:

a = 1
if condition:
print(a)  # UnboundLocalError: local 'a' referenced before assignment
a += 1


For-loops are no different. Making them their own namespace is a very
strange thing to do, it would mean you couldn't re-bind a value inside a
for-loop:

count = 0
for x in sequence:
count += 1
# raises UnboundLocalError: local 'count' referenced before assignment


It can make sense for 'x' to be local to this for-loop block (everything 
else is at it works now), and independent of any x's in outer blocks. It 
means being able to do stuff like this:


   for x in a:
 for x in b:
pass
 pass # outer x still has its value

And any even more outer x's are not affected. With 'for', especially one 
inside a list-comp, often you just need some throwaway index variable 
without worrying if it will clash with an existing local.


But it's not useful enough I think to bother changing now. Or even when 
the language was designed.


--
Bartc

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


pyicloud: TypeError: 'dict_values' object does not support indexing

2016-09-30 Thread Adam Funk
I'm trying to use pyicloud in idle3 (installed by pip3 on Ubuntu).



The basic stuff works, but access to photos (following the
instructions) fails:


>>> photos = api.photos.all
>>> for photo in photos:
print(photo.filename)


Traceback (most recent call last):
  File "", line 2, in 
  print(photo.filename)
File
  "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
  line 242, in filename
  return self.data['details'].get('filename')
File
  "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
  line 237, in data
  self._data = self.album._fetch_asset_data_for(self)
File
  "/usr/local/lib/python3.5/dist-packages/pyicloud/services/photos.py",
  line 203, in _fetch_asset_data_for
  client_ids.append(self._photo_assets[index].client_id)
  TypeError: 'dict_values' object does not support indexing

which points at this bit of the source code

240@property
241def filename(self):
242return self.data['details'].get('filename')

And I get the same exception trying to do anything with a single
photo.  Is this code not really Python 3 compatible?  Or am I doing
something stupid?

Thanks,
Adam


-- 
A firm rule must be imposed upon our nation before it destroys
itself. The United States needs some theology and geometry, some taste
and decency. I suspect that we are teetering on the edge of the abyss.
 --- Ignatius J Reilly
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using the Windows "embedded" distribution of Python

2016-09-30 Thread Paul Moore
On Friday, 30 September 2016 12:50:45 UTC+1, eryk sun  wrote:
> On Fri, Sep 30, 2016 at 11:02 AM, Paul  Moore  wrote:
> > When I run ssh.exe, it fails with the message "The program cannot start 
> > because
> > python3.dll is missing from your computer". I tried running it with 
> > sxstrace active,
> > but the resulting log file is empty.
> 
> A manifest embedded in "ssh.exe" takes precedence over
> "ssh.exe.manifest". Check for an embedded manifest:
> 
> mt -inputresource:ssh.exe -out:con >nul

I didn't think there was one, but when I looked, there is. I must have added it 
in my experimentation. Sadly, it's the same as the external one, so that 
shouldn't be a problem.

> Also, manifests get cached (probably by SuperFetch), so when you make
> a change you generally need to recompile or change the filename.

Ah, looks like that was the issue. Renaming the file fixed it. (As did just 
touching the file to update the timestamp). Caches are great, I guess, but they 
sure make debugging an adventure!

I think I now have a working solution. And I've *definitely* learned a huge 
amount.

Thanks again for the help.
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unintuitive for-loop behavior

2016-09-30 Thread Steve D'Aprano
On Fri, 30 Sep 2016 05:29 am, namenobodywa...@gmail.com wrote:

> hello pythonistas
> 
> i've had a nodding acquaintance with python for some time, and all along i
> assumed that for-loops got a namespace of their own; 

Giving for-loops their own namespace is a grossly unintuitive and a very
weird thing to do. Modules, classes and functions are obviously namespaces.
Why should arbitrary syntactic structures create their own namespace?

It would be terribly inconvenient and surprising for if...else blocks to be
separate namespaces:

a = 1
if condition:
print(a)  # UnboundLocalError: local 'a' referenced before assignment
a += 1


For-loops are no different. Making them their own namespace is a very
strange thing to do, it would mean you couldn't re-bind a value inside a
for-loop:

count = 0
for x in sequence:
count += 1  
# raises UnboundLocalError: local 'count' referenced before assignment


unless you declared it nonlocal or global, depending on whether your for
loop was inside a function or not.

To me, "make for-loops be their own scope" sounds like a joke feature out of
joke languages like INTERCAL. I'm not aware of any sensible language that
does anything like this.

No, wait a minute, I tell a lie, I recall Chris Angelico mentioning that one
of his favourite languages, Pike or REXX, does it. I forget which.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Using the Windows "embedded" distribution of Python

2016-09-30 Thread eryk sun
On Fri, Sep 30, 2016 at 11:02 AM, Paul  Moore  wrote:
> When I run ssh.exe, it fails with the message "The program cannot start 
> because
> python3.dll is missing from your computer". I tried running it with sxstrace 
> active,
> but the resulting log file is empty.

A manifest embedded in "ssh.exe" takes precedence over
"ssh.exe.manifest". Check for an embedded manifest:

mt -inputresource:ssh.exe -out:con >nul

Also, manifests get cached (probably by SuperFetch), so when you make
a change you generally need to recompile or change the filename.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a foreign function run as fast as possible in Windows?

2016-09-30 Thread Paul Moore
On Thursday, 29 September 2016 02:23:13 UTC+1, jf...@ms4.hinet.net  wrote:
> Paul  Moore at 2016/9/28 11:31:50PM wrote:
> > Taking a step back from the more detailed answers, would I be right to 
> > assume that you want to call this external function multiple times from 
> > Python, and each call could take days to run? Or is it that you have lots 
> > of calls to make and each one takes a small amount of time but the total 
> > time for all the calls is in days?
> > 
> > And furthermore, can I assume that the external function is *not* written 
> > to take advantage of multiple CPUs, so that if you call the function once, 
> > it's only using one of the CPUs you have? Is it fully utilising a single 
> > CPU, or is it actually not CPU-bound for a single call?
> > 
> > To give specific suggestions, we really need to know a bit more about your 
> > issue.
> 
> Forgive me, I didn't notice these detail will infulence the answer:-)
> 
> Python will call it once. The center part of this function was written in 
> assembly for performance. During its execution, this part might be called 
> thousands of million times. The function was written to run in a single CPU, 
> but the problem it want to solve can be easily distributed into multiple CPUs.
> 
> --Jach

OK. So if your Python code only calls the function once, the problem needs to 
be fixed in the external code (the assembly routine). But if you can split up 
the task at the Python level to make multiple calls to the function, each to do 
a part of the task, then you could set up multiple threads in your Python code, 
each of which handles part of the task, then Python merges the results of the 
sub-parts to give you the final answer. Does that make sense to you? Without 
any explicit code, it's hard to be sure I'm explaining myself clearly.

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


Re: Using the Windows "embedded" distribution of Python

2016-09-30 Thread Paul Moore
On Thursday, 29 September 2016 12:56:28 UTC+1, eryk sun  wrote:
> In that case you can use an application manifest with a dependent
> assembly. Say embedded Python 3.6 is in the "py3embed" subdirectory.
> Add the following manifest file to that directory:
> 
> py3embed.manifest:
> 
> 
> 
>version="3.6.111.1013"
>   type="win32"
>   processorArchitecture="amd64" />
> 
> 
> 
> 
> 
> Add this assembly as a dependency in the application manifest, either
> embedded in the executable (resource #1) or as a separate file named
> the same as the executable plus ".manifest", e.g. "app.exe.manifest".
> You can start with the manifest that's used by python.exe, from
> PC\python.manifest.
> 
>   
> 
>version="3.6.111.1013"
> type="win32"
> processorArchitecture="amd64" />
> 
>   

OK, I thought I understood this, but it's not quite working.

I have the following directory structure:

py3embed
py3embed.manifest
... an unpacked Python 3.6b0 embedded distribution
ssh.exe
ssh.exe.manifest

(ssh.exe is my embedded Python program)

py3embed.manifest is









ssh.exe.manifest is:

 
  
   
  
 
  
  
  
   
  
   
  
  
  
 
  

  
  
  
   
  
  
  
  
  
  
  
  
  
  
  
  
  

  
  
  
   
  
  http://schemas.microsoft.com/SMI/2016/WindowsSettings";>true
   
  
  
  
  

  
 
  
  
  

  
   
  


When I run ssh.exe, it fails with the message "The program cannot start because 
python3.dll is missing from your computer". I tried running it with sxstrace 
active, but the resulting log file is empty.

I'm not sure where to go next debugging this. Do you have any suggestions?

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


Re: Abusive Italian Spam

2016-09-30 Thread Cem Karan
Honestly, I'm impressed by how little spam ever makes it onto the list.  
Considering the absolute flood of email the lists get, it's impressive work.  
Thank you for all the hard work you guys do for all the rest of us!

Thanks,
Cem Karan

On Sep 29, 2016, at 11:30 AM, Tim Golden  wrote:

> You may have noticed one or two more of the abusive spam messages slip
> through onto the list. We do have traps for these but, as with most such
> things, they need tuning. (We've discarded many more than you've seen).
> 
> As ever, kudos to Mark Sapiro of the Mailman team for tweaking our
> custom filters and sorting out the archives in a timely fashion.
> 
> TJG
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: filesystem encoding 'strict' on Windows

2016-09-30 Thread eryk sun
On Fri, Sep 30, 2016 at 5:58 AM, iMath  wrote:
> the doc of os.fsencode(filename)  says  Encode filename to the filesystem 
> encoding 'strict'
> on Windows, what does 'strict' mean ?

"strict" is the error handler for the encoding. It raises a
UnicodeEncodeError for unmapped characters. For example:

>>> 'αβψδ'.encode('mbcs', 'strict')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'mbcs' codec can't encode characters in
position 0--1: invalid character

On the other hand, the "replace" error handler is lossy. With the
Windows "mbcs" codec, it substitutes question marks and best-fit
mappings for characters that aren't defined in the system locale's
ANSI codepage (e.g. 1252). For example:

>>> print('αβψδ'.encode('mbcs', 'replace').decode('mbcs'))
aß?d

This is the behavior of os.listdir with bytes paths, which is why
using bytes paths has been deprecated on Windows since 3.3.

In 3.6 bytes paths are provisionally allowed again because the
filesystem encoding has changed to UTF-8 (internally transcoded to the
native UTF-16LE) and uses the "surrogatepass" error handler to allow
lone surrogate codes (allowed by Windows). See PEP 529 for more
information.
-- 
https://mail.python.org/mailman/listinfo/python-list