Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Mark Lawrence via Python-list

On 29/03/2016 23:29, Marco Sulla via Python-list wrote:


Let me add that an items() and keys() for sequences will be also
useful for day-by-day programming, since they will be a shortcut for
enumerate(seq) and range(len(seq))



I cannot remember the last time I needed range(len(seq)) so I don't see 
how it can be "useful for day-by-day programming".  There is usually a 
more Pythonic way of doing things.  You need to get adjacent elements 
from a sequence?  Use the pairwise recipe from 
https://docs.python.org/3/library/itertools.html.


--
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: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Steven D'Aprano writes:

> Given a surjection (many-to-one mapping)

No. And I doubt that Wikipedia says that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me

2016-03-30 Thread Smith

Il 29/03/2016 11:17, Ben Finney ha scritto:

Smith  writes:


[a URL]


You'll get better help if you:

* Summarise the problem briefly in the Subject field.

* Actually say anything useful in the message body.


thanks a lot
--
https://mail.python.org/mailman/listinfo/python-list


HELP! With calculating

2016-03-30 Thread Yum Di
import random
import time

print ("Welcome to Pizza Shed!")

tablenum = input ("Enter table number from 1-25 \n ")
while tablenum>25 or tablenum <=0:
tablenum = input ("Enter the correct table number, there are only 25 tables 
")

#Pizza menu with prices

print ("-")

print ("Let me help you with your order!")

print ("-")

print ("Menu")

print (
"1 = cheese and tomato: 3.50, "
"2 = ham and pineapple: 4.20, "
"3 = vegetarian: 5.20, "
"4 = meat feast: 5.80, "
"5 = seafood: 5.60 " )

pizza_choice = input("Enter the type of pizza that you want to order from 1-5 
\n")
while pizza_choice>5 or pizza_choice <=1:
pizza_choice = input ("Enter the right number ")

if pizza_choice == 1:
print "You have chosen cheese and tomato. The cost for this is 3.50"
elif pizza_choice == 2:
print ("You have chosen ham and pineapple. The cost for this is 4.20")
elif pizza_choice == 3:
print ("You have chosen vegetarian. The cost for this is 5.20")
elif pizza_choice == 4:
print ("You have chosen meat feast. The cost for this is 5.80")
elif pizza_choice == 5:
print ("You have chosen sea food. The cost for this is 5.60")

print ("--")

pizza_amount = input ("Enter the amount of Pizzas that you want to order ")
while pizza_amount > 10 or pizza_amount <=0:
pizza_amount = input ("Maximum amount is 10, Please enter again ")

print ("")

#base

print ("Base")

print (
"1 = thin and crispy,"
"2 = traditional" )

base = input ("Select a base from 1-2 \n")
while base>2 or base<=1:
base = input ("There are only 2 types, Please enter again ")

if base == 1:
print "You have chosen thin and crispy"
elif base == 2:
print ("You have chosen traditional")

print ("---")

#extra toppings

print ("Extra Toppings")

toppings = input ("Enter a number for your choice of extra topping \n Enter 1 
for extra cheese \n Enter 2 for extra pepperoni \n Enter 3 for extra pineapple 
\n Enter 4 for extra peppers \n" )
while toppings >4 or toppings < 0:
toppings = input ("There are only 4 types of extra toppings, Please try 
again " )

if toppings == 1:
print ("You have chosen extra cheese. The cost for this is 0.50")
elif toppings == 2:
print ("You have chosen pepperoni. The cost for this is 0.50")
elif toppings == 3:
print ("You have chosen pineapple. The cost for this is 0.50")
elif toppings == 4:
print ("You have chosen peppers. The cost for this is 0.50")

print ("-")

#drink

print ("Drink")

print (
"1 = Cola: 0.90, "
"2 = Lemonande: 0.80, "
"3 = Fizzy Orange: 0.90 " )

drink = input ("Enter a number for your choice of drinks " )
while drink>3 or drink<0:
drink = input ("Choices start from 0 to 3 " )

if drink == 1:
print "You have chosen Cola. The cost for this is 0.90"
elif drink == 2:
print ("You have chosen Lemonande. The cost for this is 0.80")
elif drink == 3:
print ("You have chosen Fizzy Orange. The cost for this is 0.90")

drink_amount = input ("Enter the amount of drinks")
while drink_amount >10 or drink_amount<0:
drink_amount = input (" You can only have upto 10 drinks, Please try again")

print ("")
print ("Calculating bill")
print ("")
print ("")

print ("Thank You for ordering at Pizza Shed! ")


Hey, this is my code..
I need to calculate the total cost, but I m not sure how to do that.
I m still new at python.

Can someone please help me
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-03-30 Thread Sven R. Kunze

On 30.03.2016 01:43, Steven D'Aprano wrote:

On Tue, 29 Mar 2016 09:26 pm, Sven R. Kunze wrote:


On 27.03.2016 05:01, Steven D'Aprano wrote:

Am I the only one who has noticed that threading of posts here is
severely broken? It's always been the case that there have been a few
posts here and there that break threading, but now it seems to be much
more common.

I agree. Didn't we both already have a conversation about this? I
thought it is my thunderbird messing things up.

I'm not using Thunderbird, so whatever the cause of the problem, it is not
specific to Thunderbird.






Haha, how nice. My thread view shows your reply as a sibling not a child 
to my mail. I assume you replied to my mail. How strange.



Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help me

2016-03-30 Thread Ben Finney
Smith  writes:

> Il 29/03/2016 11:17, Ben Finney ha scritto:
> > You'll get better help if you:
> >
> > * Summarise the problem briefly in the Subject field.
> >
> > * Actually say anything useful in the message body.
> >
> thanks a lot

You're welcome. Feel free to ask about the Python language here,
following the advice above.

-- 
 \  “Programs must be written for people to read, and only |
  `\incidentally for machines to execute.” —Abelson & Sussman, |
_o__)  _Structure and Interpretation of Computer Programs_ |
Ben Finney

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


Re: HELP! With calculating

2016-03-30 Thread Ben Finney
Yum Di  writes:

> I m still new at python.
> Can someone please help me

Welcome to Python!

Please join our dedicated beginner forum, ‘python-tutor’
https://mail.python.org/mailman/listinfo/tutor>.


> Hey, this is my code..

That's a lot of code to dump all at once. If you have a specific
request, please reduce the example to the very minimum needed to
demonstrate the behaviour. See http://sscce.org/>.

-- 
 \   “The best in us does not require the worst in us: Our love of |
  `\ other human beings does not need to be nurtured by delusion.” |
_o__) —Sam Harris, at _Beyond Belief 2006_ |
Ben Finney

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Antoon Pardon
Op 30-03-16 om 07:43 schreef Steven D'Aprano:
> Yes, we're all very impressed that you spotted the trivial and obvious 
> loophole that changing a key:value will change the key:value that you just 
> changed *wink* but that doesn't really move the discussion anywhere.
>
> This is not an argument about dicts being mutable, because clearly they 
> aren't. This is an argument about key:value pairs being stable. "Stable" 
> doesn't mean "immutable". If you change the value associated with a key 
> directly, then it will change. That's the whole point. But if you change 
> *one* key, the relationship between *other* keys and their values shouldn't 
> change.
>
> Given a surjection (many-to-one mapping) between keys and values in a 
> mapping, we expect that changing the mapping of one key will not affect 
> other keys. To be pedantic, by "change" I mean deleting the key (and, if 
> necessary, value) or reassigning a new value to the key. To be even more 
> pedantic, mutations to the value *do not count*.

I don't expect that generally. Sure there are specific mapping implementations
for which this is true, but I see no reason to limit the word mapping only to
those kind of data-types.

What I want from a mapping is that it gives me the correct correspondence 
between
a key and a value for the application I am using it for. If that means a 
"stable"
mapping I'll limit the operations on that mapping as to keep it that way. Which
in a number of case can be perfectly done with python-lists.

So generally there is no reason to limit the word "mapping" to stable mappings.

-- 
Antoon Pardon


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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze

On 30.03.2016 01:29, Eric S. Johansson wrote:



On 3/29/2016 6:05 AM, Sven R. Kunze wrote:


Python = English

As someone who writes English text and code using speech recognition, 
I can assure you that Python is not English. :-)


:D Interesting. Never thought of how Python sounds when spoken.

Btw. the equivalence was more meant in the context of this thread. ;)

Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Tim Golden
On 30/03/2016 11:07, Sven R. Kunze wrote:
> On 30.03.2016 01:29, Eric S. Johansson wrote:
>>
>>
>> On 3/29/2016 6:05 AM, Sven R. Kunze wrote:
>>>
>>> Python = English
>>>
>> As someone who writes English text and code using speech recognition,
>> I can assure you that Python is not English. :-)
> 
> :D Interesting. Never thought of how Python sounds when spoken.

Not that you quite meant this, but I'm always amused (and still a little
startled) when I listen to talks recorded from, say, PyCon and hear
people with American accents pronouncing Python with the stress on the
slightly longer second syllable.

(I don't know how other English-speaking groups say the word, but in
England the first syllable is stressed and the second is the
conventional short "uh" sound).

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:

> Steven D'Aprano writes:
> 
>> Given a surjection (many-to-one mapping)
> 
> No. And I doubt that Wikipedia says that.


No to what? What are you disagreeing with?


-- 
Steven

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


Re: Calculate Bill

2016-03-30 Thread BartC

On 29/03/2016 23:33, Yum Di wrote:


print ("Menu")

print (
 "1 = cheese and tomato: 3.50, "
 "2 = ham and pineapple: 4.20, "
 "3 = vegetarian: 5.20, "
 "4 = meat feast: 5.80, "
 "5 = seafood: 5.60 " )



Hey.. this code works.


Sure, after you got rid of those list that were causing the trouble!

 However, i need it to calculate the total cost.

I dont know how to do that. Can someone help me..
thanks


But I think you will need a list of some sort as central place to store 
descriptions and prices. Several lists actually for the different menus. 
There are a dozen ways to this. One simple approach is below.


pizzas=( ("Cheese and Tomato", 3.50),  #0
 ("Ham and Pineapple", 4.20,), #1
 ("Vegetarian",5.20),  #2
 ("Meat Feast",5.80),  #3
 ("Seafood",5.60)) #4

descr = 0# indices into each record
cost  = 1

def showmenu(menu):
for number,selection in enumerate(menu,1):
print ("{:>3} {:30} {:3.2f}".format(number,
   selection[descr],selection[cost]))

showmenu(pizzas)

option   = 3-1# vegetarian (3 on displayed menu is 2 in list)
quantity = 2

print ("You chose",quantity,"of",pizzas[option][descr])
print ("Total is",pizzas[option][cost]*quantity)

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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze

On 30.03.2016 12:14, Tim Golden wrote:

Not that you quite meant this, but I'm always amused (and still a little
startled) when I listen to talks recorded from, say, PyCon and hear
people with American accents pronouncing Python with the stress on the
slightly longer second syllable.

