Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Chris Angelico
On Sun, Apr 2, 2017 at 4:41 PM, Terry Reedy  wrote:
> On 4/1/2017 12:00 PM, Steve D'Aprano wrote:
>
>> example of the Ugly American.
>
>
> As an American I resent your promotion and perpetuation of an ugly
> ethno-centric stereotype.

There are ugly Americans and there are non-ugly Americans. Rick is a
prime example of the former.

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Christian Gollwitzer

Am 01.04.17 um 19:38 schrieb Steve D'Aprano:

^home^steve^document.txt


I'm sure I'd get used to it in a few years...

Next: convince keyboard manufacturers to move the caret from SHIFT-6 to a
plain, unshifted key. Buggared if I'm going to hit shift every time I want
to use an absolute path...


...which is reality for a lot more people than you might think. On a 
German keyboard, / is Shift-7. Same for \ {} [] which require 
carpal-tunneling combinations with the right Alt key "Alt Gr". 
Especially bad are shortcutrs like Ctrl+\ which appear in some software.


Christian

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Marko Rauhamaa
Christian Gollwitzer :

> Am 01.04.17 um 19:38 schrieb Steve D'Aprano:
>> Next: convince keyboard manufacturers to move the caret from SHIFT-6
>> to a plain, unshifted key. Buggared if I'm going to hit shift every
>> time I want to use an absolute path...
>
> ...which is reality for a lot more people than you might think. On a
> German keyboard, / is Shift-7. Same for \ {} [] which require
> carpal-tunneling combinations with the right Alt key "Alt Gr".
> Especially bad are shortcutrs like Ctrl+\ which appear in some
> software.

Same with the Finnish keyboard. It's a crime against ergonomy. That's
why I have remapped my keyboard for my personal needs (languages,
programming).


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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread bartc

On 01/04/2017 22:35, Marko Rauhamaa wrote:

Chris Angelico :


there is no way within Python to have a string that can represent two
strings, which is what directory separators do.


Really? Try:

   >>> repr(("a", "b"))
   "('a', 'b')"

There! A string that represents two strings.

Note, however, that Python programs generally don't restrict themselves
to expressing objects via strings. There are even objects with no string
representation at all.

A pathname is a list of strings. Python could naturally express it as
just that:

  [ "usr", "bin", "python3" ]


I'm not really proposing any change to the status quo. What's done is
done. However, I do think it is awkward to ban one particular, very
common character while allowing all the rest.


Space is quite common as well, especially in titles of things chosen by 
non-technical users. That also needs special treatment.


There are quite a few other characters with special meanings that people 
might want to use. It's not just stroke.


But people, when unrestrained, will /always/ want to do something that 
may not be practical. For example, why bother with the separate concepts 
'filename' and 'file'; just have the file contents /as/ the filename! If 
there are no limits on how long a filename is or what characters it can 
have, then people will take advantage.


Or they will want to use the full path of one file, as the part of the 
filename of another; is each "/" a separator, or part of the embedded path?


Anyway, I'm sure out of the million unicode characters, there must be 
something that /looks/ like a stroke, but isn't a stroke. Just to add to 
the confusion.



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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Chris Angelico
On Sun, Apr 2, 2017 at 9:12 PM, bartc  wrote:
> But people, when unrestrained, will /always/ want to do something that may
> not be practical. For example, why bother with the separate concepts
> 'filename' and 'file'; just have the file contents /as/ the filename! If
> there are no limits on how long a filename is or what characters it can
> have, then people will take advantage.
>

This is possible. It's called a "content-based file system", and it's
the basis of tools like git, for example. But it's not the entire
solution; you still need some way to tell a program which blob to
react to.

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


Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
Dear Python friend


I have a nested  data dictonary in the below format and I need to store
1000 of  entries which are in teh below format


>>> X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4",
grade="A",payment="200")
>>> X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4",
grade="A",payment="400")
>>> X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4",
grade="A",payment="400")


I only thing thats is changing is payment and I have payment_list as a list
[100,200,400,500]:


The value salary3 ,salary4,salary4 is to be generated in the loop . Iam
trying to optimize the above code , by looping as shown below


>>> X = {}
>>> X['emp_01'] ={}
>>> for salary in range(len(payment_list)):
... X['emp_01'][salary] =  dict(sex="f", status="single", exp="4",
grade="A",payment=payment_list[salary])
...
>>> X
{'emp_01': {0: {'grade': 'A', 'status': 'single', 'payment': 100, 'exp':
'4', 'sex': 'f'}, 1: {'grade': 'A', 'status': 'single', 'payment': 200,
'exp': '4', 'sex': 'f'}, 2: {'grade': 'A', 'status': 'single', 'payment':
400, 'exp': '4', 'sex': 'f'}, 3: {'grade': 'A', 'status': 'single',
'payment': 500, 'exp': '4', 'sex': 'f'}}}
>>>


Any other suggestion ,   Please let me know  I am on python 2.7 and Linux

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Steve D'Aprano
On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:

