Re: "comprehend" into a single value

2017-10-07 Thread Andrew Z
and how about adding "IF" into the mix ? as in : a=0 dict= {10: ['a',1,'c'], 20: ['d',2,'f']} for i in dict: p+= 10 if dict[i][1] in [1,2,3,4,5] else 0 can i "squish" "for" and "if" together ? or will it be too perl-ish ? On Sun, Oct 8, 2017 at 12:37 AM, Andrew Z wrote: > Nathan, Bob

Re: "comprehend" into a single value

2017-10-07 Thread Andrew Z
Nathan, Bob - on the money. Thank you ! On Sat, Oct 7, 2017 at 11:30 PM, bob gailer wrote: > On 10/7/2017 11:17 PM, Nathan Hilterbrand wrote: > >> dict= {10: ['a',1,'c'], 20: ['d',2,'f']} >> p = sum([dict[i][1] for i in dict]) >> >> Something like that? >> > Ah, but that's 2 lines. > > sum(val[1

Re: "comprehend" into a single value

2017-10-07 Thread bob gailer
On 10/7/2017 11:17 PM, Nathan Hilterbrand wrote: dict= {10: ['a',1,'c'], 20: ['d',2,'f']} p = sum([dict[i][1] for i in dict]) Something like that? Ah, but that's 2 lines. sum(val[1] for val in  {10: ['a',1,'c'], 20: ['d',2,'f']}.values()) On Sat, Oct 7, 2017 at 11:07 PM, Andrew Z wrote: He

Re: "comprehend" into a single value

2017-10-07 Thread Nathan Hilterbrand
dict= {10: ['a',1,'c'], 20: ['d',2,'f']} p = sum([dict[i][1] for i in dict]) Something like that? On Sat, Oct 7, 2017 at 11:07 PM, Andrew Z wrote: > Hello, > i wonder how can i accomplish the following as a one liner: > > dict= {10: ['a',1,'c'], 20: ['d',2,'f']} > p = 0 > for i in dict: >

Re: Introducing the "for" loop

2017-10-07 Thread Steve D'Aprano
On Sun, 8 Oct 2017 03:58 am, Terry Reedy wrote: > No built-in function is an instance of FunctionType > >>> isinstance(compile, FunctionType) > False Ah yes, thanks Terry, I forgot that builtin functions have a distinct type. [...] > FunctionType == function defined by def statement or lambda

"comprehend" into a single value

2017-10-07 Thread Andrew Z
Hello, i wonder how can i accomplish the following as a one liner: dict= {10: ['a',1,'c'], 20: ['d',2,'f']} p = 0 for i in dict: p += dict[i][1] Thank you -- https://mail.python.org/mailman/listinfo/python-list

Re: django project avoid reload page where work algorithm

2017-10-07 Thread MRAB
On 2017-10-08 01:40, Xristos Xristoou wrote: I have a website where the user can be put three numbers on my html template and get some results from my personal mathematical algorithm. the result save at user personal table on my database and can see in specific tab in my website. my problem is

django project avoid reload page where work algorithm

2017-10-07 Thread Xristos Xristoou
I have a website where the user can be put three numbers on my html template and get some results from my personal mathematical algorithm. the result save at user personal table on my database and can see in specific tab in my website. my problem is where the algorithm to calculate result maybe t

Re: Lies in education [was Re: The "loop and a half"]

2017-10-07 Thread Richard Damon
On 10/4/17 11:22 PM, Steve D'Aprano wrote: The A and E in the word "are" are not vowels, since they are silent. The A is clearly not silent, unless you have some strange pronunciation. The fact that are is pronounced just like the NAME of the letter R doesn't mean it is silent. Compare the

Finding Old Posts on Python

2017-10-07 Thread Cai Gengyang
Hello, Does anyone know of a way to find all my old posts about Python ? Thanks a lot! GengYang -- https://mail.python.org/mailman/listinfo/python-list