(I don't know how other English-speaking groups say the word, but in
England the first syllable is stressed and the second is the
conventional short "uh" sound).

TJG


I recognize this too. I also started with the England variant but now I 
am not so sure anymore. :D


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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread BartC

On 30/03/2016 11:07, Sven R. Kunze wrote:

On 30.03.2016 01:29, Eric S. Johansson wrote:



On 3/29/2016 6:05 AM, Sven R. Kunze wrote:


Python = English


As someone who writes English text and code using speech recognition,
I can assure you that Python is not English. :-)


:D Interesting. Never thought of how Python sounds when spoken.


Among other things, it becomes case insensitive...

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Steven D'Aprano writes:

> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>
>> Steven D'Aprano writes:
>> 
>>> Given a surjection (many-to-one mapping)
>> 
>> No. And I doubt that Wikipedia says that.
>
> No to what? What are you disagreeing with?

Surjection does not mean many-to-one mapping. It means something else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Manolo Martínez
On 03/30/16 at 09:17pm, Steven D'Aprano wrote:
> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
> 
> > Steven D'Aprano writes:
> > 
> >> Given a surjection (many-to-one mapping)
> > 
> > No. And I doubt that Wikipedia says that.
> 
> 
> No to what? What are you disagreeing with?
> 

I think it's with your definition of surjection. Bijections are
surjective, no?

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Antoon Pardon
Op 30-03-16 om 12:28 schreef Jussi Piitulainen:
> Steven D'Aprano writes:
>
>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>>
>>> Steven D'Aprano writes:
>>>
 Given a surjection (many-to-one mapping)
>>> No. And I doubt that Wikipedia says that.
>> No to what? What are you disagreeing with?
> Surjection does not mean many-to-one mapping. It means something else.

I think this is my fault. I used "surjective function" wrongly in
my first response.

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Manolo Martínez writes:

> On 03/30/16 at 09:17pm, Steven D'Aprano wrote:
>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>> 
>> > Steven D'Aprano writes:
>> > 
>> >> Given a surjection (many-to-one mapping)
>> > 
>> > No. And I doubt that Wikipedia says that.
>> 
>> 
>> No to what? What are you disagreeing with?
>> 
>
> I think it's with your definition of surjection. Bijections are
> surjective, no?

Yes, and most many-to-one mappings are *not* surjective.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Manolo Martínez
On 03/30/16 at 01:40pm, Jussi Piitulainen wrote:
> Manolo Martínez writes:
 >
> > I think it's with your definition of surjection. Bijections are
> > surjective, no?
> 
> Yes, and most many-to-one mappings are *not* surjective.

Well, I don't know about most, there are uncountably many surjective and
non-surjective many-to-one mappings :)

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Antoon Pardon writes:

> Op 30-03-16 om 12:28 schreef Jussi Piitulainen:
>> Steven D'Aprano writes:
>>
>>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>>>
 Steven D'Aprano writes:

> Given a surjection (many-to-one mapping)
 No. And I doubt that Wikipedia says that.
>>> No to what? What are you disagreeing with?
>> Surjection does not mean many-to-one mapping. It means something else.
>
> I think this is my fault. I used "surjective function" wrongly in
> my first response.

Thanks. I missed that. Now I at least see why Steven may have brought
the concept up at all - it doesn't seem relevant, either.
-- 
https://mail.python.org/mailman/listinfo/python-list


sympy

2016-03-30 Thread Poul Riis
Is it possible to transfer results from sympy to 'normal' python.

In the case below I think my intention is clear enough but it does not work as 
intended. How can it be done?

Poul Riis




from sympy import *
x=Symbol('x')
ftext=diff(1/(x**2+1),x)

def f(t):
return ftext.subs(x,'t')

print(f(3))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Manolo Martínez writes:

> On 03/30/16 at 01:40pm, Jussi Piitulainen wrote:
>> Manolo Martínez writes:
>  >
>> > I think it's with your definition of surjection. Bijections are
>> > surjective, no?
>> 
>> Yes, and most many-to-one mappings are *not* surjective.
>
> Well, I don't know about most, there are uncountably many surjective
> and non-surjective many-to-one mappings :)

Ok, safer to say that some many-to-one mappings are not surjective.

I was thinking of finite sets, and not even really thinking. But even
with infinite domain and infinite codomain, there can be uncountably
many mappings without any of them being a surjection - just have the
codomain be a larger infinity.

It depends on the types. Which makes the concept not easily applicable
to Python data structures as such.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sympy

2016-03-30 Thread Ben Finney
Poul Riis  writes:

> Is it possible to transfer results from sympy to 'normal' python.

Is Sympy not “normal Python”? What transfer are you intending?

> In the case below I think my intention is clear enough but it does not
> work as intended. How can it be done?

First: no, your intention is not clear. Please write idiomatic Python:
spaces around operators, names which describe the meaning. Follow the
coding style guide PEP 8 https://www.python.org/dev/peps/pep-0008/>.

Second: no, the intent is obscured because you are using ‘from sympy
import *’. This clobbers the global namespace, making it much more
difficult to tell which names come from a different namespace. Instead,
do ‘import sympy’ and qualify names ‘sympy.Symbol’, etc.

Third: if the code “does not work as intended”, then the answer can be
no better than “change it until it works as intended”. If you want more
detail, please provide more detail on what it *is* doing, and what you
think it *should* do instead.