> On 4/1/2017 12:00 PM, Steve D'Aprano wrote:
> 
>> example of the Ugly American.
> 
> As an American I resent your promotion and perpetuation of an ugly
> ethno-centric stereotype.

I'm glad you didn't try to describe it as a *unfair* or *unjustified*
stereotype, because (let's face it) after November 8th 2016, that simply
wouldn't fly.

Not all Americans, perhaps not even a majority or a plurality, are Ugly
Americans, but there are enough of them to screw it up for everyone else.

It's an ugly stereotype, not because it is a stereotype, but because it
embodies a set of ugly attitudes and behaviours.



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

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


In Python and Windows environment how to supress certain key press and send some other key event for it

2017-04-02 Thread Krishnan Shankar
Hi All,

I was trying to build a VIM like shortcuts in windows. For example,

IF i press CAPSLOCK & h: It should "{Left}" move one to left. If CAPSLOCK &
b: It should "{Ctrl Down}{Left}{Ctrl Up}" move one word left etc.

I was successful in sending the key event. I used libraries like,

1. pynput
2. keyboard

for the same.

But i was unable to supress the Initial key event (ex: Caplock & h)

I tried using the keyboard to listen for key press events and supress them
as below.

>
import keyboard

def move_one_left():
"""
Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event
:return:
"""
keyboard.send(75)

def move_one_word_left():
"""
Wrapper for CAPS LOCK + b. The function sends LEFT ARROW Event
:return:
"""
keyboard.send('ctrl+left')

def main():
"""
This is the main loop which reads the key pressed.
According to the hotkey registered the function hooked is called.
The corresponding function will be the wrapped combination send back.
For example: CAPS + b is wrapped to Moving to left.
The main loop exits when Ctrl + c is done. So that is not registered.
:return:
"""
try:
# Start of the main loop
# Registering the hotkeys
# CAPS LOCK + H
keyboard.add_hotkey('caps lock+h', move_one_left, suppress=True)
# CAPS LOCK + B
keyboard.add_hotkey('caps lock+b', move_one_word_left,
suppress=True)

while True:
# Read the key pressed
print (keyboard.read_key())
except KeyboardInterrupt:
print("User has exited the program")

if __name__ == "__main__":
main()

<


This is working for sending the event for key press but the initial
keypress is also being send. The supress=True is not working.

Am I doing something wrong or is there any better way to supress the
initial key event and send another key event in place of that.


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


Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Peter Otten
Ganesh Pal wrote:

> Dear Python friend
> 
> 
> I have a nested  data dictonary in the below format and I need to store
> 1000 of  entries which are in teh below format
> 
> 
 X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="200")
 X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="400")
 X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="400")
> 
> 
> I only thing thats is changing is payment and I have payment_list as a
> list
> [100,200,400,500]:
> 
> 
> The value salary3 ,salary4,salary4 is to be generated in the loop . Iam
> trying to optimize the above code , by looping as shown below
> 
> 
 X = {}
 X['emp_01'] ={}
 for salary in range(len(payment_list)):

Whenever you feel the urge to write range(len(whatever)) -- resist that 
temptation, and you'll end up with better Python code ;)

> ... X['emp_01'][salary] =  dict(sex="f", status="single", exp="4",
> grade="A",payment=payment_list[salary])
> ...
 X
> {'emp_01': {0: {'grade': 'A', 'status': 'single', 'payment': 100, 'exp':
> '4', 'sex': 'f'}, 1: {'grade': 'A', 'status': 'single', 'payment': 200,
> 'exp': '4', 'sex': 'f'}, 2: {'grade': 'A', 'status': 'single', 'payment':
> 400, 'exp': '4', 'sex': 'f'}, 3: {'grade': 'A', 'status': 'single',
> 'payment': 500, 'exp': '4', 'sex': 'f'}}}

> 
> 
> Any other suggestion ,   Please let me know  I am on python 2.7 and Linux

Instead of artificially blowing up your database change its structure. For 
example:

X["emp_01"] = dict(
sex="f", 
status="single", 
exp="4", 
grade="A",
payments=[100, 200, 400, 500]
)

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


Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Steve D'Aprano
On Mon, 3 Apr 2017 02:13 am, Ganesh Pal wrote:

> Dear Python friend
> 
> 
> I have a nested  data dictonary in the below format and I need to store
> 1000 of  entries which are in teh below format
> 
> 
 X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="200")
 X['emp_01']['salary4'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="400")
 X['emp_01']['salary5'] = dict(sex="f", status="single", exp="4",
> grade="A",payment="400")

Why is payment a string?


> I only thing thats is changing is payment and I have payment_list as a
> list
> [100,200,400,500]:

And here payment is an int.


> The value salary3 ,salary4,salary4 is to be generated in the loop . Iam
> trying to optimize the above code , by looping as shown below

In the above example, you have strings "salary3", "salary4", "salary5", but
in the code below, you use 0, 1, 2 instead.

Which do you intend to use?


 X = {}
 X['emp_01'] ={}
 for salary in range(len(payment_list)):
> ... X['emp_01'][salary] =  dict(sex="f", status="single", exp="4",
> grade="A",payment=payment_list[salary])