Re: Lies in education [was Re: The "loop and a half"]

2017-10-07 Thread Pavol Lisy
On 10/5/17, Steve D'Aprano wrote: > The A and E in the word "are" are not vowels, since they are silent. Interesting! :) Is then R (half?) silent in word "Brazil"? -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating a Dictionary

2017-10-07 Thread Pavol Lisy
On 10/5/17, Chris Angelico wrote: > On Thu, Oct 5, 2017 at 12:24 PM, Stefan Ram wrote: >> One might wish to implement a small language with these commands: >> >> F - move forward >> B - move backward >> L - larger stepsize >> S - smaller stepsize >> >> . One could start with the following pse

Re: Introducing the "for" loop

2017-10-07 Thread Chris Angelico
On Sun, Oct 8, 2017 at 3:58 AM, Terry Reedy wrote: > No built-in function is an instance of FunctionType isinstance(compile, FunctionType) > False isinstance(print, FunctionType) > False type(compile) > type(int.bit_length) > > > > FunctionType == function defined by def stat

Re: exception should not stop program.

2017-10-07 Thread MRAB
On 2017-10-07 17:38, Prabu T.S. wrote: I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first checkServiceStatus('Tomcat9') has any exception.Please advice.Second function invocation not getting executed if any exception occurs in

Re: exception should not stop program.