-- 
 \   “I bet one legend that keeps recurring throughout history, in |
  `\  every culture, is the story of Popeye.” —Jack Handey |
_o__)  |
Ben Finney

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


Re: sympy

2016-03-30 Thread Ned Batchelder
On Wednesday, March 30, 2016 at 7:17:33 AM UTC-4, Poul Riis wrote:
> Is it possible to transfer results from sympy to 'normal' python.

Poul, welcome to the group.

> In the case below I think my intention is clear enough but it does not work 
> as intended. How can it be done?
> 
> from sympy import *
> x=Symbol('x')
> ftext=diff(1/(x**2+1),x)
> 
> def f(t):
> return ftext.subs(x,'t')
> 
> print(f(3))

You'd be surprised how hard it is to understand what someone else thinks
a small chunk of code should do. :)

Even if we can work out what this was meant to do, it will be easier to help
if you are explicit about the outcome you are getting, and how that differs
from the outcome you want.

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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze

On 30.03.2016 12:21, BartC wrote:

On 30/03/2016 11:07, Sven R. Kunze wrote:

On 30.03.2016 01:29, Eric S. Johansson wrote:



On 3/29/2016 6:05 AM, Sven R. Kunze wrote:


Python = English


As someone who writes English text and code using speech recognition,
I can assure you that Python is not English. :-)


:D Interesting. Never thought of how Python sounds when spoken.


Among other things, it becomes case insensitive...



Now that you mention it... ;)

You do coding with speech recognition, too?


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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Marko Rauhamaa
Jussi Piitulainen :

> Manolo Martínez writes:
>> On 03/30/16 at 01:40pm, Jussi Piitulainen wrote:
>>> Yes, and most many-to-one mappings are *not* surjective.
>>
>> Well, I don't know about most, there are uncountably many surjective
>> and non-surjective many-to-one mappings :)
>
> Ok, safer to say that some many-to-one mappings are not surjective.
>
> I was thinking of finite sets, and not even really thinking. But even
> with infinite domain and infinite codomain, there can be uncountably
> many mappings without any of them being a surjection - just have the
> codomain be a larger infinity.

I don't even know if you can say much about the cardinality (or
countability) of mappings. The general set of mappings can't exist. The
*class* of mappings does exist in some set theories, but I don't believe
classes have cardinality.


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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Wed, 30 Mar 2016 09:28 pm, Jussi Piitulainen wrote:

> Steven D'Aprano writes:
> 
>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>>
>>> Steven D'Aprano writes:
>>> 
 Given a surjection (many-to-one mapping)
>>> 
>>> No. And I doubt that Wikipedia says that.
>>
>> No to what? What are you disagreeing with?
> 
> Surjection does not mean many-to-one mapping. It means something else.


Oh, if only I had linked to the Wikipedia page earlier... oh wait, I did.
Here it is again:

https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection


The relevant definition is:


The function is surjective (onto) if every element of the codomain is
mapped to by at least one element of the domain. (That is, the image and
the codomain of the function are equal.) A surjective function is a
surjection. Notationally:

\forall y \in B, \exists x \in A \text{ such that } y = f(x).\ 



and the relevant diagram is the image labelled "Non-injective and
surjective", also seen here:

https://en.wikipedia.org/wiki/File:Surjection.svg


Why is a mapping (such as a dict) best described as a surjection? Consider:

d = {1: None, 2: 'a', 3: 'b', 4: None}


Every key has exactly one value. There are no values without a key, and
every value has *at least* one key.

To be an injection or a bijection, it must be one-to-one. Since multiple
keys can map to the same value, it's not an injection or a bijection.

Every value must have a key: there are no values in the dict without a key.
Hence, it's a surjection.

Although Wikipedia don't use the description, "many-to-one" is a good way of
describing surjections, since you can have many keys mapped to a single
value. To be precise, some surjections may be one-to-one, and not all
many-to-one relations are surjections. But the distinguishing feature of a
surjection is that each value must have *at least* one key, which describes
dicts and other such mappings.

And for those who don't trust Wikipedia:

http://mathsforall.co.uk/userfiles/SECTION%203B%20Injective%20and%20Surjective%20functions%2027_11_06.pdf




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Manolo Martínez
On 03/30/16 at 02:44pm, Marko Rauhamaa wrote:
> Jussi Piitulainen :
> 
> > Manolo Martínez writes:
> >> On 03/30/16 at 01:40pm, Jussi Piitulainen wrote:
> >>> Yes, and most many-to-one mappings are *not* surjective.
> >>
> >> Well, I don't know about most, there are uncountably many surjective
> >> and non-surjective many-to-one mappings :)
> >
> > Ok, safer to say that some many-to-one mappings are not surjective.
> >
> > I was thinking of finite sets, and not even really thinking. But even
> > with infinite domain and infinite codomain, there can be uncountably
> > many mappings without any of them being a surjection - just have the
> > codomain be a larger infinity.
> 
> I don't even know if you can say much about the cardinality (or
> countability) of mappings. The general set of mappings can't exist. The
> *class* of mappings does exist in some set theories, but I don't believe
> classes have cardinality.
> 

I guess I was thinking of the cardinality of the set of tuples with
members of the domain in the first member and their image in the second.
Many of those sets will have a well defined cardinality (unless I'm
missing something, which is entirely possible).

Anyway, this is all terribly OT. Thanks for humoring me.

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Wed, 30 Mar 2016 10:21 pm, Jussi Piitulainen wrote:

> Ok, safer to say that some many-to-one mappings are not surjective.

Can you give an example of a Python dict which is not surjective?

Or an example of something which obeys the Mapping ABC which is not
surjective?

Artificial and contrived examples such as this do not count:

class MyDict(dict):
def values(self):
for value in super().values():
yield value
yield object()  # It's a value without a key!




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Marko Rauhamaa
Steven D'Aprano :

> On Wed, 30 Mar 2016 10:21 pm, Jussi Piitulainen wrote:
>> Ok, safer to say that some many-to-one mappings are not surjective.
>
> Can you give an example of a Python dict which is not surjective?

Depends on the codomain. The values() method gives the range.

If you have an ordinary Python dictionary that maps strings to strings,
it will be neither total nor surjective. Since there are strings that
are not among the keys (not total) and there are strings that are not
among the values (not surjective).

You can of course equate keys() with the domain and values() with the
range, in which case the whole discussion becomes nonsensical.

However, a collections.defaultdict instance can be both total and
surjective in the meaningful senses of the words.


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


Re: repeat items in a list

2016-03-30 Thread Michael Selik
I prefer itertools.chain.from_iterable to the sum trick.

>>> from itertools import chain
>>> lst = list('abc')
>>> list(chain.from_iterable([s]*3 for s in lst))
['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']



On Tue, Mar 29, 2016 at 5:28 PM Vito De Tullio 
wrote:

> Random832 wrote:
>
> > How do you turn ['a', 'c', 'b'] into ['a', 'a', 'a', 'c', 'c', 'c', 'b',
> > 'b', 'b']?
>
> >>> sum([[e]*3 for e in ['a', 'c', 'b']], [])
> ['a', 'a', 'a', 'c', 'c', 'c', 'b', 'b', 'b']
>
>
> --
> By ZeD
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Random832
On Wed, Mar 30, 2016, at 01:43, Steven D'Aprano wrote:
> This is not an argument about dicts being mutable, because clearly they 
> aren't. This is an argument about key:value pairs being stable. "Stable" 
> doesn't mean "immutable". If you change the value associated with a key 
> directly, then it will change. That's the whole point. But if you change 
> *one* key, the relationship between *other* keys and their values
> shouldn't 
> change.

This doesn't mean that an object violates the contract by having a
method that changes the relationships between multiple keys and values.
I had considered including an example of replacing the _whole
dictionary_ with a new object in the ellipsis.

Absolutely nothing is stable under a *completely unrestricted* set of
operations.

> Specifically, insertions and deletions to the mapping never affect the 
> existing keys.

You can't say that, because there is no insert and delete method in the
mapping interface.

> If somebody wants to insist that this is a kind of mapping, I can't 
> disagree, but it isn't useful as a mapping type.

Javascript seems to manage it just fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Instalação

2016-03-30 Thread natalia camargo
Não consigo instalar o python no meu Windows,gostaria de alguma ajuda ou 
esclarecimento 

Enviado do Email para Windows 10

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


Re: sympy

2016-03-30 Thread Steven D'Aprano
On Wed, 30 Mar 2016 10:17 pm, Poul Riis wrote:

> Is it possible to transfer results from sympy to 'normal' python.
> 
> In the case below I think my intention is clear enough but it does not
> work as intended. How can it be done?

How can what be done? Unfortunately, we're not able to read your mind. We
can read your code, and can see what your code does, but how are we
supposed to know what it is supposed to do?


> from sympy import *
> x=Symbol('x')
> ftext=diff(1/(x**2+1),x)
> 
> def f(t):
> return ftext.subs(x,'t')
> 
> print(f(3))

This code seems to work perfectly to me. You differentiate an expression,
then substitute the 'x' variable for 't':

-2*t/(t**2 + 1)**2

What were you expecting?




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Marko Rauhamaa
Manolo Martínez :

> On 03/30/16 at 02:44pm, Marko Rauhamaa wrote:
>> I don't even know if you can say much about the cardinality (or
>> countability) of mappings. The general set of mappings can't exist.
>> The *class* of mappings does exist in some set theories, but I don't
>> believe classes have cardinality.
>
> I guess I was thinking of the cardinality of the set of tuples with
> members of the domain in the first member and their image in the
> second.

If you fix the domain and codomain, then we can discuss cardinality
again, but the answer depends on the domain and codomain. For example,
if the domain is the empty set, there exists precisely one function. And
if the codomain is the empty set as well, that function is a bijection.


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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Eric S. Johansson



On 3/30/2016 6:21 AM, BartC wrote:

On 30/03/2016 11:07, Sven R. Kunze wrote:

On 30.03.2016 01:29, Eric S. Johansson wrote:



On 3/29/2016 6:05 AM, Sven R. Kunze wrote:


Python = English


As someone who writes English text and code using speech recognition,
I can assure you that Python is not English. :-)


:D Interesting. Never thought of how Python sounds when spoken.


Among other things, it becomes case insensitive...


Which makes complying with Pep 8 quite the bitch. Fortunately, I have a 
workaround (togglename) which lets me dictate what I need to say and 
preserve the spoken to code for mapping for later translation. (I.e. 
this thing is that thing mapping).


I need a co-conspirator with better hands than mine to get through the 
next stage which is some form of an AST smart editor that operates on 
larger chunks such as idioms or snippets in a speech friendly way. 
Ideally I'd like to see a bidirectional transform between the spoken 
form and a code form so that you can edit the spoken form and regenerate 
the code.


Just one example of what I am thinking of is when you say the string 
name of a previously defined class instance, you get a dialogue of all 
available methods and string names. When you are at the point of 
speaking the argument list, it gives you an abstract form of the 
argument list that is filled in with a minimal set of speech commands. 
I'm too lazy to create the full description right now what if anybody 
wants to know more, ask and I'll fill in the blanks.


It's important to remember though that using simple or accelerated 
methods for creating code is the easy part of the problem. It's editing 
existing code that is hard because you've lost a lot of the information 
necessary for speech user interface. This is where I think an AST based 
editor will come in quite handy. So far, I haven't found any.

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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Chris Angelico
On Thu, Mar 31, 2016 at 12:06 AM, Eric S. Johansson  wrote:
> I need a co-conspirator with better hands than mine to get through the next
> stage which is some form of an AST smart editor that operates on larger
> chunks such as idioms or snippets in a speech friendly way. Ideally I'd like
> to see a bidirectional transform between the spoken form and a code form so
> that you can edit the spoken form and regenerate the code.

Sounds to me like what you want is a variant language, a
speech-friendly programming language that compiles to Python. You
effectively store the spoken version, and translate it (one way) to
Python for execution.

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Antoon Pardon
Op 30-03-16 om 14:22 schreef Steven D'Aprano:
> On Wed, 30 Mar 2016 09:28 pm, Jussi Piitulainen wrote:
>
>> Steven D'Aprano writes:
>>
>>> On Wed, 30 Mar 2016 06:12 pm, Jussi Piitulainen wrote:
>>>
 Steven D'Aprano writes:

> Given a surjection (many-to-one mapping)
 No. And I doubt that Wikipedia says that.
>>> No to what? What are you disagreeing with?
>> Surjection does not mean many-to-one mapping. It means something else.
>
> Oh, if only I had linked to the Wikipedia page earlier... oh wait, I did.
> Here it is again:
>
> https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection
>
>
> The relevant definition is:
>
>
> The function is surjective (onto) if every element of the codomain is
> mapped to by at least one element of the domain. (That is, the image and
> the codomain of the function are equal.) A surjective function is a
> surjection. Notationally:
>
> \forall y \in B, \exists x \in A \text{ such that } y = f(x).\ 
>
>
>
> and the relevant diagram is the image labelled "Non-injective and
> surjective", also seen here:
>
> https://en.wikipedia.org/wiki/File:Surjection.svg
>
>
> Why is a mapping (such as a dict) best described as a surjection? Consider:
>
> d = {1: None, 2: 'a', 3: 'b', 4: None}
>
>
> Every key has exactly one value. There are no values without a key, and
> every value has *at least* one key.

That second remark depends on what you consider the codomain. You could
of course define the codomain as the set of actual values in the mapping,
but that seems to be very artificial since it means that the codomain can
changes any time a value is changed, added or removed.

A more intuitive view would be that the codomain is the set of things
that potentially can be a value in your mapping (in this application).
So looking at your example 'c' seems to be such a potential value which
for the moment doesn't have a key. So your mapping is no surjection.
 

> To be an injection or a bijection, it must be one-to-one. Since multiple
> keys can map to the same value, it's not an injection or a bijection.
>
> Every value must have a key: there are no values in the dict without a key.
> Hence, it's a surjection.

Only if you use the special python meaning of (dictionary) values in this 
context.
If you use the ordinary (mathematical) meaning, there are lots of values that
don't have a key, like every two characters string.

-- 
Antoon.

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


Re: Help me

2016-03-30 Thread srinivas devaki
ahh, this is the beginning of a conspiracy to waste my time.

PS: just for laughs. not to offend any one.

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
On Mar 30, 2016 2:11 PM, "Ben Finney"  wrote:

> Smith  writes:
>
> > Il 29/03/2016 11:17, Ben Finney ha scritto:
> > > You'll get better help if you:
> > >
> > > * Summarise the problem briefly in the Subject field.
> > >
> > > * Actually say anything useful in the message body.
> > >
> > thanks a lot
>
> You're welcome. Feel free to ask about the Python language here,
> following the advice above.
>
> --
>  \  “Programs must be written for people to read, and only |
>   `\incidentally for machines to execute.” —Abelson & Sussman, |
> _o__)  _Structure and Interpretation of Computer Programs_ |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Adding borders to ttk radiobuttons

2016-03-30 Thread Mark Lawrence via Python-list
I believe something like this should suffice to display borders around 
the radiobuttons.


import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.

--
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: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Manolo Martínez
On 03/30/16 at 03:55pm, Marko Rauhamaa wrote:
> Manolo Martínez :
> 
> > On 03/30/16 at 02:44pm, Marko Rauhamaa wrote:
> >> I don't even know if you can say much about the cardinality (or
> >> countability) of mappings. The general set of mappings can't exist.
> >> The *class* of mappings does exist in some set theories, but I don't
> >> believe classes have cardinality.
> >
> > I guess I was thinking of the cardinality of the set of tuples with
> > members of the domain in the first member and their image in the
> > second.
> 
> If you fix the domain and codomain, then we can discuss cardinality
> again, but the answer depends on the domain and codomain. For example,
> if the domain is the empty set, there exists precisely one function. And
> if the codomain is the empty set as well, that function is a bijection.

Yeah, what I said and you quote above is wrong: I was thinking of the
cardinality of the set of those sets of tuples. This seems like the kind
of thing that would result in set-theoretic paradoxes, so yes, you are
probably right that the cardinality of mappings is not well defined.

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


Re: Instalação

2016-03-30 Thread Alan Evangelista



Não consigo instalar o python no meu Windows,gostaria de alguma ajuda ou 
esclarecimento


