Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-14 Thread Mark Lawrence via Python-list

On 14/09/2017 05:37, Terry Reedy wrote:

On 9/13/2017 2:44 AM, Paul Rubin wrote:


Are there actually Py3 codebases?


Let's think a bit.  There is the Python half of the Python3 codebase, 
perhaps 400K.  But we can discount that.


Then there are all the Py compatible modules on PyPI, which is to say, 
most of the major one.  How could not not notice those?


One of them is a little project call Django.  I believe that this is the 
one slated to be 3.x only in its 2.0 version.


I believe at least one linux distribution uses Py 3 for its system python.

A year ago, a producers of a Unicode-based app sold internationallly 
announce that their next version would be Py 3 only.  When 3.3 came out 
with the new Unicode implementation, they developed a 3.3 version of the 
app.  By 3.5, they realized that 3.3+ unicode made things much easier, 
wile maintaining the 2.7 version was painful by comparison.  They asked 
their (non-programmer) customers if they already used the 3.x version or 
could install 3.x to run the 3.x version.  95% said yes to one of these. 
  So they decided that the next version, early this year, would be 3.x 
only.


Have you ever hear of a little startup called 'Instagram'?  Earlier this 
year, they announce that they had about finished an 18 month process of 
switching most of their Python code to 3.x.  They described in fair 
detail how they did it.  Really impressive.




Not quite there yet but according to this 
https://www.reddit.com/r/Python/comments/6z6wst/twisted_is_93_ported_to_python_3/ 
a little project called Twisted is 93% ported to Python 3.


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

Mark Lawrence

---
This email has been checked for viruses by AVG.
http://www.avg.com


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


Re: Easy way to get a list of tuples.

2017-09-21 Thread Mark Lawrence via Python-list

On 21/09/2017 11:18, Sayth Renshaw wrote:

Hi

I have been toying with json and I particular area where I cannot get the 
desired result a list of tuples as my return. The json from the API is way to 
long but I don't think it will matter.

.. hitting url
data = r.json()

for item in data["RaceDay"]['Meetings'][0]['Races']:
 raceDetails = item['RacingFormGuide']['Event']['Race']
 print(raceDetails)

This returns