2017-10-07 Thread Grant Edwards
On 2017-10-07, Jorge Gimeno wrote: > Catching all exceptions in a try-except block is almost always a bad > idea. Catching it and ignoring it as the OP was doing (or assuming it's some particular exception) certainly is. If you know (or suspect) that stderr isn't going anywhere that it will be

Re: The "loop and a half"

2017-10-07 Thread Terry Reedy
On 10/7/2017 10:45 AM, Grant Edwards wrote: On 2017-10-07, bartc wrote: Interactive Python requires quit() or exit(), complete with parentheses. Nonsense. On Unix you can just press ctrl-D (or whatever you have configured as eof) at the command prompt. On windows, it's Ctrl-Z . IDLE's she

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 17:28, Steve D'Aprano wrote: On Sun, 8 Oct 2017 01:15 am, bartc wrote: You do remember this was about using programs /like/ sort as a model for writing true interactive scrolling text apps? I don't remember any such thing. I remember you *claiming* that, but if anyone actually

Re: Introducing the "for" loop

2017-10-07 Thread Terry Reedy
On 10/7/2017 5:09 AM, Steve D'Aprano wrote: On Fri, 6 Oct 2017 11:44 pm, ROGER GRAYDON CHRISTMAN wrote: Despite the documentation, I would still be tempted to say that range is a function. Taking duck-typing to the meta-level, every time I use range, I use its name followed by a pair of parenth

Re: exception should not stop program.

2017-10-07 Thread Jorge Gimeno
Catching all exceptions in a try-except block is almost always a bad idea. You can't tell the difference between an exception that you are looking to handle and an exception that should cause your program to crash and burn (because something is wrong). It's best to catch a specific exception. What

Re: The "loop and a half"

2017-10-07 Thread Grant Edwards
On 2017-10-07, Steve D'Aprano wrote: > sort *could* detect when it is reading from stdin interactively and give an > introductory message. There are some command-line utilities that try to do that: they modify their behavior when they think that stdin or stdout is connected to a "terminal" inste

Re: exception should not stop program.

2017-10-07 Thread Prabu T.S.
On Saturday, October 7, 2017 at 12:38:11 PM UTC-4, Prabu T.S. wrote: > I would like to continue to second function invocation > "checkServiceStatus('AdobeARMservice')" even if the first >checkServiceStatus('Tomcat9') has any exception.Please advice.Second > function invocation not getting e

exception should not stop program.

2017-10-07 Thread Prabu T.S.
I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first checkServiceStatus('Tomcat9') has any exception.Please advice.Second function invocation not getting executed if any exception occurs in first.Please advice. import psutil def

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sun, 8 Oct 2017 01:15 am, bartc wrote: > On 07/10/2017 14:19, Steve D'Aprano wrote: >> On Sat, 7 Oct 2017 11:06 pm, bartc wrote: > >>> So I have to copy 33,000 lines from a document, >> >> Don't be daft. Nobody says that stdin is a sufficient interface for a >> heavy-weight task like that. Wi

Re: The "loop and a half"

2017-10-07 Thread Michael Torrie
On 10/06/2017 07:24 AM, bartc wrote: > On 06/10/2017 14:11, Peter J. Holzer wrote: >> I regularly use at least cat, wc and od this way (plus a few of my own >> utilities like utf8dump). I'm sure I've used sort this way, too, though >> rather rarely. I usually don't type the input but paste it in, >

Re: The "loop and a half"

2017-10-07 Thread Chris Angelico
On Sun, Oct 8, 2017 at 2:06 AM, bartc wrote: > On 07/10/2017 15:45, Grant Edwards wrote: >> Admit it, you're just trolling. > > FFS, NOW what's wrong? > > IF you DO redefine those names, then you DO have to use other means to > terminate. I happen to call those means 'crashing out', because it's l

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sun, 8 Oct 2017 12:49 am, bartc wrote: > On 07/10/2017 14:19, Steve D'Aprano wrote: >> On Sat, 7 Oct 2017 11:06 pm, bartc wrote: > >> Ctrl-K to enter "operate on selected text" mode; >> Y to Delete >> Ctrl-K to enter "operate on selected text" mode; >> R to Read from a file (at last an actual

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 15:45, Grant Edwards wrote: On 2017-10-07, bartc wrote: Interactive Python requires quit() or exit(), complete with parentheses. Nonsense. On Unix you can just press ctrl-D (or whatever you have configured as eof) at the command prompt. On windows, it's Ctrl-Z . Steve spoke

Re: The "loop and a half"

2017-10-07 Thread eryk sun
On Sat, Oct 7, 2017 at 1:06 PM, bartc wrote: > > So I have to copy 33,000 lines from a document, get to the terminal (keeping > that document open because I'm not done with it), start 'sort', and paste > those 33,000 lines into the console, then type Ctrl-D. Which then promptly > prints the newly

Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]

2017-10-07 Thread Grant Edwards
On 2017-10-07, Steve D'Aprano wrote: > They're probably to busy re-doing working programs from scratch every > few versions, with a brand new "improved" UI (almost invariably > including a kool new design that uses light grey text on an ever so > slightly lighter grey background) Yes! That! >

Re: The "loop and a half"

2017-10-07 Thread Grant Edwards
On 2017-10-07, bartc wrote: > Interactive Python requires quit() or exit(), complete with parentheses. Nonsense. On Unix you can just press ctrl-D (or whatever you have configured as eof) at the command prompt. On windows, it's Ctrl-Z . > Unless you've redefined quit and exit as something else

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 11:54 pm, bartc wrote: > So my programs that use Escape on Windows needed > to use Escape Escape on Linux to get around that. Or you could just follow the expected Unix interface instead of inventing your own. Back in the days when I used a Mac (long before OS X), I used to

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 14:19, Steve D'Aprano wrote: On Sat, 7 Oct 2017 11:06 pm, bartc wrote: So I have to copy 33,000 lines from a document, Don't be daft. Nobody says that stdin is a sufficient interface for a heavy-weight task like that. With 33000 lines of text, I absolutely would save them to a

python multiprocessing

2017-10-07 Thread Xristos Xristoou
I have three functions in the python that each one puts an image (image path) as input and makes a simple image processing and creates a new image (image path) as output. in the example below, one function depends on the other, ie: the function of alg2 takes as input the image that generates the

Re: callable values

2017-10-07 Thread Thomas Jollans
On 07/10/17 01:58, Steve D'Aprano wrote: > On Sat, 7 Oct 2017 03:25 am, Stefan Ram wrote: > >> FWIW, in my course notes, I have coined a special word for >> this: >> >> A /prelate/ (German: "Prälat") is a callable value (object). > > In English, prelate is a kind of priest, a senior clergyman

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 14:19, Steve D'Aprano wrote: On Sat, 7 Oct 2017 11:06 pm, bartc wrote: Ctrl-K to enter "operate on selected text" mode; Y to Delete Ctrl-K to enter "operate on selected text" mode; R to Read from a file (at last an actual mnemonic command!) enter a file name That's five steps.

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 11:06 pm, bartc wrote: > That's not entering the data interactively (such as typing 'sort' then > it sits silently recording lines of text (you hope) until it sees EOF). I manually hit paste, that's just as much a form of data entry as typing characters one at a time. And then

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 09:35, Steve D'Aprano wrote: On Sat, 7 Oct 2017 11:05 am, bartc wrote: Um, that actually follows what interactive Python does. What is "that" to which you refer? If you mean, "what I, Bart C, suggested, namely having the program exit on a blank line", then you are wrong. In t

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 03:18, Chris Angelico wrote: On Sat, Oct 7, 2017 at 12:50 PM, Steve D'Aprano wrote: On Sat, 7 Oct 2017 06:21 am, Chris Angelico wrote: I'm not sure what printing to a window or image would mean, or how it's useful, but sure. Print to window: Print Preview. Print to image: exp

Re: The "loop and a half"

2017-10-07 Thread bartc
On 07/10/2017 02:46, Steve D'Aprano wrote: On Sat, 7 Oct 2017 06:18 am, bartc wrote: For sort, there is no real need. You use a text editor to create your data. Then use existing file-based sort. What you mean is, *you* see no need for sorting interactively, or sorting as part of a pipeline o

Re: Warnings (was Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"])

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 12:09 pm, Chris Angelico wrote: > So the question is: is it right for a library to raise > console warnings like that? Under what circumstances and to what > destinations should a library report on potential problems? Of course they should -- and applications should be free to

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 07:01 am, bartc wrote: > On 06/10/2017 20:38, Grant Edwards wrote: >> On 2017-10-06, bartc wrote: >> >>> For sort, there is no real need. You use a text editor to create >>> your data. Then use existing file-based sort. >> >> I sort streams on stdin far more often than I sort

Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]

2017-10-07 Thread Terry Reedy
On 10/6/2017 8:19 PM, Steve D'Aprano wrote: On Sat, 7 Oct 2017 05:33 am, Grant Edwards wrote: On 2017-10-06, Marko Rauhamaa wrote: The reason a daemon usually opens dummy file descriptors for the 0, 1 and 2 slots is to avoid accidents. Some library might assume the existence of those file de

Re: Introducing the "for" loop

2017-10-07 Thread Steve D'Aprano
On Fri, 6 Oct 2017 11:44 pm, ROGER GRAYDON CHRISTMAN wrote: > Despite the documentation, I would still be tempted to say that range is a > function. > Taking duck-typing to the meta-level, every time I use range, I use its name > followed > by a pair of parentheses enclosing one to three parameter

Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 12:12 am, Paul Moore wrote: > What really bugs me is colour settings that default to dark blues on > a black background. Amen to that! Between the very low contrast, and the stereopsis whereby blues appear to recede into the distance (and bright red pull forward, appearing to

Re: The "loop and a half"

2017-10-07 Thread Steve D'Aprano
On Sat, 7 Oct 2017 11:05 am, bartc wrote: > On 07/10/2017 00:43, Steve D'Aprano wrote: >> On Sat, 7 Oct 2017 12:24 am, bartc wrote: >> >>> print ("Enter blank expression to quit.") >> >> >> I *despise* programs that do that, and would cheerfully and >> unapologetically take their designers, dis