Natalia, you should use English in this mailing list.

- download latest Python. Python has 2 different versions under development: 
Python 2 and Python 3.
As you are a beginner, I recommend you use the more popular Python 2 version. Its latest version is 
2.7.11.

I recommend you download the Python 2.7.11 x86_64 MSI installer in
https://www.python.org/ftp/python/2.7.11/python-2.7.11.amd64.msi

- run the installer

Python is installed. You can run it from the command line.


Regards,
Alan Evangelista

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


Re: Instalação

2016-03-30 Thread Igor Korot
Hi, Natalia,

On Wed, Mar 30, 2016 at 9:13 AM, Alan Evangelista
 wrote:
>
>> Não consigo instalar o python no meu Windows,gostaria de alguma ajuda ou
>> esclarecimento
>
>
> Natalia, you should use English in this mailing list.
>
> - download latest Python. Python has 2 different versions under development:
> Python 2 and Python 3.
> As you are a beginner, I recommend you use the more popular Python 2
> version. Its latest version is 2.7.11.
> I recommend you download the Python 2.7.11 x86_64 MSI installer in
> https://www.python.org/ftp/python/2.7.11/python-2.7.11.amd64.msi
>
> - run the installer
>
> Python is installed. You can run it from the command line.

If you run into any issues during the install, you can send an e-mail here
with the exact error message (possibly translated into English).

Thank you.

>
>
> Regards,
> Alan Evangelista
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Eric S. Johansson



On 3/30/2016 9:09 AM, Chris Angelico wrote:

On Thu, Mar 31, 2016 at 12:06 AM, Eric S. Johansson  wrote:

I need a co-conspirator with better hands than mine to get through the next
stage which is some form of an AST smart editor that operates on larger
chunks such as idioms or snippets in a speech friendly way. Ideally I'd like
to see a bidirectional transform between the spoken form and a code form so
that you can edit the spoken form and regenerate the code.

Sounds to me like what you want is a variant language, a
speech-friendly programming language that compiles to Python. You
effectively store the spoken version, and translate it (one way) to
Python for execution.


That would be ideal but the problem comes with working with the team. I 
can't expect the other members the team to learn the system. I need to 
be able to work according to the teams rules (coding style etc.) for 
proper integration into an effort. Maybe I should be looking at machine 
learning for identifying patterns in the code and translation back to a 
spoken form.


It be interesting to see what people could come up with though for a 
speech friendly Python model. I've been wrestling with the problem so 
long, I probably have tons of blind spots.

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


Re: Instalação

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 14:13, Alan Evangelista wrote:



Não consigo instalar o python no meu Windows,gostaria de alguma ajuda
ou esclarecimento


Natalia, you should use English in this mailing list.

- download latest Python. Python has 2 different versions under
development: Python 2 and Python 3.
As you are a beginner, I recommend you use the more popular Python 2
version. Its latest version is 2.7.11.


I completely disagree.  A beginner should definitely start with Python 3 
and only use 2 if there's a library they need which hasn't yet been 
ported, something which is becoming increasingly rare.


Grab 3.5.1 from here https://www.python.org/downloads/

--
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: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Steven D'Aprano writes:

> On Wed, 30 Mar 2016 10:21 pm, Jussi Piitulainen wrote:
>
>> Ok, safer to say that some many-to-one mappings are not surjective.
>
> Can you give an example of a Python dict which is not surjective?

Can you give an example of a mapping which is not surjective? Can you
represent it as a Python dict?

Surjectivity requires a specified codomain. Python dicts as such do not
have one.

The Wikipedia article that you cite (the one that doesn't say what you
think it says) is about functions f that have a specified domain, which
is some set A, and a specified codomain, which is some set B. They
indicate this by writing f : A -> B. (I'm not sure if I need to point
out that the A and B in that notation in the text need not have anything
to do with the A and B in the diagrams next to the text on top of the
page. Instead they correspond to the X and Y in the diagrams.)

Do you think {1: 'D', 2: 'B', 3: 'A'} is surjective?

Do you think {1: 'd', 2: 'd', 3: 'c'} is surjective?

Those are the Wikipedia examples of non-surjective mappings on top of
the page.

Strictly speaking, these dicts represent the *graphs* of the functions,
and set("ABD") and set("cd") are the *images* of the two mappings. The
specified codomains are not recoverable from the dicts. (Do I need to
point out that the A, B, C, D and a, b, c, d in the diagrams are
abstract placeholders rather than characters or one-character strings
but using Python strings in their place does not change the abstract
structure of the data, and it's intended in these diagrams that they are
four different things when they are inside the same oval even though
that doesn't seem to be made explicit in the page?)

Yes, the restriction of any mapping to its image is surjective. No, this
does not make it even minimally informative to say of any particular
mapping that its restriction to its image is surjective - its image is
its image? Of course it is.

But it may be informative to say of a dict whether it has at least one
key for every value *in some intended codomain* - whether its image is
its codomain. That is surjectivity.

(I'm running out of pedantry, but just in case: I'm quite aware that I
didn't *explicitly* rule out the possibility of values in the dict but
not in the intended codomain. Should I have? It's part of the notion of
an intended codomain that values outside of it are not allowed at all.)

I don't think this has anything to do with the topic of the thread.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-30 Thread Ben Bacarisse
Dennis Lee Bieber  writes:

> On Tue, 29 Mar 2016 20:14:02 -0700 (PDT), Rustom Mody
>  declaimed the following:
>
>
>>Pascal ? C ? Python is a slide down because
>>Pascal had the clear distinction of procedure and function
>
>   That goes back to FORTRAN (in which one has SUBROUTINE subprocedures,
> and FUNCTION subprocedures -- yes, that is how the standard document used
> to define them), which quite predates Pascal. Strangely, the precursor to
> Pascal -- ALGOL -- apparently used PROC for both procedures and
> functions.

Algol 60 used "procedure" but it maintained the distinction in that
functions had (have?) a type and subroutines didn't (don't).  Algol 68
uses PROC for both and the type VOID for procedures with no value.

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


Re: Instalação

2016-03-30 Thread Cecil Westerhof
On Wednesday 30 Mar 2016 15:36 CEST, Mark Lawrence wrote:

> On 30/03/2016 14:13, Alan Evangelista wrote:
>>
>>> Não consigo instalar o python no meu Windows,gostaria de alguma
>>> ajuda ou esclarecimento
>>
>> Natalia, you should use English in this mailing list.
>>
>> - download latest Python. Python has 2 different versions under
>> development: Python 2 and Python 3. As you are a beginner, I
>> recommend you use the more popular Python 2 version. Its latest
>> version is 2.7.11.
>
> I completely disagree. A beginner should definitely start with
> Python 3 and only use 2 if there's a library they need which hasn't
> yet been ported, something which is becoming increasingly rare.

I agree, with one exception: if they want to run there code also in
the JVM. As far as I know jython is only for Python 2.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Jussi Piitulainen
Marko Rauhamaa writes:

> Steven D'Aprano:
>
>> On Wed, 30 Mar 2016 10:21 pm, Jussi Piitulainen wrote:
>>> Ok, safer to say that some many-to-one mappings are not surjective.
>>
>> Can you give an example of a Python dict which is not surjective?
>
> Depends on the codomain. The values() method gives the range.
>
> If you have an ordinary Python dictionary that maps strings to strings,
> it will be neither total nor surjective. Since there are strings that
> are not among the keys (not total) and there are strings that are not
> among the values (not surjective).
>
> You can of course equate keys() with the domain and values() with the
> range, in which case the whole discussion becomes nonsensical.
>
> However, a collections.defaultdict instance can be both total and
> surjective in the meaningful senses of the words.

The cited Wikipedia article uses "image" for what Marko here calls
"range" (unfortunately it also calls individual values "images" (and the
elements of the domain and codomain, "expressions"), and "range" is also
sometimes used to mean codomain :).

I'm just pointing this out because range aka image is a key concept
here, together with codomain.


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


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread ast


"Mark Lawrence"  a écrit dans le message de 
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders around the 
radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator', {'side': 'left', 'sticky': ''}), 
('Radiobutton.focus', {'side': 'left', 'sticky': '', 'children': [('Radiobutton.label', {'sticky': 
'nswe'})]})], 'sticky': 'nswe'})] 


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


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread ast


"ast"  a écrit dans le message de 
news:56fbe699$0$4548$426a7...@news.free.fr...


"Mark Lawrence"  a écrit dans le message de 
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders around the 
radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator', {'side': 'left', 'sticky': ''}), 
('Radiobutton.focus', {'side': 'left', 'sticky': '', 'children': [('Radiobutton.label', {'sticky': 
'nswe'})]})], 'sticky': 'nswe'})]


for more help:
http://www.tkdocs.com/tutorial/styles.html 


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


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 15:45, ast wrote:


"Mark Lawrence"  a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders around
the radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator',
{'side': 'left', 'sticky': ''}), ('Radiobutton.focus', {'side': 'left',
'sticky': '', 'children': [('Radiobutton.label', {'sticky':
'nswe'})]})], 'sticky': 'nswe'})]


That's as may be, but from Table 56 "ttk Radiobutton options not in 
ttk.Radiobutton" here 
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Radiobutton.html 
it says "borderwidth or bd - Configure this option using a style."


--
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: Adding borders to ttk radiobuttons

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 15:55, ast wrote:


"ast"  a écrit dans le message de
news:56fbe699$0$4548$426a7...@news.free.fr...


"Mark Lawrence"  a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders
around the radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator',
{'side': 'left', 'sticky': ''}), ('Radiobutton.focus', {'side':
'left', 'sticky': '', 'children': [('Radiobutton.label', {'sticky':
'nswe'})]})], 'sticky': 'nswe'})]


for more help:
http://www.tkdocs.com/tutorial/styles.html


For this particular problem not of much use, or I wouldn't be asking :(

--
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: sympy

2016-03-30 Thread Poul Riis
What I intend to do is to let sympy find the derivative of some welldefined 
function and next define the foundation derivative as a normal function so that 
I can calculate numerical values or even make a graph.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sympy

2016-03-30 Thread Robert Kern

On 2016-03-30 16:23, Poul Riis wrote:

What I intend to do is to let sympy find the derivative of some welldefined 
function and next define the foundation derivative as a normal function so that 
I can calculate numerical values or even make a graph.


http://docs.sympy.org/dev/modules/utilities/lambdify.html#sympy.utilities.lambdify.lambdify

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


pygtk button right/middle click

2016-03-30 Thread Grant Edwards
I'm trying to figure out how to get a pygtk button respond to
somehting other than just a simple "left click".  With a standard
3-button mouse, X11 provides at least 9 different "click" types, but
the pygtk button only seems to support one of them.