{'Number': 1, 'NumberDisplay': '01', 'Distance': 1000, 'DistanceDisplay': '1000 
METRES', 'Name': 'CLASS 3 HANDICAP', 'NameForm': 'HIGHWAY-C3'}
{'Number': 2, 'NumberDisplay': '02', 'Distance': 1600, 'DistanceDisplay': '1600 
METRES', 'Name': 'BM 90 HANDICAP', 'NameForm': 'BM90'}
{'Number': 3, 'NumberDisplay': '03', 'Distance': 1100, 'DistanceDisplay': '1100 
METRES', 'Name': 'HERITAGE STAKES', 'NameForm': 'HERITAGE'}
{'Number': 4, 'NumberDisplay': '04', 'Distance': 1400, 'DistanceDisplay': '1400 
METRES', 'Name': 'BILL RITCHIE HANDICAP', 'NameForm': 'RITCHIE'}
{'Number': 5, 'NumberDisplay': '05', 'Distance': 1400, 'DistanceDisplay': '1400 
METRES', 'Name': 'TEA ROSE STAKES', 'NameForm': 'TEA ROSE'}
{'Number': 6, 'NumberDisplay': '06', 'Distance': 1600, 'DistanceDisplay': '1600 
METRES', 'Name': 'GEORGE MAIN STAKES', 'NameForm': 'GEO MAIN'}
{'Number': 7, 'NumberDisplay': '07', 'Distance': 1100, 'DistanceDisplay': '1100 
METRES', 'Name': 'THE SHORTS', 'NameForm': 'THE SHORTS'}
{'Number': 8, 'NumberDisplay': '08', 'Distance': 2000, 'DistanceDisplay': '2000 
METRES', 'Name': 'KINGTON TOWN STAKES', 'NameForm': 'KING TOWN'}
{'Number': 9, 'NumberDisplay': '09', 'Distance': 1200, 'DistanceDisplay': '1200 
METRES', 'Name': 'BM 84 HANDICAP', 'NameForm': 'BM84'}

My goal is to select a few elements and create a list of 3 element tuples
like this
[('CLASS 3 HANDICAP', 1, 1000), ('BM 90 HANDICAP', 2, 1600), ('HERITAGE 
STAKES', 3, 1100), ('BILL RITCHIE HANDICAP', 4, 1400), ('TEA ROSE STAKES', 5, 
1400), ('GEORGE MAIN STAKES', 6, 1600), ('THE SHORTS', 7, 1100), ('KINGTON TOWN 
STAKES', 8, 2000), ('BM 84 HANDICAP', 9, 1200)]

I get close creating a list of elements but each attempt I try to create the 
list of tuples fails.

This is my closest code

data = r.json()

raceData = []

for item in data["RaceDay"]['Meetings'][0]['Races']:
 raceDetails = item['RacingFormGuide']['Event']['Race']
 raceData += 
(raceDetails['Name'],raceDetails['Number'],raceDetails['Distance'])

print(raceDetails)

which returns

['CLASS 3 HANDICAP', 1, 1000, 'BM 90 HANDICAP', 2, 1600, 'HERITAGE STAKES', 3, 
1100, 'BILL RITCHIE HANDICAP', 4, 1400, 'TEA ROSE STAKES', 5, 1400, 'GEORGE 
MAIN STAKES', 6, 1600, 'THE SHORTS', 7, 1100, 'KINGTON TOWN STAKES', 8, 2000, 
'BM 84 HANDICAP', 9, 1200]

How do I get the tuples?

Cheers

Sayth

---
This email has been checked for viruses by AVG.
http://www.avg.com



After a quick glance and hence completely untested:-

raceData.append((raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']))

--
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: [Tutor] beginning to code

2017-09-22 Thread Mark Lawrence via Python-list

On 22/09/2017 08:01, Bill wrote:

Steve D'Aprano wrote:

On Fri, 22 Sep 2017 02:57 pm, Bill wrote:


I find Python to be more more
like Java, with regard to "passing objects by reference".
Which is not a surprise, since both Python and Java use the same value 
passing

style: pass by object reference, or pass by sharing if you prefer.

Java people don't call it that. They call it pass by value, and 
categorically
deny that it is pass by reference. (They're right about the second 
point.)


I figure that, internally, an address, a pointer, is being passed by 
value to implement pass by reference.  Why do you say "they are right" 
above? Are you saying it's not pass by reference?




Please see 
http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ 
and http://effbot.org/zone/call-by-object.htm


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

Mark Lawrence

---
This email has been checked for viruses by AVG.
http://www.avg.com


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


Re: [Tutor] beginning to code

2017-09-22 Thread Mark Lawrence via Python-list

On 22/09/2017 10:53, Bill wrote:
I just wanted to mention that my comment was made in the context that 
Python is implemented by an interpreter written in C.   I realize that 
this may not always be the case.  However, I haven't heard anyone 
mention a Python interpreter written in Python yet.


The reference implementation is written in C but there's also Jython 
(Java) and IronPython (.Net).


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

Mark Lawrence

---
This email has been checked for viruses by AVG.
http://www.avg.com


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


Re: [Tutor] beginning to code

2017-09-23 Thread Mark Lawrence via Python-list

On 23/09/2017 04:06, Bill wrote:

Mark Lawrence wrote:

On 22/09/2017 08:01, Bill wrote:

Steve D'Aprano wrote:

On Fri, 22 Sep 2017 02:57 pm, Bill wrote:


I find Python to be more more
like Java, with regard to "passing objects by reference".
Which is not a surprise, since both Python and Java use the same 
value passing

style: pass by object reference, or pass by sharing if you prefer.

Java people don't call it that. They call it pass by value, and 
categorically
deny that it is pass by reference. (They're right about the second 
point.)


I figure that, internally, an address, a pointer, is being passed by 
value to implement pass by reference.  Why do you say "they are 
right" above? Are you saying it's not pass by reference?




Please see 
http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ 
and http://effbot.org/zone/call-by-object.htm





I would would agree with the description provided for the C++ example 
provided


string some_guy = "fred";
  is replaced by
char* some_guy="fred";

To see that this is correct, note the some_guy may subsequently be 
assigned to a character string much longer then "fred".  An additional 
note: A character string literal, like "cat", never occurs more than 
once in compiled C++ program unit.  This also shows that the provided 
description can't be completely correct. One last thing,


string some_guy = "fred"

is really the same thing as

string some_guy("fred");

and both equivalently call the string constructor.

The data type of "fred" is const char*, not (class) string.



I have no interest it what the C++ does, looks like or anything else. 
All I'm bothered about is that two highly respected members of the 
Python community have stated quite clearly that Python is call by 
object.  Many other people have stated the same in this thread or 
previously, yet still people who know squat about Python continue to 
debate the subject.  Why waste effort going over old ground?  Is it 
completely impossible for people to step outside of their world of pass 
by value or pass by reference?


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

Mark Lawrence

---
This email has been checked for viruses by AVG.
http://www.avg.com


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


Re: Printing a Chunk Of Words

2017-09-28 Thread Mark Lawrence via Python-list

On 26/09/2017 01:15, Cai Gengyang wrote:

"""
  Boolean Operators

True and True is True
True and False is False
False and True is False
False and False is False

True or True is True
True or False is True
False or True is True
False or False is False

Not True is False
Not False is True

"""

If I simply want to print a chunk of words and a paragraph like the above, what 
command should I use ?



If you are looking for quiet mode code I suggest you stick to the answer 
given by Chris Angelico earlier.


If you want verbose aka Steven D'Aprano :) mode code how about:-

from operator import and_, or_
from itertools import product

print('''
 Boolean Operators

''', end='')

l = {and_: 'and', or_: 'or'}
bools = (True, False)
for logic in (and_, or_):
for a, b in product(bools, repeat=2):
ans = logic(a, b)
print(f'{a} {l[logic]} {b} is {ans}')
print()
for b in bools:
print(f'Not {b} is {not b}')

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

Mark Lawrence

---
This email has been checked for viruses by AVG.
http://www.avg.com


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


Re: Python 2 -> 3, urllib.urlOpen

2017-10-14 Thread Mark Lawrence via Python-list

On 13/10/17 23:27, Irv Kalb wrote:

One of the colleges where I teach has just moved from Python 2 to Python 3.  I am in 
the process of converting my beginning Python class from Python 2 to Python 3.  
Everything has gone smoothly, until I just tried to convert some code that imports 
and uses urllib.urlOpen to fetch data through an API.  I am using an API that I found 
here:http://www.jarloo.com/yahoo_finance/ 


As a minimal example, I am trying to get the latest stock price for Apple.

The following example works perfectly in Python 2:

import urllib

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = urllib.urlopen(fullURLWithParameters).read()

print 'Response is: ', response

This is asking for a stock name (s=) and I am adding in aapl as a stock symbol.  I am 
also adding a "flag" parameter (f=) and setting it to l1 to get the last trade 
price.  When I run this in Python 2, I see:

Response is:  156.99


If I take the same program and just modify the print statement to add 
parentheses, then try to run it in Python 3.6 (on a Mac):


import urllib

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = urllib.urlopen(fullURLWithParameters).read()

print('Response is: ', response)

I get the following:

Traceback (most recent call last):
   File "   s/StockQuoteYahooAPIMinimal.py", line 9, in 
 response = urllib.urlopen(fullURLWithParameters).read()
AttributeError: module 'urllib' has no attribute 'urlopen'


I've looked at the Python 3.6 documentation for urllib, and I see that certain 
calls have been changed and others have been eliminated.  But my eyes glaze 
over trying to figure out what to use instead.

My question is: Is there a simple (hopefully one or two line) replacement for my call 
to url lib.urlopen().read()

I know that there are other modules out there that handle requests (like the 
Requests module), but this is a strictly controlled university environment.  I 
cannot download any external packages (other then pygame, which I got special 
permission for) onto the computers in the school.  Therefore, I'm looking for 
something in the Python 3.6 Standard Library.

Thanks in advance,

Irv



Hopefully this https://docs.python.org/3/howto/pyporting.html will help.

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


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: 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: 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: 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: 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: Python Array

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

On 31/03/2016 06:34, tdspe...@gmail.com wrote:

I am creating the following

aData = []


This is a Python list, not an array as the subject gives.



# 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"])}})


Please cut and paste your code, don't try to type it in.  The above 
gives a syntax error at the second colon, which should presumably be a 
comma.




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


Yes, as you are using a standard dict within the list.  There is 
https://docs.python.org/3/library/collections.html#collections.OrderedDict 
which retains the insertion order.




Regards

Colin




--
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-31 Thread Mark Lawrence via Python-list

On 31/03/2016 12:58, Marco Sulla via Python-list wrote:

On 31 March 2016 at 04:40, Steven D'Aprano  wrote:

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.



1. the example was for confuting your assertion that an implementation
of sequences as extended classes of maps violate the map contract.
2. I already linked a real-world example previously. Google it and you
can find tons of examples like that.


On 31 March 2016 at 04:44, Steven D'Aprano  wrote:

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?


I do not understand what you mean with this example. A zip object is
not a sequence nor a map. My definition of sequences as "ordered maps
with integer keys that start from zero and have no gaps" is perfectly
valid as I demonstrated to you, while zip objects have nothing in
common with sequences and maps, apart the fact they are all iterables.



The definition of sequence is given here 
https://docs.python.org/3/glossary.html#term-sequence.



An iterable which supports efficient element access using integer 
indices via the __getitem__() special method and defines a __len__() 
method that returns the length of the sequence. Some built-in sequence 
types are list, str, tuple, and bytes. Note that dict also supports 
__getitem__() and __len__(), but is considered a mapping rather than a 
sequence because the lookups use arbitrary immutable keys rather than 
integers.


The collections.abc.Sequence abstract base class defines a much 
richer interface that goes beyond just __getitem__() and __len__(), 
adding count(), index(), __contains__(), and __reversed__(). Types that 
implement this expanded interface can be registered explicitly using 
register().



As this is a Python list the above definition clearly takes priority 
over your definition, so can you please take this discussion offline, 
thanks.


--
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-31 Thread Mark Lawrence via Python-list

On 31/03/2016 13:49, Marco Sulla via Python-list wrote:


On 31 March 2016 at 14:30, Mark Lawrence via Python-list
 wrote:

Note that dict also supports
__getitem__() and __len__(), but is considered a mapping rather than a
sequence because the lookups use arbitrary immutable keys rather than
integers.


Thank you for confirming for what I already wrote and quoted, but I suppose you
missed some of my previous messages, my dear friend.



Thanks for misquoting me by deliberately snipping the bit about taking 
this completely useless discussion offline.  Please do not "dear friend" 
me as I don't take kindly to people who go out of their way to waste 
time and effort on this list.  This just isn't going to happen, so 
please drop it, or do you not realise when you're fighting a losing 
battle, and it's time to retreat?


There are of course other options, you could join in the effort to 
produce Python 2.8 or RickedPython.  I'm sure that they'd welcome some 
additional help and your patch for your absolutely awesome suggestion.


--
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-31 Thread Mark Lawrence via Python-list

On 31/03/2016 14:08, Antoon Pardon wrote:

Op 31-03-16 om 13:57 schreef Chris Angelico:

Okay. I'll put a slightly different position: Prove that your proposal
is worth discussing by actually giving us an example that we can
discuss. So far, this thread has had nothing but toy examples (and
bogoexamples that prove nothing beyond that the author knows how to
mess with Python - fun, but not a strong argument on either side).
Give us some real meat to work with, instead of these drips of
tantalizing blood.


What a strange request. Whether or not something is worth discussing
is a personal judgement. So there can be no proof of such a thing.
I would say: judge for yourself and act accordingly.



Drivel.  This is comp.lang.python, where "Practicality beats purity" 
every time, not comp.theoretical.claptrap.


--
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-31 Thread Mark Lawrence via Python-list

On 31/03/2016 14:27, Random832 wrote:

On Thu, Mar 31, 2016, at 09:17, Mark Lawrence via Python-list wrote:

On 31/03/2016 14:08, Antoon Pardon wrote:

Op 31-03-16 om 13:57 schreef Chris Angelico:

Okay. I'll put a slightly different position: Prove that your proposal
is worth discussing by actually giving us an example that we can
discuss. So far, this thread has had nothing but toy examples (and
bogoexamples that prove nothing beyond that the author knows how to
mess with Python - fun, but not a strong argument on either side).
Give us some real meat to work with, instead of these drips of
tantalizing blood.


What a strange request. Whether or not something is worth discussing
is a personal judgement. So there can be no proof of such a thing.
I would say: judge for yourself and act accordingly.


Drivel.  This is comp.lang.python, where "Practicality beats purity"
every time, not comp.theoretical.claptrap.


So can we discuss how a unified method to get a set of all valid
subscripts (and/or subscript-value pairs) on an object would be a useful
thing to have without getting bogged down in theoretical claptrap about
the meaning of the mapping contract?



We can discuss anything here until the cows come home, but it's a 
complete waste of time if the powers that be over on python-ideas and/or 
python-dev don't agree.  This was suggested a day or two back but seems 
to have gone completely over people's heads.


--
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-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 08:59, Antoon Pardon wrote:

Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list:

On 31/03/2016 14:27, Random832 wrote:

So can we discuss how a unified method to get a set of all valid
subscripts (and/or subscript-value pairs) on an object would be a useful
thing to have without getting bogged down in theoretical claptrap about
the meaning of the mapping contract?



We can discuss anything here until the cows come home, but it's a
complete waste of time if the powers that be over on python-ideas
and/or python-dev don't agree.  This was suggested a day or two back
but seems to have gone completely over people's heads.


Just because you are not interested, doesn't mean it's a complete waste of time.
Discussions like this often enough produce suggestions on how one could handle
these things within python without the need for the powers that be to agree on
anything.

If you are not interested just don't contribute. Others can make up their own
mind on whether this is a waste of their time or not.



Who said I'm not interested?  It is a simple fact of life in Python 
world that anything that gets discussed has to go through python-dev, 
and possibly python-ideas first.  You can spend years discussing 
anything you like here and get 100% agreement, but if the devlopers say 
no it does not happen.


I believe that this proposal is like trying to change the design of the 
Morris Minor and a McClaren Mercedes because they're both cars, so you 
can make them similar.


--
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: Drowning in a teacup?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 21:27, Fillmore wrote:


notorious pass by reference vs pass by value biting me in the backside
here. Proceeding in order.


It is pass by object.

By definition your following analysis is wrong.

To my knowledge this has been discussed at least twice a year for the 
past 15 years.


I would suggest that you search the archives, but that would upset 
teacher, so I won't.


--
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: [beginner] What's wrong?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 23:10, Michael Okuntsov wrote:

Nevermind. for j in range(1,8) should be for j in range(8).


Thank you for your correction, we in Python land greatly appreciate such 
things :)


--
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: Strange range

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 21:44, Marko Rauhamaa wrote:

Rob Gaddi :


Marko Rauhamaa wrote:

There's a bit of a cognitive dissonance between iterables and iterators.
On the one hand, they behave identically in many contexts. On the other
hand, the distinction is crucial in some special cases.


You're missing a key point.  All (well-behaved) iterators are iterables,
with their __iter__ method returning themselves.


I don't know what I'm missing.

Marko



Neither do we, which is why so many threads here belong, eventually, on 
comp.lang.theoretical.claptrap.


I remember when we used to have Bots here commenting on the Python 
language.  Obviously they've all given up as so much drivel is spouted, 
and/or they've gone to join the Norwegian Blue.


--
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: [beginner] What's wrong?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 23:44, sohcahto...@gmail.com wrote:

On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:

Nevermind. for j in range(1,8) should be for j in range(8).


I can't tell you how many times I've gotten bit in the ass with that off-by-one 
mistake whenever I use a range that doesn't start at zero.

I know that if I want to loop 10 times and I either want to start at zero or 
just don't care about the actual number, I use `for i in range(10)`.  But if I 
want to loop from 10 to 20, my first instinct is to write `for i in range(10, 
20)`, and then I'm left figuring out why my loop isn't executing the last step.



"First instinct"?  "I expected"?  The Python docs might not be perfect, 
but they were certainly adequate enough to get me going 15 years ago, 
and since then they've improved.  So where is the problem, other than 
failure to RTFM?


--
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: Drowning in a teacup?

2016-04-02 Thread Mark Lawrence via Python-list

On 02/04/2016 06:51, Michael Selik wrote:

On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio  wrote:


Fillmore wrote:


I need to scan a list of strings. If one of the elements matches the
beginning of a search keyword, that element needs to snap to the front
of the list.


I know this post regards the function passing, but, on you specific
problem,
can't you just ... sort the list with a custom key?

something like (new list)

 >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'],
 ... key=lambda e: not e.startswith('yes'))
 ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']

or (in place)

 >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x']
 >>> l.sort(key=lambda e: not e.startswith('yes'))
 >>> l
 ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']



If the number of matches is small relative to the size of the list, I'd
expect the sort would be slower than most of the other suggestions.



My gut feeling about how fast something is in Python has never once been 
right in 15 years.  There is only way way to find out, measure it with 
things like https://docs.python.org/3/library/profile.html and 
https://docs.python.org/3/library/timeit.html.  IIRC Steven D'Aprano has 
a wrapper for the latter called Stopwatch.


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


tkinter Entry validation modes

2016-04-02 Thread Mark Lawrence via Python-list

A typical call to create an Entry field would be:-

e = Entry(master, validate='all', ...)

Once this call has been made is it possible to change the validation 
mode at runtime?  Background, I'm knocking up an app so I can play with 
the various modes so that I can see how they work, as I'm just venturing 
into the tkinter world.


--
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: [beginner] What's wrong?

2016-04-02 Thread Mark Lawrence via Python-list

On 02/04/2016 17:31, Dennis Lee Bieber wrote:

On Sat, 2 Apr 2016 19:15:36 +1100, Chris Angelico 
declaimed the following:


On Sat, Apr 2, 2016 at 3:27 PM, Random832  wrote:

On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote:

Humans have always had trouble with this, in many contexts. I remember
being annoyed at folks saying the year 2000 was the first year of the new
millennium, rather than 2001. They'd forgotten the Gregorian calendar
starts from AD 1.


Naturally, this means the first millennium was only 999 years long, and
all subsequent millennia were 1000 years long. (Whereas "millennium" is
defined as the set of all years of a given era for a given integer k
where y // 1000 == k. How else would you define it?)

And if you want to get technical, the gregorian calendar starts from
some year no earlier than 1582, depending on the country. The year
numbering system has little to do with the calendar type - your
assertion in fact regards the BC/AD year numbering system, which was
invented by Bede.

The astronomical year-numbering system, which does contain a year zero
(and uses negative numbers rather than a reverse-numbered "BC" era), and
is incidentally used by ISO 8601, was invented by Jacques Cassini in the
17th century.



Are you sure? Because I'm pretty sure these folks were already talking about BC.


Bede's BC/AD goes back to circa 700AD. It is the use of negative years
for astronomical counting that is circa 1650AD


http://xenohistorian.faithweb.com/holybook/quotes/YK.html


And that I'll take as something suited for the first of April... It's
almost on par with an old story (in Asimov's I think) on why the pyramids
were behind schedule -- among other things, the pile of government mandated
documentation, on clay tablets of course, was becoming larger than the
pyramid being built; the older records (on the bottom of the stack) were
decomposing from the pressure, etc. If I recall, they discover cuneiform as
more condense than hieroglyphics, and then learn of papyrus/ink (but then
have to support an entire industry of workers to transcribe the old clay
tablets...)




Here we go again, yet another completely useless thread that is 
irrelevant to the Python programming language.  Hardly surprising that 
the bots don't bother any more.  Are any of the bots still alive?


--
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: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Mark Lawrence via Python-list

On 02/04/2016 23:23, Loop.IO wrote:

On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote:

On 02/04/2016 22:59, Loop.IO wrote:

Hey

So I built a keylogger using python as a test, got the code from the tutorial 
online, I want to improve on it to make it more automated, but the issue I'm 
having is it won't create the file until I press return, any clues where I'm 
going wrong?

If I press return it makes the batch file, otherwise it just hangs.



  name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'


You're asking for a file name to be entered. So that if ABC is pressed,
followed by Enter, it will use:

C:\Documents\PythonCoding\ABClaunch2.bat

Assuming that's the intention, then Enter is needed so that it knows
when the user has completed typing the name. If not, then just use:

name='C:\\Documents\\PythonCoding\\launch2.bat'

(If you want a single character name, without pressing Enter, that's
harder to do. Someone else will have to help.)

--
Bartc


Hey Bartc

I don't quite understand what you mean?

The file is just supposed to be created, I don't want to have to press "Enter" or 
"Return" for it to complete the file creation

the info i followed to create the file advised I had to add the file name and 
extension on after like in the code



There is no point asking BartC about Python as he has repeatedly stated 
that he knows nothing about Python.  OTOH there are loads of people here 
who do know Python, backwards, sideways and inside out.  If you state 
precisely what you are trying to achieve then you will get the correct 
answer.


--
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: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Mark Lawrence via Python-list

On 02/04/2016 23:37, Michael Selik wrote:

I might be overlooking something, but raw_input (Python 2) and input
(Python 3) won't return the input from sys.stdin until you type ENTER. Or
did I misunderstand the question?

On Sat, Apr 2, 2016 at 6:30 PM BartC  wrote:


On 02/04/2016 23:16, Ned Batchelder wrote:

On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote:

On 02/04/2016 22:59, Loop.IO wrote:

Hey

So I built a keylogger using python as a test, got the code from the

tutorial online, I want to improve on it to make it more automated, but the
issue I'm having is it won't create the file until I press return, any
clues where I'm going wrong?


If I press return it makes the batch file, otherwise it just hangs.



   name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'


You're asking for a file name to be entered. So that if ABC is pressed,
followed by Enter, it will use:

 C:\Documents\PythonCoding\ABClaunch2.bat


That line of code will prompt the user:

  C:\Documents\PythonCoding\

then the user enters ABC:

  C:\Documents\PythonCoding\ABC

and raw_input returns "ABC", so name becomes "ABClaunch2.bat".


Yes, of course. I ran the code and picked up the wrong line even though
I printed out 'name'!

But, it does look as though that path is supposed to form part of the
resulting filename.

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



BartC is renowned for knowing nothing about Python by his own 
admittance, and would you please not top post on the list.


--
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: [beginner] What's wrong?

2016-04-02 Thread Mark Lawrence via Python-list

On 03/04/2016 00:49, Steven D'Aprano wrote:

On Sun, 3 Apr 2016 03:12 am, Thomas 'PointedEars' Lahn wrote:


Marko Rauhamaa wrote:


Steven D'Aprano :

So you're saying that learning to be a fluent speaker of English is a
pre-requisite of being a programmer?


No more than learning Latin is a prerequisite of being a doctor.


Full ACK.  Probably starting with the Industrial Revolution enabled by the
improvements of the steam machine in England, English has become the
/lingua franca/ of technology (even though the French often still
disagree, preferring words like « ordinateur » and « octet » over
“computer” and “byte”, respectively¹).  (With the Internet at the latest,
then, it has also become the /lingua franca/ of science, although Latin
terms are common in medicine.)


And this is a BAD THING. Monoculture is harmful, and science and technology
is becoming a monoculture: Anglo-American language expressing
Anglo-American ideas, regardless of the nationality of the scientist or
engineer.

During the heyday of the scientific revolution, the sciences and mathematics
were much diverse. Depending on your field, the professional scientist
needed at least a working knowledge of German, French, English and Latin,
possibly some Greek and Russian. Likewise for engineering.

I don't think that it is a coincidence that the great scientific theories
like relativity (both of them), quantum mechanics, evolution by natural
selection and continental drift had time to mature in smaller, national
communities before diffusing out to broader international communities.

Fortunately at least some people are aware of the problem and doing
something about it:

https://blog.stackoverflow.com/2014/02/cant-we-all-be-reasonable-and-speak-english/

Unlike the rest of us, Stackoverflow have actually run the numbers:

10% of the world's programmers are in China
1.4% of their visits come from China

so either Chinese developers are so brilliant and knowledgeable that they
have no need of Stackoverflow, or they're unable to make use of it because
they cannot participate in English-only forums.



Nowadays software companies and communities are international. You never
know who needs to maintain your code. At work, I need to maintain code
that was created in Japan, with coworkers from all over the world. The
Japanese author had had a hard time with English, and made some
awkward naming choices, but had the common sense to use English-only
names in his code.


One will have a hard time finding a company or community, international or
not, that does not have at least a basic knowledge of English included in
what they require of a software developer.


Particularly if one keeps a Euro-centric perspective and doesn't look to
Asia or Brazil.



My mum was from Tredegar.  She was very upset because English newspaper 
correspondents were biased against her "boys", and because the selectors 
never even put her into the squad, let alone the starting lineup.


Of course this is completely irrelevant on the Python programming main 
mailing list, but it appears that any old crap is acceptable in the year 
2016.


A Bot, a Bot, any kingdom for a Bot.

--
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: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Mark Lawrence via Python-list

On 03/04/2016 01:12, BartC wrote:

On 02/04/2016 23:31, Loop.IO wrote:


Oh i see, so the code prompts for a name.. so i'm more lost than i
thought, what do I need to change to make it just create the file with
the chosen name Launch2.bat without the prompt?


If you don't want the user to enter anything, then I explained how
before, just use:

  name='C:\\Documents\\PythonCoding\\launch2.bat'

if that's the file name you need.



name = r'C:\Documents\PythonCoding\launch2.bat'

Alternatively you could just use a forward slash.

I'm not sure which is the most efficient, I'll leave that to others to test.

--
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: [beginner] What's wrong?

2016-04-02 Thread Mark Lawrence via Python-list

On 03/04/2016 01:48, Steven D'Aprano wrote:

On Sun, 3 Apr 2016 07:42 am, Michael Selik wrote:


Gaming also helps your reaction time. Normally 0.3 ms, but 0.1 ms for top
gamers. And fighter pilots.


Does gaming help reaction time, or do only people with fast reaction times
become top gamers?

Personally, in my experience gaming hurts reaction time. I ask people a
question, and they don't reply for a week or at all, because they're too
busy playing games all day.



I must agree.  When you're trying to get the ball away, and 23 stone of 
bone and muscle smashes into you, that slows your reaction time.  I am 
of course referring to the sport of rugby, not that silly "World 
Series", which takes part in only one country, where for some reason 
unknown to me they wear huge quantities of armour and need oxygen masks 
after they've run a few yards.  What would happen to the poor little 
darlings if they had to spend the entire match on the pitch?


--
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: Strange range

2016-04-04 Thread Mark Lawrence via Python-list

On 03/04/2016 17:28, Ethan Furman wrote:

On 04/02/2016 11:58 PM, Marko Rauhamaa wrote:

Stephen Hansen :


I'm pretty sure that 99+% of the non-stdlib code out there is also
completely inaccessible (or at least inconveniently accessible) to
Stephen as well.



http://nullege.com/codes/search?cq=range would appear to be as good a 
starting point as any.


--
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: [beginner] What's wrong?

2016-04-04 Thread Mark Lawrence via Python-list

On 02/04/2016 23:49, Michael Torrie wrote:

Mark, your messages are showing up to the list as being from "python,"
at least on my email.  Any reason for this?



Assuming that you're referring to me, frankly I haven't a clue.  I read 
this list with Thunderbird on Windows, I hit "reply" to something, I 
type, I hit "send", job done.  Thereafter, as far as I'm concerned, a 
miracle occurs and hundreds if not thousands of subscribers get to see 
my reply.


--
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: Best Practices for Internal Package Structure

2016-04-04 Thread Mark Lawrence via Python-list

On 04/04/2016 19:45, Michael Selik wrote:

On Mon, Apr 4, 2016 at 6:04 PM Sven R. Kunze  wrote:


Hi Josh,

good question.

On 04.04.2016 18:47, Josh B. wrote:

My package, available at https://github.com/jab/bidict, is currently

laid out like this:


bidict/
├── __init__.py
├── _bidict.py
├── _common.py
├── _frozen.py
├── _loose.py
├── _named.py
├── _ordered.py
├── compat.py
├── util.py


I'd like to get some more feedback on a question about this layout that

I originally asked here: <
https://github.com/jab/bidict/pull/33#issuecomment-193877248>:


What do you think of the code layout, specifically the use of the _foo

modules? It seems well-factored to me, but I haven't seen things laid out
this way very often in other projects, and I'd like to do this as nicely as
possible.



Using the _module.py convention for internals is fine, except that you have
few enough lines of code that you could have far fewer files. Why create a
package when you can just have a module, bidict.py?

I find it easier to find the right section of my code when I have just a
few files open rather than a dozen or so in different windows and tabs.



+1

--
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: IDLE's subprocess didn't make connection. Either IDLE can't start or personal firewall software is blocking connection.

2016-04-04 Thread Mark Lawrence via Python-list

On 04/04/2016 21:19, Steven Gao wrote:

I’m getting “IDLE's subprocess didn't make connection. Either IDLE can't start 
or personal firewall software is blocking connection.”. Any ideas?

Sent from Mail for Windows 10



Asked and answered repeatedly, please search the archives for the answer.

--
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: Label behavior's difference between tkinter and ttk

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 07:57, ast wrote:

Hello

I currently migrate a GUI from tkinter to ttk and I found a problem

Here is a piece of code, with comments which explain what is wrong.

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""

img = tk.BitmapImage(data=BITMAP0, foreground='white', background='black')

# This Label comes from ttk

label = ttk.Label(root, image=img)

# This Label comes from tk. To be uncommented to test behavior'difference
# label = tk.Label(root, image=img)

label.pack()

# The graphic is not refreshed after entering following commands
# when Label comes from ttk. You have to fly over the label with # the
mouse to get the right color.
# The graphic is immediately updated when Label comes from tk

# Enter these commands by hand, in a shell

img.config(foreground='red')
img.config(foreground='lime')
img.config(foreground='yellow')


It looks like a ttk bug, isn't it ?
I am using python 3.5.1

I tried a root.update_idletasks() to refresh the graphic
but it changed nothings.



I'm no tkinter expert, but I do know that there is a huge difference 
between the way that tk and ttk widgets are configured.  Here are a few 
links that I hope will give you an idea.


http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Label.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-layouts.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-map.html
http://www.tkdocs.com/tutorial/styles.html

In the latter you might like to note that there is a section called 
"Sound Difficult to you?".  It's well worth the read.


--
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: tkinter Entry validation modes

2016-04-05 Thread Mark Lawrence via Python-list

On 02/04/2016 19:45, Terry Reedy wrote:

On 4/2/2016 11:11 AM, Mark Lawrence via Python-list wrote:

A typical call to create an Entry field would be:-

e = Entry(master, validate='all', ...)

Once this call has been made is it possible to change the validation
mode at runtime?


AFAIK, every keyword-only configuration option can be changed.

e['validate'] = xyz
e.config(validate=xyz)



Yes, there's an write up on it here 
http://effbot.org/tkinterbook/tkinter-widget-configuration.htm


--
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: python script for .dat file

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 16:23, Muhammad Ali wrote:


Hello,

Could any body tell me a general python script to generate .dat file after the 
extraction of data from more than 2 files, say file A and file B?

Or could any body tell me the python commands to generate .dat file after the 
extraction of data from two or more than two files?

I have to modify some python code.

Looking for your valuable posts.

Thank you.

Ali



https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

--
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: Install request

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 16:56, Igor Korot wrote:

  Hi, python community,
Recently there was a huge number of e-mail stating that the python
installer does not work.

When asked about it, people reveal that they wee using Windows and
they were getting
errors about missing DLL.

I know for a fact that in the InstallShield it is possible to detect
the OS you are trying
to install on.

So, here is my request: if its not possible to include the DLL in
question in the installer,
can the installer check for the OS version and ask the user to go to
Microsoft.com,
download and install the library?

It looks like people don't want to use their common sense and just
wanted to waste
everybody's time by asking what went wrong instead of just download
the dll executable
from MS site and install it.

Can something like this be done to eliminate those questions in the
future and let people
concentrate on the real python issues?

Thank you.



I fail to see why anybody in the Python community should put themselves 
out to answer a question for someone who is too bone idle to do any 
research in the first place, especially when the question has been asked 
and answered repeatadly over a period of months.  For those who 
disagree, they can provide the patches, or the edits to a wiki as 
appropriate.


--
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: Best Practices for Internal Package Structure

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 19:49, Sven R. Kunze wrote:


It appears to me as if you like messy code then. ;)



The messy code is with the person who needlessly splits a single module 
of a few thousand lines into several modules just for the sake of it. 
If you want to play yo-yo, leaping from source file to source file, 
running the risk of circular imports, feel free, I won't lose any sleep 
over it, but give me one, clean file any day of the week.


--
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: python script for .dat file

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 21:35, Michael Selik wrote:

What code have you written so far?



Would you please not top post on this list, it drives me nuts!!!

--
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: Promoting Python

2016-04-06 Thread Mark Lawrence via Python-list

On 06/04/2016 12:06, BartC wrote:

On 05/04/2016 06:48, Gordon( Hotmail ) wrote:

I am struggling to understand the basic principles of Python having
spent many years as a pure Amateur tinkering with a variety of BASIC


Last time I looked, there seemed to be around 250 dialects of Basic, and
with wildly differing implementations from pure interpreters to full
compilers, from GWBASIC to .NET. (Is there even an official standard?)

With Python there are two dialects, and it's often already installed on
a system (probably not on Windows though). There are a few different
implementations too, but code I think is largely compatible across them.


The problem I am finding is most of the sites claiming to help
understand Python devote
far too much space bragging about the wonders of Python instead of...


See if you can find one or more here 
http://noeticforce.com/best-free-tutorials-to-learn-python-pdfs-ebooks-online-interactive 
that suits.




I fully agree. But you don't have to use classes, exceptions,
decorators, generators, iterators, closures, comprehensions, meta
classes, ... the list of meaningless buzzwords just goes on.


You were five days late.



It'll cope with ordinary coding as well, although such programs seem to
be frowned upon here; they are not 'Pythonic'.



How can you (plural) write Python code when you don't know Python?

--
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: Checking function's parameters (type, value) or not ?

2016-04-06 Thread Mark Lawrence via Python-list

On 06/04/2016 14:07, ast wrote:

Hello

I would like to know if it is advised or not to test
a function's parameters before running it, e.g
for functions stored on a public library ?

Example:

def to_base(nber, base=16, use_af=True, sep=''):

assert isinstance(nber, int) and nber >= 0
assert isinstance(base, int) and base >= 2
assert isinstance(use_af, bool)
assert isinstance(sep, str) and len(sep) == 1

   tbc

With these tests, you are sure that the function to_base is
well used. But it slows down the program.
Without, python interpreter may crash later in the function
or worse provide a meaningless result.

What library designers do ?




Please see 
http://ftp.dev411.com/t/python/python-list/13bhcknhan/when-to-use-assert


--
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: Promoting Python

2016-04-06 Thread Mark Lawrence via Python-list

On 06/04/2016 14:54, BartC wrote:

On 06/04/2016 12:46, Marko Rauhamaa wrote:

BartC :



It'll cope with ordinary coding as well, although such programs seem
to be frowned upon here; they are not 'Pythonic'.


I wonder what is left of Python after your list of exclusions.


There are plenty of features that /I/ consider must-have, which Python
doesn't have. It has to emulate them, unsatisfactorily, with variables
or classes or functions, or do without.


Please list all these features.  Precisely what is unsatisfactory about 
the emulation?  Please state why you're still here if Python is such a 
poorly designed language that it doesn't fit your needs.  Or is it 
simply that your mindset cannot get to grips with something that is 
different to that you've previously used?




But you're right in that little is actually essential. Basic has shown
that.

You need expressions, IF, GOTO, variables and assignments, and some
means of doing I/O.


Are you suggesting that 21st century programming should return to the 
era of spaghetti code?




Pretty much every language has (had) those, although it's fashionable
now to do away with GOTO, and some are getting rid of (rewritable)
variables too!


It's 50 years to my knowledge since the first paper stating that GOTO 
isn't needed, hardly "fashionable now".  I get a very strong impression 
that you've never had to maintain appalingly written code.  The overuse 
of GOTO will certainly help in that area.  How does it go, something 
like "always consider that the person maintaining your code in six 
months time is a homicidal maniac armed with an axe"?


--
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: Promoting Python

2016-04-06 Thread Mark Lawrence via Python-list

On 06/04/2016 15:34, Ned Batchelder wrote:

On Wednesday, April 6, 2016 at 10:25:13 AM UTC-4, Mark Lawrence wrote:

On 06/04/2016 14:54, BartC wrote:

On 06/04/2016 12:46, Marko Rauhamaa wrote:

BartC :



It'll cope with ordinary coding as well, although such programs seem
to be frowned upon here; they are not 'Pythonic'.


I wonder what is left of Python after your list of exclusions.


There are plenty of features that /I/ consider must-have, which Python
doesn't have. It has to emulate them, unsatisfactorily, with variables
or classes or functions, or do without.


Please list all these features.  Precisely what is unsatisfactory about
the emulation?  Please state why you're still here if Python is such a
poorly designed language that it doesn't fit your needs.  Or is it
simply that your mindset cannot get to grips with something that is
different to that you've previously used?


No, please, let's not ask BartC to list these features.  We've already
well established Bart's point of view, let's not revisit this debate.
He prefers very different languages than Python.  We get it.  We don't
have to try to convince him to like Python, it's been tried, it doesn't
work.

--Ned.



So why isn't he politely told to shove off as he's not welcome on this 
Python list?


--
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: Promoting Python

2016-04-06 Thread Mark Lawrence via Python-list

On 06/04/2016 18:55, Ned Batchelder wrote:


It took us a while to understand where Bart was coming from, but now we
understand, and we don't have to go around in circles.



No it didn't, it was quite clear from the beginning that he knew squat, 
and since then he's admitted that he knows squat.  About Python.  On the 
main Python list.  Perhaps he should hence forward be known as RUE2? 
Actually that is unfair, the original RUE only complains about PEP393 
unicode, BartC complains about everything.  I still do not believe that 
he could organise a piss up in a brewery, let alone write decent code. 
Until such time as I see proof that he has any idea at all as to what 
he's talking about, he stays firmly in my dream team.


--
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: deque is not a subclass of Sequence.

2016-04-07 Thread Mark Lawrence via Python-list

On 07/04/2016 10:25, Antoon Pardon wrote:


the index() method seems to be added in 3.5, so is deque
a subclass of Sequence in 3.5?



Yes, this http://bugs.python.org/issue23704 refers.

Use the builtin 
https://docs.python.org/3/library/functions.html#issubclass to try it.


>>> issubclass(deque, Sequence)
True

--
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: how to convert code that uses cmp to python3

2016-04-07 Thread Mark Lawrence via Python-list

On 07/04/2016 13:05, Antoon Pardon wrote:

I am looking at my avltree module for converting it to
python3.

One of the things that trouble me here is how python3 no
longer has cmp and how things have to be of "compatible"
type in order to be comparable.

So in python2 it wasn't a problem to have a tree with
numbers and strings as keys. In python3 that will not
be so evident.

In python2 descending the tree would only involve at
most one expensive comparison, because using cmp would
codify that comparison into an integer which would then
be cheap to compare with 0. Now in python3, I may need
to do two expensive comparisons, because there is no
__cmp__ method, to make such a codefication.

Is there a way to work around these limitations or
should I resign myself to working within them?



HTH https://docs.python.org/3/library/functools.html#functools.cmp_to_key

--
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: how to convert code that uses cmp to python3

2016-04-07 Thread Mark Lawrence via Python-list

On 07/04/2016 21:56, Antoon Pardon wrote:

Op 07-04-16 om 14:22 schreef Chris Angelico:

...


There's no __cmp__ method, but you could easily craft your own
compare() function:

def compare(x, y):
 """Return a number < 0 if x < y, or > 0 if x > y"""
 if x == y: return 0
 return -1 if keyify(x) < keyify(y) else 1

I'm not sure how your tree is crafted and how your "cheap" and
"expensive" comparisons previously worked, but give something like
this a try. I think you'll find it adequate.


That solution will mean I will have to do about 100% more comparisons
than previously.

Lets simplify for the moment and suppose all keys are tuples of
integers. Now because how trees are organised, the lower you
descend in the tree, the closer the keys are together. In the
case of tuples that means higher probability you have to traverse
the two tuples further in order to find out which is greater.

With the __cmp__ method, you only had to traverse the two tuples
once in order to find out whether they were equal or if not which
is the smaller and which is the greater.

With this method I have to traverse the two tuples almost always
twice. Once to find out if they are equal and if not a second
time to find out which is greater.



Have you read this https://wiki.python.org/moin/HowTo/Sorting ?

--
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: [beginner] What's wrong?

2016-04-08 Thread Mark Lawrence via Python-list

On 08/04/2016 23:59, sohcahto...@gmail.com wrote:

On Friday, April 1, 2016 at 3:57:40 PM UTC-7, Mark Lawrence wrote:

On 01/04/2016 23:44, sohcahto...@gmail.com wrote:

On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:

Nevermind. for j in range(1,8) should be for j in range(8).


I can't tell you how many times I've gotten bit in the ass with that off-by-one 
mistake whenever I use a range that doesn't start at zero.

I know that if I want to loop 10 times and I either want to start at zero or 
just don't care about the actual number, I use `for i in range(10)`.  But if I 
want to loop from 10 to 20, my first instinct is to write `for i in range(10, 
20)`, and then I'm left figuring out why my loop isn't executing the last step.



"First instinct"?  "I expected"?  The Python docs might not be perfect,
but they were certainly adequate enough to get me going 15 years ago,
and since then they've improved.  So where is the problem, other than
failure to RTFM?

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

Mark Lawrence


Holy hell, why such an aggressive tone?

I understand how range(x, y) works.  It's just a simple mistake that I 
frequently do it wrong and have to correct it after the first time I run it.  
It's not like I'm saying that the implementation needs to change.  I'm just 
saying that if I want to loop from 10 to 20, my first thought is to use 
range(10, 20).  It is slightly unintuitive.

*YES*, I know it is wrong.  *YES*, I understand why the correct usage would be 
range(10, 21) to get that list from 10 to 20.

Get off your high horse.  Not everybody is like you and has been using Python 
for 15 years and apparently never makes mistakes.



*plonk*

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

Mark Lawrence

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


Re: QWERTY was not designed to intentionally slow typists down

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 01:43, Ben Finney wrote:

Dennis Lee Bieber  writes:



Yet another completely irrelevant thread that has nothing to do with 
Python.  As this is meant to be the main Python mailing list, why don't 
the moderators put a stop to such tripe?


--
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: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 18:13, Joe wrote:

On Saturday, 9 April 2016 18:44:20 UTC+2, Ian  wrote:

On Sat, Apr 9, 2016 at 8:18 AM, Joe  wrote:

How to find the number of robots needed to walk through the rectangular grid
The movement of a robot in the field is divided into successive steps

In one step a robot can move either horizontally or vertically (in one row or 
in one column of cells) by some number of cells

A robot can move in one step from cell X to cell Y if and only if the distance 
between the centers of the cells X and Y is equal to the sum of integers 
contained in X and Y

Cell X is reachable for robot A if either A is currently standing in the cell X 
or A can reach X after some number of steps. During the transfer the robot can 
choose the direction (horizontal or vertical) of each step arbitrarily
[![enter image description here][1]][1]

I started implementing it by first checking the row and print the index of the 
Cell X and Y where the distance is equal to the sum of integers contained in X 
and Y

but after coding I found it difficult to remember the index when moving 
vertically

  So I thought to Build a graph where nodes are grid cells and edges are legal 
direct movements, then run any connected components algorithm to find which 
cells are reachable from each other


Can anyone implement it with graphs or queue?


I'd use a disjoint-set data structure. The number of robots needed is
equal to the number of disjoint subsets.

https://en.wikipedia.org/wiki/Disjoint-set_data_structure


Could you post a formal solution of disjoint-set using my algorithm



You write the code, we comment on it.  No code, no comment.  Got the 
message?


--
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: Unicode normalisation [was Re: [beginner] What's wrong?]

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 17:08, Rustom Mody wrote:

On Saturday, April 9, 2016 at 7:14:05 PM UTC+5:30, Ben Bacarisse wrote:

The problem with that theory is that 'er/re' (this is e and r in either
order) is the 3rd most common pair in English but have been placed
together.  ou and et (in either order) are the 15th and 22nd most common
and they are separated by only one hammer position.  On the other hand,
the QWERTY layout puts jk together, but they almost never appear
together in English text.


Where do you get this (kind of) statistical data?



Again, where is the relevance to Python in this discussion, as we're on 
the main Python mailing list?  Please can the moderators take this stuff 
out, it is getting beyond the pale.


--
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: QWERTY was not designed to intentionally slow typists down

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 20:25, Tim Golden wrote:

On 09/04/2016 20:13, Mark Lawrence via Python-list wrote:

On 09/04/2016 01:43, Ben Finney wrote:

Dennis Lee Bieber  writes:



Yet another completely irrelevant thread that has nothing to do with
Python.  As this is meant to be the main Python mailing list, why don't
the moderators put a stop to such tripe?



I'm sorry Mark but, whether you like it or not, this list / newsgroup
has never been averse to taking a detour into interesting side-channels.
You can easily mute a thread if you want to (or just delete the posts as
they come).


I do not find this acceptable. I want to discuss PYTHON on the MAIN 
PYTHON MAILING LIST, not some shite that someone thinks is interesting, 
they can take that offline.  QWERTY, what next, today's football results?




Added to which, moderators give their time as freely as anyone else, and
we'd have a merry time of it if we had to vet every subthread and post
to make sure it met some notional guideline of language purity.

TJG


Very amusing to see that some highly qualified 'moderators' have been so 
bloody rude on other Python mailing lists in the last days.  Do as I 
say, not as I do?


--
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: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 20:41, Joe wrote:


Sorry, I was desperate
I deleted the post



You didn't.  This will be showing in the archives in several places, e.g 
https://mail.python.org/pipermail/python-list/2016-April/707160.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: QWERTY was not designed to intentionally slow typists down

2016-04-09 Thread Mark Lawrence via Python-list

On 09/04/2016 21:22, alister wrote:

On Sat, 09 Apr 2016 20:13:15 +0100, Mark Lawrence wrote:


On 09/04/2016 01:43, Ben Finney wrote:

Dennis Lee Bieber  writes:



Yet another completely irrelevant thread that has nothing to do with
Python.  As this is meant to be the main Python mailing list, why don't
the moderators put a stop to such tripe?


Because it is also a newsgroup which means they CANT (at least not 100%
effectively) even if the want to.



They could certainly be more effective.  Thankfully the RUE was seen 
off.  Talk about grateful for small mercies, given the number of others 
who continue to insult the Python community and get away scott free, 
whilst they continue to discriminate against me in complete breach of 
the ethics that they claim to hold so dear.  Talk about bloody 
hypocrites.  Actually how do you get the job of moderator, insult the 
BDFL as Ethan Furman did just a day or so back?


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


Network protocols, sans I/O,(Hopefully) the future of network protocols in Python

2016-08-08 Thread Mark Lawrence via Python-list
This may be of interest to some of you 
http://www.snarky.ca/network-protocols-sans-i-o


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