You should almost never need to write `range(len(payment_list))`.


payment_list = [100, 200, 400, 500]

employees = {}
employees['emp_01'] = {}
for salary, payment in enumerate(payment_list, 3):
# I don't know why salary starts at 3 instead of 1 or 0.
salary = 'salary' + str(salary)
employees['emp_01'][salary] = dict(
sex="f", status="single", exp="4", grade="A", payment=payment
)

from pprint import pprint
pprint(employees)


{'emp_01': {'salary3': {'exp': '4',
'grade': 'A',
'payment': 100,
'sex': 'f',
'status': 'single'},
'salary4': {'exp': '4',
'grade': 'A',
'payment': 200,
'sex': 'f',
'status': 'single'},
'salary5': {'exp': '4',
'grade': 'A',
'payment': 400,
'sex': 'f',
'status': 'single'},
'salary6': {'exp': '4',
'grade': 'A',
'payment': 500,
'sex': 'f',
'status': 'single'}}}




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

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


Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
On Sun, Apr 2, 2017 at 10:35 PM, Steve D'Aprano 
wrote:

>
> Why is payment a string?
>
> Yes it should be int


>
> > The value salary3 ,salary4,salary4 is to be generated in the loop . Iam
> > trying to optimize the above code , by looping as shown below
>
> In the above example, you have strings "salary3", "salary4", "salary5", but
> in the code below, you use 0, 1, 2 instead.
>
> Which do you intend to use?
>
>  It must be Salary1,Salary2



> payment_list = [100, 200, 400, 500]
>
> employees = {}
> employees['emp_01'] = {}
> for salary, payment in enumerate(payment_list, 3):
> # I don't know why salary starts at 3 instead of 1 or 0.
> salary = 'salary' + str(salary)
> employees['emp_01'][salary] = dict(
> sex="f", status="single", exp="4", grade="A", payment=payment
> )
>
> from pprint import pprint
> pprint(employees)
>
>
> {'emp_01': {'salary3': {'exp': '4',
> 'grade': 'A',
> 'payment': 100,
> 'sex': 'f',
> 'status': 'single'},
> 'salary4': {'exp': '4',
> 'grade': 'A',
> 'payment': 200,
> 'sex': 'f',
> 'status': 'single'},
> 'salary5': {'exp': '4',
> 'grade': 'A',
> 'payment': 400,
> 'sex': 'f',
> 'status': 'single'},
> 'salary6': {'exp': '4',
> 'grade': 'A',
> 'payment': 500,
> 'sex': 'f',
> 'status': 'single'}}}
>
>
>
>
Thanks ;
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
>
>
> Whenever you feel the urge to write range(len(whatever)) -- resist that
> temptation, and you'll end up with better Python code ;)
>
>
Thanks for this suggestion but for my better understanding can  explain
this further even Steve did point the same mistake.


>
> Instead of artificially blowing up your database change its structure. For
> example:
>
>
Good point Actually , I might be heading towards this, let me ask this in a
fresh email thread
-- 
https://mail.python.org/mailman/listinfo/python-list


Cheetah 3.0.0a1

2017-04-02 Thread Oleg Broytman
Hello! I'm happy to announce I revived development of Cheetah.
Unfortunately I have to fork the project.

I'm pleased to announce version 3.0.0a1, the first alpha of the upcoming
release of branch 3.0 of CheetahTemplate3.


What's new in CheetahTemplate3
==

Contributors for this release are Adam Karpierz and Jonathan Ross Rogers.

- !!!THIS RELEASE REQUIRES RECOMPILATION OF ALL COMPILED CHEETAH TEMPLATES!!!
- Stop supporting Python older than 2.7.
- Update code to work with Python 3.3+. Tested with 3.3, 3.4, 3.5 and 3.6.
- Run tests at Travis (Linux) and AppVeyor (w32) with Python 2.7, 3.3, 3.4,
  3.5 and 3.6; x86 and x64.
- Fix a bug in multiple inheritance (#extend Parent1, Parent2).
  Pull request by Jonathan Ross Rogers.


What is CheetahTemplate3


Cheetah3 is a free and open source template engine.
It's a fork of the original CheetahTemplate library.

Python 2.7 or 3.3+ is required.


Where is CheetahTemplate3
=

Site:
http://cheetahtemplate.org/

Development:
https://github.com/CheetahTemplate3

Download:
https://pypi.python.org/pypi/Cheetah3/3.0.0a1

News and changes:
http://cheetahtemplate.org/news.html

Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
https://mail.python.org/mailman/listinfo/python-list


Tcp Socket Receive

2017-04-02 Thread specx
Hello,
�
I have a tcp server coded with python and my packets include a 2 bytes header 
which is just the length of the following data. The problem is how can I be 
sure I received 2 bytes and not just one byte. In Qt, I use bytesAvailable 
function. However, here I just use sock.recv(2) but it can fetch less than 2 
since the parameter is the maximum length. Do we have any method?
�
Greetz

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


Re: Temporary variables in list comprehensions

2017-04-02 Thread Robert L.
On 1/8/2017, Steven D'Aprano wrote:

> Suppose you have an expensive calculation that gets used two or
> more times in a loop. The obvious way to avoid calculating it
> twice in an ordinary loop is with a temporary variable:
> 
> result = []
> for x in data:
> tmp = expensive_calculation(x)
> result.append((tmp, tmp+1))
> 
> 
> But what if you are using a list comprehension? Alas, list comps
> don't let you have temporary variables, so you have to write
> this:
> 
> [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data]
> 
> Or do you? ... no, you don't!
> 
> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]