[Yes, I know there are left-handled mouse configurations -- by "left"
click I'm using the common term to mean the primary mouse button.]

After googling for some time, I haven't found any good answers.  Some
people just say things like "use the button_release_event signal of
the button widget".

But, that signal is depricated (and AFAICT still doesn't make the
button actually respond to the left/middle click by "depressing" the
way it should).

Other answers are things like "you'll have to write you own button
class in C, not C++".

Is the gtk button widget really incapable of handling left or middle
mouse buttons or shift/ctrl/alt modifiers?

-- 
Grant Edwards   grant.b.edwardsYow! CHUBBY CHECKER just
  at   had a CHICKEN SANDWICH in
  gmail.comdowntown DULUTH!
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Python 201 - Intermediate Python book

2016-03-30 Thread Mike Driscoll
Hi,

I just wanted to let you know that I am hard at work on my second book, which 
is entitled Python 201 which will come out this Fall 2016. I currently have a 
Kickstarter going where you can pre-order the book: 
https://www.kickstarter.com/projects/34257246/python-201-intermediate-python

I actually posted to this list last year about what you would consider to be 
intermediate topics in Python. From that discussion and from some ideas I had 
already been working, this book was born. The book is aimed for people who 
already know the basics of Python but would like to learn more. It is also 
written with Python 3 in mind. 

Let me know if you have any questions.

Thanks,
Mike Driscoll

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


Re: repeat items in a list

2016-03-30 Thread Peter Otten
Michael Selik wrote:

> I prefer itertools.chain.from_iterable to the sum trick.
> 
 from itertools import chain
 lst = list('abc')
 list(chain.from_iterable([s]*3 for s in lst))
> ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']

If you want to make this completely lazy:

>>> from functools import partial
>>> from itertools import repeat, chain
>>> items = list("abc")
>>> list(chain.from_iterable(map(partial(repeat, times=3), items)))
['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']


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


Re: pygtk button right/middle click

2016-03-30 Thread Chris Angelico
On Thu, Mar 31, 2016 at 2:36 AM, Grant Edwards  wrote:
> I'm trying to figure out how to get a pygtk button respond to
> somehting other than just a simple "left click".  With a standard
> 3-button mouse, X11 provides at least 9 different "click" types, but
> the pygtk button only seems to support one of them.

You're looking at a couple of different, but related, things. The
clicked() event means "the button was activated", which might have
been caused by a mouse event, or possibly a keyboard or other
activation.

What you want is to react to other forms of mouse event. For that, you
should be able to hook the generic widget handling...

> After googling for some time, I haven't found any good answers.  Some
> people just say things like "use the button_release_event signal of
> the button widget".

... which is what this is talking about. What you'll get is button
press and release events, and it'll be up to you to figure out if they
represent clicks or not. But you'll get events for every mouse button
that way.

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


Re: sympy

2016-03-30 Thread Steven D'Aprano
On Thu, 31 Mar 2016 02:23 am, Poul Riis wrote:

> What I intend to do is to let sympy find the derivative of some
> welldefined function and next define the foundation derivative as a normal
> function so that I can calculate numerical values or even make a graph.


I'm glad you explained what you *actually* wanted, because I was going to
guess that you wanted to evaluate the derivative at x = 3:


py> ftext.evalf(subs={x:3})
-0.0600



-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Thu, 31 Mar 2016 12:12 am, Antoon Pardon wrote:

> Op 30-03-16 om 14:22 schreef Steven D'Aprano:

[...]
>> Why is a mapping (such as a dict) best described as a surjection?
>> Consider:
>>
>> d = {1: None, 2: 'a', 3: 'b', 4: None}
>>
>>
>> Every key has exactly one value. There are no values without a key, and
>> every value has *at least* one key.
> 
> That second remark depends on what you consider the codomain. You could
> of course define the codomain as the set of actual values in the mapping,
> but that seems to be very artificial since it means that the codomain can
> changes any time a value is changed, added or removed.

But that's exactly what the mapping does.

Let's start with something that looks like a mathematical mapping, a
function f(x) from positive integers to positive integers:

f(x) = x**2

Here's our dict:

d = {1: 1, 2: 4, 3: 9, 4: 16}

You're saying that the codomain should be "all positive integers", and
likewise the domain. But this is wrong, because the mapping d isn't defined
for all positive integers:

d[5]  # raise KeyError

We can only say that the domain is the *actual keys in the dict*.

And likewise for the codomain. We can't say that the codomain is all
positive integers, since the mapping is not defined for any values of x
except the given keys.

Because dicts are mutable, we can do this:

d[2] = 7


but that's precisely what we *can't* do with mathematical functions! We
can't just declare that, from now on, x**2 will equal 7 if x is 2. So any
modification of the dict must give us a new and different function. Before,
we had the function:

# d equivalent to
f(x): {1,2,3,4} --> {1,4,9,16} where 
f(1) = 1
f(2) = 4
f(3) = 9
f(4) = 16


After executing the line d[2] = 7, we have the completely different
function:

f(x): {1,2,3,4} --> {1,7,9,16} where 
f(1) = 1
f(2) = 7
f(3) = 9
f(4) = 16


Now consider what happens when we execute:

del d[4]
d['a'] = None


That's the nature of dicts as mappings: they don't actually come very close
to the semantics of mathematical functions. Any talk of surjections,
domains, codomains etc is going to be, at best, an analogy.

So all of this discussion is stretching the mathematical terms to their
breaking point. Dicts aren't actually functions in the mathematical sense,
and in the general case, they don't have well-defined domains and
codomains.

Describing them as surjective (or any other such term) requires a lot of
hand-waving. I happen to think that the analogy works very well (otherwise
I wouldn't have given it), but others think I'm being sloppy, well, yes I
am, and I'll withdraw it.

Because fundamentally, it doesn't matter whether dicts are surjections or
not. They're still many-to-one mappings, and those mappings between keys
and values should not change due to the insertion or deletion of unrelated
keys.

If the OP wants to create his own "StrangeDict", which he himself described
as "terrible", then he can do so. But to make all dicts and lists behave in
this "terrible" and "strange" way is a terrible idea.



[...]
> Only if you use the special python meaning of (dictionary) values in this
> context. If you use the ordinary (mathematical) meaning, there are lots of
> values that don't have a key, like every two characters string.

Well, we're actually discussing Python dictionaries. So, damn straight, of
course I'm going to use the meaning of words as they apply to dicts.




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Wed, 30 Mar 2016 11:50 pm, Random832 wrote:

> Absolutely nothing is stable under a *completely unrestricted* set of
> operations.

Yes, you're absolutely correct. If I create a Python dict, {1: 'a'}, and
then smash the computer to smithereens with a 50lb sledge hammer, neither
the key nor the value will still be accessible. Well done. I never would
have thought of that violation of the dict invariants without you.


>> Specifically, insertions and deletions to the mapping never affect the
>> existing keys.
> 
> You can't say that, because there is no insert and delete method in the
> mapping interface.

There are in the dict API though.

# insertions
d[key] = value

# deletions
del d[key]



>> If somebody wants to insist that this is a kind of mapping, I can't
>> disagree, but it isn't useful as a mapping type.
> 
> Javascript seems to manage it just fine.

I wouldn't exactly hold Javascript up as the exemplar of intelligent design
decisions.


-- 
Steven

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


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread Terry Reedy

On 3/30/2016 11:01 AM, Mark Lawrence via Python-list wrote:

On 30/03/2016 15:45, ast wrote:


"Mark Lawrence"  a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders around
the radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator',
{'side': 'left', 'sticky': ''}), ('Radiobutton.focus', {'side': 'left',
'sticky': '', 'children': [('Radiobutton.label', {'sticky':
'nswe'})]})], 'sticky': 'nswe'})]


That's as may be, but from Table 56 "ttk Radiobutton options not in
ttk.Radiobutton" here
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Radiobutton.html
it says "borderwidth or bd - Configure this option using a style."


Components depend on the theme.  In some themes, Radiobutton does have a 
border.  On Windows 10, I ran


>>> for s in style.theme_names():
style.theme_use(s)
style.theme_use()
style.layout('TRadiobutton')

Theme names are ('winnative', 'clam', 'alt', 'default', 'classic', 
'vista', 'xpnative') with 'vista'the default. Outputs were the same as above


'vista'
[('Radiobutton.padding', {'sticky': 'nswe', 'children':
[('Radiobutton.indicator', {'sticky': '', 'side': 'left'}),
 ('Radiobutton.focus', {'sticky': '', 'children':
[('Radiobutton.label', {'sticky': 'nswe'})], 'side': 'left'})]})]

except for this

'classic'
[('Radiobutton.highlight', {'sticky': 'nswe', 'children': 
[('Radiobutton.border', {'sticky': 'nswe', 'children': 
[('Radiobutton.padding', {'sticky': 'nswe', 'children': 
[('Radiobutton.indicator', {'sticky': '', 'side': 'left'}), 
('Radiobutton.label', {'sticky': 'nswe', 'side': 'left'})]})]})]})]


.theme_names() only displays the themes for the OS.  I believe that 
there is a way to access themes for other OSes (unix, mac) but don't 
remember.


--
Terry Jan Reedy


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


Re: Help me

2016-03-30 Thread Ethan Furman

On 03/30/2016 06:10 AM, srinivas devaki wrote:


ahh, this is the beginning of a conspiracy to waste my time.

PS: just for laughs. not to offend any one.


It's fair:  you waste ours, we waste yours.  :)  A fair, if not good, trade.

--
~Ethan~

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


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread Terry Reedy

On 3/30/2016 11:14 AM, Mark Lawrence via Python-list wrote:

On 30/03/2016 15:55, ast wrote:


"ast"  a écrit dans le message de
news:56fbe699$0$4548$426a7...@news.free.fr...


"Mark Lawrence"  a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...

I believe something like this should suffice to display borders
around the radiobuttons.

import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('BW.TRadiobutton', borderwidth=5)
buttonVar = tk.IntVar()
rb1 = ttk.Radiobutton(text='Hello mum', variable=buttonVar, value=1)
rb1.configure(style='BW.TRadiobutton')
rb1.grid(row=0, column=0)
rb2 = ttk.Radiobutton(text='Hello dad', variable=buttonVar, value=2)
rb2.configure(style='BW.TRadiobutton')
rb2.grid(row=1, column=0)
root.mainloop()

