Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
Thank you for the advice everyone. > > The first thing to try is find every place where you update myMax, and This was actually where I was going wrong. I was setting max but then overwriting it with item. Then kept checking item only to return myMax. I went looking for other solutions as I th

Re: immutability is not strictly the same as having an unchangeable value, it is more subtle

2019-04-18 Thread Gregory Ewing
Arup Rakshit wrote: What protocols I need to learn, to define a custom immutable class ? That depends on how strictly you want to enforce immutability. The easiest thing is not to enforce it at all and simply refrain from mutating it. This is very often done. You can provide some protection a

Re: Function to determine list max without itertools

2019-04-18 Thread Chris Angelico
On Thu, Apr 18, 2019 at 5:41 PM Sayth Renshaw wrote: > > Thank you for the advice everyone. > > > > > The first thing to try is find every place where you update myMax, and > > This was actually where I was going wrong. I was setting max but then > overwriting it with item. Then kept checking ite

Re: immutability is not strictly the same as having an unchangeable value, it is more subtle

2019-04-18 Thread Chris Angelico
On Thu, Apr 18, 2019 at 6:16 PM Gregory Ewing wrote: > > Arup Rakshit wrote: > > What protocols I need to > > learn, to define a custom immutable class ? > > That depends on how strictly you want to enforce immutability. > > The easiest thing is not to enforce it at all and simply refrain > from m

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Gregory Ewing
DL Neil wrote: Thus the basic question: why do we (apparently) so seldom consider the possibility of an ImportError? Because the cases in which we can do something useful about it are relatively rare. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-18 Thread MRAB
On 2019-04-18 08:39, Sayth Renshaw wrote: Thank you for the advice everyone. The first thing to try is find every place where you update myMax, and This was actually where I was going wrong. I was setting max but then overwriting it with item. Then kept checking item only to return myMax.

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Wed, 17 Apr 2019, Sayth Renshaw wrote: Apologies I don't know the answer but went looking. This guide should answer the question. Didn't know it was so difficult to be honest. https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#example-directory-structure Then there

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Thu, 18 Apr 2019, dieter wrote: Python knows about 2 kinds of "regular" imports: absolute ones and relative ones. "Absolute" imports are guided by "sys.path" -- in the simple case, a sequence of folders containing modules and/or pacakges. Relative imports are guided in a similar way by the cu

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Grant Edwards
On 2019-04-18, DL Neil wrote: > On 18/04/19 8:44 AM, Grant Edwards wrote: >> On 2019-04-17, DL Neil wrote: >> >>> Do you bother with exception handling for import statements? >> >> Sometimes. There are two cases when I do that: >> >> 1. When the module has different names under Python2 and

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
DL Neil writes: > On 18/04/19 8:44 AM, Grant Edwards wrote: > > 2. When the program can still do something useful (if perhaps > > feature-limited) without the imported module by substituting > > something else in its place. > > Any (publishable) examples? One of the targets my RSS fet

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 1:36 AM Akkana Peck wrote: > One example: there are a gazillion whois modules, and when I run my > domaincheck program on a machine where I haven't yet installed > whois, it's helpful to have a reminder of which one I should > install. (Of course, if you have one of the oth

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Manolo Martínez
On 2019-04-17, DL Neil wrote: > 2. When the program can still do something useful (if perhaps > feature-limited) without the imported module by substituting > something else in its place. Isn't this a very common scenario, similar to what package management systems call "optional de

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Rhodri James
On 18/04/2019 17:10, Manolo Martínez wrote: On 2019-04-17, DL Neil wrote: 2. When the program can still do something useful (if perhaps feature-limited) without the imported module by substituting something else in its place. Isn't this a very common scenario, similar to what

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes: > I write this as: > > import whois # ImportError? pip install python-whois [ ... ] > it means that normal exception handling is still > happening (which might be important if I import this into something > else), plus it's printing the message to stderr rather than stdout [

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 2:46 AM Akkana Peck wrote: > > Chris Angelico writes: > > I write this as: > > > > import whois # ImportError? pip install python-whois > [ ... ] > > it means that normal exception handling is still > > happening (which might be important if I import this into something > >

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes: > Actually, only the Python interpreter has to be able to do those > steps. That's why I put the comment *on the same line* as the import > statement (not immediately above it, for instance). It comes out like > this: > > (env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.

Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 3:27 AM Akkana Peck wrote: > > Chris Angelico writes: > > Actually, only the Python interpreter has to be able to do those > > steps. That's why I put the comment *on the same line* as the import > > statement (not immediately above it, for instance). It comes out like > >

[no subject]

2019-04-18 Thread trisha guillot
-- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
> > > It's still overly complicated. > This is where I have ended up. Without itertools and max its what I got currently. def maximum(listarg): myMax = listarg[0] for item in listarg: for i in listarg[listarg.index(item)+1:len(listarg)]: if myMax < i:

Re: Function to determine list max without itertools

2019-04-18 Thread Rob Gaddi
On 4/18/19 4:35 PM, Sayth Renshaw wrote: It's still overly complicated. This is where I have ended up. Without itertools and max its what I got currently. def maximum(listarg): myMax = listarg[0] for item in listarg: for i in listarg[listarg.index(item)+1:len(li

Re: Function to determine list max without itertools

2019-04-18 Thread Grant Edwards
On 2019-04-18, Rob Gaddi wrote: > On 4/18/19 4:35 PM, Sayth Renshaw wrote: > >> This is where I have ended up. Without itertools and max its what I got >> currently. >> >> def maximum(listarg): >> myMax = listarg[0] >> for item in listarg: >> for i in listarg[listarg.index(ite

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
> > In English rather than Python, how do you find the maximum element in a > list? > > -- > Rob Gaddi, Highland Technology Get first 1 item in the list and compare it to the rest. If it is larger than rest its the max. However if another list member is larger it replaces the first item a

Re: Function to determine list max without itertools

2019-04-18 Thread DL Neil
On 19/04/19 5:22 PM, Sayth Renshaw wrote: In English rather than Python, how do you find the maximum element in a list? -- Rob Gaddi, Highland Technology Get first 1 item in the list and compare it to the rest. If it is larger than rest its the max. However if another list member is larger