[2,3,5].map{|n| tmp = Math.sqrt n; [tmp, tmp+1]}

 ===> 
[[1.4142135623730951, 2.414213562373095],
 [1.7320508075688772, 2.732050807568877],
 [2.23606797749979, 3.23606797749979]]


-- 
I don't believe in western morality, i.e. don't kill civilians or children
The only way to fight a moral war is the Jewish way: Destroy their holy sites.
Kill men, women, and children (and cattle). --- Rabbi Manis Friedman
web.archive.org/web/20090605154706/http://www.momentmag.com/Exclusive/2009/2009-06/200906-Ask_Rabbis.html
archive.org/download/DavidDukeVideo/TheZionistMatrixOfPowerddhd.ogv
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Gene Heskett
On Sunday 02 April 2017 12:26:40 Steve D'Aprano wrote:

> On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:
> > On 4/1/2017 12:00 PM, Steve D'Aprano wrote:
> >> example of the Ugly American.
> >
> > As an American I resent your promotion and perpetuation of an ugly
> > ethno-centric stereotype.
>
> I'm glad you didn't try to describe it as a *unfair* or *unjustified*
> stereotype, because (let's face it) after November 8th 2016, that
> simply wouldn't fly.

While I too detest that label, I will have to admit that I am one of the 
conservatives, believing our Constitution and Bill of Rights have been 
used as TP by the "establishment" over the last 65+ years, who enabled 
that surprise.

Wash., DC has been turned into a polluted swamp that needed drained and 
cleaned up, and the Donald was the only one that wasn't part of the same 
old, same old, bull crap establishment, and with enough money to run.

However, I'll be the first to admit I am less than impressed with his 
efforts vis-a-vis global warming. He, I suspect, will be a 1 term 
president unless he starts listening to the technical people's warnings.

I'd also make the prediction that the 2020 winner will _not_ be from the 
establishment. Maybe not even from the two party system. I am hoping 
that this will cause all (surviving) parties to do some navel gazing, 
and contemplating not how to enrich the constituent businesses they own 
under the table, but maybe, actually work for the common good. Taking 
money completely out of the equation would be one way, but you could 
hear the gored oxen that would wound fatally clear out to Pluto, without 
a radio.

Human avarice being what it is, whether I'll live long enough to see that 
happen isn't up to me. At 82, it doesn't look like near as big a chance 
as it did when I was 60.
>
> Not all Americans, perhaps not even a majority or a plurality, are
> Ugly Americans, but there are enough of them to screw it up for
> everyone else.
>
Generally, I try to stay out of the Ugly camp. Then I look in the mirror 
and know its hopeless. :(

[...]

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Temporary variables in list comprehensions

2017-04-02 Thread breamoreboy
On Sunday, April 2, 2017 at 1:08:17 AM UTC+1, Robert L. wrote:

> I don't believe in western morality, i.e. don't kill civilians or children
> The only way to fight a moral war is the Jewish way: Destroy their holy sites.
> Kill men, women, and children (and cattle). --- Rabbi Manis Friedman
> web.archive.org/web/20090605154706/http://www.momentmag.com/Exclusive/2009/2009-06/200906-Ask_Rabbis.html
> archive.org/download/DavidDukeVideo/TheZionistMatrixOfPowerddhd.ogv

Completely agree with Steven D'Aprano so would the moderators please ban Robert 
L with immediate effect.

Kindest regards.

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


Re: Text-mode apps (Was :Who are the "spacists"?)

2017-04-02 Thread Terry Reedy

On 4/2/2017 12:26 PM, Steve D'Aprano wrote:

On Sun, 2 Apr 2017 04:41 pm, Terry Reedy wrote:


On 4/1/2017 12:00 PM, Steve D'Aprano wrote:


example of the Ugly American.


As an American I resent your promotion and perpetuation of an ugly
ethno-centric stereotype.


I'm glad you didn't try to describe it as a *unfair* or *unjustified*


I refrained because it would be off-topic and a diversion from my point: 
all bigotry is inappropriate here on this list, including anti-Americanism.


(I actually think raw bigoty is inappropriate everywhere.  While there 
are places to discuss the relative average beauty and niceness of 
various groups of people, this is not one of them.  Even comparisons of 
computer languages is not the main focus of this list.)



stereotype, because (let's face it) after November 8th 2016, that simply
wouldn't fly.


The 'Ugly American' meme is at least 60 years old.  National bigotry is 
as old as nations.


Yesterday, Chris Angelico, I believe it was, asked someone to stop 
including anti-Jew messages in posts here.  So I asked the same of you 
regarding your anti-American expression.



Not all Americans, perhaps not even a majority or a plurality, are Ugly
Americans, but there are enough of them to screw it up for everyone else.


Shall we discuss Ugly Australians, or whatever the appropriate epithet 
would be?



It's an ugly stereotype, not because it is a stereotype, but because it

> embodies a set of ugly attitudes and behaviours.

I am sure I have seen similar things written by various other people 
justifying their prejudices.



--
Terry Jan Reedy

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


Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Terry Reedy

On 4/2/2017 1:59 PM, Ganesh Pal wrote:

> 'someone' wrote

Whenever you feel the urge to write range(len(whatever)) -- resist that
temptation, and you'll end up with better Python code ;)



Thanks for this suggestion but for my better understanding can explain
this further even Steve did point the same mistake.


Before 2.2, one could only iterate through a sequence of integers, or 
something that pretended to be such.  So the way to iterate though a 
finite sequence of non-ints was


for i in range(len(seq)):
item = seq[i]


The current iterator protocol allows one to separate item access or 
generation from item processing and to hide the former in an iterator. 
One then says in the header what collection of items one want to process 
and in what order (one at a time) and in the body what one wants to do 
with them.


for item in seq:  # items of seq in normal order


for item in iterable:  # not restricted to sequences, default order


Some other variations in the new form.

for item in reversed(iterable):  # finite collection in reversed order


for i, item in enumerate(seq):


for item1, item2 in zip(seq1, seq2):
 

--
Terry Jan Reedy

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


All people deserve respect. Ideas are not people. (was: Text-mode apps)

2017-04-02 Thread Ben Finney
Terry Reedy  writes:

> On 4/2/2017 12:26 PM, Steve D'Aprano wrote:
> > Not all Americans, perhaps not even a majority or a plurality, are Ugly
> > Americans, but there are enough of them to screw it up for everyone else.
>
> Shall we discuss Ugly Australians, or whatever the appropriate epithet
> would be?

Provided that, just as Steven has done, the discussion criticises ideas,
attitudes, and behaviours: that would not be bigotry nor prejudice at
all.

It's a difficult distinction, but an essential one: we *must* be free
always to hold ideas and behaviours to harsh criticism when warranted,
no matter who holds or does them, while respecting the dignity and
rights and individuality of all persons.

> > It's an ugly stereotype, not because it is a stereotype, but because
> > it embodies a set of ugly attitudes and behaviours.
>
> I am sure I have seen similar things written by various other people
> justifying their prejudices.

Prejudice on the basis of a person's innate traits has no place in civil
society.

Ideas are not people, and are not innate to the person who holds them.
An idea is not deserving of respect; that respect must not be assumed,
it must be earned.

More importantly, ideas inform behaviour. That is what makes robust
criticism of bad ideas so important.

Once an idea is expressed or demonstrated through behaviour, that idea
or behaviour is not innately deserving of respect, and it becomes fair
game for open criticism.

What we need to always keep in mind is that the *idea* should be
criticised, without attacking the *person*.

-- 
 \   “Value your freedom or you will lose it, teaches history. |
  `\ “Don't bother us with politics,” respond those who don't want |
_o__)to learn.” —Richard M. Stallman, 2002 |
Ben Finney

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


Re: All people deserve respect. Ideas are not people.

2017-04-02 Thread Michael Torrie
On 04/02/2017 05:10 PM, Ben Finney wrote:
> 
> Ideas are not people, and are not innate to the person who holds them.
> An idea is not deserving of respect; that respect must not be assumed,
> it must be earned.
> 
> More importantly, ideas inform behaviour. That is what makes robust
> criticism of bad ideas so important.
> 
> Once an idea is expressed or demonstrated through behaviour, that idea
> or behaviour is not innately deserving of respect, and it becomes fair
> game for open criticism.
> 
> What we need to always keep in mind is that the *idea* should be
> criticised, without attacking the *person*.

Very well said.  Thank you.

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


Re: All people deserve respect. Ideas are not people.

2017-04-02 Thread Michael Torrie
On 04/02/2017 06:00 PM, Alex Kaye wrote:
> Michael,  Thanks for your comment.
> 
> However, If one derails from the core subject
> 
> they need to be in another stream.  Alex

I think you'll find that the subject line was changed by Ben Finney to
reflect the new direction he was taking it, which is the usual and
expected list etiquette.  The change of subject line puts it in "another
stream" as you say.  Steve D'Aprano should have probably changed it a
long time ago. And of course RR should have been plonked by Steven and
others a long time ago also.  But I digress.

Again I am very glad Ben posted what he did and glad to show my support
for what he said, though it will likely fall on deaf ears.

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


Two variable dictionary comprehension

2017-04-02 Thread Deborah Swanson
It seems like this should be easy to rewrite as a dict comprehension:

records_idx = {}
for idx, label in enumerate(records[0]):
records_idx[label] = idx

Maybe I'm having another "dumb day", or maybe I've just been struggling
with this (larger) problem for too long, but eveything I try to get an
equivalent dict comprehension for the 3 lines above is not working.

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


Re: Two variable dictionary comprehension

2017-04-02 Thread Chris Angelico
On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson
 wrote:
> It seems like this should be easy to rewrite as a dict comprehension:
>
> records_idx = {}
> for idx, label in enumerate(records[0]):
> records_idx[label] = idx
>
> Maybe I'm having another "dumb day", or maybe I've just been struggling
> with this (larger) problem for too long, but eveything I try to get an
> equivalent dict comprehension for the 3 lines above is not working.

Should be this:

records_idx = {label: idx for idx, label in enumerate(records[0])}

That's a direct translation of your code.

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


Re: Two variable dictionary comprehension

2017-04-02 Thread Ben Finney
"Deborah Swanson"  writes:

> It seems like this should be easy to rewrite as a dict comprehension:
>
> records_idx = {}
> for idx, label in enumerate(records[0]):
> records_idx[label] = idx

How about this::

records_idx = {
label: idx
for (idx, label) in enumerate(collection_of_labels)
}

You may have tripped on the ambiguity of the comma in its surrounding
context. I always prefer to put parens around the items I intend to be
comma-separated, to remove that ambiguity.

-- 
 \“[It's] best to confuse only one issue at a time.” —Brian W. |
  `\  Kernighan, Dennis M. Ritchie, _The C programming language_, 1988 |
_o__)  |
Ben Finney

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


RE: Two variable dictionary comprehension

2017-04-02 Thread Deborah Swanson
Chris Angelico wrote, on April 02, 2017 6:37 PM
> 
> On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson 
>  wrote:
> > It seems like this should be easy to rewrite as a dict 
> comprehension:
> >
> > records_idx = {}
> > for idx, label in enumerate(records[0]):
> > records_idx[label] = idx
> >
> > Maybe I'm having another "dumb day", or maybe I've just been 
> > struggling with this (larger) problem for too long, but eveything I 
> > try to get an equivalent dict comprehension for the 3 lines above is

> > not working.
> 
> Should be this:
> 
> records_idx = {label: idx for idx, label in enumerate(records[0])}
> 
> That's a direct translation of your code.
> 
> ChrisA

Well, wouldncha know it, I never tried using a colon. That's what I get
for just trying to guess.

Thanks Chris

Deborah

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


RE: Two variable dictionary comprehension

2017-04-02 Thread Deborah Swanson
Ben Finney wrote, on April 02, 2017 6:38 PM
> 
> "Deborah Swanson"  writes:
> 
> > It seems like this should be easy to rewrite as a dict 
> comprehension:
> >
> > records_idx = {}
> > for idx, label in enumerate(records[0]):
> > records_idx[label] = idx
> 
> How about this::
> 
> records_idx = {
> label: idx
> for (idx, label) in enumerate(collection_of_labels)
> }
> 
> You may have tripped on the ambiguity of the comma in its 
> surrounding context. I always prefer to put parens around the 
> items I intend to be comma-separated, to remove that ambiguity.
> 
> -- 
>  \"[It's] best to confuse only one issue at a time." 
> -Brian W. |
>   `\  Kernighan, Dennis M. Ritchie, _The C programming 
> language_, 1988 |
> _o__) 
>  |
> Ben Finney

That's a neat way to think about the problem. Me, I was guessing all the
way, and pleasantly surprised when the 3-statement concoction I came up
with worked.

Thanks Ben!

Deborah

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


Re: Two variable dictionary comprehension

2017-04-02 Thread Ben Finney
"Deborah Swanson"  writes:

> Chris Angelico wrote, on April 02, 2017 6:37 PM
> > 
> > On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson 
> > > Maybe I'm having another "dumb day" […]
>
> Well, wouldncha know it, I never tried using a colon. That's what I
> get for just trying to guess.

Yes, guessing *is* dumb when the reference documentation is available
https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries>.
I was sure you'd have been reading the manual before guessing, but I'll
know better in future :-)

-- 
 \   “A computer once beat me at chess, but it was no match for me |
  `\ at kick boxing.” —Emo Philips |
_o__)  |
Ben Finney

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


Traversal help

2017-04-02 Thread R. Bryan Smith
Hello,

I am working with Python 3.6.  I’ve been trying to figure out a solution to my 
question for about 40 hrs with no success and hundreds of failed attempts.  
Essentially, I have bitten off way more than I can chew with processing this 
file.  Most of what follows, is my attempt to inform as best I can figure.

I have a JSONL (new line) file that I downloaded using requests and the 
following code: 
with open(fname, 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024):
fd.write(chunk)

The file was in gzip format (the encoding on the API says - UTF-8) to a windows 
8 (it’s current, but 8) machine.
These files are rather large, maybe around 4GB.
I used the ‘shebang' for ‘UTF-8’ at the top of my Python program: # -*- 
encoding: utf-8 -*-

After I save the file, I read it using this:
def read_json(path):
'''Turns a normal json LINES (cr) file into an array of objects'''
temp_array = []
f = codecs.open(path, 'r', 'utf-8', ‘backslashreplace')
for line in f:
record = json.loads(line.strip('\n|\r'))
temp_array.append(record)
return temp_array

I am working on a Linux server to partitioning the List returned above, there 
are three linked levels of detail (A, B, C) that can exist in any collection 
within the JSON and each Collection can contain wildly varying and/or repeating 
fields.  The data contained within is scraped from websites all over the world. 
 I wanted to ‘traverse' the file structure and found an algorithm that I think 
will work:

def traverser(obj, path=None, callback=None):
if path is None:
path = []

if isinstance(obj, dict):
value = {k: traverser(v, path+[k], callback)
 for k, v in obj.items()}
elif isinstance(obj, list):
value = [traverser(elem, path+[[]], callback)
 for elem in obj]
else:
value = obj

if callback is None:
return value
else:
return callback(path, value)

The only problem and the subsequent question that follows is:  I have yet to 
successfully decode / How do I then ‘collect’ each of these objects while I am 
traversing the JSON New Line Collection into some sort of container (handling 
encoding errors) so that I can then write to a csv file (w/ ‘utf-8’ and won’t 
error out when I try to import it into a IBM ‘utf-8’ encoded DB)?  Actually, 
after that, I would like to learn how to grab a specific element, if present in 
each Collection, whenever I need it, as well - but, that can wait.

I’ve tried using the JSON module on the JSONL file, but the structure is really 
complicated and changing with lot’s of different control and spacing 
characters, in addition to some odd (potentially non-unicode characters).  
Here’s the schema: http://json-schema.org/fraft-04/schema# 
 

I’m not a programmer, but I am learning through assimilation.  Any help is 
greatly appreciated.  Even if it’s pointing me to documentation that can help 
me learn what to consider and lead me to what to do.  

Thank you,
R. Smith

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


Behavior of auto in Enum and Flag.

2017-04-02 Thread Oren Ben-Kiki
The current behavior of `auto` is to pick a value which is one plus the
previous value.

It would probably be better if `auto` instead picked a value that is not
used by any named member (either the minimal unused value, or the minimal
higher than the previous value). That is, in this simple case:

class MyEnum(Enum):
FOO = 1
BAR = auto()
BAZ = 2

It would be far better for BAR to get the value 3 rather than today's value
2.

In the less simple case of:

class MyEnum(Enum):
FOO = 2
BAR = auto()
BAZ = 3

Then BAR could be either 1 or 4 - IMO, 1 would be better, but 4 works as
well.

After all, `auto` is supposed to be used when:

"If the exact value is unimportant you may use auto instances and an
appropriate value will be chosen for you."

Choosing a value that conflicts with BAZ in above cases doesn't seem
"appropriate" for a value that is "unimportant".

The docs also state "Care must be taken if you mix auto with other values."
- fair enough. But:

First, why require "care" if the code can take care of the issue for us?

Second, the docs don't go into further detail about what exactly to avoid.
In particular, the docs do not state that the automatic value will only
take into account the previous values, and will ignore following values.

However, this restriction is baked into the current implementation:
It is not possible to just override `_generate_next_value_` to skip past
named values which were not seen yet, because the implementation only
passes it the list of previous values.

I propose that:

1. The documentation will be more explicit about the way `auto` behaves in
the presence of following values.

2. The default behavior of `auto` would avoid generating a conflict with
following values.

3. Whether `auto` chooses (A) the minimal unused value higher than the
previous value, or (B) the minimal overall unused value, or (C) some other
strategy, would depend on the specific implementation.

3. To allow for this, the implementation will include a
`_generate_auto_value_` which will take both the list of previous ("last")
values (including auto values) and also a second list of the following
("next") values (excluding auto values).

4. If the class implements `_generate_next_value_`, then
`_generate_auto_value_` will invoke `_generate_next_value_` with the
concatenation of both lists (following values first, preceding values
second), to maximize compatibility with existing code.

Thanks,

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


RE: Two variable dictionary comprehension

2017-04-02 Thread Deborah Swanson
Ben Finney wrote. on April 02, 2017 7:41 PM
> 
> "Deborah Swanson"  writes:
> 
> > Chris Angelico wrote, on April 02, 2017 6:37 PM
> > > 
> > > On Mon, Apr 3, 2017 at 11:26 AM, Deborah Swanson
> > > > Maybe I'm having another "dumb day" [.]
> >
> > Well, wouldncha know it, I never tried using a colon. That's what I 
> > get for just trying to guess.
> 
> Yes, guessing *is* dumb when the reference documentation is 
> available 
> https://docs.python.org/3/reference/expressions.html#disp
> lays-for-lists-sets-and-dictionaries>.
> I was sure you'd have been reading the manual before 
> guessing, but I'll know better in future :-)
> 
> -- 
>  \   "A computer once beat me at chess, but it was no 
> match for me |
>   `\ at kick boxing." 
> -Emo Philips |
> _o__) 
>  |
> Ben Finney
> 

Oh, come on. That's a fairly obscure citation in the docs, one that
would take a good deal of experience and time reading through them to
know was there, experience and years with Python that I don't have. But
you knew that ... ;)

Deborah

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


Re: Behavior of auto in Enum and Flag.

2017-04-02 Thread Chris Angelico
On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki  wrote:
> "If the exact value is unimportant you may use auto instances and an
> appropriate value will be chosen for you."
>
> Choosing a value that conflicts with BAZ in above cases doesn't seem
> "appropriate" for a value that is "unimportant".
>
> The docs also state "Care must be taken if you mix auto with other values."
> - fair enough. But:
>
> First, why require "care" if the code can take care of the issue for us?
>
> Second, the docs don't go into further detail about what exactly to avoid.
> In particular, the docs do not state that the automatic value will only
> take into account the previous values, and will ignore following values.

Sounds to me like the current behaviour is compliant with what the
docs say, and as such, I would be disinclined to change the code.
Perhaps a documentation clarification would suffice?

"""Care must be taken if you mix auto with other values. In
particular, using auto() prior to explicitly-set values may result in
conflicts."""

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


Re: Behavior of auto in Enum and Flag.

2017-04-02 Thread Oren Ben-Kiki
While "the current behaviour is compliant with what the docs say" is true,
saying "as such, I would be disinclined to change the code" misses the
point.

The current documentation allows for multiple behaviors. The current
implementation has an chosen to add an arbitrary undocumented restriction
on the behavior, which has a usability issue. Even worse, for no clear
reason, the current implementation forces _all_ implementations to suffer
from the same usability issue.

The proposed behavior is _also_ compliant with the current documentation,
and does not suffer from this usability issue. The proposed implementation
is compatible with existing code bases, and allows for "any" other
implementation to avoid this issue.

That is, I think that instead of enshrining the current implementation's
undocumented and arbitrary restriction, by explicitly adding it to the
documentation, we should instead remove this arbitrary restriction from the
implementation, and only modify the documentation to clarify this
restriction is gone.

Oren.

On Mon, Apr 3, 2017 at 8:38 AM, Chris Angelico  wrote:

> On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki 
> wrote:
> > "If the exact value is unimportant you may use auto instances and an
> > appropriate value will be chosen for you."
> >
> > Choosing a value that conflicts with BAZ in above cases doesn't seem
> > "appropriate" for a value that is "unimportant".
> >
> > The docs also state "Care must be taken if you mix auto with other
> values."
> > - fair enough. But:
> >
> > First, why require "care" if the code can take care of the issue for us?
> >
> > Second, the docs don't go into further detail about what exactly to
> avoid.
> > In particular, the docs do not state that the automatic value will only
> > take into account the previous values, and will ignore following values.
>
> Sounds to me like the current behaviour is compliant with what the
> docs say, and as such, I would be disinclined to change the code.
> Perhaps a documentation clarification would suffice?
>
> """Care must be taken if you mix auto with other values. In
> particular, using auto() prior to explicitly-set values may result in
> conflicts."""
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thread within for loop

2017-04-02 Thread dieter
Iranna Mathapati  writes:
> How to fix it and now i got below error for same script

Fixing "timeout" problems is (usually) not a Python question.

A "timeout" can have various reasons:

 * you make something fundamentally wrong - i.e. try to connect
   to something which is inaccessible (e.g. by "firewall" rules)

   You must check whether this is the case, e.g. by trying
   to access the server with other means as "pexpect".

 * the remote operation takes an extraordinary amount of time.

   You may need to adjust the "timeout" configuration used
   by the Python access library ("pexpect" in your case).
   Look at the documentation, to find out whether and how this
   is supported.

 * ...


> *runtimeerror threads can only be started once then*

Apparently, you try to start the same thread twice.
Create different "Thread" instances, instead.


> On Sat, Apr 1, 2017 at 1:15 PM, dieter  wrote:
>
>> Iranna Mathapati  writes:
>> > ...
>> > Exception in thread Thread-5:
>> > Traceback (most recent call last):
>> > ...
>> >   File
>> > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-
>> packages/pexpect/__init__.py",
>> > line 1466, in expect_list
>> > timeout, searchwindowsize)
>> >   File
>> > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-
>> packages/pexpect/__init__.py",
>> > line 1568, in expect_loop
>> > raise TIMEOUT(str(err) + '\n' + str(self))
>> > TIMEOUT: Timeout exceeded.
>>
>> "Timeout" means that the "pexpect" partner did not respond sufficiently
>> fast.
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>

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


Re: Two variable dictionary comprehension

2017-04-02 Thread Gregory Ewing

Deborah Swanson wrote:


Oh, come on. That's a fairly obscure citation in the docs, one that
would take a good deal of experience and time reading through them to
know was there,


You seemed to know that there was something called a "dict
comprehension". Googling for "python 3 dict comprehension"
gives me a link to an example of one in the docs as the
second result.

The first result is a page in Dive Into Python containing
a section on dict comprehensions.

Part of being a good programmer is knowing how to track
down the information you need!

Having said that, the index of the Python docs could be
improved a bit in this area -- currently it only mentions
"list" under "comprehension" (although the page it leads
to discusses the other types as well).

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