Sadly no borders :(  What have I missed?  Python 3.5.1 on Windows 10.



it seems there is no border on the radio button


style.layout('BW.TRadiobutton')


[('Radiobutton.padding', {'children': [('Radiobutton.indicator',
{'side': 'left', 'sticky': ''}), ('Radiobutton.focus', {'side':
'left', 'sticky': '', 'children': [('Radiobutton.label', {'sticky':
'nswe'})]})], 'sticky': 'nswe'})]


for more help:
http://www.tkdocs.com/tutorial/styles.html


For this particular problem not of much use, or I wouldn't be asking :(


This page has some of the info needed to get a radiobutton with a 
border, at least my machine.  See my answer to your other response.


--
Terry Jan Reedy


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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Random832
This discussion is getting a bit distracted from the original request.
Let's look at it from a higher level.

What is being requested, regardless of if you call it a "map interface"
or whatever, is a single way, for sequences and maps... broadly,
anything with a __getitem__, to iterate over all values which one might
pass to __getitem__, so that one might (among other things) call
__setitem__ to mutate the collection.

Like, these are common patterns:

for i, x in enumerate(l):
   # do some stuff, sometimes assign l[i]

for k, v in d.items():
   # do some stuff, sometimes assign d[k]

A way to apply that pattern generically to an object which may be either
a sequence or a mapping might be nice. Or some other way of doing this
operation - maybe a writable iterator like C++ or Java.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-30 Thread Rustom Mody
On Wednesday, March 30, 2016 at 7:56:50 PM UTC+5:30, Ben Bacarisse wrote:
> Dennis Lee Bieber  writes:

Sorry Dennis
Dont see you at all
Neither on googlegroups -- which of course everyone loves to hate
Nor the archive: 
https://mail.python.org/pipermail/python-list/2016-March/date.html

Only see your posts when someone quotes them

Yes Fortran (and Basic) had procedures and functions
At least the BBC-micros that I grew up on had that distinction
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-30 Thread Random832
On Wed, Mar 30, 2016, at 12:59, Rustom Mody wrote:
> On Wednesday, March 30, 2016 at 7:56:50 PM UTC+5:30, Ben Bacarisse wrote:
> > Dennis Lee Bieber  writes:
> 
> Sorry Dennis
> Dont see you at all
> Neither on googlegroups -- which of course everyone loves to hate
> Nor the archive:
> https://mail.python.org/pipermail/python-list/2016-March/date.html

Looking at the headers of his emails, I see "X-No-Archive: YES"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-30 Thread Rustom Mody
On Wednesday, March 30, 2016 at 10:37:58 PM UTC+5:30, Random832 wrote:
> On Wed, Mar 30, 2016, at 12:59, Rustom Mody wrote:
> > On Wednesday, March 30, 2016 at 7:56:50 PM UTC+5:30, Ben Bacarisse wrote:
> > > Dennis Lee Bieber  writes:
> > 
> > Sorry Dennis
> > Dont see you at all
> > Neither on googlegroups -- which of course everyone loves to hate
> > Nor the archive:
> > https://mail.python.org/pipermail/python-list/2016-March/date.html
> 
> Looking at the headers of his emails, I see "X-No-Archive: YES"

Yes
Earlier I used to see (in GG) Dennis' posts with some message such as
"Will be removed in 6 days" or some such
Now not at all.
-- 
https://mail.python.org/mailman/listinfo/python-list


ArtWork in PyPyBox - Pure Python

2016-03-30 Thread Salvatore DI DIO
In pure Python, here is a nice image (for me at least)

http://salvatore.diodev.fr/pypybox/

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


Re: pygtk button right/middle click

2016-03-30 Thread Grant Edwards
On 2016-03-30, Chris Angelico  wrote:
> On Thu, Mar 31, 2016 at 2:36 AM, Grant Edwards  
> wrote:
>> I'm trying to figure out how to get a pygtk button respond to
>> somehting other than just a simple "left click".  With a standard
>> 3-button mouse, X11 provides at least 9 different "click" types, but
>> the pygtk button only seems to support one of them.
>
> You're looking at a couple of different, but related, things. The
> clicked() event means "the button was activated", which might have
> been caused by a mouse event, or possibly a keyboard or other
> activation.

Right.

> What you want is to react to other forms of mouse event. For that,
> you should be able to hook the generic widget handling...

So I've got to re-implement all the low-level stuff that the button
already does for the "left" button (changing appearance on
button-press and restoring it on button-release), calling the handler,
etc.  I sure seems like the batteries are missing...

-- 
Grant Edwards   grant.b.edwardsYow! Hmmm ... A hash-singer
  at   and a cross-eyed guy were
  gmail.comSLEEPING on a deserted
   island, when ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread justin walters
On Mar 30, 2016 8:41 AM, "Mike Driscoll"  wrote:
>
> Hi,
>
> I just wanted to let you know that I am hard at work on my second book,
which is entitled Python 201 which will come out this Fall 2016. I
currently have a Kickstarter going where you can pre-order the book:
https://www.kickstarter.com/projects/34257246/python-201-intermediate-python
>
> I actually posted to this list last year about what you would consider to
be intermediate topics in Python. From that discussion and from some ideas
I had already been working, this book was born. The book is aimed for
people who already know the basics of Python but would like to learn more.
It is also written with Python 3 in mind.
>
> Let me know if you have any questions.
>
> Thanks,
> Mike Driscoll
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Can you go over a couple of the topics you are going to cover?

Are you going to cover any of the most popular packages such as Django and
scrapy?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread Mike Driscoll
Hi Justin,

> > https://mail.python.org/mailman/listinfo/python-list
> 
> Can you go over a couple of the topics you are going to cover?
> 
> Are you going to cover any of the most popular packages such as Django and
> scrapy?

Sure! I'm planning on covering several of the more popular intermediate-level 
modules from Python's standard library, such as collections, contextlib, 
functools and itertools.

I am also going to be covering benchmarking, encryption, connecting to 
databases, etc.

There is a section on Web-related chapters. While I don't plan to cover a web 
framework, I am going to cover other items related to working with the internet 
using Python. I do plan to talk about creating a web crawler / scraper, but I 
hadn't decided if I was going to use scrapy for that or not. I also plan to 
write about working with web APIs, such as Amazon's or Google's APIs. There 
will probably be some kind of chapter about Selenium / Web Driver too. I have 
some other ideas too.

I hope that answered your question.

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


Re: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread justin walters
On Mar 30, 2016 11:21 AM, "Mike Driscoll"  wrote:
>
> Hi Justin,
>
> > > https://mail.python.org/mailman/listinfo/python-list
> >
> > Can you go over a couple of the topics you are going to cover?
> >
> > Are you going to cover any of the most popular packages such as Django
and
> > scrapy?
>
> Sure! I'm planning on covering several of the more popular
intermediate-level modules from Python's standard library, such as
collections, contextlib, functools and itertools.
>
> I am also going to be covering benchmarking, encryption, connecting to
databases, etc.
>
> There is a section on Web-related chapters. While I don't plan to cover a
web framework, I am going to cover other items related to working with the
internet using Python. I do plan to talk about creating a web crawler /
scraper, but I hadn't decided if I was going to use scrapy for that or not.
I also plan to write about working with web APIs, such as Amazon's or
Google's APIs. There will probably be some kind of chapter about Selenium /
Web Driver too. I have some other ideas too.
>
> I hope that answered your question.
>
> Mike
> --
> https://mail.python.org/mailman/listinfo/python-list

That absolutely answers my questions. I'll keep an eye out for your book
when it is realeased. It seems like it will cover some topics that could be
useful in continuing my learning.

I am especially interested in encryption as that is something I have yet to
dive into.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Antoon Pardon
Op 30-03-16 om 17:56 schreef Steven D'Aprano:
> On Thu, 31 Mar 2016 12:12 am, Antoon Pardon wrote:
> 
>> Op 30-03-16 om 14:22 schreef Steven D'Aprano:
> 
> [...]
>>> Why is a mapping (such as a dict) best described as a surjection?
>>> Consider:
>>>
>>> d = {1: None, 2: 'a', 3: 'b', 4: None}
>>>
>>>
>>> Every key has exactly one value. There are no values without a key, and
>>> every value has *at least* one key.
>>
>> That second remark depends on what you consider the codomain. You could
>> of course define the codomain as the set of actual values in the mapping,
>> but that seems to be very artificial since it means that the codomain can
>> changes any time a value is changed, added or removed.
> 
> But that's exactly what the mapping does.

No it generally doesn't. I see no reason when at one moment I can write the 
following.

  assert map.values == {2, 5, 7, 9}
  map[3] = 8

to claim the codomain has changed. The actual function has changed yes but
since the application shows that the universe of possible mapping represented
by this specific variable containes functions in which 8 is an element of
the function image. This is best expressed by saying 8 is part of the codomain
whether or not 8 is part of the actual values at any specific moment.

Sure you sometimes work with a map in which the image is the domain, like
you did with your map of a limit square function but I consider those
as exceptions, not the general case.


> And likewise for the codomain. We can't say that the codomain is all
> positive integers, since the mapping is not defined for any values of x
> except the given keys.
> 
> Because dicts are mutable, we can do this:
> 
> d[2] = 7
> 
> 
> but that's precisely what we *can't* do with mathematical functions! We
> can't just declare that, from now on, x**2 will equal 7 if x is 2. So any
> modification of the dict must give us a new and different function. Before,
> we had the function:

So? The best way IMO to look at this is as a family of functions between
a domain and a codomain. Because that is the problem space you are looking
at. If within this problem space you have found a surjection, the normal
way to understand that is that you have found a function in which the
image is the total of the possible value set.

> # d equivalent to
> f(x): {1,2,3,4} --> {1,4,9,16} where 
> f(1) = 1
> f(2) = 4
> f(3) = 9
> f(4) = 16
> 
> 
> After executing the line d[2] = 7, we have the completely different
> function:

So? Since this change of a function is presumably a step in searching
a solution within some problem space, the domain and codomain of both
functions are the same. Even if the function is not total nor surjective
in this way.

> That's the nature of dicts as mappings: they don't actually come very close
> to the semantics of mathematical functions. Any talk of surjections,
> domains, codomains etc is going to be, at best, an analogy.

At any specific time a dictionary is a perfect representation of a
mathematical function.

> So all of this discussion is stretching the mathematical terms to their
> breaking point. Dicts aren't actually functions in the mathematical sense,
> and in the general case, they don't have well-defined domains and
> codomains.

But that part of the problem you represent by the dictionary often enough
has a well defined domain and codomain.

> Because fundamentally, it doesn't matter whether dicts are surjections or
> not. They're still many-to-one mappings, and those mappings between keys
> and values should not change due to the insertion or deletion of unrelated
> keys.

Repeating your opion without further arguments doesn't lend any support
to that opinion. If within the problem space you are working on, such a change
would make sense as a step to generate the next mapping from the previous
one, i don't see what the problem is if one could make use of this.

> If the OP wants to create his own "StrangeDict", which he himself described
> as "terrible", then he can do so. But to make all dicts and lists behave in
> this "terrible" and "strange" way is a terrible idea.

Calling something a terrible idea isn't a strong arguement. Other "terrible"
ideas have made it in the language.

> [...]
>> Only if you use the special python meaning of (dictionary) values in this
>> context. If you use the ordinary (mathematical) meaning, there are lots of
>> values that don't have a key, like every two characters string.
> 
> Well, we're actually discussing Python dictionaries. So, damn straight, of
> course I'm going to use the meaning of words as they apply to dicts.

How so? We were talking about functions and how dicts could represent them.
So when next we talk about a characteristic of such functions I don't see
why we should use the meaning as they apply to dicts, since we weren't talking
about the dicts.

-- 
Antoon.


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


Re: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread Ethan Furman

On 03/30/2016 11:41 AM, justin walters wrote:


That absolutely answers my questions. I'll keep an eye out for your book
when it is realeased. It seems like it will cover some topics that could be
useful in continuing my learning.


KickStarter plug:

If you want to pledge to buying the book now on KickStarter, that will 
guarantee you the book when it comes out, plus contribute to possibly 
have more content in the book as higher reward levels are unlocked.


Currenty his book is past the "it will definitely happen" stage, and the 
next reward level will unsure even more content.


Note:  I'm not affiliated with the book, probably won't pledge (only a 
couple topics apply to me), but I am a KickStarter fan (having purchased 
more games than was probably wise ;) .


--
~Ethan~

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


Re: pygtk button right/middle click

2016-03-30 Thread Wildman via Python-list
On Wed, 30 Mar 2016 15:36:12 +, Grant Edwards wrote:

> I'm trying to figure out how to get a pygtk button respond to
> somehting other than just a simple "left click".  With a standard
> 3-button mouse, X11 provides at least 9 different "click" types, but
> the pygtk button only seems to support one of them.
> 
> [Yes, I know there are left-handled mouse configurations -- by "left"
> click I'm using the common term to mean the primary mouse button.]
> 
> After googling for some time, I haven't found any good answers.  Some
> people just say things like "use the button_release_event signal of
> the button widget".
> 
> But, that signal is depricated (and AFAICT still doesn't make the
> button actually respond to the left/middle click by "depressing" the
> way it should).
> 
> Other answers are things like "you'll have to write you own button
> class in C, not C++".
> 
> Is the gtk button widget really incapable of handling left or middle
> mouse buttons or shift/ctrl/alt modifiers?

This might help...

http://faq.pygtk.org/index.py?req=show&file=faq05.004.htp

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygtk button right/middle click

2016-03-30 Thread Grant Edwards
On 2016-03-30, Wildman  wrote:

>> Is the gtk button widget really incapable of handling left or middle
>> mouse buttons or shift/ctrl/alt modifiers?
>
> This might help...
>
> http://faq.pygtk.org/index.py?req=show&file=faq05.004.htp

Yep, I found that.  I'm just missing the clues required to use those
two pieces.

-- 
Grant Edwards   grant.b.edwardsYow! My face is new, my
  at   license is expired, and I'm
  gmail.comunder a doctor's care
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygtk button right/middle click

2016-03-30 Thread Grant Edwards
On 2016-03-30, Grant Edwards  wrote:
> On 2016-03-30, Wildman  wrote:
>
>>> Is the gtk button widget really incapable of handling left or middle
>>> mouse buttons or shift/ctrl/alt modifiers?
>>
>> This might help...
>>
>> http://faq.pygtk.org/index.py?req=show&file=faq05.004.htp
>
> Yep, I found that.  I'm just missing the clues required to use those
> two pieces.

FWIW, I've decided to give up on this.  Since it took only a few lines
of code to handle the "left" click, I assumed that like some other
toolkits, it would be similarly easy to handle "right" and "middle".

I don't have the time to re-invent the wheel at the moment, so this
project will have to be postponed.

-- 
Grant Edwards   grant.b.edwardsYow! I want to mail a
  at   bronzed artichoke to
  gmail.comNicaragua!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Marco Sulla via Python-list
On 30 March 2016 at 02:55, Terry Reedy  wrote:
> To me [seq.items() and seq.keys()] are useless and confusing duplications 
> since enumerate()(seq)
> and range(len(seq)) are quite different from dict.items and dict.keys.

It's true. Indeed IMHO it's enumerate() that will be a confusing duplication.


On 30 March 2016 at 02:55, Terry Reedy  wrote:
> At least in CPython, changing a dict disables view iterators.

OrderedDict does not.


On 30 March 2016 at 07:43, Steven D'Aprano
 wrote:
> This is not an argument about dicts being mutable, because clearly they
> aren't. This is an argument about key:value pairs being stable.


So you basically say "I expect to get the value x from key y". Let me
apply your point of view to lists. In lists, I expect to get the value
x from index y. If I insert an item in a position before index y, I
expect to get x at index y+1. But what if I write a class with a
method insertPlus() that sets None at y+1 and x at y+2? I can say it
does not violate the list contract, since you're extending the base
class and implementing a new method that is not present in base class.

If you extend a dict to act as a list, you're only adding
*constraints* to existing methods and adding new methods. You're not
completely change the existing ones, so the implementation is
perfectly valid.

Finally, let me quote the official docs:

A mapping object maps hashable values to arbitrary objects [...] A
dictionary’s keys are almost arbitrary values [...]
https://docs.python.org/3/library/stdtypes.html#dict

Mapping:A container object that supports arbitrary key lookups
https://docs.python.org/3/glossary.html#term-mapping

A sequence satisfies all these requirements, with the only exception
that keys are not arbitrary. But no one will tell you that a child
class that make a *restriction* over the original one will break
rules.

On 30 March 2016 at 17:56, Steven D'Aprano  wrote:
> If the OP wants to create his own "StrangeDict", which he himself described
> as "terrible", then he can do so. But to make all dicts and lists behave in
> this "terrible" and "strange" way is a terrible idea.

You did not understand well what I mean, my dear friend. I applied the
word "terrible" to my code, not to the concept. You've demonstrated
that a fair thinker, so do not fall in the temptation to play with
words.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Marco Sulla via Python-list
Let me also add that even if it seems that my idea will not break any
official contracts, I can create a new ABC class and let maps and
sequence types inherit from it. IMHO it's absolutely not needed, but
at least the discussion will be no more distracted my secondary
considerations, since the main topic is about the usefulness and the
advantage to have a base contract for maps and sequences.

PS: I intend to write:
You've demonstrated to be a fair thinker, so do not fall into
temptation to play with
words.
My English is terrible as much as StrangeDict code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 20:35, Marco Sulla via Python-list wrote:

On 30 March 2016 at 02:55, Terry Reedy  wrote:

To me [seq.items() and seq.keys()] are useless and confusing duplications since 
enumerate()(seq)
and range(len(seq)) are quite different from dict.items and dict.keys.


It's true. Indeed IMHO it's enumerate() that will be a confusing duplication.



Please explain how a builtin that was brought in due to popular demand 
can be a "confusing duplication".


--
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: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 21:00, Marco Sulla via Python-list wrote:

Let me also add that even if it seems that my idea will not break any
official contracts, I can create a new ABC class and let maps and
sequence types inherit from it. IMHO it's absolutely not needed, but
at least the discussion will be no more distracted my secondary
considerations, since the main topic is about the usefulness and the
advantage to have a base contract for maps and sequences.


1) maps ain't sequences, sequences ain't maps, and never the twain shall 
meet.

2) if it ain't broke, don't fix it.
3) KISS



