Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Gregory Ewing
Terry Reedy wrote: One of the ironies (or puzzles) of Guido's choice is that he once condemned Perl's 'value if cond' as wretched. I don't think that's the same thing. Perl allows 'statement if cond' as an alternative way of writing "if (cond) statement'. Nobody has ever seriously considered al

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
Ben Bacarisse writes: > Jussi Piitulainen writes: > >> BartC writes: >> >>> On 17/08/2016 07:39, Steven D'Aprano wrote: Rather than ask why Python uses `trueval if cond else falseval`, you should ask why C uses `cond ? trueval : falseval`. Is that documented anywhere? >>> >>> I'm no

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Gregory Ewing
Terry Reedy wrote: What the *current* version removed from an earlier version is that there was a clear community consensus against the condition-in-the-middle syntax Guido proposed The way I remember it, condition-in-the-middle was first suggested by others, and Guido expressed dislike for it

Re: The Joys Of Data-Driven Programming

2016-08-17 Thread Chris Angelico
On Thu, Aug 18, 2016 at 2:47 PM, Marko Rauhamaa wrote: > Lawrence D’Oliveiro : > >> Solution: set up a table of rules > > Without judging the individual merits of rules for your use case, I just > want to mention that as a rule, I dislike rules. Rule languages tend to > grow out of all bounds, alw

Re: Why monkey patching on module object doesn't work ?

2016-08-17 Thread Ian Kelly
On Wed, Aug 17, 2016 at 10:14 PM, Shiyao Ma wrote: > Hi, > > I am using Python2. > > For the following snippet, > > http://ideone.com/i36pKO > > I'd suppose the dummy_func would be invoked, but seems not. > > Indeed, heapq.heapify does invoke cmp_lt per here: > https://hg.python.org/cpython/file/2

Re: The Joys Of Data-Driven Programming

2016-08-17 Thread Marko Rauhamaa
Lawrence D’Oliveiro : > Solution: set up a table of rules Without judging the individual merits of rules for your use case, I just want to mention that as a rule, I dislike rules. Rule languages tend to grow out of all bounds, always remain deficient and have impenetrable, ad-hoc semantics. Inst

Why monkey patching on module object doesn't work ?

2016-08-17 Thread Shiyao Ma
Hi, I am using Python2. For the following snippet, http://ideone.com/i36pKO I'd suppose the dummy_func would be invoked, but seems not. Indeed, heapq.heapify does invoke cmp_lt per here: https://hg.python.org/cpython/file/2.7/Lib/heapq.py#l136 So why this way of monkey patching failed? Reg

Re: type lookuperror