PS: I intend to write:
You've demonstrated to be a fair thinker, so do not fall into
temptation to play with
words.


No idea at all what you mean by this, please explain.


My English is terrible as much as StrangeDict code.



StrangeDict broke "Practicality beats purity", no further comment needed.

--
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: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread Mike Driscoll
On Wednesday, March 30, 2016 at 2:21:08 PM UTC-5, Ethan Furman wrote:
> On 03/30/2016 11:41 AM, justin walters wrote:
> 
> > That absolutely answers my questions. I'll keep an eye out for your book
> > when it is realeased. It seems like it will cover some topics that could be
> > useful in continuing my learning.
> 
> KickStarter plug:
> 
> If you want to pledge to buying the book now on KickStarter, that will 
> guarantee you the book when it comes out, plus contribute to possibly 
> have more content in the book as higher reward levels are unlocked.
> 
> Currenty his book is past the "it will definitely happen" stage, and the 
> next reward level will unsure even more content.
> 
> Note:  I'm not affiliated with the book, probably won't pledge (only a 
> couple topics apply to me), but I am a KickStarter fan (having purchased 
> more games than was probably wise ;) .
> 
> --
> ~Ethan~

You'll also get early access to the book so you'll get to see the chapters as 
soon as I'm done with them (most of the time).

Mike

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


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Gregory Ewing

Tim Golden wrote:


(I don't know how other English-speaking groups say the word, but in
England the first syllable is stressed and the second is the
conventional short "uh" sound).


I can attest that New Zealand follows the UK on this. I was
surprised when I first heard an American pronounce it too.

The curious can hear the difference on these pages:

British:  http://www.oxforddictionaries.com/definition/english/python
American: http://www.dictionary.com/browse/python?s=t

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


Re: pygtk button right/middle click

2016-03-30 Thread Wildman via Python-list
On Wed, 30 Mar 2016 19:23:35 +, Grant Edwards wrote:

> On 2016-03-30, Grant Edwards  wrote:
>> On 2016-03-30, Wildman  wrote:
>>
 Is the gtk button widget really incapable of handling left or middle
 mouse buttons or shift/ctrl/alt modifiers?
>>>
>>> This might help...
>>>
>>> http://faq.pygtk.org/index.py?req=show&file=faq05.004.htp
>>
>> Yep, I found that.  I'm just missing the clues required to use those
>> two pieces.
> 
> FWIW, I've decided to give up on this.  Since it took only a few lines
> of code to handle the "left" click, I assumed that like some other
> toolkits, it would be similarly easy to handle "right" and "middle".
> 
> I don't have the time to re-invent the wheel at the moment, so this
> project will have to be postponed.

I'm sorry to say I have no experience using pygtk.  My only gui
experience is with Tkinter.  In Tk you would do something like
this to trap a right-click.

# create the popup menu and add commands as needed
self.menu = tk.Menu(self, tearoff=0)
self.menu.add_command(label="Whatever",
  command=self.do_whatever)

# bind the button with mouse right-click
self.button.bind("", self.popup)

# define the handler for the menu
def do_whatever(self):
# do whatever

# define the popup handler, this displays the menu
def popup(self, event):
self.menu.post(event.x_root, event.y_root)

I posted this on the off chance there might be a way to translate
this to gtk code.

-- 
 GNU/Linux user #557453
"The Constitution only gives people the right to
pursue happiness. You have to catch it yourself."
  -Benjamin Franklin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding borders to ttk radiobuttons

2016-03-30 Thread Mark Lawrence via Python-list

On 30/03/2016 17:35, Terry Reedy wrote:


.theme_names() only displays the themes for the OS.  I believe that
there is a way to access themes for other OSes (unix, mac) but don't
remember.



Possibly http://bugs.python.org/issue17397 which refers to 
http://code.activestate.com/lists/python-tkinter-discuss/3373/ ?


--
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: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-30 Thread Random832
On Wed, Mar 30, 2016, at 19:01, Dennis Lee Bieber wrote:
>   Though I'm surprised GoogleGroups would expire that fast.
> 
>   Google is the reason I inserted that header -- I started back in the
> days when news-servers routinely expired stuff (text groups about monthly
> lifespan, the binary groups were expiring at 24 hours). Then along came
> Google with the "lifetime availability" threat.

I guess I'm not sure I understand the motive for considering such a
thing a "threat". Why do you _care_ if technical discussions about
Python are available forever? I mean, it's useful for there to be a
record of the discussion that led to making a decision about a PEP, or
prior arguments against an idea.

Sure, one person's posts being missing doesn't do much to that overall,
but I do have to wonder why you care. AIUI, most people's contemporary
reasoning for objecting to DejaNews (if "Google" was truly the reason
you inserted it, you're a latecomer to the idea) was the supposed
exploitation inherent in the fact that it was ad-funded, and most never
claimed to care about it being around forever.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Python 201 - Intermediate Python book

2016-03-30 Thread Chris Angelico
On Thu, Mar 31, 2016 at 6:21 AM, Ethan Furman  wrote:
> Note:  I'm not affiliated with the book, probably won't pledge (only a
> couple topics apply to me), but I am a KickStarter fan (having purchased
> more games than was probably wise ;) .

Heh, me too - though more other things than games. Between Kickstarter
and Twitch.tv, I've collected a lot of great artwork and Alice in
Wonderland memorabilia.

This also isn't for me, but if anyone's interested, I strongly
encourage going for it. Don't worry if you don't have the money yet;
you won't be charged until the campaign ends (in a week or
thereabouts). Get the book sooner than anyone else does, and be a part
of making it happen!

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Thu, 31 Mar 2016 06:07 am, Antoon Pardon wrote:

>> Because fundamentally, it doesn't matter whether dicts are surjections or
>> not. They're still many-to-one mappings, and those mappings between keys
>> and values should not change due to the insertion or deletion of
>> unrelated keys.
> 
> Repeating your opion without further arguments doesn't lend any support
> to that opinion. If within the problem space you are working on, such a
> change would make sense as a step to generate the next mapping from the
> previous one, i don't see what the problem is if one could make use of
> this.


Enough of the hypothetical arguments about what one could do or might do.
Let's see a concrete example of actual real world code used in production,
not a mickey-mouse toy program, where it is desirable that adding or
deleting one key will modify the rest of the keys in the mapping.

Arguing for the sake of arguing about what somebody might want is not
productive. Let's see some actual concrete use cases where you have a
database or mapping between keys and values, say something like this:

mapping = {
 # name: address
 "fred": "123 Smith Street",
 "george": "27 Main Road",
 "sally": "72a Short Street"
 }


where it is desirable to have this behaviour:

# adding a new key
mapping["mary"] = "31 King Street"
# changes the other keys
assert mapping["george"] != "27 Main Road"


No hypothetical cases where somebody might or could want this behaviour. I'm
not interested in "mights" and "coulds". I want to see an actual
application where adding a new key to a mapping is expected to change the
other keys.



-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Steven D'Aprano
On Thu, 31 Mar 2016 03:52 am, Random832 wrote:

> Like, these are common patterns:
> 
> for i, x in enumerate(l):
># do some stuff, sometimes assign l[i]
> 
> for k, v in d.items():
># do some stuff, sometimes assign d[k]


for a, b in zip(spam, eggs):
# do some stuff, sometimes assign x[a] or b[a] or who knows what?


Does this mean that "lists, dicts and zip" should all support the same
interface?

Not every coincidental and trivial piece of similar code is actually
related.


> A way to apply that pattern generically to an object which may be either
> a sequence or a mapping might be nice.

Nice, and easy.

# Duck-typing version.
def iterpairs(obj):
if hasattr(obj, 'items'):
it = obj.items
else:
it = enum(obj)
yield from it


# Type-checking version.
def iterpairs(obj):
if isinstance(obj, collections.abc.Mapping):
it = obj.items
elif isinstance(obj, collections.abc.Sequence):
it = enum(obj)
else:
raise TypeError('not a sequence or a mapping')
yield from it


Pick which one you prefer, stick it in your own personal toolbox of useful
utilities functions, and off you go.




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-30 Thread Paul Rubin
Steven D'Aprano  writes:
> I want to see an actual application where adding a new key to a
> mapping is expected to change the other keys.

directory["mary.roommate"] = "bob"
directory["mary.address"] = None   # unknown address
...
directory["bob.address"] = "132 Elm Street"

Since Bob and Mary are roommates, they have the same address, so the
application might want to update both addresses once it learns one of
them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sympy

2016-03-30 Thread Gregory Ewing

Steven D'Aprano wrote:

On Thu, 31 Mar 2016 02:23 am, Poul Riis wrote:


What I intend to do is to let sympy find the derivative of some
welldefined function and next define the foundation derivative as a normal
function


py> ftext.evalf(subs={x:3})
-0.0600


Given all that, it looks like you want

def f(t):
  return ftext.evalf(subs={x:t})

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


Re: Threading is foobared?

2016-03-30 Thread Mark Sapiro
Hi all,

I'm jumping in on this thread because Tim asked.

I'm here because I'm a Mailman developer and the primary maintainer of
Mailman for the @python.org lists.

Regarding the initial post in this thread from Steven D'Aprano
suggesting that broken threading is more common recently and quoting a
couple of Message-ID:/References: headers wherein a message ID was
apparently munged from

<1392737302.749065.1459024715818.javamail.ya...@mail.yahoo.com>
to
<1392737302.749065.1459024715818.javamail.yahoo@mail.yahoo.com>

Some Background:

Our long time mail.python.org server provided by xs4all died of severe
hardware failure late last October. We were able to get a replacement
server through the PSF and get it configured and running within a couple
of days, but this new server couldn't access the nntp server at xs4all.
With the kind assistance of members of the community we were able to get
access to a news server at the Free University of Berlin which is now
our gateway to Usenet.

This server undoubtedly has different policies and behaviors from the
prior server at xs4all. I'm not sure what mail or news server is
responsible for munging the IDs as above, but it could be our new Usenet
gateway. All I know for sure is that Mailman doesn't do that specific
munging.

What Mailman does do as noted by Random832 is replace the Message-ID:
header value in posts gated to Usenet with a list specific, Mailman
generated unique value. There is a reason for this, and that reason is
if a message is cross-posted to two lists which both gateway to Usenet,
and Mailman didn't make the Message-IDs unique, the news server would
discard one of the two posts as a duplicate and the post would be
missing from one of the recipient Usenet groups.

Granted that this is bad and breaks threading, but avoiding message loss
is a more important goal.

I understand I'm not providing any solutions here, but perhaps a more
complete understanding of what the issues are will ease the pain.

-- 
Mark Sapiro The highway is for gamblers,
San Francisco Bay Area, Californiabetter use your sense - B. Dylan



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-03-30 Thread Random832
On Thu, Mar 31, 2016, at 00:50, Mark Sapiro wrote:
> What Mailman does do as noted by Random832 is replace the Message-ID:
> header value in posts gated to Usenet with a list specific, Mailman
> generated unique value. There is a reason for this, and that reason is
> if a message is cross-posted to two lists which both gateway to Usenet,
> and Mailman didn't make the Message-IDs unique, the news server would
> discard one of the two posts as a duplicate and the post would be
> missing from one of the recipient Usenet groups.
> 
> Granted that this is bad and breaks threading, but avoiding message loss
> is a more important goal.
> 
> I understand I'm not providing any solutions here, but perhaps a more
> complete understanding of what the issues are will ease the pain.

Any chance that it could fix reference headers to match?

Actually, merely prepending the original Message-ID itself to the
references header might be enough to change the reply's situation from
"nephew" ("reply to [missing] sibling") to "grandchild" ("reply to
[missing] reply"), which might be good enough to make threading work
right on most clients, and would be *easy* (whereas maintaining an
ongoing reversible mapping may not be).

And if it's not too much additional work, maybe throw in an
X-Mailman-Original-Message-ID (and -References if anything is done with
that) field, so that the original state can be recovered.

Rather than exclusively rewriting for usenet, maybe the rewritten
headers could also be included in outgoing emails and the archive?

Putting it in outgoing emails would solve the problem entirely, though
it would mean people get duplicates if they're subscribed to multiple
lists to which something is posted or get CC'd. The archive wouldn't
have this issue.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-03-30 Thread Random832
On Thu, Mar 31, 2016, at 01:25, Random832 wrote:
> > if a message is cross-posted to two lists which both gateway to Usenet,
> > and Mailman didn't make the Message-IDs unique, the news server would
> > discard one of the two posts as a duplicate and the post would be
> > missing from one of the recipient Usenet groups.

One additional thing that would be nice and would solve most of the
duplicate problem with hypothetically including the rewritten
Message-IDs in outgoing emails, would be to detect crossposts to
multiple lists in the same Mailman instance, and to send them to Usenet
(and to subscribers) as a single message, with appropriate headers for a
crosspost.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-03-30 Thread Random832
On Thu, Mar 31, 2016, at 01:25, Random832 wrote:
> Actually, merely prepending the original Message-ID itself

append, not prepend... I'd misremembered the order that References go
in.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Array

2016-03-30 Thread tdsperth
I am creating the following

aData = []

# get my data from database

for row in rows:
 
aData.append({row["tierid"]:"name":row["tiername"],"description":row["tierdesc"],"option":row["tieroption"],"price":str(row["tierprice"])}})
 


when I display the output the order the data was entered is not what is 
displayed 

{'BBS': {'option': 'Small', 'description': 'Broadband Bundle', 'name': 
'Broadband', 'price': '179.00
{'BBM': {'option': 'Medium', 'description': 'Broadband Bundle', 'name': 
'Broadband', 'price': '215.0
{'BBL': {'option': 'Large', 'description': 'Broadband Bundle', 'name': 
'Broadband', 'price': '295.00

as you can see the option element was added third but is the first one 
displayed.

Is this just standard - I am using Python 3.5

Regards

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


Re: Python Array

2016-03-30 Thread Chris Angelico
On Thu, Mar 31, 2016 at 4:34 PM,   wrote:
> as you can see the option element was added third but is the first one 
> displayed.
>

Dictionaries don't have any order to them, so yes, this is something
you'll have to accept.

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


Re: Python Array

2016-03-30 Thread Stephen Hansen
On Wed, Mar 30, 2016, at 10:34 PM, tdspe...@gmail.com wrote:
> as you can see the option element was added third but is the first one
> displayed.
> 
> Is this just standard - I am using Python 3.5

The order of items in dictionaries is based on the hash value -- which
while stable, should be considered random and not reliable. If you want
to maintain insertion order, consider using an OrderedDict:

https://docs.python.org/3.5/library/collections.html#collections.OrderedDict

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


  1   2   >