2016-08-17 Thread meInvent bbird
when try keystone_client.tenants.get got error, isn't this method for all kinds of function? >>> m = "4c9a0da00b904422a23341e35be7f8d7" >>> ten = checkexception(keystone_client.tenants.get, >>> tenant_id=checkexception(m.encode,encoding='ascii',errors='ignore')) Unexpected error: None On Th

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 12:55:33 PM UTC+12, Terry Reedy wrote: > > On 8/17/2016 7:13 PM, Lawrence D’Oliveiro wrote: > >> On Thursday, August 18, 2016 at 8:25:37 AM UTC+12, Terry Reedy wrote: >>> >>> for section_name, line_number in text.parser.toc: >>> def goto(line=li

The Joys Of Data-Driven Programming

2016-08-17 Thread Lawrence D’Oliveiro
Problem: let the user specify certain parameters for a screen display (width, height, diagonal, pixel density, pixels across, pixels down, optimum viewing distance) and from the ones specified, work out the parameters which were not specified. Solution: set up a table of rules

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Larry Hudson via Python-list
On 08/17/2016 04:24 AM, Jussi Piitulainen wrote: ... http://www-formal.stanford.edu/jmc/recursive/node2.html (the paper famously titled "Part I" without any Part II, unless I mistake much.) Totally OT here, but... This reminds me of a old record I have with the (deliberately tongue-in-cheek)

Re: type lookuperror

2016-08-17 Thread Chris Angelico
On Thu, Aug 18, 2016 at 12:13 PM, meInvent bbird wrote: > would like to check errors for every function i run, > got error type lookuperror > > def checkexception(func, **kwargs): > try: > result = func(*tuple(value for _, value in kwargs.iteritems())) > except: > print "Un

type lookuperror

2016-08-17 Thread meInvent bbird
would like to check errors for every function i run, got error type lookuperror def checkexception(func, **kwargs): try: result = func(*tuple(value for _, value in kwargs.iteritems())) except: print "Unexpected error:", sys.exc_info()[0] try: print(fun

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Terry Reedy
On 8/17/2016 7:13 PM, Lawrence D’Oliveiro wrote: On Thursday, August 18, 2016 at 8:25:37 AM UTC+12, Terry Reedy wrote: for section_name, line_number in text.parser.toc: def goto(line=line_number): text.yview(line) drop.add_command(label=sectio

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Chris Angelico
On Thu, Aug 18, 2016 at 9:13 AM, Dennis Lee Bieber wrote: > On Wed, 17 Aug 2016 18:52:22 +0100, MRAB > declaimed the following: > > >> >>If "p" points to a struct (record), then "*p" is that struct, and if >>that struct has a member (field) "m", then that member can be accessed >>by "(*p)->m" (th

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 8:25:37 AM UTC+12, Terry Reedy wrote: > > for section_name, line_number in text.parser.toc: > def goto(line=line_number): > text.yview(line) > drop.add_command(label=section_name, command=goto) You don’t think of t

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 6:28:06 AM UTC+12, Terry Reedy wrote: >> https://www.python.org/dev/peps/pep-0308/ > > What the *current* version removed from an earlier version is that there > was a clear community consensus against the condition-in-the-middle > syntax Guido proposed and for so

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 5:53:14 AM UTC+12, MRAB wrote: > C uses "->" for dereferencing a pointer to the member of a struct. The only reason why “s->f” was added was because “(*s).f” was considered an unwieldy thing to have to write all the time. And the only thing that made that unwield

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 6:28:06 AM UTC+12, Terry Reedy wrote: > >> Why couldn’t they have adopted the standard C >> syntax, as used in a whole bunch of other C-derivative languages? >> cond ? trueval : falseval > > That particular syntax was not really considered. At least 10

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Terry Reedy
On 8/17/2016 2:39 PM, Random832 wrote: On Wed, Aug 17, 2016, at 14:27, Terry Reedy wrote: That particular syntax was not really considered. At least 10 versions using 'if', 'then', 'else', and other tokens were. They all had the problem of requiring a new keyword such as 'then' or some other i

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Terry Reedy
On 8/17/2016 2:43 PM, Marko Rauhamaa wrote: Terry Reedy : On 8/17/2016 2:39 AM, Steven D'Aprano wrote: "If I finish work on on time, go to the movies, otherwise just go home." is also real English syntax, and to me, more graceful. It is certainly more neutral among the alternatives. The inver

Re: JSON confusion

2016-08-17 Thread Terry Reedy
On 8/17/2016 12:35 PM, Steve Simmons wrote: I'm trying to write a small utility to find the closest railway station to a given (UK) postcode but the result is in JSON and I'm not familiar with it. I've got as far as extracting the JSON object and I can print the first level elements ("success" an

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Ben Bacarisse
Jussi Piitulainen writes: > BartC writes: > >> On 17/08/2016 07:39, Steven D'Aprano wrote: >>> Rather than ask why Python uses `trueval if cond else falseval`, you >>> should ask why C uses `cond ? trueval : falseval`. Is that documented >>> anywhere? >> >> I'm not fond of C's a ? b : c but the p

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Ben Bacarisse
MRAB writes: > On 2016-08-17 18:19, Jussi Piitulainen wrote: >> MRAB writes: >> >>> On 2016-08-17 12:24, Jussi Piitulainen wrote: BartC writes: > On 17/08/2016 07:39, Steven D'Aprano wrote: >> Rather than ask why Python uses `trueval if cond else falseval`, you >> should ask

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Terry Reedy
On 8/17/2016 2:07 AM, Steven D'Aprano wrote: I realise that there are occasions where we might deliberate choose to assign an intermediate value to its own variable, but all else being equal, which would you prefer? #A alist = [] alist.append(2) alist.append(4) alist.append(8) process(alist) #

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Marko Rauhamaa
MRAB : > On 2016-08-17 19:39, Random832 wrote: >> Why not just if(cond, trueval, falseval), a la Visual Basic? > > Well, it looks too much like a function call, which don't > short-circuit. Well, in Scheme, everything looks like a function call: (define (deflate x) (if (> 0 x)

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread MRAB
On 2016-08-17 19:39, Random832 wrote: On Wed, Aug 17, 2016, at 14:27, Terry Reedy wrote: That particular syntax was not really considered. At least 10 versions using 'if', 'then', 'else', and other tokens were. They all had the problem of requiring a new keyword such as 'then' or some other in

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread MRAB
On 2016-08-17 19:00, Grant Edwards wrote: On 2016-08-17, MRAB wrote: C uses "->" for dereferencing a pointer to the member of a struct. If "p" points to a struct (record), then "*p" is that struct, and if that struct has a member (field) "m", then that member can be accessed by "(*p)->m" (the

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread MRAB
On 2016-08-17 18:58, Marko Rauhamaa wrote: MRAB : C uses "->" for dereferencing a pointer to the member of a struct. What "->" is for C, "." is Python and Java. Python doesn't have C's ".". C has both stacked-allocated and heap-allocated records. That's not the case with Python or Java.

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Marko Rauhamaa
Terry Reedy : > On 8/17/2016 2:39 AM, Steven D'Aprano wrote: > "If I finish work on on time, go to the movies, otherwise just go home." > is also real English syntax, and to me, more graceful. It is certainly > more neutral among the alternatives. The inverted version implies a > clear preferenc

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Random832
On Wed, Aug 17, 2016, at 14:27, Terry Reedy wrote: > That particular syntax was not really considered. At least 10 versions > using 'if', 'then', 'else', and other tokens were. > > They all had the problem of requiring a new keyword such as 'then' or > some other innovation. Why not just if(co

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Terry Reedy
On 8/17/2016 2:39 AM, Steven D'Aprano wrote: On Wednesday 17 August 2016 06:59, Lawrence D’Oliveiro wrote: Here are some examples of that varying mileage. Quote: The Python syntax for conditional expressions (i

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Grant Edwards
On 2016-08-17, MRAB wrote: > C uses "->" for dereferencing a pointer to the member of a struct. > > If "p" points to a struct (record), then "*p" is that struct, and if > that struct has a member (field) "m", then that member can be accessed > by "(*p)->m" (the parens are necessary because of t

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Marko Rauhamaa
MRAB : > C uses "->" for dereferencing a pointer to the member of a struct. What "->" is for C, "." is Python and Java. Python doesn't have C's ".". Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread MRAB
On 2016-08-17 18:19, Jussi Piitulainen wrote: MRAB writes: On 2016-08-17 12:24, Jussi Piitulainen wrote: BartC writes: On 17/08/2016 07:39, Steven D'Aprano wrote: Rather than ask why Python uses `trueval if cond else falseval`, you should ask why C uses `cond ? trueval : falseval`. Is that

Re: What's the best way to minimize the need of run time checks?

2016-08-17 Thread Michael Selik
On Sun, Aug 14, 2016 at 11:01 AM wrote: > On Sunday, August 14, 2016 at 7:09:47 AM UTC+1, Paul Rubin wrote: > > Steven D'Aprano writes: > > > If the Python community rallies around this "record" functionality and > > > takes to it like they took too namedtuple > > > > I like namedtuple and I thin

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
MRAB writes: > On 2016-08-17 12:24, Jussi Piitulainen wrote: >> BartC writes: >> >>> On 17/08/2016 07:39, Steven D'Aprano wrote: Rather than ask why Python uses `trueval if cond else falseval`, you should ask why C uses `cond ? trueval : falseval`. Is that documented anywhere? >>> >

Re: JSON confusion

2016-08-17 Thread Steve Simmons
On 17/08/2016 17:49, Jon Ribbens wrote: On 2016-08-17, Steve Simmons wrote: I'm trying to write a small utility to find the closest railway station to a given (UK) postcode but the result is in JSON and I'm not familiar with it. I've got as far as extracting the JSON object and I can print th

Re: JSON confusion

2016-08-17 Thread Jon Ribbens
On 2016-08-17, Steve Simmons wrote: > I'm trying to write a small utility to find the closest railway station > to a given (UK) postcode but the result is in JSON and I'm not familiar > with it. I've got as far as extracting the JSON object and I can print > the first level elements ("success"

JSON confusion

2016-08-17 Thread Steve Simmons
I'm trying to write a small utility to find the closest railway station to a given (UK) postcode but the result is in JSON and I'm not familiar with it. I've got as far as extracting the JSON object and I can print the first level elements ("success" and "result") but I've totally confused myse

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread MRAB
On 2016-08-17 12:24, Jussi Piitulainen wrote: BartC writes: On 17/08/2016 07:39, Steven D'Aprano wrote: Rather than ask why Python uses `trueval if cond else falseval`, you should ask why C uses `cond ? trueval : falseval`. Is that documented anywhere? I'm not fond of C's a ? b : c but the p

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Marko Rauhamaa
Grant Edwards : > On 2016-08-17, Marko Rauhamaa wrote: > >> Somewhat analogously, I remember how confusing it was to learn formal >> logic in college. I was having a hard time getting the point of >> definitions like: >> >>(x ∧ y) is true iff x is true and y is true >> >> That's because I had

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Grant Edwards
On 2016-08-17, Marko Rauhamaa wrote: > Somewhat analogously, I remember how confusing it was to learn formal > logic in college. I was having a hard time getting the point of > definitions like: > >(x ∧ y) is true iff x is true and y is true > > That's because I had learned in highschool that

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Marko Rauhamaa
"D'Arcy J.M. Cain" : > On Wed, 17 Aug 2016 16:39:30 +1000 > Steven D'Aprano wrote: >> cond ? trueval : falseval >> >> Because the C syntax is horrifically ugly, whereas the Python syntax >> is very close to real English syntax. > > Or, put another way, Python prefers English over line n

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread D'Arcy J.M. Cain
On Wed, 17 Aug 2016 16:39:30 +1000 Steven D'Aprano wrote: > cond ? trueval : falseval > > Because the C syntax is horrifically ugly, whereas the Python syntax > is very close to real English syntax. Or, put another way, Python prefers English over line noise. -- D'Arcy J.M. Cain Syste

Re: pystl

2016-08-17 Thread Peter Otten
Poul Riis wrote: > I tried the following: > > from pystl import PySTL > with PySTL('stl_test.stl') as stl: > stl.add_triangle((0,0,0),(1,0,0),(0,1,0)) > > I got the following error message: > > Traceback (most recent call last): > File > "C:/Users/pr/AppData/Local/Programs/Python/Pytho

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Sivan Greenberg
My first attempt at a large code base was with an Ubuntu project, the reason I learned Python was Ubuntu's sabdfl insisting on it be used throughout the OS (back in 2004 I was an Ubuntu developer contributing packages to main) . It was easy to get a job , but I started very early when there were n

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
BartC writes: > On 17/08/2016 07:39, Steven D'Aprano wrote: >> Rather than ask why Python uses `trueval if cond else falseval`, you >> should ask why C uses `cond ? trueval : falseval`. Is that documented >> anywhere? > > I'm not fond of C's a ? b : c but the principle is sound. I generally [- -]

Re: pystl

2016-08-17 Thread Steven D'Aprano
On Wednesday 17 August 2016 18:56, Poul Riis wrote: > I tried the following: > > from pystl import PySTL > with PySTL('stl_test.stl') as stl: > stl.add_triangle((0,0,0),(1,0,0),(0,1,0)) > > I got the following error message: Ah, bad news I am afraid. That looks like a bug in pystl. I don'

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread BartC
On 17/08/2016 07:39, Steven D'Aprano wrote: On Wednesday 17 August 2016 06:59, Lawrence D’Oliveiro wrote: [Quote] trueval if cond else falseval "Go to the movies, if I finish work on time, otherwise just go home." Is there /any/ programming language that uses a similar form? Apar

Re: pystl

2016-08-17 Thread Poul Riis
I tried the following: from pystl import PySTL with PySTL('stl_test.stl') as stl: stl.add_triangle((0,0,0),(1,0,0),(0,1,0)) I got the following error message: Traceback (most recent call last): File "C:/Users/pr/AppData/Local/Programs/Python/Python35-32/Lib/idlelib/pystl_module_test_1.py"

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Christian Gollwitzer
Am 17.08.16 um 08:39 schrieb Steven D'Aprano: Quote: The Python syntax for conditional expressions (introduced in Python 2.5) is trueval if cond else falseval I think this is bloody awful. Why couldn’t they have adopted the standard C syntax, as used in a whole bunch of oth