Re: Odd truth result with in and ==

2018-11-21 Thread DL Neil

Serhiy,

On 22/11/18 10:50, Serhiy Storchaka wrote:

21.11.18 22:17, Cameron Simpson пише:
Can someone show me a real world, or failing that - sane looking, 
chained comparison using "in"?


     s[0] == s[-1] in '\'"'

Tests that string s starts and ends with a single or double quote.



Am admiring this solution. Don't most people resort immediately to 
regular expressions?


Did you just 'come up with' this idea, or have you performed any testing 
to say that this is the most efficient/not too much more expensive...?


--
Please advise =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: What Python books to you recommend to beginners?

2018-12-03 Thread DL Neil

Songbird,



[post ok'd by them]


=this time I've remembered to hit ReplyAll. Duh!



There are plenty of Python books 'about'. Beyond the 'basics' they tend to
become more topical, eg Scientific, Financial, Data Analysis... so what
suits you might not me.


   i'm pretty well read so i can adapt to a lot of
subject matters as long as the concepts are geared
towards what i'm after.  a solid example is a good
thing as long as it covers the concepts - the
problem i usually have with many examples though is
that they are too simplistic to be interesting enough
but that's just me being picky.  ha...


=yes and no (and nothing to do with you, personally).

=firstly, various specialist areas do tend towards their own 
sub-culture. For (trivial) example, data analysis, statistics, and 
(obviously) pure math guys will tend towards 'algebra', whereas more 
commercial folk preach the virtues of longer, more meaningful object naming.


=secondly, Python has such wide application that there are whole swathes 
of the PSL which people don't use/don't find relevant. Another trivial 
example: 'control' applications and file-based data analysis have little 
use for GUI programming.


=However, some flexibility in your skill set is a strong selling-point; 
so your aim of being "well read" is exactly right (IMHO).




Your question is rather broad and open-ended. Do you have access to a decent
library? What is available there? Have you looked at the various free
books/downloads and YouTube subscriptions? Happy reading!


   i do have access to a library and it is connected to
the rest of the state and country if i can't get any
of the mentioned items within the network.  though i
much prefer an electronic copy because the amount of
time it may take me to get through a longer text.


=conversely, I prefer the written (?printed) word for non-fiction and 
reserve eBooks almost entirely for fiction. At first I put that down to 
being a grumpy, old man - we who grew up with books can re-locate 
material by remembering roughly how far 'down' the book, whether on the 
left or right sheet, and perhaps even its proximity to a certain 
diagram/picture. Presumably eBook users (from birth) develop similar, 
yet quite different strategies. In a somewhat ironic twist, recent 
research suggests that even the 'digerati' are finding similarly, and 
asking for 'dead trees' over 'electrons'. So, what would I know?


=Like you, I am blessed with a library system that regards all of its 
libraries as holding a common (and most importantly, user-searchable) 
book stock (for free). There is also a nation-wide library inter-loan 
system (payable). Then there is access to universities' libraries, 
although most would only have borrowing rights at one (involves travel 
in my case). So, when tackling a new topic, I order one or two books, 
then when they arrive, one or two more - thus the later 'latency' period 
is absorbed by my devouring the first set! (and my aberrant greed not 
too obvious - I hope) However, the library idea would work so much 
better if everyone else just left-alone all the books I want, when I 
want them...



=Another thought: it's not a "book" but some/most enjoy Raymond 
Hettinger's talks, available from various PyCon sites/YouTube. He 
specialises in showing the smart techniques that I think you seek/will 
enjoy learning.


=Similarly, in following the various python.org mailing lists I note 
when/where various PyCons will be held around the world - especially 
those too distant to attend. Afterwards I look to see if they've 
recorded the talks. It's a good way for me to become aware of new 
developments in Python itself, and to see the myriad applications and 
(pertinent to your enquiry) the techniques folk use to accomplish such ends.
PS becoming involved in a local PyCon or PUG is a good way to pick-up 
ideas and make contact with folk who have said ideas!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-03 Thread DL Neil

On 3/01/19 2:03 PM, Avi Gross wrote:

Challenge: Can we name any computer language whose name really would suggest it 
was a computer language?

I think the name is the least important aspect of a computer language.



Perhaps not.

If you subscribe to the wider StackOverflow Driven Design philosophy 
(SODD), then it would be a kindness to choose the language's name so as 
to be (close to) unique when entered as a search key.


Thus the OP's original assumption/confusion between a programming 
language and a serpent; Java and a large island; right down to C, R, etc 
which are too short to be usable search terms in most engines.


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Recommendations for a novice user.

2019-01-07 Thread DL Neil

Hüseyin,

On 7/01/19 3:35 PM, rbowman wrote:

On 01/02/2019 05:14 AM, Hüseyin Ertuğrul wrote:
I don't know the software language at all. What do you recommend to 
beginners to learn Python.
What should be the working systematic? How much time should I spend 
every day or how much time should I spend on a daily basis.


As much time as you can stand. If you want to make a career of software 
you will be studying for the rest of your life. Get used to it.



That comment is correct. Python has many facets and is used in many 
application-areas - some of which are quite different from any of the 
others. Professionals in each area use Python, but they use the same 
language in quite a different way from others.


To answer your question: it depends a little upon how you learn! Some 
people prefer books, others go to in-person classes.


You might like to check-out Coursera.com for on-line courses. There are 
a couple of ($free) basic Python courses available from U.Mich, 
including one from the venerable "Dr Chuck".


You will also find plenty of web-sites and other organisations offering 
Python training or discussing particular facilities of the language. 
Your search engine is your friend. If you (first) choose one, others 
here may be able to advise you, based upon their personal experience.


Returning to your previous respondent: the ONLY method of learning 
Python is to write Python code - so don't rush any course or reading, 
take the time to prove that you can perform every single step. (even if 
only proving to yourself!)


All the best...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-07 Thread DL Neil

On 7/01/19 9:09 AM, Avi Gross wrote:

[Can we ever change the subject line?]
{REAL SUBJECT: degrees of compilation.}
Peter wrote:

"...
Hoever, this is the Python list and one of the advantages of Python is that we 
don't have to compile our code. So we need a different excuse for fencing on 
office chairs ;-).
..."


You had time for that? We had to move to working on program-B whilst 
awaiting the compile-print-return of program-A - sometimes even 
system/application-B!


In some respects I think the imposed compartmentalisation of one's work 
was a positive aspect. We concentrated on ensuring that solid progress 
was made, run by run - whereas the ease and simplicity of making small 
changes (one after the other) can easily consume tracts of time. (at 
some risk) We would try to foresee problems, and ensure that the code 
would 'continue to work' rather than falling at the first hurdle. On the 
other hand, once the batch was "submitted", we could completely drop 
that program's concerns from our minds. At times a massive stress 
reduction (hence the sword play?), and a good way to approach the next 
task with a constructive (?and less-cluttered) mind.


YMMV!



I won't share my own war stories of how to compile in what now seem primitive 
environments on overloaded machines where you often figured out your mistakes 
on paper before the compiler quit and showed you officially 😊


Ah yes, the ?good, old days when computers were powered by dinosaurs 
running in treadmills...


It wasn't that the machine was overloaded so much, more that the Ops 
staff were charged with 'making efficient use of the machine' - that is 
to say, the 40~45% of CPU time that IBM didn't take to run the OpSys. 
Accordingly, our batch-compile jobs went into a long queue, just so that 
the machine could attend to them when it had some 'spare' capacity.


Since then, Moore's law etc, the economics have changed and the cost of 
programmer time is prioritised over computing costs. This became a 
paradigm-shift for me, because my (?junior) colleagues enacted a 
philosophy of 'throw it at the machine and let the 
real-time/time-sharing mini-computer/PC test it for you' (if only). 
Initially this seemed a scandalous waste of resources, but was also 'the 
way of the future'.


However, with large programs and poor test methods, using the above 
'machine as tester' idea, the costs of running a series of 'long' tests 
with only minor changes between soon exposes economic limits! So, I've 
never quite lost that habit of <>>. That said, the 
tenets of Test-driven development continue to erode my 
conservatism/appeal to my inherent laziness...


Conversely, I have been (admittedly, rather quickly) auditing a Coursera 
MOOC series (Python 3 Programming Specialisation = five courses, out of 
U.Mich). Without commenting on their pedagogical success or otherwise, I 
was struck by their presenting the idea of a 'paper computer'* - even 
having an 'intelligent text book' tool to demonstrate step-wise 
execution of code. (without having to introduce the complexities of a 
debugger) It is a good way to help new-comers understand the 
relationships between a variable's name, its value, its type, its 
mutability, etc, etc - which (IIRC) is where they introduced the idea. 
However, later lessons have included exhortations to review that new 
work, using the 'paper computer' technique.


* apologies: this is the term I learned (all those years ago, mumble, 
mumble) and I'm quite sure they have a different name. The essence is 
the same.


I'm only about 40% through the courses, and will be interested to see if 
they continue to refer to the technique as code-complexity builds...



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-07 Thread DL Neil

On 7/01/19 2:52 PM, rbowman wrote:

On 01/04/2019 09:34 AM, Avi Gross wrote:
Although I used FORTRAN ages ago and it still seems to be in active 
use, I am not clear on why the name FORMULA TRANSLATOR was chosen. I 
do agree it does sound more like a computer language based on both the 
sound and feel of FORTRAN as well as the expanded version.


It made sense at the time. I first learned FORTRAN in 1965 in 
engineering school. At that time 'computer science' was in its infancy 
and our everyday tool was a slide rule. The computer, an IBM System 
360/30, was seen as another useful tool and engineers should learn to 
translate their formulas into a form acceptable to it. You wrote your 
efforts on coding forms, laboriously transferred those to punch cards, 
and offered your deck up to the priests who fed it to the god visible 
behind plate glass in his air conditioned lair.



Prior to FORTRAN, particularly in the pre-360 IBM mainframe world, the 
only choice was Assembler - a 'language' which was merely a one-to-one 
restatement of machine instructions in an acronym-like form. The issue 
was that every machine type's instruction set was different and 
consequently every Assembly language was different, ie there was no ONE 
Assembler 'language'.


System/360 changed all that. (Brooks's book "The Mythical Man-Month" is 
still a recommended text and a salutary tale) Now we had a series of 
machines, at different sizes (the 360-30 was towards the bottom-end, or 
one of the early sales - depending upon when in the time-line you look), 
but as far as software was concerned, one machine behaved like the next. 
(and IBM very much hoped that we would 'grow' and thus regularly need to 
upgrade the processor - as well as adding peripherals... An IBM salesman 
was not just for Christmas, he was for life!)


This practicality fuelled the (international) standards effort. It 
became possible to have a (single understanding of) FORTRAN (others have 
noted that there were in fact, implementational differences and matters 
of scale), CODASYL went nuts with COBOL, and so-on (Ada anyone?). Also, 
we had manufacturers attempting to impose, um, create a de-facto 
'standard', eg IBM and PL/1 - nothing like the behaviors of today's 
Googles, Microsofts, Apples, etc; of course...


Back to software, languages, and specifically Assembler: every 
computation had to be broken down and coded as individual "low-level" 
instructions:

load 2 into register-A
load 3 into register-B
add register-B into register-A
(note the lack of variable names, also pre-dating the ideas of 
stack-architecture and modern/Intel CPUs!)


After Assembler, FORTRAN 'made all our dreams came true', because we 
were able to write the likes of:

PI = 3.14159
AREA = PI * RADIUS * RADIUS

Can you see the step 'up' to the *formula* part!

Then, we would run our FORTRAN source-code through the *translator* 
(later the generic term became "compiler"). It would translate our code 
into assembler/machine code (varying by machine), saving us from the 
more laborious and pedantic task of expressing ourselves at that level.


Oh the relief!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-07 Thread DL Neil

On 7/01/19 3:25 PM, rbowman wrote:

On 01/04/2019 10:45 AM, Peter J. Holzer wrote:

FORTRAN is older than most of us. So it influenced what we think a
computer language should sound like.


Sadly, not for all of us...  FORTRAN seeded later languages with terms 
that are obscure, like rewind().  A blazing powerhouse like the IBM 


Why is that obscure? It makes perfect sense - to those of us who have 
used tape/serial storage! Perhaps less-so to [bobble-heads], sorry I 
mean people who grew-up with 'bubble memory' (Memory sticks, 'flash 
drives', SSDs). In point-of-fact, Python Context Managers


Whilst Python docs and tutorials usually make the opposite point: that 
once a file/context has been read, it is "exhausted" and to continue is 
illogical; don't forget that there is still seek() which does indeed 
enable a "rewind"!


By the same token what thoughts does this sort of code induce?
print( f'The magic number is {result}. So there!' )

Why "print"? I thought I was displaying something on the screen (indeed 
STDIO might go to a file, eg log-like). Whither print?



Reminds me of the person who upon being told to move his mouse to the 
top of the screen, picking-up the device and raised it from the desk 
surface. Made sense to him!



Similarly, one team I joined used Sublime Text for coding. I was happy 
to adapt until I wanted to 'print' my source-code (even though 
"line-flow" stationery is harder to source these days). There is no 
print function in that package!



...

free form input. Prior to that it still assumed you were using Hollerith 
cards. I don't think it ever moved beyond the DO loop.


...and yet PEP-8 and countless 'style guides' maintain the 80 (actually 
72 and 79 to be hob-goblin-ish) which I'm quite sure has nothing to do 
with machine-sizes or relationships to a (single/one, US) dollar bill!



Refs:
https://en.wikipedia.org/wiki/Bobblehead
https://en.wikipedia.org/wiki/Punched_card
https://www.python.org/dev/peps/pep-0008/#maximum-line-length
https://docs.python.org/3.6/tutorial/inputoutput.html

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-10 Thread DL Neil

On 8/01/19 4:59 PM, rbowman wrote:> On 01/07/2019 02:10 PM, DL Neil wrote:
>> Why is that obscure? It makes perfect sense - to those of us who have
>> used tape/serial storage! Perhaps less-so to [bobble-heads], sorry I
>> mean people who grew-up with 'bubble memory' (Memory sticks, 'flash
>> drives', SSDs). In point-of-fact, Python Context Managers
>
> Bubble memory, now there is a blast from the past...


More like a whimper...

Working with a bunch of younger folk (who may technically be of the age 
of 'grand-children' - pardon me, I almost fell over my (long, grey) 
beard), I am frequently the butt of their gentle, if ageist, jokes. 
However, my sardonic amusement is to watch them wrestling with concepts 
'we' readily recognise, perhaps from as long ago as mainframe-days.


A similar observation relates to technologies which have come-and-gone, 
eg CCDs, and the bleeding-edge/crest-of-the-wave philosophies that it 
may not be worth rushing into every new technology - because it may not 
actually last the distance...
(Santayana's "Those who cannot remember [learn from] the past are 
condemned to repeat it." - my addition in list-brackets*)


* which was added only to be able to make tenuous claim of relevance to 
a Python discussion list!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-10 Thread DL Neil

On 8/01/19 12:04 PM, Dennis Lee Bieber wrote:

On Tue, 8 Jan 2019 10:10:13 +1300, DL Neil 
declaimed the following:



Why is that obscure? It makes perfect sense - to those of us who have
used tape/serial storage! Perhaps less-so to [bobble-heads], sorry I
mean people who grew-up with 'bubble memory' (Memory sticks, 'flash
drives', SSDs). In point-of-fact, Python Context Managers


Apologies, but "bubble memory" is something completely different --
using movable magnetic domains rather than capacitive charged bits.



You are correct.

Although, back in the days of such excitement: that we had a 
rapidly-approaching possibility of a cost-effective alternative to other 
forms of memory - particularly 'spinning rust'; only the electrical 
engineers worried too much about the underlying technologies. In fact, 
many of the early devices were too optimistic and didn't enjoy 
longevity. However, with persistence (hah!) here we are today, taking 
SSDs for granted...



As mentioned 'elsewhere', that particular team I joined had their 
average-age considerably elevated when I arrived. As such an object of 
curiosity, one of the things noticed was that I ("pomodoro") take 
regular seat-breaks to stretch and move. Apparently, the arm and 
shoulder-loosening movements gained fans, so one tea-break I arrived to 
find them all lined-up around the room, with joined hands, doing a 
night-club dance version of the Brazilian Wave and giggling insanely.


However, as some (already) suffer neck and head-aches, I was(seriously) 
asked for ideas to combat that common oppression. I taught them to 
rotate the head (slowly, but fully) sideways (in the fashion of a 
westerner saying "no") + three repeats, then to nod (westerner saying 
"yes") etc, and finally to 'waggle' the top of the head side-to-side 
(Indian "agreement").


Perhaps you can imagine the next tea-time, dance-floor routine! In 
between chuckles, I referred to them as a bunch of "bubble-heads". (with 
some dispute as to whether I actually said "bobble-heads", but the term 
took their fancy and entered into common parlance)...


At about the same time, someone turned-up with a bust of Mozart, 
Beethoven, or some-such; making a point about having stiff necks that 
felt solid... The next thing I knew, someone else has added to the 
collection, a particularly ugly bobble-head doll. A day or so later, 
someone else 'improved' on it with a bobble-headed dog...


Finally, during a meeting last week (just before this conversation 
on-list), someone made the mistake of describing an incomplete idea as 
"bubbling-up in my mind", which utterly brought the house down!


With lightning wit (moving at a speed which belies my years) I took full 
advantage by claiming that not just he, but they all have having 
bobble/bubble memories!


(you don't have to be mad to work here - but it helps!)


OK, so that's more than you ever wanted to know about why I (erroneously 
or otherwise) used such a term...


Refs:
https://www.youtube.com/watch?v=v2E8f-_ERl0
http://www.bobbledad.com/man-in-mankini-bobblehead
https://www.ebay.com/sch/i.html?LH_CAds=&_ex_kw=&_fpos=&_fspt=1&_mPrRngCbx=1&_nkw=bobble+head+dog&_sacat=&_sadis=&_sop=12&_udhi=&_udlo=&_fosrp=1
(here do we stumble upon the reason eBay's server is called "rover"?)



Why "print"? I thought I was displaying something on the screen (indeed
STDIO might go to a file, eg log-like). Whither print?


Using the wrong language then... COBOL has DISPLAY 


Indeed, and it survived into the CICS/terminal-based era!
(although these days I recommend handing-off to HTML as a front-end - I 
guess then I should observe that HTML has no command to display/print!)




Why "print" -- least surprise! Languages back to FORTRAN (and predating
terminals) had "print" as the quick&dirty output statement (vs the more
complex formatted output). FORTRAN, BASIC, Pascal, probably Modula-2.


"Print" only has "least-surprise" to those of us who can claim a history 
like yours/ours. When we used Teletype terminals and all user 
(human-readable) output went to a line printer, then the word was 
appropriate. To programming neophytes it makes no sense whatsoever, any 
more than would "type".


From your own description, what about "output"?

DISPLAY works for me. I've heard folk talk about "emit", there's 
"write"*, and "type", "present", "exhibit" - from photography 
"expose"... Going to an ink-jet printer could we say "spit" or to a 
laser, "burn"?


Referring back to an earlier point, I don't "print" but have developed 
the habit of using another, 

Re: the python name

2019-01-10 Thread DL Neil

On 11/01/19 8:57 AM, Chris Angelico wrote:

On Fri, Jan 11, 2019 at 6:48 AM DL Neil  wrote:

Working with a bunch of younger folk (who may technically be of the age
of 'grand-children' - pardon me, I almost fell over my (long, grey)
beard), I am frequently the butt of their gentle, if ageist, jokes.
However, my sardonic amusement is to watch them wrestling with concepts
'we' readily recognise, perhaps from as long ago as mainframe-days.


My Dad was in computing back in the mainframe days, and used to regale
me with stories of holding a kilobyte of memory. But now I've started
doing the same sorts of things - I can expound upon the wonders of
engineering floppy disk boot sectors and finding that one spare byte
that I could use for something unrelated, or writing MS-DOS TSRs, or
*avoiding* writing a TSR by having it invoke another program and then
clean up after itself when that program finished... I distinctly
remember hooking the Print Screen interrupt to switch from one screen
to another so that I could play Colossal Caves (aka "ADVENTUR") and
keep track of which treasures I'd collected. Young folks these days
would say "why couldn't you just alt-tab"...



Ah yes, the ?good, old, days! Things were so much better then, before 
'young experts' came along and complicated 'everything'...


However, as I rock my porch-chair and reminisce, I find that even 
nostalgia ain't as good as it once used to be...


PS the smart reply: who do you think coded the Alt-Tab window-switching 
mechanism?
or, whose shoulders' do you young, whipper-snappers think you're 
standing on? (and, "please get down, and go and wash your feet")

...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-10 Thread DL Neil

Chris,

On 11/01/19 10:06 AM, Chris Angelico wrote:

On Fri, Jan 11, 2019 at 8:01 AM DL Neil  wrote:

PS the smart reply: who do you think coded the Alt-Tab window-switching
mechanism?
or, whose shoulders' do you young, whipper-snappers think you're
standing on? (and, "please get down, and go and wash your feet")


Hold on hold on. "Window-switching mechanism"? That implies that you
have windows to switch between. First, we have to have the concept of
multiple programs running at once. Then the concept of each of those
programs having its own isolated display, which you can then switch
between...


Before Windows or windows per-se, we had switching between Foreground 
and Background - but using those terms today encourages people to start 
raving about Themes and color choices...


I had people 'on the hook' for quite a while talking about WIMPs. They 
thought I was into some long-winded, shaggy-dog style of joke. They had 
no concept that what they think of as MS-Windows, or indeed Linux 
windows managers; actually consists of a number of inter-related concepts...




But yeah, "whose shoulders are you standing on" is the right way to
look at it. Also: "are you offering YOUR shoulders to the next
generation?"


+1
Excellent!

(and no, in our 'get it done yesterday' environment I see plenty of 
collaboration but little meaningful 'training' or investment beyond 'the 
job')


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python read text file columnwise

2019-01-12 Thread DL Neil

On 12/01/19 1:03 PM, Piet van Oostrum wrote:

[email protected] writes:


Hello


I'm very new in python. I have a file in the format:

2018-05-31  16:00:0028.90   81.77   4.3
2018-05-31  20:32:0028.17   84.89   4.1
2018-06-20  04:09:0027.36   88.01   4.8
2018-06-20  04:15:0027.31   87.09   4.7
2018-06-28  04.07:0027.87   84.91   5.0
2018-06-29  00.42:0032.20   104.61  4.8


I would like to read this file in python column-wise.

I tried this way but not working 
   event_list = open('seismicity_R023E.txt',"r")
 info_event = read(event_list,'%s %s %f %f %f %f\n');



To the OP:

Python's standard I/O is based around data "streams". Whilst there is a 
concept of "lines" and thus an end-of-line character, there is not the 
idea of a record, in the sense of fixed-length fields and thus a 
defining and distinction between data items based upon position.


Accordingly, whilst the formatting specification of strings and floats 
might work for output, there is no equivalent for accepting input data. 
Please re-read refs on file, read, readline, etc.




Why would you think that this would work?


To the PO:

Because in languages/libraries built around fixed-length files this is 
how one specifies the composition of fields making up a record - a data 
structure which dates back to FORTRAN and Assembler on mainframes and 
other magtape-era machines.


Whilst fixed-length records/files are, by definition, less flexible than 
the more free-form data input Python accepts, they are more efficient 
and faster in situations where the data (format) is entirely consistent 
- such as the OP is describing!



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-16 Thread DL Neil

On 17/01/19 4:45 PM, Larry Martell wrote:

On Wed, Jan 16, 2019 at 9:35 PM Avi Gross  wrote:


Chris,

The comparison to Y2K was not a great one. I am not sure what people did in
advance, but all it took was to set the clock forward on a test system and
look for anomalies. Not everything would be found but it gave some hints.


Clearly you did not live through that. I did and I got over 2 years of
real work from it. Companies hired me to check their code and find
their Y2K exposures. Things like a hard coded '19' being added to a 2
digit year. Or code that only allocated 2 bytes for the year. I could
go on and on. At one client I had I found over 4,000 places in their
code that needed to be modified. And there was no widespread use of
VMs that you could easily and quickly spin up for testing. It was a
real problem but because of many people like me, it was dealt with.
Now the next thing to deal with is the Jan. 19, 2038 problem. I'll be
80 then, but probably still writing code. Call me if you need me.



Same.

The easy part was finding the hardware, configuring identical systems, 
and changing the date-era. Remember that we pre-dated TDD, so we pretty 
much re-designed entire testing suites! The most difficult work was with 
the oldest systems - for which there was no/little/worthless 
documentation, and usually no dev staff with 'memory'.


Then there were the faults in OpSys and systems programs on which we 
could supposedly rely - I still have a couple of certificates somewhere, 
for diagnosing faults which MSFT had not found... The difficulty of 
multi-layer fault-finding is an order of magnitude more difficult than 
Python debugging alone!


I'm told there are fewer and fewer COBOL programmers around, and those 
that survive can command higher rates as a consequence. Would going 
'back' to that be regarded as "up" skilling?


Does this imply that there might one day be a premium chargeable by 
Py2.n coders?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-17 Thread DL Neil

On 17/01/19 6:10 PM, Gregory Ewing wrote:

Avi Gross wrote:

The question that seems to come up too often about the python name is a
distraction. In particular, it is answered fairly prominently in many 
places

as just being a nonsensical name because a founder once liked a comedic
entity that chose an oddball name, so they did too.



There's a long tradition of naming things after animals that have some
of the qualities you want people to associate with them. In the case
of Python, it's not a particularly fast animal, but it is sleek and
powerful, and its minimal design has a certain elegance to it.
So, I think it's very appropriate.


Elsewhere there is discussion about the long tail (life) of v2. So, is 
there also some notion of Python shedding its skin, ie making way for 
newer concepts and greater consistency?


(not that New Zealanders need to know much about snakes!)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-17 Thread DL Neil

On 18/01/19 8:20 AM, Dennis Lee Bieber wrote:

On Thu, 17 Jan 2019 18:12:33 +1300, Gregory Ewing
 declaimed the following:


Dennis Lee Bieber wrote:

Getting too close to REXX (which was something like Restructured
EXtended eXecutor).


And if we continue the theme of dinosaur evolution, we end up
with Tyrannosaurus REXX.


I'd propose that the Regina project be renamed to that -- one tyrant to
rule all REXX 



LotR reference aside, just how many pythonistas do you think also speak 
Latin - to be able to appreciate that joke?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-17 Thread DL Neil

On 17/01/19 6:53 PM, Chris Angelico wrote:

On Thu, Jan 17, 2019 at 3:55 PM Avi Gross  wrote:

The forthcoming UNIX 2038 problem will, paradoxically happen on January 19.



Paradoxically? What do you mean by that?



First we had to duck the Y2K problem.
By moving everything to 64-bits, we duck the Unix Millennium problem.

There you go: two ducks - a pair-o-ducks!


I assume the paradox involves noting that the end of the (32-bit) Unix 
epoch, does not coincide with the end of a (Gregorian) calendar year.



Actually, aren't there three date-time problems to be ducked? Wasn't 
Python's move to having wider timestamps (+= fractions of seconds) in 
part connected with the need to modify NTP - which hits the wall a few 
years before 2038...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic Y2K

2019-01-17 Thread DL Neil

Back in the computer world, Y2K gave such managers some cover. There was a
FIRM deadline. I wonder how many used the impending arrival of the year 2000
as an excuse to perhaps clean up other parts of their act and charge it to
prevention. I mean they might suggest they rewrite some legacy COBOL or even
machine language programs into something more modern or other improvements
like getting a new database including new hardware.


Of course we did!

However, as pointed-out elsewhere, sometimes the costs of re-writing 
seemed less than those required to ameliorate any number of unknown 
issues in the legacy code. Remembering that we would also remove 
unneeded cruft, and (usually) add features needed for 'today's use'.


What were you saying about politicians 'playing' with retirement funds 
and public money? The other advantage to a re-write decision was even 
more under-hand: once agreed, that became a dev project (with a 
31Dec1999 drop-dead deadline) and was NO LONGER part of the Y2K project, 
ie no longer 'my problem'!


I recall at least one project where the users over-egged their case 
(IMHO), taking the dev option even against my advice. They failed to 
make the deadline. Let's just say, on their part, there was a lot of 
fancy-footwork during the first days of 2000...




I also wonder if jobs for some programmers declined sharply in the years
after when not only were they not desperately needed, but perhaps not needed
at all unless they developed new talents.


No, quite the opposite. What happened was that many other projects were 
put-off pending Y2K amelioration. Once we could release staff, they were 
greeted with open arms, and often far, far, greater appreciation than 
normally meets a new dev upon arrival.




Just FYI, the name Y2K always struck me as similar nonsense. They
abbreviated Year and 2000 from at least 8 characters to 3 and did it wrong
as 2K is 2048. As far as I know, nothing special will happen in 2048 and I
also have no special vision for 2020.


You don't seem to understand journalism: Never let the truth (facts) 
interfere with a 'good story'!


I was just talking with a (tech) librarian, who had asked me about "the 
Unix Millennium bug" a few weeks ago, and mentioned this thread. He 
groaned, wondering how long it will be before some hack writes a 
sensationalist book with which to greet the end of the (binary) world...



My play-time this afternoon will involve using Python to keep 
(time-code) track of when/where to superimpose components into a video 
stream...

(I should be back before 2038)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: checking protocols.

2019-01-23 Thread DL Neil

Avi

Haven't noticed an answer to this. Did I miss anything?


On 20/01/19 11:07 AM, Avi Gross wrote:

Short question. Checking if a protocol is set up?


=do you mean that to check/require that a class exhibits a particular 
protocol we should use abstract classes - will not instantiate unless 
all the required components are coded?




Many python improvements are changes to classes that implement a protocol.
There are things you can do to make your own classes work with the protocol
by setting various dunder variables like __iter__, __next__ and writing
appropriate ode including throwing the right error class when done.
Similarly the "with" statement works with objects that implement __enter__
and __exit__. There can be plenty of others like this and more can be
anticipated in the future.

So, several related questions. Tools that help a developer add appropriate
things to an object to implement the protocol or to test if it was done
right. Perhaps a function with a name like is_iterable() that tells if the
protocol can be applied. For the specific case of an iterable, I found
something that seems to work for at least some cases:

from collections import Iterable
item = [1, 2, 3, 4]

isinstance(item, Iterable)

Not sure if it would work on one I created that did the right things or what
it checks.


=your code should be 'approved' if it implements the next() method, etc. 
Did you try such?




I am interested in a pointer to something that describes many of the known
protocols or extensions and maybe to modules designed sort of as I said
above. I am aware some protocols may be not-quite standard with parts of the
protocol embedded in different objects like wrappers or objects returned
upon a request to have a proxy and many other techniques that seem to abound
and allow multiple layers of indirection or seemingly almost magical as in
multiple inheritance drop-ins and so on. That is what may make these things
harder if someone uses something like __getattr__ or descriptors to
intercept calls and provide the functionality without any actual sign of the
dunder key normally expected.


=Questioning similarly, I recall finding one of these - but do you think 
that I can re-find it now? Apologies.


I (too) think it would be handy to have such a list. There are many for 
the 'magic methods' themselves, in all the better Py3 texts.


Yesterday I needed to add __LT__() to allow a list of class instances to 
be sorted, __EQ__ to enable a list of (other) instances to be searched 
(if element in list_of_instances), and made a class callable 
(__call__()). Each time I wondered: is this the best way to accomplish 
or is there already a mechanism I could be employing/not 'reinventing 
the wheel'. (perhaps incompletely!)



For your further reading pleasure (maybe):

On the this topic, one of many references is Interfaces in Python: 
Protocols and ABCs 
http://masnun.rocks/2017/04/15/interfaces-in-python-protocols-and-abcs/


Which reminded me of the amusingly titled: Duck Typing vs. Goose Typing, 
Pythonic Interfaces 
https://dgkim5360.github.io/blog/python/2017/07/duck-typing-vs-goose-typing-pythonic-interfaces/


Diving into the docs (although not finding exactly what we seek):
https://docs.python.org/3/library/abc.html
- didn't include all, eg context managers:
https://docs.python.org/3/library/contextlib.html

At a deeper level:
https://docs.python.org/3/c-api/abstract.html?highlight=abstract
and
https://docs.python.org/3.6/c-api/object.html
- again, incomplete in the sense (I gained) of this enquiry.

Hopefully there's something to keep your mind occupied...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: checking protocols.

2019-01-24 Thread DL Neil

Avi


Haven't noticed an answer to this. Did I miss anything?

I never saw the original message appear and thus expected no replies. I see a 
later post by Chris indicating he did not see it either. I assumed perhaps a 
moderator needed to approve it.


=a silly question on my part. A quick check of the list archive shows 
your original post but no previous responses.




My question really boils down to being intrigued how the python language can be 
extended using documented protocols in more ways and having a place where you 
can see a list of the ones out there and a way to join in with your own classes 
reliably and so on.


=if I am interpreting your intent correctly (equally that of Pythonic 
thinking) the idea is for 'more' to happen at compile-time. This 
expectation likely comes?came from our earlier training in more 
strict/rigid languages. Whereas many characteristics of Python flow 
directly as consequences of it being (chosen/designed to be) a dynamic 
language - and thus many?most such decisions delayed until run-time.


=The first (related) example which springs to mind is object 
polymorphism. It must be so much harder to achieve such incredible power 
and flexibility (as Python does) when 'rules' are 'cast in stone' early.


=However, it might be worth making suggestions generated 'here' to the 
(hard-working) docs team. There are discussions of specific protocols, 
in their individual locations throughout the manual/library. Is it 
sufficiently clear what is expected when building our own classes 
according to 'the' protocol?


=Rather than collecting all the protocols' documentation together (cf 
the sequence currently used), maybe an cross-index somewhere?




I note there may be many unpublished protocols used internally within modules 
that also create similar structures but do not expect to be emulated.


=coming from Python, the PSL, or third-parties?



I see interpolated comments below and will interpolate within that but it gets 
confusing.


=am using line-prefix to help differentiate. Interleaved comments help 
(?me) with following the conversational flow - and ensuring that each 
point/question is addressed (he hopes)




On 20/01/19 11:07 AM, Avi Gross wrote:

Short question. Checking if a protocol is set up?


=do you mean that to check/require that a class exhibits a particular protocol 
we should use abstract classes - will not instantiate unless all the required 
components are coded?

== I am not looking for any specific options but indeed including an 
abstract class might be one way to go. It might supply a reasonable way to ask 
if the class you make yourself INTENDS on running that protocol and would 
enforce the presence of the required methods somewhere in the inheritance 
chain. Of course the functions could be stubs that don't do the right thing, or 
anything passable.

... (previous content removed, as no longer necessary)


=The phrase "we're all adults here" is often used to justify Python's 
apparent inexactitude (cf other languages*). However, I often wonder 
whether that is merely an excuse to avoid explaining oneself properly. 
For example, 'here' (or is it another list, strictly speaking?) I read 
ANNouncements of package updates. How many tell me wonderful additions 
to the package, how much work went into them, what I'd now be able to do 
with it, and who I should credit for all such goodness - but don't 
actually get around to mentioning the package's objectives or 
applicability? Unless I know said package, these ANNs are a waste of my 
reading-time!


=On the other hand, such 'openness' as non-enforced "private variables" 
(applying the 'adults' phrase) enables us to consider them "private" in 
the normal course, but to abuse the notion should the need take us (and 
caution have been thrown to the wind)!


=Back to protocols: and if I want to code certain magic methods, etc, 
comprising a protocol, should I be allowed to choose to ignore other(s)? 
Be it on my own head!


* comparing Python to other languages is (IMHO) neither a reliable nor 
particularly logical argument. How can we be 'the best' if all we do is 
copy and reproduce everyone else - and would that even be possible? 
Surely the valid comparison is between the problems which must be solved 
and the facilities of the language chosen to code the solution?


=That said, there is no question that Python has been developing 
somewhat schizoid tendencies. Another mantra has always been: 'it is 
better to ask forgiveness than permission'*, and thus we should wrap 
assumptive code in a try...except block. This change took a long time to 
sit comfortably in my (albeit small) brain - and possibly still requires 
conscious consideration. My thought pattern** is still: first check the 
data, then ..., ie ensure denominator is not zero before dividing rather 
than


try:
divide
except (whatever):
print( "Not by zero, bub!" )

* (originally attributed to Adm Grace Hopper of COBOL fa

Re: preferences file

2019-01-24 Thread DL Neil

Dave,

On 25/01/19 8:42 AM, Dave wrote:
I'm doing a small application and want to add user preferences.  Did 
some googling to see if there are standard Python ways/tools, but it 
seems not so much.  My specific questions are:


1. Best practices for a user preference file/system?

> [edited]
> Would like to find a Python library that handles all of this, but so 
far...


=Had a similar need. Also looked around, but failed. Will be interested 
in any discussion that follows...




2. File format favored and why - ini, JSON, etc?


=Am no great fan of .ini (a) where it is most used, ie cynicism and 
bias; and (b) and because it is too "flat".


=Initially thought to use .conf, comforted by frequent use on Linux 
servers, but similar criticism.


(at this point the PSL's configparser bows out)

=Looked at .JSON and liked the syntactic similarities to Python.

(utility available in PSL)

=Settled on .YAML, mostly because not very different to .JSON yet has 
specific, applicable design philosophy.


(IIRC picked this up through pip3)

=Ended-up coding my own little utility to call from any/every 
application; based on import yaml. Will be interested to see if someone 
suggests something I missed back-then...



=Have been gradually adding further facilities, eg commandLN overrides. 
Also, been wondering about its applicability to my web work - 
particularly when it comes to separating versions, eg "live" from (user 
acceptance) "test"...


=Once done, I've noticed myself coding fewer global constants, instead 
putting them into the .yaml configuration file. Of course, this adds a 
point-of-failure - particularly if the user has access/editing rights on 
the file (but with great power, comes ...!)



3. File location?  I'm using Ubuntu and I believe that the correct 
location would be home/.config/ .  What about Mac and Windows?


=Makes good sense, but ultimately depends upon usage/the application/how 
it is to be delivered to the users (and possibly more). Obviously if the 
user is not on that machine, or you run on behalf of several users that 
won't work (perhaps implement separate .../userNM/ sub-directories and 
use such for both config input and any output files/reports).


=Again, will be interested to see others' ideas...

(this smart-alec locates his windows in the wall, and keeps his mac in 
the cupboard/closet)


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-27 Thread DL Neil

On 25/01/19 4:22 PM, Bill Campbell wrote:

On Thu, Jan 24, 2019, Dave wrote:

I'm doing a small application and want to add user preferences.  Did some
googling to see if there are standard Python ways/tools, but it seems not so
much.  My specific questions are:

1. Best practices for a user preference file/system?


Generally I put them in the user's $HOME or $HOME/etc directory
with appropriate permissions unless working in a virtual
environement.


Good idea.

What about running a multi-tenant application (for multiple users who 
are not also system-users) - cf them logging-on to run their own. It is 
appropriate, possibly even "required" to keep Fred's config file, 
reports, graphs, logs, etc; separate from Barney's. Ideally they will 
not be sub-dirs of the application/package.


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread DL Neil

On 29/01/19 1:29 AM, Karsten Hilbert wrote:

On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:


What about running a multi-tenant application (for multiple users who
are not also system-users) - cf them logging-on to run their own. It is
appropriate, possibly even "required" to keep Fred's config file,
reports, graphs, logs, etc; separate from Barney's. Ideally they will
not be sub-dirs of the application/package.


   if it is per user defined then $HOME/.config/,
$HOME/.local/share/ and any temporary data can go
in $HOME/.cache/ will do it for posix on Windows
there is the per user app stuff which i haven't sorted out
yet.

   $HOME changes per user login name change.


$HOME/.config///
$HOME/.cache///



+1

The latter for tmp/intermediate files (without hassles, eg creating 
unique fileNMs!). - and which can be wiped with a single command at the 
end of the run!


The former for 'valuable stuff'. With the opportunity, to separate 
output presentations and inputs using sub-dirs!


(noticed in one such implementation, the need to separate different 
'runs' of the same app, by the same client, using alternate hypotheses - 
that required another 'layer' of sub-dirs!)


Thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-28 Thread DL Neil

On 29/01/19 7:11 AM, songbird wrote:

DL Neil wrote:

On 29/01/19 1:29 AM, Karsten Hilbert wrote:

On Mon, Jan 28, 2019 at 07:02:47AM -0500, songbird wrote:


What about running a multi-tenant application (for multiple users who
are not also system-users) - cf them logging-on to run their own. It is
appropriate, possibly even "required" to keep Fred's config file,
reports, graphs, logs, etc; separate from Barney's. Ideally they will
not be sub-dirs of the application/package.


if it is per user defined then $HOME/.config/,
$HOME/.local/share/ and any temporary data can go
in $HOME/.cache/ will do it for posix on Windows
there is the per user app stuff which i haven't sorted out
yet.

$HOME changes per user login name change.


$HOME/.config///
$HOME/.cache///



...The latter for tmp/intermediate files (without hassles, eg creating
unique fileNMs!). - and which can be wiped with a single command at the
end of the run!
...


   oh, well i don't need anything that complicated but
usually there is a way of generating unique file names
and managing temporary files.


=if the directory is dedicated to a user (and thus the files therein 
driven by his/her/their particular config file), then the issue of 
unique fileNMs no longer exists. Less complexity = more happiness 
(potential)...




   if you are running an application by a login user
which does not log out then eventually you may need
to use some other method of cleaning up the application's
files somehow but to me that is a whole different topic
from the issue of where to put them.


=(a) context managers

=(b) when the intermediate files (from an 'inherited system') are 
over-large (see also Backlog list!), this can become an issue.


Yes, it appears some way from the OP's intent (apologies to him, if 
appropriate).


However, K's comment encouraged a re-think:
- whilst re-developing the app into a multi-tenant possibility, using 
config files to separate the individuals/project teams/departments (back 
to the original question), my thought was that the intermediate files 
"belonged to" the app. Hence they were re-sited under (Linux) /tmp 
(considerations per above).
- if the consideration of "separation" between the multiple 'tenants' is 
important (not in my case), then a generalised drop-zone, eg /tmp, is 
NOT acceptable, eg security/privacy.
- hence the conclusion that any intermediate files should also be 
separated 'under' , ie that they 'belong to' the user and NOT 
to the app!
- this naturally leads to another convenience: unlike concerns for 
over-filling /tmp, there is no need to keep track of what has/not been 
created in $HOME/.cache/// because at the end of the 
run, all contents of the directory (incl/excl) can?should be deleted! (a 
context manager?)


Obvious when you think about it, but wasn't 'at the time'. Ideas 
appended to Project's Backlog...


Again, thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-29 Thread DL Neil

On 30/01/19 5:12 PM, Cameron Simpson wrote:

On 30Jan2019 04:24, Chupo  wrote:

I am trying to figure out what data type is assigned to variable p in
this code snippet:

for p in game.players.passing():
   print p, p.team, p.passing_att, p.passer_rating()


Well, Python comes with a type() builtin function:

  print type(p)



Alternately/additionally, if you ask help(p), it will reveal-all about 
the "class" (of which p is an "instance") - including some answers to 
your second question (and perhaps others which logically follow-on).


If these terms are unfamiliar to you, then 'the manual' reference is 
https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes 
(although from the code above, it would appear that you are looking at 
Python 2.n!). There are plenty of other tutorials available. 
Additionally, Coursera has announced a course starting this week 
(U.Michigan), in Python and its classes - which can be audited for $free 
or used to obtain some sort of certification...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-30 Thread DL Neil

On 31/01/19 3:38 PM, Chupo via Python-list wrote:

In article , DL
Neil  says...

Alternately/additionally, if you ask help(p), it will reveal-all about
the "class" (of which p is an "instance") - including some answers to
your second question (and perhaps others which logically follow-on).


Yes, but unfortunately this was all I had:

https://stackoverflow.com/q/28056171/1324175



It can't be - there must be some source for p (code and data)! Surely 
you're only showing us a small portion of the code?


Like printing the type() or the string representation, using help() is a 
matter of adding one line to the source code...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread DL Neil

On 1/02/19 9:00 AM, Chris Angelico wrote:

On Fri, Feb 1, 2019 at 6:56 AM Chupo via Python-list
 wrote:

In article <[email protected]>,
Rick Johnson  says...




I was thought there aren't stupid questions, just stupid answers and I
for sure won't apologize for asking any question. If someone things the
question I asked is stupid they can ignore it. I am not affraid of
losing my reputation by asking a question.



There are stupid questions, but I enjoy answering those too. You don't

...

(TLDR?: the are "stupid questions", here's why, and some ideas with 
which to frame/consider responses)



Many years ago, gulp, decades ago; when I first started-out in 
vocational training, I also thought 'there are no stupid questions, only 
stupid answers'. Possibly I was?am idealistic in other ways too.


Whilst this phrase 'sounds good', is it logical? It seems to assume that 
a questioner can never ask something in a stupid fashion, whilst at the 
same time assuming/insulting a respondent with the opposite assumption. 
(notwithstanding that it can be difficult to find the right words with 
which to phrase a question - particularly someone learning Python's 
concepts. Also, we should never forget that many 'here' are not 
communicating in their primary/home language - thank you for making that 
effort!)



Back when we rode dinosaurs to school, the maxim was "children should be 
seen and not heard". The teacher was 'the sage on the stage' and 
questions had to be invited/were not encouraged - talking to others was 
either "behind the teacher's back" or "cheating", and thus subject to 
discipline (yes, there was such a thing, once upon a time). Today, there 
is a more social approach to learning, where questions, of the teacher 
or of peers are encouraged - and if you'll permit me to disappear into 
cognitive psychology for a moment, it is a much more efficient way to 
learn! However, it also requires that whereas we didn't 'interfere' with 
others' learning by keeping silent, the members of such a 'modern' 
society find new levels of respect for each other, when it is (not) 
acceptable to do such things, etc, etc.


Contrarily, we also live in 'the Internet Age' which includes the rise 
of a sense (?right) of "immediacy". In short: we want it now! Sadly, 
this engenders an apparent motivation to rush 'in' (see also "panic"), 
rather than holding-fire and thinking first - or as the old dinosaur 
used to say "put brain into gear, before mouth into motion"!


I should also mention that the above is very much a description of how 
things are 'in the west' (ie 'western world', 'western culture'). 
Younger colleagues educated in India and China (per example only) tell 
me that their educational modus 'today' is much closer to my own 'back 
then'. Accordingly, until friendships are establish, preparedness to ask 
questions is low - is thought to reveal ignorance, even lack of respect 
of 'teacher'.



There are 'bad questions':

- someone unable to immediately solve a problem, turns to his 
colleague/this list and garbles:

- there may be facts, but are they sufficient?
	- there is often no background to understand the motivation for the 
question
	- there is usually a component of 'how do I fix my solution' cf here is 
the (actual) problem to be solved


- laziness, ie asking someone else to exert effort to save self
- eg no evidence of an attempted solution
- no reference to web or book research

- learning avoidance (even 'destruction'):
	- see current conversation on list where student has clearly said that 
he is dealing with a teacher-directed assignment



So the definition of 'bad question' may boil-down to the motivation of 
the questioner being 'good' or 'bad', rather than the wording itself. 
Why are you asking this question?



Amusingly enough, that's amongst the training given to anyone learning 
training (if you follow): always try to (first) understand why the 
person is asking you this question, then try to answer in similar mode!


- a question asked on-impulse pretty much implies that a direct/complete 
answer will be taken similarly. In which case, it is extremely unlikely 
that the questioner will *learn* from the experience - thus will be 
forced to ask again 'next time'. "Give a man a fish and he eats today. 
Teach a man to fish and he eats every day!" (only an aphorism, sadly not 
literal fact!) Accordingly, 'answering' the original question with 
clarification questions is not a 'silly answer'. Indeed neuroscience 
shows that taking a break from a problem allows the brain to move 'the 
facts' from "working memory" into 'the back of my mind' and/or more 
permanent memory (ie learning); and possibly more important to 
problem-solving, from the logico-cortex into other parts of the brain 
where 'the facts' become associated with "prior knowledge" and other 
components of 'intelligence' may be brought to bear. How often have you 
taken a sh

Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil
When a client demanded his way on this issue, the action we took was, as 
below, to create a list (called ordinal) and to use the dd (day) value 
as an index.




[ nthSuffix(day) for day in range(1,32)]

['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th',
'11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th',
'20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th',
'29th', '30th', '31st']



I'm not sure if employing a dict with hashed retrieval would be any more 
efficient than indexing into a list.




Not having a default case as in switch forced you to write out all possible 
combinations.

I think the intent and readbility of switch statements is a bit nicer.



Perhaps not. A list look-up is self-documenting, and the fact that every 
choice is covered reduces error-risk.


The criticism above, "demanded", is justified by the international 
standard for dates (ISO 8601).


This would normally see us coding "2019-02-03". The arrangement of 
larger to ever more precise time-units is very useful in databases and 
applications such as file-names, because it sequences logically.


However, that is not the way 'normal people' like to write their dates. 
The trouble with 'common practice' though, is that it is localised. 
There is great confusion between the way different cultures (even 
staying within the English-speaking world) express dates. Is 3/2/2019 
referring to "3rd February" or "March 2nd"?


Not part of the standard, but given the differences between US and 
European commonly-used date formats, I used to insist upon dd-mmm-yy or 
ccyy, thus 3-Feb-2019. Before handy PSL date utilities, this raised the 
need for another list - of month names/abbreviations.


Why lists? The other advantage is realised when we move out of English.

It is easy to have multiple lists - one for each language (assuming 
Gregorian calendar - given that other calendar systems are quite another 
discussion!) and thus select by date and by location.


Now back to ordinal dates - the "st", "th", etc suffixes only work in 
English. You'd need another list (but no great coding complexity) to 
cope with a second, third, ... language!


(ACK: the OP didn't specify such extensive needs)


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil

Chris,

On 3/02/19 9:45 PM, Chris Angelico wrote:

On Sun, Feb 3, 2019 at 7:40 PM DL Neil  wrote:

This would normally see us coding "2019-02-03". The arrangement of
larger to ever more precise time-units is very useful in databases and
applications such as file-names, because it sequences logically.

However, that is not the way 'normal people' like to write their dates.
The trouble with 'common practice' though, is that it is localised.
There is great confusion between the way different cultures (even
staying within the English-speaking world) express dates. Is 3/2/2019
referring to "3rd February" or "March 2nd"?


Which is why I always write dates in sorted format, usually eschewing
delimiters:

//CJA 20160511: Is this still happening? I don't remember seeing it in
three parts of forever.


Sure is. It is an acceptable alternative under the ISO standard.

Some would say it is more sensible to use when storing data because it 
removes the dash/hyphen separators in exchange for implying the 
fixed-format. (more bytes/characters saved if extend to include the time)


I'm not going there - recalling folk from these memory-is-cheap times 
being less able to understand why we used to save 'expensive' storage 
space by using yy-years (instead of ccyy) and thus 'causing' "the 
millennium bug" aka Y2K!


I wouldn't use it in a 'visible' situation though, eg a fileNM. Yes, it 
is shorter, but as my eyes age (they are already older than my teeth!), 
I find it much slower to decode than reading the same with embedded 
separators!




That said, I am aware that I am not in any way a "normal person".
Using month names as per your other example is probably a fair
compromise with other humans.


There's normal and there's normal - like it's tomato or tomato?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil

On 3/02/19 10:16 PM, Chris Angelico wrote:

On Sun, Feb 3, 2019 at 8:09 PM DL Neil  wrote:

On 3/02/19 9:45 PM, Chris Angelico wrote:

Which is why I always write dates in sorted format, usually eschewing
delimiters:
//CJA 20160511: Is this still happening? I don't remember seeing it in
three parts of forever.

Sure is. It is an acceptable alternative under the ISO standard.


Not sure if you're responding to the content of the comment there;


Comment? I don't see no #, ''', or """!
(am teasing)


[ccyymmdd cf ccyy-mm-dd]

Some would say it is more sensible to use when storing data because it
removes the dash/hyphen separators in exchange for implying the
fixed-format. (more bytes/characters saved if extend to include the time)

I'm not going there - recalling folk from these memory-is-cheap times
being less able to understand why we used to save 'expensive' storage
space by using yy-years (instead of ccyy) and thus 'causing' "the
millennium bug" aka Y2K!


Skipping the delimiter isn't about saving space, it's about
consistency. If I say "non-delimited sorted date", you can almost
certainly write out a character-for-character identical date - handy
if you want to search a bunch of files, for instance. Having
delimiters leaves people free to dispute whether they should be
slashes, hyphens, dots, or maybe something else.


This logic indisputable.

However, the whole purpose of an ISO standard is to remove "dispute", 
locally and internationally! Thus, if not sufficiently-well stated 
earlier, the standard is actually for information interchange purposes.



>> I find it much slower to decode than reading the same with embedded
>> separators!
> Sure. I mainly use it in contexts where the most important information
> is simply "that's a date", rather than actually caring what the date
> *is*.
[paras re-ordered]

+1


In case other readers are following-along-at-home, and the (above) 
purpose of the standard was insufficiently obvious, I did a bit of 
review 'homework':


- ISO standards are still not $free

- a good write-up from the ISO appears on the Wayback machine at 
https://web.archive.org/web/20110614235056/http://www.iso.org/iso/support/faqs/faqs_widely_used_standards/widely_used_standards_other/date_and_time_format.htm
- the above makes the point about "interchange" and offers similar 
examples of date-confusion to those 'here'/earlier

- mention is made of formats including/excluding delimiters
(I haven't been able to check this, but can't find any evidence that 
separators other than "-" are allowed (in dates) )


- in lieu of the ISO text, those of us working over the Internet will 
turn to RFC 3339

- this is a slight simplification of the ISO standard
- the ABNF appendix *requires* a dash/hyphen as (date) separator

- Markus Kuhn at Cambridge (British university) provides a readable and 
thought-provoking summary at https://www.cl.cam.ac.uk/~mgk25/iso-time.html

- uses dashes/hyphens
- discusses international considerations (I've just learned that the 
Chinese date notation preceded the ISO order, as did the conventions of 
a number of other countries)
- supports the compact/'no debate' format "The hyphens can be omitted if 
compactness of the representation is more important than human 
readability" (as well as caring for my fading vision)




I wouldn't use it in a 'visible' situation though, eg a fileNM. Yes, it
is shorter, but as my eyes age (they are already older than my teeth!),

Guess your teeth better work on catching up...


Can't put them under the pressure of thinking it is a race - they could 
decide to drop out!




That said, I am aware that I am not in any way a "normal person".
Using month names as per your other example is probably a fair
compromise with other humans.


In this life, one does have to make allowances...



There's normal and there's normal - like it's tomato or tomato?

I dunno. I'm the kind of normal that likes tomatoes (not to be
confused with tomatoes). Does that help?


If you like tomatoes, and tomatoes are fruit, do you (normally) chug 
tomato sauce (ketchup) as if it is fruit juice?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil

Christian,


On 4/02/19 10:00 AM, Christian Gollwitzer wrote:

Am 03.02.19 um 09:32 schrieb DL Neil:
Now back to ordinal dates - the "st", "th", etc suffixes only work in 
English. You'd need another list (but no great coding complexity) to 
cope with a second, third, ... language!


Only for some languages. In other languages there can be, for example, 
cases (inflections). Then the suffix not only depends on the number, but 
also on the case, which is governed by e.g. a preposition or the use in 
the sentence. Slavic languages have 6 or 7 cases.


I was unaware of that - not having had to cope with any of the Slavic 
languages, to-date. Are multiple cases/inflections used for dates? 
French has two, including both male and female ordinals, but only one 
applies to dates!



Of course you can make the list two-dimensional to cover that, but then 
another language will appear which has yet another different thing


Basically you'll need to rewrite the whole thing when going to a 
completely different language.

Ouch!

However, such limitation also applies to the 'case solution', and worse, 
if that additional language/those languages' exceptions apply to 
different values, eg 1st, 11th, 2nd, 3rd which are "hard-coded" in the 
English convention.


Not good science, but I have been sampling my correspondence today, 
inspecting letters, emails, etc, for date-formats. Guess how many use 
ordinals? Stuff from the US tends to use numerics in the mm/dd/ccyy 
convention. Stuff from the UK and British Commonwealth (excluding 
Australia) tends to use month-words or abbreviations (but not ordinals).



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Implement C's Switch in Python 3 [OT languages]

2019-02-04 Thread DL Neil

On 4/02/19 9:25 PM, Christian Gollwitzer wrote:

Am 04.02.19 um 09:18 schrieb Christian Gollwitzer:
I think English is quite "unique" with writing out the ending of the 
ordinals attached to arabic numerals.




Of course, there is a Wikipedia page about it:

 https://en.wikipedia.org/wiki/Ordinal_indicator

So I was wrong and the abbreviated suffix is as common as the period 
over the European languages.


 Christian



That's a comprehensive read. Thanks!

Left me with a few thoughts:
1 the Irish is "syncopated". No wonder that accent presents me with 
difficulties!

2 this is all very difficult, and
3 the OP must be re-thinking his choices (or questioning his sanity) by now!

Following your earlier contribution and its use of words such as "rare", 
"unusual", "mess", and "unique" I wondered just how relevant the ordinal 
might be?


Herewith a few minutes of very un-scientific/statistically-irrelevant 
discovery - wherein I learned that English investors are leery of 
Alphabet because of their rate of investment (!?) and the Portuguese are 
concerned that their schools' computers are aged-rubbish.


I surveyed a number of the better-known European news-papers' web-sites 
to see what they do (under the (perhaps mistaken) assumption that they 
represent their country's use of dates):-


Great Britain
The Times (of London) February 5 2019, 12:01am,

French (translations: 'published on-site at...', 'published on the...')
Le Monde avec AFP Publié hier à 08h06, mis à jour hier à 12h08
Publié le 14 janvier 2019 à 15h04 - Mis à jour le 14 janvier 2019 à 16h03
Le Figaro: Publié le 04/02/2019 à 19:45

Germany
Handelsblatt Dienstag, 5. Februar 2019 (also FAZ)
Welt  Stand: 01.02.2019 | Lesedauer: 4 Minuten
Bild 05.02.2019

Italy
la Repubblica 05 Febbraio 2019

Portugal
Diário de Notícias Terça-feira, 5 de fevereiro de 2019
Publico 4 de Fevereiro de 2019

Spain
El País 5 FEB 2019
El Mundo martes, 5 de febrero de 2019


So, even with the French making their dates into sentences, not a single 
one uses ordinals!
- did the computer people in all these languages/cultures decide that 
the more numeric approach was better/easier/...

(ie simpler/less-complex)

Not even the convention/use of title-case is consistent!


After all this, I think I need to quietly go away and sleep it off...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Loop with else clause

2019-02-04 Thread DL Neil
What is the pythonic way to handle the situation where if a condition 
exists the loop should be executed, but if it does not something else 
should be done?



Why am I asking?
Today's code review included a for...else structure. I've rarely seen 
such a thing, and even knowing it exists, cannot recall ever using it! 
The coder intended to implement the scenario (above) but did not realise 
that the else-clause means 'execute if the loop ended without using 
break'. She thought it meant 'if there's nothing in the iterable, 
execute the else clause' (per if...then...else... ie the two clauses are 
mutually-exclusive*) - which one assumes is the reason why the BDfL is 
claimed to have said it should never have been implemented (this way). 
She neglected to test the exception properly, and was lulled into a 
false sense of security by the coverage reporting 100%. Oops!


*see also the more commonly-used try...except...else...[finally...]


When/how does this occur?
Our client is more than a little commercially-sensitive. So as a really 
simple scenario, imagine a report is required, naming people who have 
become eligible for something, eg students qualified to enter an 
advanced class, Oscar film award nominees, entrants who have fulfilled 
the requirements of a competition from which a winner will be randomly 
selected...


The names all appear in a list, so the most frequent use-case is trivial:

print( "And the winners are:" )
for name in list:
print( name )

but, if no-one actually qualifies, a warning message is required, eg

print( "Sorry, no-one is eligible" )


Possible solution:
To make anything more than the trivial case readable, I think I'd put 
the list processing into one function, and the exception into another 
(except that this case is so trivial), ie


if list:
process_list() #the heading and for-loop, as above
else:
print( "Sorry...


Others wanted to add a semaphore/flag inside the loop to indicate if it 
was executed at least once. Yes, could even use the else clause then!


The ideas went (rapidly) down-hill from there...


Is there another, more pythonic, approach to conditional (for/while) 
loop processing?


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


Re: Loop with else clause

2019-02-04 Thread DL Neil

On 5/02/19 8:12 PM, Steve wrote:

Would it be a hyphythonitical question?


Is that one of the new meta-classes in release 3.99, or a perhaps a 
project to remove the GIL and take advantage of multi-core architectures?


As well as embarrassing the poor coder, this question vexed quite a few 
minds this afternoon (even allowing for the gathering mood - tomorrow 
being a public holiday!).


Even though it seemed so straightforward to me, others felt it 
reasonable that there would be some way to tell that a loop never 
executed - there must be a simpler, more pythonic, construct...




=
Footnote:
Zamboni locks up after running into large patch of loose teeth.





-Original Message-
From: Python-list  On
Behalf Of DL Neil
Sent: Monday, February 4, 2019 11:29 PM
To: 'Python' 
Subject: Loop with else clause

What is the pythonic way to handle the situation where if a condition exists
the loop should be executed, but if it does not something else should be
done?


Why am I asking?
Today's code review included a for...else structure. I've rarely seen such a
thing, and even knowing it exists, cannot recall ever using it!
The coder intended to implement the scenario (above) but did not realise
that the else-clause means 'execute if the loop ended without using break'.
She thought it meant 'if there's nothing in the iterable, execute the else
clause' (per if...then...else... ie the two clauses are
mutually-exclusive*) - which one assumes is the reason why the BDfL is
claimed to have said it should never have been implemented (this way).
She neglected to test the exception properly, and was lulled into a false
sense of security by the coverage reporting 100%. Oops!

*see also the more commonly-used try...except...else...[finally...]


When/how does this occur?
Our client is more than a little commercially-sensitive. So as a really
simple scenario, imagine a report is required, naming people who have become
eligible for something, eg students qualified to enter an advanced class,
Oscar film award nominees, entrants who have fulfilled the requirements of a
competition from which a winner will be randomly selected...

The names all appear in a list, so the most frequent use-case is trivial:

print( "And the winners are:" )
for name in list:
print( name )

but, if no-one actually qualifies, a warning message is required, eg

print( "Sorry, no-one is eligible" )


Possible solution:
To make anything more than the trivial case readable, I think I'd put the
list processing into one function, and the exception into another (except
that this case is so trivial), ie

if list:
process_list() #the heading and for-loop, as above
else:
print( "Sorry...


Others wanted to add a semaphore/flag inside the loop to indicate if it was
executed at least once. Yes, could even use the else clause then!

The ideas went (rapidly) down-hill from there...


Is there another, more pythonic, approach to conditional (for/while) loop
processing?

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



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Loop with else clause

2019-02-07 Thread DL Neil
Further to our discussion of how to improve a code review's discovery of 
the mistaken handling of a for...else... construct:-



Yesterday was a national holiday, but today gave some opportunity to 
research. Way back in 2009 there was spirited discussion over on the 
Python Ideas list (warning, even the mailing list's index covers 
multiple screen-lengths):


- this confusion is not new by any measure, herewith a list of previous 
occasions "fists were raised concerning for..else."

https://mail.python.org/pipermail/python-ideas/2009-October/006164.html

- an excellent summary of the 2009 debate which offers no less than six 
ways to 'improve' for... else...

https://mail.python.org/pipermail/python-ideas/2009-October/006155.html

- (as mentioned earlier) the BDFL weighed-in a couple of times. His 
regret is: "That's a flaw, and I don't quite know what to do about it. 
It's about 20 years too late to remove or rename it. But we probably 
should not do more of these. That's a lesson."
(OK, so make that thirty years - older than the coder who the 
code-review noticed falling into this coding 'gotcha'!)

https://mail.python.org/pipermail/python-ideas/2009-October/006083.html

- herewith a (rather complicated) suggestion, and critique
https://mail.python.org/pipermail/python-ideas/2009-October/006054.html

- one rather hopeful option (actual words to be used notwithstanding)
for i in SEQ:
  A
except:
  B
else:
  C
appears here:
https://mail.python.org/pipermail/python-ideas/2009-October/006044.html


Somewhat related, PEP 548 proposed an "More Flexible Loop Control". This 
was addressing the confusion caused by break within a loop. It was rejected.



Each of the above addresses issues 'within', that is to say happenings 
during iteration - whether the entire loop or iteration cut-short by a 
break (and thus the idea that "else" might be re-worded to indicate 
'after a break').


However, as mentioned by one contributor, the specific use-case our team 
faced was an issue that arises prior to the loop. Alternately-expressed: 
that according to Python's logic, prevents even a single iteration of 
that loop. Thus, any 'solution' would reside outside of for and while 
statements because they only consider if a loop should continue or 
terminate - not handling the question of whether it should start at all!


PEP 315 is the only discussion (I've found) which looks 'outside' or 
'before' the loop itself. It proposed an "Enhanced While Loop", 
attempting to separate 'setup' or loop control from loop content. It was 
rejected.



So, reading-around brought nothing much useful. Back to the code-face...

Thank you to the several folk who responded with ideas to express/improve:

if list:
process_list() #the heading and for-loop, as above
else:
print( "Sorry...

NB this is a constructed 'toy example' attempting to be the shortest 
illustration of use-cases and invented purely to communicate the need 
and structure. It was expected to be interpreted as pseudo-python-code. 
(you'd not use/allow "process_list" as the name of a function, would you?)


(With apologies as necessary) one of the dangers of 'toy examples' is 
the reader taking them at face value, instead of as (over-)simplified 
illustrations. In 'real life' the loop code and the no-loop exception 
are both considerably longer than a single line. Accordingly, using a 
function would be a good way to summarise and self-document the 
activity, ie the if statement's two code-blocks would make the whole 
statement very/too-long (readability)!


The "if list:" expression is overly-simplistic. The recommendation of 
"if len(list):" is absolutely sound, for reasons of polymorphism.


In-lieu of a Python construct, there are definitely situations when use 
of a sentinel makes better sense. However, given their risk, in many 
ways Python tries to avoid using such, eg consuming iterators until a 
StopIteration exception is returned. (includes files, is subsumed by 
ContextManagers...), thus "pythonic". That said, the classic use of 
for... else... is in searching for a particular element within an 
iterable which has all the hallmarks of a "sentinel".



Today, kicking ideas around, I coded three other possible 'solutions' 
for the review team's discussions:


One of these involves coding three functions: the decision (yielding a 
boolean), the expected-case, and the unusual-case. The satisfaction in 
this was readability factors with a simple if statement..


Somewhat more complex, and I feel a bit OTT, was to sub-class list() and 
write a method which would indicate an empty list, plus include much of 
both the expected-case and the empty-list methods therein. Somehow 
"class ListShouldNotBeEmpty" doesn't seem a catchy (if descriptive) 
title - however, it works! The decision 'function' could also/then be 
made @property and (perhaps) thus contribute to readability.


Lastly, I 'remembered' conditi

Re: Loop with else clause

2019-02-09 Thread DL Neil

Possibly the final contribution:-


On 9/02/19 1:30 AM, Adriaan Renting wrote:


Wow, you dug deep.


=Thank you. It started to 'bug' me, so I really was 'scratching an itch'!



My example was the reverse of the "toy example"'s you mention as I find
that often code becomes much clearer if you order it such that
specific cases, sanity checking and exceptions go first, and then the
default case at the end.


=we have also had this discussion during code reviews. Do you think that 
choice/code sequence/prioritisation is related to one's facility with TDD?

(some might claim it is to do with experience and/or professionalism)

=My observation is that the TDD-people tend to do it 'your way', but 
those who 'first get it working' and then 'go looking for potential 
trouble' do the action-first, and exceptions-later.


=presumption: that the TDD people have thought more about definitions of 
'working' and 'failing' and like to implement all the 'fails' (get them 
'out of the way') in order to leave the 'pure' solution.

(no, let's not disappear too deeply down another 'rabbit hole'!)



So my general suggestion would be to handle your empty list/no valid
candidates cases first,
and then do the for loop at the end.

If you style this with if/elif/else, or put return statements in
certain places, I have no opinion about and will depend on the specific
problem.


...

=I offered the three ideas to the original coder of the actual application:-



Today, kicking ideas around, I coded three other possible 'solutions'



for the review team's discussions:

One of these involves coding three functions: the decision (yielding

a

boolean), the expected-case, and the unusual-case. The satisfaction

in

this was readability factors with a simple if statement..

Somewhat more complex, and I feel a bit OTT, was to sub-class list()

and

write a method which would indicate an empty list, plus include much

of

both the expected-case and the empty-list methods therein. Somehow
"class ListShouldNotBeEmpty" doesn't seem a catchy (if descriptive)
title - however, it works! The decision 'function' could also/then be



made @property and (perhaps) thus contribute to readability.

Lastly, I 'remembered' conditional expressions. Thus, furthering the



idea of two/three functions:

  process_list() if list_has_contents() \
else process_empty_list()



=she has grabbed the class construct and started to 'run with it'. At 
first I feared that I had 'created a monster'. However, once she'd 
improved my outline all manner of other code was filling-in the class. 
It turns-out that the zero-data consideration was not the only way in 
which this data/list varies from the standard. So, she is now monitoring 
how many entries are expected on the list, cf how many have been 
captured, and is planning to evaluate them with a sort & key=.


=Thus my solution, to sub-class from list and (only) modify 
__getitem__(), ie the "lazy" approach, has been changed to monitor the 
creation of the list. She no longer uses anything obvious such as len() 
but is keeping track with several booleans:

1 that there is actually some data,
2 how many elements are in the list,
3 how many elements are required for the application.
(perhaps someone who favored semaphores is going to say "ahah!"?)

=Using the 'toy' example of the film Oscar awards:
1. is exactly as discussed 'here'
2. the traditional use of len()
3. only the top four nominees are mentioned (thus the sort, enables a 
'cursor' featuring only the first four elements), before moving into the 
grand "and the winner is..." (the film receiving the most votes ie 
element[ 0 ] )


=Am almost looking forward to the follow-up code review...


Many thanks (to all) for contributing ideas and advice!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to exit from a nested loop in python

2019-02-09 Thread DL Neil

On 8/02/19 7:45 PM, Kaka wrote:

for i  in range(len(A.hp)):

 for j in range(len(run_parameters.bits_Mod)):
  req_slots[j] = math.ceil((A.T[i])

  for g in Temp[i]["Available_ranges"][j]:
   for s in range(g[0], g[-1]):
   if (s+req_slots[j]-1) <= g[-1]:
  if (Temp[i]['cost'][j] <= (run_parameters.PSD):  -- When 
this condition is true i want to break the nested loop and start from the begining
served_count +=1
A.T[i]["First_index"]= s
A.T[i]["Last_index"]= s+req_slots[j]-1
A.T[i]["Status"]= 1
A.T[i]["Selected_MOD"] = j
break

I have this code. When the last "if" condition is satisfied, i want to break 
all the loops and start the nested loop for next i. else, the loop should continue.



Put the nest inside a try...except block and raise an exception
(illustrated in many web refs)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: A limit to writing to a file from a loop?

2019-02-12 Thread DL Neil

Steve,

On 13/02/19 7:56 AM, Steve wrote:

My program reads from a text file (A), modifies the data, and writes to another 
file (B).
This works until I reach about 300 writes and no more lines are written to file 
(B).
I had to create a Counter and increment it to 250 when it gets reset.
Upon reset, I close the file (B) being written and reopen it for append.
Then it accepts the entire list of lines of data.
Bizarre?

  
 CycleCounter += 1

 if CycleCounter > 250:
   CycleCounter = 1
   DateReadings.close()
   DateReadings=open("Date-ReadingsAndDoses.txt", "a")
   DateReadings.write("{0:15} {1:>8} {2:>8} {3:>8} {4:<2} {5:>8} {6:>8} 
{7:>10}".format
   (ThisTimeDate, ThisReading, ThisDose1, 
ThisSensor, ThisTrend,
ThisTS, ThisPercent, SensorNumberDay2) + "\n")



Perhaps part of the transfer to email, but won't this code only output 
once per 250 records, cf 250 records per cycle?



Some suggestions:-

Test one: Prove that there is valid input
- is the code successfully reading more than '250' records?

Test two: Check the actual data
- is there anything strange about the '250th' record (the one that first 
exhibits the problem)?


Test three: Prove that it is not some Python<->file system issue
- what happens if the first input record is written (to a 'junk file') 
250+ times?


Test four: (possibly unnecessary after the above) Disprove a size issue
- what happens if you output a simple/hello world string (of the same 
number of bytes) instead of the incoming data, 250+ times?



Report back. If there are still problems, please show the original code 
and exception report...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sum of few numbers by using for and range

2019-02-17 Thread DL Neil

^Bart,

Which course are you attempting?

What are you using as learning material?
(it seems ineffectual)

- further comments interspersed, below:-


On 18/02/19 5:30 AM, Chris Angelico wrote:

On Mon, Feb 18, 2019 at 3:26 AM ^Bart  wrote:

I need to do what I wrote in the subject but... I don't understand how
could I fix my code... :\



When you want homework help, it is extremely useful to post the entire
challenge you were given, not just a one-line summary. What are you
actually expected to do? What are the restrictions?


Also, are you aware that there is a separate email list "for folks who 
want to ask questions regarding how to learn computer programming with 
the Python language and its standard library."?

(https://mail.python.org/mailman/listinfo/tutor)



I suspect, from your last few posts, that you should not be taking
particular challenges, but should instead go back to the basics of how
Python works. Reread the earliest material in your course and make


+1

As explained earlier, asking helpful people 'here' to complete the task 
for you helps no-one!
- you haven't really learned, and are unlikely to have mastered 
techniques necessary to pursue employment or hobby-interests, in future

- you've asked community-minded folk to give-up their time
- your trainer is unlikely to be fooled for long...



sure you truly understand what is going on. Try to piece together what
a section of code is doing, step by step. Write down on a piece of
paper what the variables are at each point in the program. Then, AFTER
doing the work manually, run the code and see if you were right.


+1

I recently audited a set of courses (last one yet to be released) on 
Coursera, out of U.Mich (Michigan, USA): Python 3 Programming 
Specialization 
(https://www.coursera.org/specializations/python-3-programming). I'm not 
recommending it particularly - it doesn't fit with my personal approach 
(which may say more about me!)


NB Coursera uses a 'freemium' business model. In my context "audit" 
meant 'evaluation', but in Coursera-jargon it means $free. Paying for 
such a course adds invitations to participate in project work, (?)final 
exam, and one hopes, earn a certificate.


The reason this course caught my attention (and which is relevant to 
you, per Chris' and Dennis' recent advice) is that the course revolves 
around an 'active textbook'. This intersperses learning material with 
mastery exercises, and pertinently, uses a 'widget' which steps through 
code, line-by-line, showing exactly what is happening to each variable. 
I was impressed!


In 'the good old days', we used to talk about having a 'paper computer'. 
In appearance, this was almost exactly like the above - where we could 
'see' exactly (what we thought) was happening inside the CPU. It was a 
testing/debugging tool before the first line of code hit the Python (or 
whichever) interpreter/compiler. (who says Test-driven Development is a 
"new" idea?). In short, it is an excellent tool for visualising learning!


NB There is a Python Debugger tool which operates similarly, but the 
learning tool is illustrative in nature, cf diagnostic.


Having mentioned U.Mich/Coursera, one of the most famous Python courses 
available over-the-Internet is Dr Chuck's "Python for Everyone". I'm not 
aware if he has upgraded those to use the same active textbook tool. 
That said, it is an enormously-popular avenue for exploring Python!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Sum of few numbers by using for and range

2019-02-17 Thread DL Neil

On 18/02/19 8:32 AM, Chris Angelico wrote:

On Mon, Feb 18, 2019 at 6:12 AM DL Neil  wrote:

The reason this course caught my attention (and which is relevant to
you, per Chris' and Dennis' recent advice) is that the course revolves
around an 'active textbook'. This intersperses learning material with
mastery exercises, and pertinently, uses a 'widget' which steps through
code, line-by-line, showing exactly what is happening to each variable.
I was impressed!


That sounds like an EXCELLENT way to do the second part - running the
code to see if you were right. I would still recommend doing it 100%
manually first, *writing down* your expectations, and only *then*
letting the computer do it. It's easy to watch the computer do
something and go "yes, of course that's what happens", but to still
not be able to replicate it yourself. True comprehension means being
able to predict what will happen.

Consider it like a falsifiable hypothesis in scientific research. "I
expect that, when I do X, Y, and Z, the result will be Q." Then you
actually perform those steps, and see what the result is. Were you
right? If not, how do you modify your expectations/hypothesis to
correct it? It's the last step that is the most interesting, because
that's where you truly learn. (And sometimes, that learning is
expanding the corpus of human knowledge. It's only when you disprove
your expectations that you can begin to pin down something like "oh so
time flows at different rates depending on gravity" or "huh, so it
turns out black-body radiation doesn't behave the way all the math
said it would".)


+1

For reference Chris (et al):
The 'active textbook' offers 'windows' which seem to be Idle, but in a 
controlled and prescribed environment. So, the learner first writes 
his/her code, and only then can run and/or step-through, as described.



+for ^Bart:
IIRC the early stages of the U.Mich/Coursera Py3 Pgmg course included 
coverage of "accumulators", which concept you have yet to learn - and 
certainly lists and ranges appear. Thus dealing with both of the 
conceptual errors causing grief in the original code-snippet. All the best!



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to play with Python in an existing app

2019-02-20 Thread DL Neil

Edmer,

On 21/02/19 7:56 AM, [email protected] wrote:

So I'm a newbie to Python. I got access to an existing RavenDB and am supposed 
to install it on aws.amazon.com. If I succeed in setting this up, I am supposed 
to write some Python code.

But how can I play with Python and test some querries without f#cking up the 
database? Because the RavenDB is working with an app that's currently being 
used by a few hundreds of people.

Should I ask for a copy of the RavenDB database and test it locally on my PC 
with PyCharm, for example?

Thanks for any suggestions on how to setup a safe working environment for an 
app that's already in use, so a beginner can play, learn and grow without 
damaging something :-)



Won't an entirely separate environment, whether on AWS or your local PC, 
solve your problem and prevent 'accidents'. NEVER test on 'live'!


Not being familiar with RavenDB, how easy is it to replicate the DBMS?

Worst case: how difficult would it be to create a second set of DBs for 
dev/testing; and then what differences would there be between the code 
used for testing and that used in production (the more changes needed, 
the more likely something will go wrong at the last step of 'going live'!)?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing performance question

2019-02-20 Thread DL Neil

George

On 21/02/19 1:15 PM, george trojan wrote:

def create_box(x_y):
 return geometry.box(x_y[0] - 1, x_y[1],  x_y[0], x_y[1] - 1)

x_range = range(1, 1001)
y_range = range(1, 801)
x_y_range = list(itertools.product(x_range, y_range))

grid = list(map(create_box, x_y_range))

Which creates and populates an 800x1000 “grid” (represented as a flat list
at this point) of “boxes”, where a box is a shapely.geometry.box(). This
takes about 10 seconds to run.

Looking at this, I am thinking it would lend itself well to
parallelization. Since the box at each “coordinate" is independent of all
others, it seems I should be able to simply split the list up into chunks
and process each chunk in parallel on a separate core. To that end, I
created a multiprocessing pool:



I recall a similar discussion when folk were being encouraged to move 
away from monolithic and straight-line processing to modular functions - 
it is more (CPU-time) efficient to run in a straight line; than it is to 
repeatedly call, set-up, execute, and return-from a function or 
sub-routine! ie there is an over-head to many/all constructs!


Isn't the 'problem' that it is a 'toy example'? That the amount of 
computing within each parallel process is small in relation to the 
inherent 'overhead'.


Thus, if the code performed a reasonable analytical task within each box 
after it had been defined (increased CPU load), would you then notice 
the expected difference between the single- and multi-process 
implementations?




From AKL to AK
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing performance question

2019-02-21 Thread DL Neil

George: apologies for mis-identifying yourself as OP.

Israel:

On 22/02/19 6:04 AM, Israel Brewster wrote:
Actually not a ’toy example’ at all. It is simply the first step in 
gridding some data I am working with - a problem that is solved by tools 
like SatPy, but unfortunately I can’t use SatPy because it doesn’t 
recognize my file format, and you can’t load data directly. Writing a 
custom file importer for SatPy is probably my next step.


Not to focus on the word "toy", the governing issue is of setup cost cf 
the acceleration afforded by the parallel processing. In this case, the 
former is/was more-or-less as high as the latter, and your efforts were 
insufficiently rewarded.


That said, if the computer was concurrently performing this task and a 
number of others, the number of cores available to you would decrease. 
At which point, speeds start heading backwards!


This is largely speculation because only you know the task, objectives, 
and circumstances - however, for those 'playing along at home' and 
learning from your experiment...



That said, the entire process took around 60 seconds to run. As this 
step was taking 10, I figured it would be low-hanging fruit for speeding 
up the process. Obviously I was wrong. For what it’s worth, I did manage 
to re-factor the code, so instead of generating the entire grid 
up-front, I generate the boxes as needed to calculate the overlap with 
the data grid. This brought the processing time down to around 40 
seconds, so a definite improvement there.


Doing it on-demand. Now you're talking! Plus, if you're able to 'fit' 
the data into each box as it is created, that will help justify the 
setup/tear-down overhead cost for each async process.


Well done!




---
Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

On Feb 20, 2019, at 4:30 PM, DL Neil <mailto:[email protected]>> wrote:


George

On 21/02/19 1:15 PM, george trojan wrote:

def create_box(x_y):
return geometry.box(x_y[0] - 1, x_y[1],  x_y[0], x_y[1] - 1)
x_range = range(1, 1001)
y_range = range(1, 801)
x_y_range = list(itertools.product(x_range, y_range))
grid = list(map(create_box, x_y_range))
Which creates and populates an 800x1000 “grid” (represented as a flat 
list

at this point) of “boxes”, where a box is a shapely.geometry.box(). This
takes about 10 seconds to run.
Looking at this, I am thinking it would lend itself well to
parallelization. Since the box at each “coordinate" is independent of all
others, it seems I should be able to simply split the list up into chunks
and process each chunk in parallel on a separate core. To that end, I
created a multiprocessing pool:



I recall a similar discussion when folk were being encouraged to move 
away from monolithic and straight-line processing to modular functions 
- it is more (CPU-time) efficient to run in a straight line; than it 
is to repeatedly call, set-up, execute, and return-from a function or 
sub-routine! ie there is an over-head to many/all constructs!


Isn't the 'problem' that it is a 'toy example'? That the amount of 
computing within each parallel process is small in relation to the 
inherent 'overhead'.


Thus, if the code performed a reasonable analytical task within each 
box after it had been defined (increased CPU load), would you then 
notice the expected difference between the single- and multi-process 
implementations?




From AKL to AK
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list




--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: sys.modules

2019-02-21 Thread DL Neil

Hello,


On 22/02/19 5:40 AM, ast wrote:

Is it normal to have 151 entries in dictionary sys.modules
just after starting IDLE or something goes wrong ?
 >>> import sys
 >>> len(sys.modules)
151


I don't use Idle. Written in python, doesn't it require various packages 
to run before it even talks to you, eg tkinter? Thus am not sure if they 
are also being counted. However:-


After firing-up Python 3.7 from the cmdLN, my system reported only 60.

Remember also, that the sys Run-time service is described as 
"System-specific parameters and functions", which will account for 
(some) differences by itself.




Most of common modules seems to be already there,
os, itertools, random 
I thought that sys.modules was containing loaded modules
with import command only.


Not quite true! Whereas the manual says
<<<
sys.modules This is a dictionary that maps module names to modules which 
have already been loaded.

>>>

also remember that import is not the only way modules are "loaded"! 
Built-in types (etc) are/must be loaded as part of python, otherwise 
nothing would work, eg float, int, list, contextlib, collections, 
functools, ... This is the modular/boot-strap method that is a feature 
of python.


Web-refs:
https://docs.python.org/3/tutorial/modules.html#standard-modules
https://stackoverflow.com/questions/7643809/what-are-default-modules-in-python-which-are-imported-when-we-run-python-as-for

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread DL Neil

Vergos,

Please provide more information and show how you've debugged the code so 
far...



On 25/02/19 7:03 AM, [email protected] wrote:

pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, hits, 
downloads, authuser FROM guests
WHERE pagesID = (SELECT ID FROM pages 
WHERE url = %s) ORDER BY visits DESC''', page )
data = pymydb.fetchall()
 for visit in visits:
   visit = visit.strftime('%A %e %b,  %I:%M %p')


Is this the actual code? How do we get from the collection of 
tuples/dicts called "data", to an iterable called "visits"?


Also: %e should likely be %w or %d.

Which 'connector' are you using between MySQL and Python?
(may not be the same as the one I favor)



'visit' is being returned from database containing a MySQL datatime field that 
i want to change to another format which is ('%A %e %b, %I:%M %p') thats why 
i'm using that function. If not convert or comment out then results are not 
appearing normally.


Where are these actual results? (might they help us to help you?)
What do you see, as the same row/col, when using the MySQL cmdLN shell 
or MySQL-Workbench (etc)?


Have you shown us what comes back as the first row's value for "visit"?
Please check its type() before the code processes it further - is it 
coming back as a Python date or time format, or is it a string?

Remember logging or even debug print()-s are your friend!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to format a datetime MySQL database field to local using strftime()

2019-02-24 Thread DL Neil

Vergos,

On 25/02/19 11:53 AM, [email protected] wrote:

Τη Δευτέρα, 25 Φεβρουαρίου 2019 - 12:38:43 π.μ. UTC+2, ο χρήστης 
[email protected] έγραψε:

Τη Κυριακή, 24 Φεβρουαρίου 2019 - 8:52:03 μ.μ. UTC+2, ο χρήστης DL Neil έγραψε:

Vergos,

Please provide more information and show how you've debugged the code so
far...


On 25/02/19 7:03 AM, [email protected] wrote:

pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, hits, 
downloads, authuser FROM guests
WHERE pagesID = (SELECT ID FROM pages 
WHERE url = %s) ORDER BY visits DESC''', page )
data = pymydb.fetchall()
  for visit in visits:
visit = visit.strftime('%A %e %b,  %I:%M %p')


Is this the actual code? How do we get from the collection of
tuples/dicts called "data", to an iterable called "visits"?

Also: %e should likely be %w or %d.

Which 'connector' are you using between MySQL and Python?
(may not be the same as the one I favor)



'visit' is being returned from database containing a MySQL datatime field that 
i want to change to another format which is ('%A %e %b, %I:%M %p') thats why 
i'm using that function. If not convert or comment out then results are not 
appearing normally.


Where are these actual results? (might they help us to help you?)
What do you see, as the same row/col, when using the MySQL cmdLN shell
or MySQL-Workbench (etc)?

Have you shown us what comes back as the first row's value for "visit"?
Please check its type() before the code processes it further - is it
coming back as a Python date or time format, or is it a string?
Remember logging or even debug print()-s are your friend!

--
Regards =dn


The  'connector' that i'am using between MySQL and Python is 'bottle-pymysql'

In the following code:

def coalesce( data ):
newdata = []
seen = {}
for host, ref, location, useros, browser, visits, hits, 
downloads, authuser in data:
# Here i have to decide how to group the rows together
# I want an html row for every unique combination of 
(host) and that hits should be summed together
key = host
if key not in seen:
newdata.append( [ [host], [ref], location, 
useros, browser, [visits], hits, [downloads], authuser ] )
seen[key] = len( newdata ) - 1  # Save 
index (for 'newdata') of this row
else:   # This row is a duplicate row with a different 
referrer & visit datetime & torrent download
rowindex = seen[key]
newdata[rowindex][0].append( host )
newdata[rowindex][1].append( ref )
newdata[rowindex][5].append( visits )
newdata[rowindex][6] += hits
newdata[rowindex][7].append( downloads )
return newdata


pymydb.execute( '''SELECT host, ref, location, useros, browser, visits, 
hits, downloads, authuser FROM guests
WHERE pagesID = (SELECT ID FROM pages 
WHERE url = %s) ORDER BY visits DESC''', page )
data = pymydb.fetchall()


newdata = coalesce( data )
for row in newdata:
(hosts, refs, location, useros, browser, visits, hits, 
downloads, authuser) = row

# start of table
pdata = pdata + ''

pdata = pdata + ' 
%s ' % hosts[0]

pdata = pdata + ''
for ref in refs:
pdata = pdata + ' %s ' % ref
pdata = pdata + ''

for item in (location, useros, browser):
pdata = pdata + ' %s 
' % item

print( visits )
pdata = pdata + ''
for visit in visits:
print( visit)
pdata = pdata + ' %s ' % visit
pdata = pdata + ''


if i try to print 'visits' filed before and during the loop the results is 
multiple

[Mon Feb 25 00:23:55.165094 2019] [wsgi:error] [pid 15158] [remote 
46.103.69.193:5068] visits
[Mon Feb 25 00:23:55.165098 2019] [wsgi:error] [pid 15158] [remote 
46.103.69.193:5068] visits
[Mon Feb 25 00:23:55.165102 2019] [wsgi:error] [pid 15158] [remote 
46.103.69.193:5068] visits
[Mon Feb 25 00:23:55.165107 2019] [wsgi:error] [pid 15158] [remote 
46.103.69.193:5068] visits
[Mon Feb 25 00:23:55.165111 2019] [wsgi:error] [pid 15158] [remote 
46.103.69.193:5

Re: How to format a datetime MySQL database field to local using strftime()

2019-02-25 Thread DL Neil

On 26/02/19 7:47 AM, Dennis Lee Bieber wrote:

On Mon, 25 Feb 2019 13:00:03 -0500, Dennis Lee Bieber
 declaimed the following:


My apologies for the mis-attribution -- due to spam, I tend to filter
out @gmail.com posts (the one flaw with Forte Agent -- it only filters news
groups on subject or author, whereas it can filter email on many other
headers -- but I don't use Agent for email ). I didn't realize I was
replying to a reply...



No problem - have done same myself.

I noted that "Wulfraed" answered a very similar question, right 'here', 
a few years back - so I was half-waiting for you to jump in!


At this stage, the OP doesn't seem to have mastered converting MySQL 
results into Python (a pain in and of itself). Accordingly, whilst a 
pythonic improvement was suggested along with debugging methods, had 
deferred SQL improvements until the root-problem was solved.


Thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Quirk difference between classes and functions

2019-02-25 Thread DL Neil

On 26/02/19 5:25 AM, ast wrote:

I noticed a quirk difference between classes and functions
 >>> x=0
 >>> class Test:
     x = x+1
     print(x)
     x = x+1
     print(x)

...


Previous code doesn't generate any errors.
x at the right of = in first "x = x+1" line is
the global one (x=0), then x becomes local
within a function, this is not allowed
 >>> x = 0
 >>> def f():
     x = x+1
 >>> f()
UnboundLocalError: local variable 'x' referenced before assignment
Since x is written inside the function, it is considered as a local
variable and x in x+1 is undefined so this throw an exception
Any comment ?



At first I misunderstood the question, and even now I'm slightly mystified:-

Is the observation to do with the principles of "closure" (being applied 
to the function) compared with the differences between class and 
instance variables?


For a little more fun, try expanding Test with:
def __init__( self ):
self.x = "something else"

What happens when you look at Test.__dict__?

What happens after instantiation:

t = Test()
print( t.__dict__ )

For extra credit: how does this change if we try modifying attributes 
from 'outside' the class definition?


t.x = 3.33

Are they all 'the same' or 'all different'?


A question from me: (I'm not an O-O 'native' having taken to it long 
after first learning 'programming') I've used class attributes to hold 
'constants', eg


MAXIMUM_WEIGHT = 100

Thus only an assignment to which reference/assertions will be made 'later'.

I have initialised a counter to zero and then incremented within the 
instantiated object's __init__(), ie keeping track of how many of 'these 
objects' have been instantiated.


So, I can imagine taking a value from outside the class' namespace, 
modifying it in some way (per the first "x = x+1") and then retaining 
the result as a class attribute (a calculation performed once - when the 
class code is compiled).


However, (after that first calculation/definition of the class 
attribute) why would one (normally) want to redefine the same class 
attribute (the second x = x+1), at the 'class level'?

(perhaps just done for its amusement value?)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Connector/Python, MySQL Workbench Issue

2019-02-25 Thread DL Neil

Scott,

On 26/02/19 2:15 PM, Scott Sorgent wrote:


I was trying to install MySQL Workbench and it asked me to install the 
Connector/Python 3.7.  I installed Python 3.7.2, restarted the computer and 
tried to install MySQL workbench again and it told me again that I needed to 
install Connector/Python 3.7.  I found the download for MySQL Connector/Python 
3.7 then downloaded and tried installing, but immediately, I get a popup saying 
Python v3.7 not installed.  Why is this happening and what should I do to get 
everything installed and working?



Can we start with the name and version of the Operating System you are 
using?


Are you installing the three products as a user or root/an administrator?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Connector/Python, MySQL Workbench Issue

2019-02-25 Thread DL Neil

Scott,

Someone else will be better able to assist - I use Linux.

In the mean-time, may I suggest combing-through the MySQL docs for 
installing on Windows - the suspicion about Administrator cf user remains...


Yes, I often find MySQL-Workbench a useful tool when interacting with 
RDBMSes on remote machines and VPSes. Also, have been hung-up on 
mismatching v5.n or v8.n between my m/c and the other. Sigh!



On 26/02/19 3:16 PM, Scott Sorgent wrote:
OS:  Windows 10 Home version 1803, 64 bit, x64 processor, Intel Core I7 
Processor


I believe I'm just installing as an individual user.  I opted for the 
Full Installation on the MySQL Workbench program though which tries to 
install everything.  I'm going to be using for a big MySQL database 
through AWS.


*From:* Python-list 
 on behalf of DL 
Neil 

*Sent:* Monday, February 25, 2019 5:50 PM
*To:* 'Python'
*Subject:* Re: Connector/Python, MySQL Workbench Issue
Scott,

On 26/02/19 2:15 PM, Scott Sorgent wrote:


I was trying to install MySQL Workbench and it asked me to install the Connector/Python 3.7.  I installed Python 3.7.2, restarted the computer and tried to install MySQL workbench again and it told me again that I needed to install Connector/Python 3.7. I found the download for MySQL Connector/Python 3.7 then downloaded and 
tried installing, but immediately, I get a popup saying Python v3.7 not 
installed.  Why is this happening and what should I do to get everything 
installed and working?



Can we start with the name and version of the Operating System you are
using?

Are you installing the three products as a user or root/an administrator?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using PyArg_ParseTuple to with optional fields.

2019-02-28 Thread DL Neil

Anthony,


On 28/02/19 10:18 PM, Anthony Flury via Python-list wrote:
I am trying to write an extension module with a function (actually an 
__init__ method, but I am not sure that matters) where the function can 
be called as either :

     my_func()
or
     my_func( a, b, c, d) - where a,b,c,d are all doubles.
I would prefer not to allow the function to be called with some 
arguments specified - it is either all four - or none.


Perhaps it does matter - __init__() only ever returns None, which 
may/not be of-concern at the 'top end'.


During the last few days, either 'here' or over on Python-Tutor, there 
has been a discussion about alternate ways to instantiate an object, ie 
with different numbers of arguments.




I have tried the following format strings to PyArg_ParseTuple :
  * "" - but this a mandatory 4 doubles - doesn't allow for the no

...> Can I do what I want with a single call to PyArg_ParseTuple  ?

+1 for using provided (and optimised) standard facilities!

What advantages does PyArg provide? Has its use become 'blinkers' - a 
straight-jacket to your thinking?


If the data is coming from outside Python directly, is it not possible 
to use named-keyword arguments, ie pick-up the 'optional' 
auto-magically? Somewhere in the existing code there's probably already 
some coding for the 'empty args' option, inserting default values...


How about *args (or *kwargs)? Remember that the "args" (sans asterisk) 
becomes a tuple inside the method. It can be empty or filled. That 
leaves you with two tests: len() zero or four, and (optionally) a loop 
to check that the four arg-tuple elements are all() floats.


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Class Issue`

2019-03-05 Thread DL Neil

Milt,

On 6/03/19 11:39 AM, Milt wrote:

The following code gives me unusual results - base on experience with C++.
class Car:
    # carColor = None
    # mileage = None
    def __init__(self, color = None, miles = None):
   self.mileage = miles
   self.carColor = color
    def print(self):
   print(f"Color:   {self.carColor}")
   print(f"Mileage: {self.mileage}")
myCar = Car('blue', 15000)
myCar.print()
print()
myCar = Car(25000, 'orange')
myCar.print()

When executed the following results:
Color:   blue
Mileage: 15000
Color:   25000
Mileage: orange
It appears that the constructor ignores the assignment statements and 
makes the assignment based on the ordering in the __init__ declaration.



It is risky to decide that Python should behave in a certain fashion, 
just because another language does. Would you decide that the word 
"blue" may not be used because in French it is "bleu"? If all 
programming languages did look/work the same way, why would there be 
multiple languages? However, your understanding of C++ gives you a 
flying start with Python - apart from a few pesky 'gotchas'!



In the term "ignores the assignment statements", what "assignment 
statements" are being discussed?



Yes, without keywords, the positional rule applies.

myCar = Car('blue', 15000)
is the same as:
myCar = Car(color = 'blue', miles = 15000)

Instead of:
myCar = Car(25000, 'orange')
try:
myCar = Car(miles=25000, color='orange')

If you've gone to the trouble of defining keyword-arguments in the 
method, greater satisfaction will be gained from calling the method 
similarly (and cause less confusion on the part of your readers!)



Meantime I have a very low-mileage Edsel in an attractive lemon color, 
going cheap...



Jokes aside: using the __str__() and __repr__() "magic methods" is more 
'pythonic' than adding a print method to a class.


For a nicely-formatted output (albeit without mentioning that it is 
describing a "Car" or "myCar" - per print(), above):


 def __str__(self):
return f"Color:   {self.carColor}\nMileage: {self.mileage}"
...
myCar = Car(color = 'blue', miles = 15000)
print( myCar )

For extra credit, seeing we're talking about 'being pythonic': car_color 
and my_car.



Alternately, to present the output formatted as a class definition/ready 
for instantiation:


 def __repr__(self):
return f"Car( color={self.car_color}, miles={self.mileage} )"

NB if both methods appear in a class, printing the class (ie print( 
my_car ) ) will prefer __repr__() over __str__().



All the best...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: System Beep?

2019-03-08 Thread DL Neil

Dear Squeak, sorry, Dear Steve,

Back in the ?good, old days when we used to walk alongside a mainframe 
CPU whilst it cogitated, we would often use the BEL character to alert 
us to job completion (and meantime bunk-off to go have a coffee, cakes, 
...) - more seriously, it alerted telegraph and telex operators to an 
incoming message (you can still hear similar "beeps" on some 
emergency-worker radio systems, NASA moon mission video-replays, etc).


In the grips of nostalgia, I tried to make it work using the REPL, and 
failed, but first...



On 9/03/19 7:13 AM, Steve wrote:

How can I cause a system beep using code?
This is using the computer's internal speaker, not an audio external
speaker.
Do I have control of duration or volume?


The BEL character was included in the ASCII standard as chr(7)*. Back in 
those days, the rest of the world didn't exist - the "A" stands for 
"American". Accordingly, the huge advance was that we would be allowed 
to use lower-case letters, instead of all-caps (capital letters). Using 
French accents or German umlauts (etc), anything beyond the "standard" 
26-letters of "the" alphabet, would have been infra-dig to a well 
brought-up, clean-cut, American boy ("truth, justice, and the American 
way"*) - excepting that he wouldn't have understood the term, because 
didn't know of any other language than English. This problem was 
acknowledged and solved with Unicode. Viva Python 3!


Before you laugh, perhaps in disbelief that at one time computers ran 
exclusively in upper-case, take a closer look at ASCII, because even 
then there was no "$" or "£", only a generic currency symbol, "¤". What 
were they thinking? Simple: computers worked with numbers - why 
clutter-up the place by adding pesky letters, labelling 'answers', and 
stuff like that?


Whilst we have protocols or understandings in Python, eg a file simply 
ends, there is no need for any special indication or code; back in those 
?good, old days there were a number of different ways to encode 
characters AND to indicate other features of a file. Accordingly, the 
"II" part of ASCII - Information Interchange.


So, it was not merely a character set in terms of an alphabet, but by 
standardising some universal 'understandings' made "interchange" 
possible between computer systems (without which the Internet would 
never have become a possibility!). We knew these non-alpha components as 
"control characters". They still exist in various forms today - I was 
helping a Network Tech revise for his exams, and we ran through the 
exchanges necessary to establish a computer on a network using DHCP, and 
instead of "right" or "correct" I joked with him by saying "ACK" (and 
later, when he made a mistake "NAK") which really made him blink!


The really 'fun' ones today (because there is a difference between Linux 
and MS-Windows, ie we've lost the "standard") are "carriage return" (the 
process of pushing a typewriter's "carriage" (roller holding the paper) 
from the (right-hand!) end of one line all the way to the left again), 
"line feed" which was the second half of the typewriter process, when 
you first pulled the big handle at the top-right of the machine, it 
rolled the paper upward (normally) one line - sometimes called "New 
line". Thus "CR", "LF", and often "CRLF", and "NL". (why have two codes 
to perform what is (now!) one action?)


"BEL" is one of those "control characters".

If you are familiar with Python's chr() and ord(), you will remember 
that characters can be represented both as strings and as integers (in 
the case of ASCII, one character occupied one byte; but now that Python 
3 uses Unicode, the one-to-one is no longer necessarily true). Thus 
control characters can be expressed in either representation*. In the 
case of BEL, my elephantine memory immediately recalled it as 7! As if 
that wasn't enough, Python also has its set of string literals and 
escape characters*.


Just for fun, I started playing in the Python shell. I couldn't persuade 
v3.6 to ring my bell (sob, sob). Searching revealed discussion of "\A" 
and of an official Unicode character, but despite the "you got mail" 
message ringing in my ears, I couldn't bell the cat* (er, python)


>>> print( chr( 7 ) )

>>> print ('\a')

>>> print( u"\u2407" )

[in each case, the blank line of 'output' and end="\n" default-action 
should have followed the bell ringing/beeping, but didn't]


Does it work for you?


* web-refs:
https://en.wikipedia.org/wiki/Bell_character
https://docs.python.org/3.6/reference/lexical_analysis.html#literals
https://linuxconfig.org/list-of-python-escape-sequence-characters-with-examples

in case you program in multiple languages:
https://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell

being supercilious:
https://www.outsidethebeltway.com/superman_truth_justice_and_all_that_stuff/
https://en.wikipedia.org/wiki/Belling_the_Cat
[this guy is an ancestor - does that perhaps explain why I answer 
questions

Re: System Beep?

2019-03-08 Thread DL Neil

Steve,

On 9/03/19 11:03 AM, Steve wrote:

I tried all three, nothing audio.  I am beginning to wonder if something I the 
operating system is at fault.
The three lines do produce symbols.  The first two are a rectangle with a space in the 
middle and the last one spelled out "bel" in short/small characters.



You've piqued my interest. I haven't worked with sound using Python, but 
a future project, presently graphics/video, could easily expand...


I don't think it is an OpSys fault, per-se. Someone with some 
Python-audio, indeed Linux-audio (in my case) experience may well 
blow-apart my theory, but here goes (E&OE):


Python print()s to files. Normally the shell and a running program will 
print() to the screen. This can be piped or re-directed to a disk-file 
(for example). Thus, many such implementations have no bell to ring!


In the case of Linux, audio has long been problematic. Indeed there are 
Python interfaces to both Alsa and gstreamer. Ahah! Does this mean that 
the Python-OpSys relationship doesn't include sound, natively? ie that 
one interfaces?pipes sound to an audio sub-system rather than the OpSys 
itself.


Web-searching for "python sound" produces a number of 'hits'. A quick 
scan revealed a preference for working with audio files, eg mp3, wav; cf 
ASCII (or whatever) characters. I did come across 
https://pypi.org/project/kaching/ which offers similar facilities to 
those described earlier, from my mainframe days: "it worked", "it 
didn't", "you're a winner!".



A Linux 'solution' which led to my thinking (above):
ossaudiodev — Access to OSS-compatible audio devices
This module allows you to access the OSS (Open Sound System) audio 
interface. OSS is available for a wide range of open-source and 
commercial Unices, and is the standard audio interface for Linux and 
recent versions of FreeBSD.

https://docs.python.org/3/library/ossaudiodev.html
(presumably it relates to the Windows i/f others have mentioned)

A survey:
https://wiki.python.org/moin/Audio
(last edited three years ago)

No date on this one, but comments are very recent:
Play sound in Python
Play sound on Python is easy. There are several modules that can play a 
sound file (.wav).

These solutions are cross platform (Windows, Mac, Linux).
The main difference is in the ease of use and supported file formats. 
All of them should work with Python 3. The audio file should be in the 
same directory as your python program, unless you specify a path.

https://pythonbasics.org/python-play-sound/

Playsound 1.2.2 (last release nine months ago)
Pure Python, cross platform, single function module with no dependencies 
for playing sounds.

https://pypi.org/project/playsound/

Pypi has:
762 projects for "sound"
https://pypi.org/search/?q=sound

"Python and Sound" is a constructive tutorial which looks a bit old, but 
may suit your application (beyond BEL). However, it uses JES (which I 
came across years-and-years ago, but rejected because it is Java-based 
(bias alert!) which may/not be available for Python (or Jython!?) these 
days):

http://www.cs.uregina.ca/Links/class-info/325/PythonSound/index.html


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python resources recommendations

2019-03-09 Thread DL Neil

Hello Arup,

On 10/03/19 3:01 AM, Arup Rakshit wrote:

Hello Python,
This is my first time in this mailing list. I am a Ruby/JS developer by day. I have 
decided to learn Python now this year. Being an experienced developer as I said above 
which resources I should pick to learn Python in and out? Currently I am reading this 
https://docs.python.org/3/tutorial/index.html 
 . What next you would recommend 
me after this? I would like to learn Flask once I feel good with Python core.



There is such a wealth of resources to learn Python that this question 
is somewhat difficult to answer.


Firstly, there is another mailing list 'here', called Python-Tutor.

Secondly, it depends upon your starting-point and your preferred mode of 
learning.


Apparently you are a programmer, so you don't need to be told the 
difference between integers and reals/floating-point numbers, and thus 
'My first programming book using Python' would be ineffectual.


There are Python courses on all of the major learning platforms, eg edX, 
Coursera, Lynda/LinkedIn, etc. Most of which one may access for $free or 
pay for a certificate (pending tests, assignments, etc). I've recently 
audited a "Py3" course out of U.Mich which features an interesting 
on-line course-book and coding environment (if you head this way, I'll 
be interested to hear feedback!) The same also offer "Dr Chuck's" 
'Python for Everyone' courseware (videos alongside his "Python for 
Informatics" book).


There are many, many books - if you ask for specific recommendations you 
will be inundated! The book I used (many years ago, 'Chun') was Python2. 
I recommend that you start with Python3 and not look back! Several 
'books' are available for download/CC-license. If you have access to a 
library, they're likely to have something, otherwise your favorite 
search engine...


All the best!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python resources recommendations

2019-03-09 Thread DL Neil

AK,


On 10/03/19 12:41 PM, Alex Kaye wrote:

DL,
Good advice.
U of M is well done and interesting.


Actually, I criticised them - but was looking at matters such as 
"delivery" and from a cognitive psychology perspective - on behalf of, 
but quite different to, the needs of 'the average' trainee!


From a programming/Pythonic view-point, I sadly noted Java-influence 
creeping-in: weak use of Python terminology, pythonic coding approaches, 
and similar. Probably won't hurt the average beginner, but not the best 
training approach.


At the moment, there are a number of unhappy people who purchased the 
entire specialisation (five courses), but currently stalled because the 
last course will not be produced and ready for use until early next 
month. Slightly naughty, but courseware needs to be carefully 
constructed and that (as per program design) is both time-consuming and 
something it pays not to rush!


On the plus-side, the material covers the ground, and does-so quite 
quickly. I haven't seen any feedback from 'beginners' to be sure of 
pace. There are a number of interesting worked-examples, which can be a 
point-of-boredom in training/'toy examples' (I played with Python's 
"turtle", simply because I'd never touched that sort of thing before).


So, to the OP, please put my bias(es) aside, take AK's positive 
experience, and try it for yourself...
(you can always start-out $free, and once satisfied, return later to 
fulfil the requirements and achieve certification!)




One wonders what Arup plans to use Python for.


That's a very good point, which I didn't cover, earlier. Whereas 
previously one started with books that might be called 'Python for raw 
beginners' or some-such, these days there are plenty of more specialised 
books, eg 'Learn Python for Data Science', etc.




I am dabbling and am relearning from DOS and machine language on AppleII.


Which is another somewhat specialised area: MicroPython, Python for 
Raspberry Pi, and similar for other smaller/older machines, SBCs, etc! 
We now risk confusing the OP...


I remember those words - back in the days when my hair had color (and 
not from out of a bottle either). Using the power of Linux, every day I 
see much of the 'old' from DOS, CP/M, PDP minis; in our ever-green 
terminal interface. However, despite much of my hardware being 'old' (by 
other people's standards) I have no wish to go back as far as the Apple 
][ - floppy disks, poor-quality display screens, etc. IMHO, there's too 
much to learn, attempting to keep-up with 'the modern stuff', the 
opening of new vistas... However, I can imagine the appeal of 'history'. 
Have fun!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help!!! How to apply my created function to another function

2019-03-10 Thread DL Neil

Dear Joyce,


On 11/03/19 7:30 AM, [email protected] wrote:

...

A = [ 4, 5, 1]

#TASK0

def displayVector(v) :

 print(v)

displayVector(A)

...


B = buildRandomVector(A)

def vectorMagnitude(v) :

 tsum = 0

 for i in v:

 tsum = tsum + i**2

 x = math.sqrt(tsum)

 print(x)

vectorMagnitude(B)  == this is problem



Perhaps "this..." is not, but is merely where you *notice* a problem?

After defining B, and before assessing its magnitude, try displaying 
that vector.


Does it contain what you expect?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help!!! How to apply my created function to another function

2019-03-10 Thread DL Neil

Luuk,


On 11/03/19 8:02 AM, Luuk wrote:

On 10-3-2019 19:30, [email protected] wrote:

Please see the last line


When reading above, i was thinking about this joke:

...> ;)


Yes, I had a similar reaction to the wording: why not put *it* first. 
Having lived and worked in many countries/cultures, I try not to demand 
high degrees of English spelling or grammatical competence - and ask 
that natives of such places expect (only) similarly of me, in their 
language!



OTOH...

One of the disadvantages of an interpreted language is that 'things' 
must be defined before they can be 'used' (except in certain specific 
cases). So, it is not possible to execute func( args ) until 'the last 
line' - or more accurately, until *after* the

def func( params ):
etc
definition.

[insert discussion about "single-pass" and "multi-pass" interpreters here]

I often think how much more preferable it would be to begin my programs 
with the 'mainline' and leave the 'compiler' to integrate the mentioned 
functions, classes, modules... 'later'/as-needed - instead of having

if __name__ == "__main__" :
towards the "last line", and having to find/scroll the editor to start 
reading.


[yes, much web-based code has a 'director' as its mainline/.wsgi file; 
and imports routines as (page) handlers!]


When you think about it, Python often says 'see later'/'see the last 
line'. Maybe the 'joke' is on us?



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: "use strict"

2019-03-11 Thread DL Neil

Abdur-Rahmaan, with greetings,


On 12/03/19 6:45 AM, Abdur-Rahmaan Janhangeer wrote:

Greetings,
would it be a good idea to add a use strict in py like js?
recently i was helping someone and that was one annoying part where a typo
in a var name caused an unintended variable to slip in.
maybe something like that
# -*- strict -*-
# -*- explicit -*-
could be used to prevent it



We asked for this consideration, in COBOL and FORTRAN, back in the 
seventies - when the time between "submitting a job" and the computer 
reporting typos was measured in hours, if not 'overnight'. Surely the 
computer could auto-correct:


AND ONE TO COUNTER.

to:

ADD ...

The problem with that, is that if the computer does something 'wrong' in 
its attempt to be 'right', it would be even more "annoying"!


When we moved to PCs, the 'bright, young, things' pointed-out that 
computer-time had become cheap (and staff-time expensive) and that I 
should become more inclined to 'throw' my code at the interpreter and 
have it 'check for errors'. However, you've pointed-out the 'down-side' 
to such practice (even if your experience was accidental)!



Is there any substitute for reviewing one's code with a critical eye - 
do the job descriptions say "attention to detail"?



Perhaps there is some happy medium?


More constructively: doesn't every competent programming editor 
anticipate data-entry: suggesting variableNMs, python key-words and even 
whole constructs, also offer a spelling-checker? I find such, VERY helpful!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: "use strict"

2019-03-11 Thread DL Neil

On 12/03/19 8:00 AM, Abdur-Rahmaan Janhangeer wrote:

about the editor part i think yes it'd underline unused variables or
somewhat similar.


is that the best we can hope for (coupled with type annotations)?



the problem was that i was reviewing the code, since everything worked (no
errors but wrong output for sure) it took sometimes to find that var. it
was like someone telling me there is fish in that lake and i was throwing
my line trying ...
just a way to flag those types of vars when needed.



Yes. Such is enormously frustrating, but where does it fit in the wider 
scope of coding in Python? Proportionally?



Once again at risk of tripping over my long, flowing, beard: in the 
(?)good, old days, when every compilation resulted in a pile of 
print-out (and hopefully no syntax errors or typos); we could request a 
list of all of the variables/symbols defined in the code. One still had 
to scan that list manually, and pick-out any inconsistencies, eg 
misspellings!



Which made me think about the Python debugger 
(https://docs.python.org/3/library/debug.html)


[regret: since working with a team that demanded I update/learn/follow 
TDD (Test-driven Development), I haven't (?gone back to) used PDB since 
the time when all of my coding was in Py2!]


If you haven't already, it might be worth a quick shufti. Aspects may 
help you/your colleague!



A debugger will enable you to monitor the values stored in variables - 
but may not be so helpful, in that you must either look at 'everything' 
or first be aware of which variable(s) is/are causing problems. (per my 
'history lesson', above)


There are a variety of Python-compatible debuggers. One may suitably 
cover your need. (https://wiki.python.org/moin/PythonDebuggingTools)



In other threads I've enthused about the learning tools employed in the 
new-ish U.Mich/Coursera Py3 course. One of those tools, which your 
colleague might find helpful, is Philip Guo's Python Tutor 
(http://www.pythontutor.com/).


This tool also allows one to step-through Python code (or run to 'the 
end'), and right beside its 'terminal window', dynamically maintains a 
diagrammatic view of current-values and where they are kept in storage 
(making use of the "frames" within Python's 'innards') - so, also handy 
for noting separations of "scope"...


Trivial example: 
http://www.pythontutor.com/visualize.html#code=a%20%3D%201%0Ab%20%3D%202%0Ac%20%3D%20a%20%2B%20b%0Aprint%28%20f'%7Ba%7D%20%2B%20%7Bb%7D%20%3D%20%7Bc%7D'%20%29%0A&cumulative=false&curInstr=4&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false

[NB I'm not sure how long this link will live]

Ahah! Showing the global frame/list of variables and their values, 
immediately highlights the situation where an "h" shows-up when we think 
we're using "g".



OTOH it's a tutorial tool - so its use may be more trouble than it is 
worth in the professional environment. So, returning to my (personal) 
comment about PDB. (which was not meant to be at all derisive - every 
tool has its place) My experience (again, personal - if I may), is that 
once 'the guys' tuned me in to TDD, I found that because we were writing 
(and testing) smaller units of code at one time (for later 
assembly/integration into larger units), 'silly mistakes', eg my making 
a typo, became evident much 'earlier' - and when the 
debugging/tracing/testing was so much easier! That said, I can 
immediately see why a 10~20 line function is unlikely to require my 
pulling-out a "big gun" such as PDB - and if it was particularly 
tricky/causing me frustration, such would be easy-enough to drop into 
the PythonTutor tool!



[others may counsel differently - in which case, I'm ready to (re-)learn...]
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python scope question

2019-03-12 Thread DL Neil

Arup,


On 13/03/19 3:38 AM, Arup Rakshit wrote:

I have questions how nonlocal and global affecting the variable assignment. 
Also how each print statement looking up the values for the spam variable. This 
scope thing in python is very confusing too me still. Can anyone help me to 
understand this code w.r.t to scope in Python?

...

$ python3 sample.py
After local assignment: test spam
After nonlocal assignment: nonlocal spam
After global assignment: nonlocal spam
In global scope: global spam



Think this will help.

Watch the scopes 'appear' and operate in front of your very eyes: 
https://goo.gl/JC6SSh


or
http://pythontutor.com/visualize.html#code=def%20scope_test%28%29%3A%0A%20%20%20%20def%20do_local%28%29%3A%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22local%20spam%22%0A%0A%20%20%20%20def%20do_nonlocal%28%29%3A%0A%20%20%20%20%20%20%20%20nonlocal%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22nonlocal%20spam%22%0A%0A%20%20%20%20def%20do_global%28%29%3A%0A%20%20%20%20%20%20%20%20global%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22global%20spam%22%0A%0A%20%20%20%20spam%20%3D%20%22test%20spam%22%0A%20%20%20%20do_local%28%29%0A%20%20%20%20print%28%22After%20local%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_nonlocal%28%29%0A%20%20%20%20print%28%22After%20nonlocal%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_global%28%29%0A%20%20%20%20print%28%22After%20global%20assignment%3A%22,%20spam%29%0A%0Ascope_test%28%29%0Aprint%28%22In%20global%20scope%3A%22,%20spam%29%0A&cumulative=false&curInstr=24&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&te
xtReferences=false


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: UG Announcement - Python Mauritius User-Group (pymug)

2019-03-14 Thread DL Neil

On 14/03/19 6:53 PM, Abdur-Rahmaan Janhangeer wrote:

As per requirements, i'm announcing the existence of the Python User-Group
for Mauritius, an island in the Indian Ocean. Below are some info.


Congratulations!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Not Defined error in basic code

2019-03-14 Thread DL Neil

Jack,


On 15/03/19 3:05 AM, Jack Dangler wrote:

Just getting started with tutorials and such, and don't understand this -



Did you answer the post asking which tutorial you were following/copying?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Not Defined error in basic code

2019-03-14 Thread DL Neil
Just getting started with tutorials and such, and don't understand 
this -

Did you answer the post asking which tutorial you were following/copying?

Sorry - it is this -
https://www.learnpython.org/en/ ..
The section is on classes and objects - 
https://www.learnpython.org/en/Classes_and_Objects



Wanted to check: Someone publishing the 'first code' in this thread as 
training material, would have been 'unhelpful'.


Those guys have a good reputation - if the code camp approach suits the 
learner, rapid progress can be made.


The examples they provide illustrate attributes being 'defined' with a 
value. (unlike the first code 'here' which only listed attributes)


This feature of Python's dynamic nature often confuses folk who come 
from other, more rigidly defined, languages - there is no need to 
declare "id" as an integer per-se, passing it an integer constant as its 
value performs two tasks for the price of one!


Advice (if I may): don't be too literal in attempting to write Python 
the way you currently write xyz-language code.


You may find it helpful to combine those tutorials with similar 
information from additional sources, eg the Python docs site's tutorial, 
other on-line books, 'dead-tree' sources, other on-line training, etc. 
Whilst it seems like more work (it's certainly more reading/scanning), 
two non-identical statements of 'the same thing', will express things 
differently. Often something from one source that is initially puzzling, 
when compared with another presentation of the 'same', helps learners' 
minds go 'click' or to enjoy that 'ahah moment'.


All the best...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Not Defined error in basic code

2019-03-14 Thread DL Neil
Thank you sir. I think you may be on to something there. I've done 
mainframe, machine, 3GL, and 4GL languages, but the last couple I've 
taken on have given me headaches. I guess I'll have to just read a bunch 
first and then try and write something simpler than what I'm attempting 
to take on... Thanks for your help and understanding.


Apologies for any misunderstanding. Don't 'stop'!

Keep reading one 'chunk' of learning at a time, and then proving it has 
lodged 'between the ears' by experimenting.


However, if it doesn't make sense/come together for you, 'read around'. 
The frequent practice is vital to effective and efficient learning (in 
my professional opinion).


In fact, as you have probably noted throughout your career, one of the 
best things a professional can do, is to keep reading, even re-reading, 
about the chosen topic.



PS us 'silver surfers' have to stick together...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: I wrote a free book about TDD and clean architecture in Python

2019-03-19 Thread DL Neil

On 17/03/19 12:29 AM, [email protected] wrote:

I published on Leanpub a free book, "Clean Architectures in Python". It's a 
humble attempt to organise and expand some posts I published on my blog in the last years.
You can find it here: https://leanpub.com/clean-architectures-in-python

The main content is divided in two parts, this is a brief overview of the table 
of contents
* Part 1 - Tools
- Chapter 1 - Introduction to TDD
- Chapter 2 - On unit testing
- Chapter 3 - Mocks
* Part 2 - The clean architecture
- Chapter 1 - Components of a clean architecture
- Chapter 2 - A basic example
- Chapter 3 - Error management
- Chapter 4 - Database repositories



Unfortunately, the Kindle edition does not have a Table of Contents.

One might make a joke about (the book's) "architecture", but such humor 
often fails to carry-across language-translations.


A great effort, G!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: I wrote a free book about TDD and clean architecture in Python

2019-03-19 Thread DL Neil

On 20/03/19 7:18 AM, Leonardo Giordani wrote:

Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub 
processing chain (I believe, I'll have a look just to be sure). I hope the book 
will be useful even with this little issue. Thanks for reading it!



To be fair, that was one of my assumptions - publishers often imagine 
that a simple tool will convert between formats. (Um, no!) However, if 
they think it acceptable to publish a learned text without a ToC (or an 
Index? - haven't read that far), then I'd recommend finding another 
publisher who will properly respect your efforts! "Lean" shouldn't mean 
"lazy"!


Yes, I'm happy reading from cover-to-cover. Unfortunately, not being 
able to refer back to (say) the Mocks chapter, means it will be of 
little utility (to me) in-future. After all, if I access your blog 
on-line, can't I use a search facility to find a remembered post/'chapter'?

(ComSc: sequential/serial cf direct-access!)

Publishing criticisms aside, thank you!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: File not closed

2019-03-20 Thread DL Neil

On 2019-03-20, ast  wrote:

In the following snippet, a file is opened but
without any variable referring to it.
So the file can't be closed.

[line.split(":")[0]
   for line in open('/etc/passwd')
   if line.strip() and not line.startswith("#")]

What do you think about this practice ?


As others have agreed, the lack of close() is not good practice, even if 
it is unlikely to reduce anyone to tears.


Two other points, if I may:

1 it is a fairly complex line, having been split into three. If it is 
simplified into an explicit foreach-loop, then a file-handle becomes 
necessary - and can be closed. NB The greatest benefit there lies in the 
simplification/readability.

(not a reflection on you, but thinking of 'future-readers')

2 this (revealed snippet of) code will fail on a huge number of 
machines. [insert comment about the superiority of Linux/the failings of 
MS-Windows, here] Accordingly, it should be wrapped into a try...except 
block. That being the case, by unwinding the foreach-loop (1) and adding 
try...finally, it'll 'tick all your boxes'! There's also room for an 
illuminating (and educational) "I can't do that Dave" errmsg...


(despite my also being a fan of context-managers, per previous advice!)

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Might be doing this wrong? (Turtle graphics)

2019-03-20 Thread DL Neil

Jason,

On 21/03/19 12:34 PM, [email protected] wrote:

So, I typed in code:
from turtle import *
forward(100)
right(120)
clear()
It didn't work! It kept on saying that there was an indent and the first line 
was wrong. Help!



It would be most helpful if you gave us the exact error msg, in the same 
way that you copy-pasted the source-code.


"Turtle" is not part of the Python 'core'. It has to be added from the 
Python Standard Library (PSL).


My !GUESS! is that the Turtle library is not (yet) available on your 
system. Did you first "pip" or otherwise download the library?


(I have, and the code works happily)

WebRefs: (modify to suit the version of Python in-use)
https://docs.python.org/3/installing/index.html?highlight=pip
https://docs.python.org/3/library/turtle.html

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: log file

2019-03-21 Thread DL Neil

On 22/03/19 4:25 PM, Sharan Basappa wrote:

I am running a program and even though the program runs all fine, the log file 
is missing. I have pasted first few lines of the code.

Any suggestions where I maybe going wrong?

import os
import csv
import logging
import assertion_design as asd
import random

#Create and configure logger
logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s 
%(message)s')
import os
import csv
import logging
import assertion_design as asd
import random

#Create and configure logger
logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s 
%(message)s')




Do all of these lines actually appear, or is it an accidental 
copy-paste+paste?


What do you use to actually record data in the log? eg

logging.info("Informational message")

Any error message from Python?

When you say "the log file is missing" do you mean that there is no such 
file, that there is an empty file, or what? Which directory do you run 
the code from, and in which directory do you expect to find the log file?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple log files using logging module

2019-03-24 Thread DL Neil

On 25/03/19 6:13 AM, Sharan Basappa wrote:

I have a test program that imports a design program.
Both the programs need to log messages.
...> I would like to get comment from members here as well as some 
simple programs to illustrate this ...



Have you copied this code from somewhere?

Which tutorial, book, web article, or ??? are you using as your learning 
material?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.7 Bug

2019-03-25 Thread DL Neil

Bassam,
Greetings.


On 26/03/19 1:14 AM, Bassam Abdul-Baki wrote:

Greetings,

In the following code, there's a bug on certain parameters.

--

def per(n, steps = 0):
  digits = [int(i) for i in str(n)]
  result = 1
  for j in digits:
   result *= j
  steps += 1
  print(steps, result, sep=" - ")
  if result == 0:
   print(result, str(result), len(str(result)), sep=" - ")
  if len(str(result)) == 1:
   print(" --- DONE ---")
   return "DONE"
  else:
   per(result, steps)

--

What the program does:
If I run per(X) and X is a multiple of 10, I should end up with 0 in a
finite amount of steps.

The problem:
If I run per(54), I do not get 'DONE' printed through the return
statement.  WRONG!

If I run per(20), I do get 'DONE' printed through the return statement.
CORRECT!

20, 30, etc. are correct.  25, 45, etc. are not.

Is this a bug?



No - the Python 3.7 does exactly what you've asked it to do!

0
What is the objective of this piece of code? Other than "CORRECT!" and 
"WRONG!" there are few hints, especially the function name: "per". What 
does "per" mean - not everyone is a mathematician.


1
Had we been shown two entire output reports, eg one for 20 (correct) and 
another for 25 (incorrect), the answer would have been immediately apparent.


2
Is it a good idea/best practice to sometimes code the two values as 
"results" followed by "steps", and sometimes "steps" followed by 
"results"; or does this invite confusion?


3
Please express "len(str(result)) == 1" in English (or your preferred 
spoken-language). Is there an easier way to find numbers expressed in 
multiple digits? (and that's another overly-complicated way to say the 
same thing!)


4
If a 'debug print' is added at the beginning of the function, is the 
function being "called" more times than expected? Should/could more 
debug-print statements be added to check other sub-calculations along 
the way?


(PS 'debug-print' added to your code for debugging/testing and then 
removed for 'production-use' is a quick-and-dirty tactic. Please add a 
note to your Python ToDo list: "learn to use logging library instead of 
debug-print", otherwise wiser heads will criticise this advice, which 
works well when learning but perhaps not at the professional level)


5
Humility: that it might be a bug in your code rather than in Python 3.7.
Respect: It would be polite to mention if this is a student/homework 
assignment - or the text that you are following for self-improvement.
Charity begins at home: That people here will volunteer to help you, and 
can be more helpful if you help us - particularly by providing 
information which will save our (valuable) time.



Here's hoping you are now equipped to find the source of the problem...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Your IDE's?

2019-03-25 Thread DL Neil

On 26/03/19 10:38 AM, John Doe wrote:


What is your favorite Python IDE?



In case you are tempted to reply, neither of "John"'s supposed domains 
resolves (to a web site)/has been registered.


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Your IDE's?

2019-03-25 Thread DL Neil

On 26/03/19 12:55 PM, Gene Heskett wrote:

On Monday 25 March 2019 18:20:29 DL Neil wrote:


On 26/03/19 10:38 AM, John Doe wrote:

What is your favorite Python IDE?


In case you are tempted to reply, neither of "John"'s supposed domains
resolves (to a web site)/has been registered.

--
Regards =dn

your email agent is inventing links? There were none in the single msg I
got from a john doe. Unless they were buried in the headers that kmail
doesn't show me..


The invention is not mine: aside from his name, have a look at the OP's 
purported email address, and his requested ReplyTo: address. Then check 
the veracity of those domainNMs...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: configparser - which one?

2019-03-25 Thread DL Neil

Dave,


On 26/03/19 1:10 PM, Dave wrote:
I use Python3 3, and expected learning how to use configparser would be 
no big deal.  Well!  Seems there is configparser, stdconfigparser, and 
safeconfigparser, and multiple ways to set the section and entries to 
the section.  A little confusing.  I want to future-proof may code, so 
what should I be using?



(with apologies for not answering the question directly)

After striking this problem, I was encouraged to take a look at JSON, 
and thence YAML. Once there, as they say, didn't look back!

- multi-dimensional possibilities, cf .ini
- similarity/correspondence with Python data structures
- convenient PSL
- easily adopted by (power-)users, cf Python code


WebRefs:

- similar Q: 
https://stackoverflow.com/questions/5055042/whats-the-best-practice-using-a-settings-file-in-python


- article: https://martin-thoma.com/configuration-files-in-python/

- similar discussion: 
https://stackoverflow.com/questions/3085029/pros-and-cons-for-different-configuration-formats


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


OT Re: Your IDE's?

2019-03-26 Thread DL Neil

Those of delicate disposition should look away now...



The invention is not mine: aside from his name, have a look at the
OP's purported email address, and his requested ReplyTo: address. Then
check the veracity of those domainNMs...


I only rarely do so as I can usually detect such from the pull on my
leg. :)
Cheers, Gene Heskett



Would that be a pull on your jeans' leg?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: configparser - which one?

2019-03-26 Thread DL Neil

On 27/03/19 2:44 AM, Grant Edwards wrote:

On 2019-03-26, Cameron Simpson  wrote:


Like JSON, YAML etc are far far easier than XML for the reader.


If "far far easier than XML for the reader" is the bar, then we'll
have to keep "nailgun to the eyeballs" on the list...

That said, I agree with the rest of Cameron's post: for simpler stuff
.ini is darn hard to beat.  If you need nesting/arrays, then I'd
probably pick YAML over JSON.  Making simple changes to an
automatically-generated JSON file by hand is easy enough. But, I find
generating anything remotely complex by hand is far easier in YAML
than it is in JSON.  As usual, YMMV.



In my users' case, choosing YAML was a decision made before the 
(relatively) recent improvements to the .ini interface. (Thanks for that 
news!)


From a programmer's PoV, the convenience of having whatever 
config-file-rules handled within a library, so that your incoming data 
is 'reduced' to a dict/list structure, cannot be understated.


From a user's PoV, (the few who should ever be allowed to come into 
contact with such things) both .ini and YAML (and presumably) JSON are 
readily understandable, in my experience (YMMV) - perhaps in this case 
I've been 'blessed' with scientific/math/stats-types who are relatively 
'power users' and used to planning their experiments/analyses!


As far as specs go, I can't say I've ever bothered to read those for 
JSON, YAML, or even .ini. Have you? Read some article(s), started 
'playing', achieved what was required, no fuss-no muss... The previous 
post criticising same, lacks specifics, so can't learn from it. Earlier, 
mention was made of multiple 'dimensions' which are (at least to me, and 
those users) 'cleaner' in YAML/JSON/XML - however, heading 'too far' in 
that direction invites 'trouble'. What does the Zen of Python say about 
simplicity!


As with all tools, one really important criteria is the quality of 
information-provided when things 'go wrong'. We've all been frustrated 
because a 'missing comma/bracket/colon/...' "on line nnn" is not 
supposed to be there at all - and we've had to comb 'backwards' through 
the code to find where the missing punctuation should have been...


Given the relative ease with which both .ini and YAML can (now) be 
utilised (both by 'them' and by 'us'), there are not sufficient 
advantages/disadvantages to make it a 'big deal'. Other factors come 
into play and assume greater import: the OP mentioned 
user-preference/spec; whichever format this user's other systems 
utilise; the ease (reduced cost) of reaching into one's 'bag of tricks' 
for an already-coded ("re-usable") config-function...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Handy utilities = Friday Filosofical Finking

2019-03-28 Thread DL Neil
How do you keep, use, and maintain those handy snippets, functions, 
classes... - units of code, which you employ over-and-over again?



Having coded 'stuff' once, most of us will keep units of code, 
"utilities", which we expect will be useful in-future (DRY principle), 
eg functions to rename files, choose unique back-up/new fileNMs, 
accessing a DB, journalling (logging) start/stop msgs, building specs 
from YAML/JSON/XML/.ini config files (tongue~cheek), etc.


Do you 'keep' these, or perhaps next time you need something you've 
'done before' do you remember when/where a technique was last 
used/burrow into 'history'?

(else, code it from scratch, all over again)

How do you keep them updated, ie if add some new idea, better 
err-checking, re-factor - how to add these 'back' into previous places 
utility is used?
(who wants more "technical debt", plus handling classic 
update/versioning issue)


How do you keep these? eg special file/dir, within IDE, leave in app and 
'remember', on paper, ... If the former, how do you access/import them 
from the various applications/systems?

(Python's import rules and restrictions, change control/version control)


Am interested to hear your tactics; to learn, compare, and contrast...
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding the MRO with multiple inheritance

2019-03-29 Thread DL Neil

Arup,

There is a minefield here. Are you using Python 2 or 3?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Handy utilities = Friday Filosofical Finking

2019-04-01 Thread DL Neil

Gidday Cameron,

Thanks for this - some thoughts below:-


On 2/04/19 11:57 AM, Cameron Simpson wrote:

On 29Mar2019 09:32, DL Neil  wrote:
How do you keep, use, and maintain those handy snippets, functions, 
classes... - units of code, which you employ over-and-over again?

Having coded 'stuff' once, most of us will keep units of code,
"utilities", which we expect will be useful in-future (DRY principle), 
eg functions to rename files, choose unique back-up/new fileNMs, 
accessing a DB, journalling (logging) start/stop msgs, building specs 
from YAML/JSON/XML/.ini config files (tongue~cheek), etc.


Do you 'keep' these, or perhaps next time you need something you've 
'done before' do you remember when/where a technique was last 
used/burrow into 'history'?

(else, code it from scratch, all over again)


I put them into modules for import. I've got a tree of Python modules 
named "cs.this", "cs.that" for various things. Then just import stuff 
like any other library module.


Agreed - but Python doesn't (natively) like imports from a 
different/parallel/peer-level dir-tree. (see also Apache httpd)



For personal projects (if they aren't just part of that tree) I just 
need to symlink the tree into the local Python library as "cs".


I was doing this.

Much of my work is a simple-delivery, ie copying code from my dev m/c to 
the client's PC or server - so I don't 'package it up'* because of the 
(perceived) effort required cf the one-to-one (or maybe a couple) 
machine relationships.


However, during 'delivery' to another machine, have to remember to 
rsync/copy including the symlink, as well as to transfer both dir-trees.



Recently, stopped to organise the code into (more) modules (as also 
suggested here) and moved to adding the 'utilities' directories into 
PYTHONPATH. Now I have to remember to modify that on the/each target m/c!



(and you can guess what happens when I'm asked to remember something! 
Although, in my defence, I know this and (apparently) 
write-down/document a lot more than many/most of my colleagues. (puff, 
puff) )



If I get something well enough defined and sufficiently cleaned up for 
use beyond my own code (or just good enough that others might want it), 
up it goes to PyPI so that it can just be "pip install"ed.


So I've got this huge suite of modules with stuff in them, and a subset 
of those modules are published to PyPI for third party reuse.


Am dubious that any of the 'little bits' that I have collected are 
sufficiently worthy, but that's 'proper' F/LOSSy thinking!


*will be interested to hear if you think I should stop 'being lazy' and 
invest some time-and-effort into learning 'packaging' options and do 
things 'properly'?professionally...




Happy to elaborate on the details.


One of the points which intrigue me is that my colleagues don't keep 
snippets/a library, preferring to remember (hah!) when/where they used 
particular techniques in the past, and copying/duplicating, to fit the 
new system's requirements. Am wondering if this is true beyond our 
little band?


Yet, here on the list, interest was shown in 'being organised' (even if 
few have actually weighed-in)...



Thanks!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Handy utilities = Friday Filosofical Finking

2019-04-01 Thread DL Neil

On 2/04/19 1:25 PM, Chris Angelico wrote:

On Tue, Apr 2, 2019 at 11:16 AM DL Neil  wrote:

One of the points which intrigue me is that my colleagues don't keep
snippets/a library, preferring to remember (hah!) when/where they used
particular techniques in the past, and copying/duplicating, to fit the
new system's requirements. Am wondering if this is true beyond our
little band?

Until I've done something the same way two or three times, I just
recollect and steal. There are a few things that are in the back of my
mind to refactor out and make into libraries, but it's hard when they
aren't actually identical. Otherwise, it waits till there are a few
replicas, and then might get put into a central location somewhere.


In the ?good, old days (when computers were lubricated with open-fire 
rendered dinosaur fat) I would have followed such a practice!


However... when I was converted to the 'religion' of OOP, JIT/Agile, 
etc; I started working on one function/method (and class) at a time. 
(which inherently involves a balancing act between preparing some 
'useful tools' and YAGNI) Accordingly, extracting 'useful bits' into a, 
or to form a new, module is not difficult - and only requires the 
addition of an import statement to the original pgm/module. Accordingly, 
I try (very hard) not to find myself with the 'thrills' which you 
describe here...

(but hey, I'm an old ...)

Such also makes it easier to take care of the 'almost identical' nature 
of the programmer's existence...


Having said that, and cast aspersions about other members of the team 
'here', I couldn't believe that I'm the only ... Python coder in this world?




Sometimes, I recollect and reference, which creates some very weird
interdependencies until I get around to refactoring...


but some fairly hairy "technical debt" meantime?



https://github.com/Rosuav/MegaClip/blob/master/deviquotes.py
imports https://github.com/Rosuav/shed/blob/master/emotify.py
which gets an API key from the non-sample version of
https://github.com/Rosuav/MustardMine/blob/master/config_sample.py
and the end result of deviquotes is to rebuild this
https://github.com/DeviCatOutlet/devicatoutlet.github.io/blob/master/quotes.md


The twists and turns are positively admirable, but promoting the above 
as a training exemplar might not be the best idea!


Back to the original question(s): something I didn't want to do was to 
have a hard-coding of the import sourceDIR (per above). Whilst the 
PYTHONPATH is (at the very least) a form of "hard coding", at least I 
can do that to/on a client's m/c separately/in-addition to loading the 
s/w AND know that the Python code 'there' is the same as I have (in 
repo) 'here'!





So running that one script can potentially involve four different
repositories, because I haven't yet made any of the pieces into proper
libraries...


- and if I did the same, would you pay me (as much) for delivering such? 
(different rules for personal stuff)


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Handy utilities = Friday Filosofical Finking

2019-04-01 Thread DL Neil

On 2/04/19 1:56 PM, Cameron Simpson wrote:

On 02Apr2019 13:14, DL Neil  wrote:

On 2/04/19 11:57 AM, Cameron Simpson wrote:

On 29Mar2019 09:32, DL Neil  wrote:
Do you 'keep' these, or perhaps next time you need something you've 
'done before' do you remember when/where a technique was last 
used/burrow into 'history'?

(else, code it from scratch, all over again)


I didn't say it before, but I _loathe_ the "files with code snippets" 
approach. Hard to search, hard to reuse, promotes cut/paste coding which 
means that bugfixes _don't_ make it into all the codebases, just the one 
you're hacking right now.


...and I didn't say it earlier, but *my* unit-of-code in this 
conversation is a function/module and maybe a whole class. However, 
that's me, and directly relates to my background with "subroutine 
libraries" etc.


I'm not sure how much code can still be defined as a "snippet"? This 
idea - how small is too small, plus how large is too... was intended to 
be a part of the conversation...


As far as having unlabelled units of code, describable only as 'a bunch 
of lines which go-together': I agree, the cost of searching probably 
exceeds most peoples' will to live. I guess it is like many other 
decisions: do I spend time now, in the hopes of saving time later...


Yes, the inevitable evolution of this units of code, creates a 
maintenance issue in-and-of itself (another conversational topic I was 
hoping ppl might explore). Personally I don't trust Git sufficiently, 
and have started adding version numbers to the fileNMs so that whereas 
system-X was written to import widgetv1.py, I can update it to 
widgetv2.py as part of system-Y's dev process, and add the possibly/not 
needed update to system-X's backlog.

(well, best laid plans of mice and men...)

However, in my last greenfield project, everything include-d was taken 
as-is and not 'improved'. That might indicate a degree of 'maturity' and 
RoI. Alternatively, that the project was not particularly demanding (it 
was not!)


The other thought I have, in my learning to embrace OOP later in life, 
is that if the 'snippet' is a class, and extensions are needed, perhaps 
a sub-class will side-step such issues, per your warning?

(more best-laid plans, hopes, dreams...)


I put them into modules for import. I've got a tree of Python modules 
named "cs.this", "cs.that" for various things. Then just import stuff 
like any other library module.
Agreed - but Python doesn't (natively) like imports from a 
different/parallel/peer-level dir-tree. (see also Apache httpd)


Well, you have several options:
- modify $PYTHONPATH
- make a virtualenv
- make a symlink; Python imports from the current directory - not my 
  favourite feature, but very handy in the dev environment


Yes, thanks for this. Ideas tossed-around earlier.

As you will have experienced, until recently virtual, Python 
environments had their disadvantages and quirks. I was one of the 
grumblers.


What came along before the recent Py3.? improvements, was VirtualBox. 
This became my preferred virtual modus-operandi, because it very cleanly 
separates one client/department/project from another (and separates 
non-Python components, eg databases and entire file systems). Thus, also 
Python appv2 from v1! If I've managed to convince the client to also run 
their live-system under VBox, then most of the delivery/memory problems 
discussed 'go away'! Sadly nirvana lies just out-there, somewhere beyond 
tomorrow...
(many of these systems sit on a central 'server' somewhere, likely 
sharing a central DB and/or source-data - which is a bit different from 
desktop systems delivered to nn-hundred users; plus web-server projects 
which are similarly 'centralised')



For personal projects (if they aren't just part of that tree) I just 
need to symlink the tree into the local Python library as "cs".

I was doing this.
This works really well for me. In particular, in my development tree I 
symlink to my _dev_ "cs" tree, so that if I modify things (fix a bug, 
add a feature etc) to a cs.* module the change is right there in the 
repo where I can tidy it up and commit it and possibly publish it.


That ability to update the 'repo' as required by the application-dev 
task, is key.



Much of my work is a simple-delivery, ie copying code from my dev m/c 
to the client's PC or server - so I don't 'package it up'* because of 
the (perceived) effort required cf the one-to-one (or maybe a couple) 
machine relationships.
I'm doing something similar right now, but where I've used a cs.* module 
in their code it will go through PyPI as part of the prepare-for-deploy 
process so that they can reproduce the build themselves.


The last

Re: Clicking a specific item within a drop down list

2019-04-02 Thread DL Neil

On 3/04/19 7:53 AM, [email protected] wrote:

What code would allow me to automatically select and click the "Quarterly" value from the 
drop-down box labeled "Statement Type" on the web page below.

I'm new to Python and have been struggling with this one. Any help is immensely 
appreciated. Thanks!


Welcome!
People here offer great assistance.

To help you, please advise:
Which Python book, course, or tutorial have you been following?
Is this task course-work or for some other purpose?
Which GUI library are you using?
What code do you have so far?
What error message and/or screen behavior results?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Clicking a specific item within a drop down list

2019-04-02 Thread DL Neil

Richard,
(this is a Python list, and whilst the question is quite proper - your 
are using Python after all, the answer delves into Selenium and then 
dives into HTML and finally disappears into 'the dark side' of JavaScript!)



On 3/04/19 2:02 PM, [email protected] wrote:

Hi dn,
Thank you kindly for your warm greeting.  Please forgive my lack of forum 
decorum, I just started Python 2 days ago out of necessity, so I'm still quite 
unknowledgable about a lot of things.
I'm working on a person project.  So far, my only resources to date have been 
forums based off of Google searches, and a YouTube video: 
https://www.youtube.com/watch?v=rfscVS0vtbw
This is the code that I have so far:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://financials.morningstar.com/balance-sheet/bs.html?t=XNAS:AAPL®ion=usa&culture=en-US";)
import time
time.sleep(2)
driver.find_element_by_id("menu_A")
driver.("Quarterly")
When I run it, I get this error code:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: 
{"method":"link text","selector":"Quarterly"}
I've exhausted all of the forum posts I can find on this topic, but I've still 
been unable to solve it.  Any suggestions on how to solve it are eagerly 
welcomed.



Python is being helpful. Stop and read the error message: "Unable to 
locate element". What can you learn from the components of that msg?


The error was found by Selenium.
Did you look within their documentation?
Sadly, a quick web-search link to their web site basically repeats the 
err.msg. Big deal!


The subject Selenium is examining is a web page.
In this case the word "element" is not part of Python, nor is it part of 
Selenium (per-se), but is an HTML term.
Have you opened that page in your web-browser? (bring it up again, if 
necessary)


Usually I would suggest using the web-browser to look at HTML elements, 
indeed Firefox's (right-mouse-click) Context Menu offers an "Inspect 
Element" function, or use of the "Developer Tools" (F12). NB 
Chromium/Chrome and presumably the Apple and MSFT products offer similarly.


In this case, may I recommend (first) using the web-browser's "View 
Source" facility (Context or Tool menus) to inspect the HTML code of 
this web page.

What happens when you try to find "Quarterly" on the page?

Yes, it is found, but that's not in the place you expect ("menu_A")!

Return to the web page and now try the "Inspect Element" function.
Ahah, the "quarterly" link content *is* there.
What is going on?

Return to the page source, scroll through to (manually) find the Balance 
Sheet. It's not there either!

Yet, on the web page you can see it with your own eyes!!!???

What is there, around line 259 of the HTML, is a call to a JavaScript 
script.

What did I say about "going over to the dark side"?

You ask Selenium to load a web page. In turn, the browser/driver 
discovers that the web-page/HTML loads other items/files, eg graphics, 
CSS files, and JavaScript code files.


That's where the problem (seems to) lies - and it also explains the 
difference between Firefox's "View Source" facility and the "Developer 
Tools". Selenium works fast. Accordingly, as soon as the HTML page is 
available, it finds "menu_A" and thence attempts to find the "Quarterly" 
link. Unfortunately, the JavaScript needs to be loaded (from a separate 
file on the web server) and executed. You have a "race condition". The 
solution (hopefully - I have not tested it) is to add a delay between 
the page-load and the search-analysis (and possibly again, to allow the 
quarterly analysis to load before commencing the next step...


WebRefs:
https://stackoverflow.com/questions/6936149/how-to-use-find-element-by-link-text-properly-to-not-raise-nosuchelementexcept
https://en.wikipedia.org/wiki/Race_condition


Let us know how you get on...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: fs package question - cp -p semantics when copying files?

2019-04-02 Thread DL Neil

Skip,

On 3/04/19 8:06 AM, Skip Montanaro wrote:

I posed this yesterday on the PyFilesystem discussion Google Group but
it's so far not even garnered a single view, so perhaps that group is
defunct. I turn to the knowledgeable folks here:

I am copying files from one filesystem instance to another. I see no
(easy) way to tell fs.copy.copy_fs to preserve file permissions when
copying files (the equivalent of the cp(1)'s -p flag). So, accessed,
created, modified times, as well as permissions. It seems I need to
craft a dictionary with only marginally documented structure, which I
can then pass to the destination filesystem's setinfo method,
something like this:

 dst_fs.setinfo(dst_path, )

I suspect I will figure this out (painfully), but if someone has some
hints, they'd be appreciated.


Is there an (unstated) reason why you're using Python and not a system 
tool such as rsync?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging module and datetime - oil & water for some reason?

2019-04-02 Thread DL Neil

Skip,


On 2/04/19 9:54 AM, Skip Montanaro wrote:

I assiduously avoided using Python's logging package for about the
first dozen years of its existence. I eventually gave in and started


I'm glad you're stepping-up!

I'm never sure whether to be amazed or dismayed by the huge number of 
folk expressing/hiding this sort of 'fear'.

(not that I'm insulting you - you might be bigger than I!)

Have spent some time over the last two days, contemplating an 'upgrade' 
from ordinary files to a RotatingFileHandler, so, with the manual fresh 
in my mind, you're in-luck!

(maybe)



using it relatively recently in the guise of a thin wrapper provided
by a colleague at work. Today I had occasion to tweak the timestamp
format only to discover that logging still uses time.localtime or
time.gmtime as its underlying source of time fields, so subsecond
timestamps are hacked in, with no straightforward way to log both
milliseconds and the timezone in normal order. I have need for both,
as I work for a company with offices in multiple timezones, and
sometimes need subsecond time resolution for quick-n-dirty analysis.


Prepare for that "thin wrapper" (and most of the provided 'convenience 
functions') to disappear in your rear-view mirror!




I stole a custom formatter class from a StackOverflow thread and am
now back in business (milliseconds *and* timezones, yay!). Still,
peeking at the 2.7 documentation, I see that both the logging package
and the datetime module were added to the standard library in Python
2.3 (2003). Why is logging still relying on the suboptimal
time.{localtime,gmtime} API? Surely, if there was no
backwards-compatible way to introduce datetime into the system, a
small breaking change could have been made for Python 3000 and
probably affected very few users.


The formatTime method was added to the Formatter class in Python 3.3. 
(see docs, if v3.3 is an option available to you)


Otherwise, your idea of implementing a sub-class was likely the best 
approach.


Another introduction (v3.2) has been LoggerAdapter objects. I've not 
used them(!) but wondered if they might have purpose in such situations?


In multi-national situations, my recommendation has long been to 
standardise all times (incl logging) as UTC.


I'm not sure if it was available as far back as Py2, but there is a 
SysLogHandler() which enables disparate and dispersed applications to 
log to a central 'logging server'. (although I wonder if the formatters 
would still be using local time (or whatever), or if the 'time' relates 
to that central server)


Am unable to comment on, or answer, the last question.

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: I want understand how this word wrap program playing on input

2019-04-04 Thread DL Neil

Arup,

On 5/04/19 7:33 AM, Arup Rakshit wrote:

I am reading a Python book, where the author used a simple word wrap program to 
explain another concept. But I am not understanding some parts of the program.

...

A technique for solving this sort of comprehension-problem is to 
simulate the operations of the computer/CPU on-paper. 
Instruction-by-instruction, write down the names of the objects 
instantiated and their (current) values. As you loop through the code, 
those (current) values change, and you will see exactly how they change 
- divining (and defining) the 'why', as you go...


Of course, only old-***s (like me) have the skills to handle pen/pencil 
and paper technology! So, may I recommend an excellent tool which will 
(hopefully) achieve the same ends for you: http://pythontutor.com/



PS don't be shy about mentioning your "book", its "author", and its 
title (hey, go 'full-APA' adding ISBN, pageNR...). Such will be a credit 
to the author(s) and a possible recommendation/inspiration to fellow 
Pythonista!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Logging cf Reporting = Friday Filosofical Finking

2019-04-04 Thread DL Neil
Is the logging module an ideal means to provide (printed) user reports, 
or is it a 'bad fit' and not designed/fit for such a purpose?



PSL's logging module (per discussion 'here' earlier this week) is often 
quietly avoided by 'the average Python programmer'. It is unwieldy, yet 
that is, in-part, a function of its power and flexibility. Its 
explanation in the Library docs requires multiple pages - and even after 
sending us first to the 'HowTo', still many people turn away (vaguely 
promising to 'come back later'). For the nit-picky amongst us: it 
dramatically fails PEP-8* (and we won't even mention higher numbers).


Once the framework is learned, its flexibility appreciated, and its 
strictures accepted; (IMHO) the library comes into its own. Over the 
years, the range of output options ("handlers") has grown and become 
ever more sophisticated. Simple text files are now supplemented by 
"rotating" mechanisms; simple socket transmissions have formalised into 
SMTP (email), HTTP, queues, and datagrams; and both MS-Win and *nix 
syslog mechanisms are covered. Similarly, the traditional formatting of 
messages with ToD-clock, technicalIDs, and error-level preceding the 
'real content', whilst still standard, can be completely replaced to 
suit the application and circumstance.


The received-wisdom of text books and tutorials is that Python trainees 
should 'evolve' from using quick-and-dirty debug-print functionality, to 
logging. This idea(l) promotes the virtue of providing a full 
information flow when it is vitally-needed, but not cluttering-up the 
display with excessive and extraneous data, when not - especially when 
GUIs are involved! (plus obviating that pesky-business of going-through 
ensuring every debug-print is deleted or commented-out, before delivery 
to 'live'!) However, there's always a lot to learn - too many toys, too 
little time!


Recently, I was building a little "batch job"# for an author-friend 
who'd lost control of his extensive and burgeoning library of files, 
back-ups, half-dead disks, archives... Being a 'good boy'& I was 
throwing all the debug/test/demo info out to a log-file. Without (my) 
thinking too much, all the useful listings ended-up in the same place. 
Oops! Rather than bringing them 'back' out to the screen (which, because 
he prefers to work from paper rather than the screen - "now you tell 
me". Sigh!) would also have meant capturing sys.stdout to grant the user 
his (late-expressed) desire; I established another logger and made minor 
mods to the code so that it would instead emit the 'useful' output 
there. Hence, an "output report".


I was chuckling at how my 'mistake' turned into a 'plus', because 
without a lot of work to 'fix' things, the user was given exactly what 
he wanted! ("oh, and it would be nice if you could send the file to me 
by email..." - they're always, um, never, (quite) satisfied...)



In the more general case, when at least some of an application's output 
goes to file (or similar), is it a 'smart move'% to use the logging 
library to collect more than behind-the-scenes debugging, or 
application/syslog-level data?



* but then, so do I!
# https://en.wikipedia.org/wiki/Batch_processing
& if you believe that, you'll believe anything!
% 
https://www.quora.com/What-is-meant-by-the-Mark-Twain-quote-To-a-man-with-a-hammer-everything-looks-like-a-nail

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


Re: I want understand how this word wrap program playing on input

2019-04-06 Thread DL Neil

Arup,

Good choice! (thought I recognised the example-problem) The three books 
in the "Python Craftsman" series/bundle: "Apprentice", "Journeyman", and 
"Master" are a thoroughly recommendable resource. As the titles infer, 
they start at a beginner level and become more complex over time. Even 
seasoned pythonista can learn from them.


Did you start with "Apprentice" and work 'up'? How are you finding them? 
Are they recommendable to others?


Did the Python Tutor help you 'see' what was happening and how values 
were changing whilst the code executed?



Web-Ref:
https://leanpub.com/b/python-craftsman

Disclaimer:
I have no relationship with either resource, other than as a happy user.


On 7/04/19 3:38 AM, Arup Rakshit wrote:

Hello,

DL, the book I am reading is https://leanpub.com/python-journeyman .. It is an 
awesome book. The code is in page #351.

David and Chris, The analogy you used to answer my questions were super 
helpful. I could answer my own question by putting some effort by dry running 
the code ofcourse. In that case, I am 100% sure the analogies were used in this 
email would never come to me.

Thanks again to all of you.



Thanks,

Arup Rakshit
[email protected]




On 05-Apr-2019, at 1:24 AM, DL Neil  wrote:

Arup,

On 5/04/19 7:33 AM, Arup Rakshit wrote:

I am reading a Python book, where the author used a simple word wrap program to 
explain another concept. But I am not understanding some parts of the program.

...

A technique for solving this sort of comprehension-problem is to simulate the 
operations of the computer/CPU on-paper. Instruction-by-instruction, write down 
the names of the objects instantiated and their (current) values. As you loop 
through the code, those (current) values change, and you will see exactly how 
they change - divining (and defining) the 'why', as you go...

Of course, only old-***s (like me) have the skills to handle pen/pencil and 
paper technology! So, may I recommend an excellent tool which will (hopefully) 
achieve the same ends for you: http://pythontutor.com/


PS don't be shy about mentioning your "book", its "author", and its title (hey, 
go 'full-APA' adding ISBN, pageNR...). Such will be a credit to the author(s) and a possible 
recommendation/inspiration to fellow Pythonista!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list




--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging cf Reporting = Friday Filosofical Finking

2019-04-08 Thread DL Neil

Is logging an unpopular package?
Is extending its use, as described, 
interesting/inappropriate/illogical/downright-crazy?



On 5/04/19 8:34 AM, DL Neil wrote:
Is the logging module an ideal means to provide (printed) user reports, 
or is it a 'bad fit' and not designed/fit for such a purpose?



PSL's logging module (per discussion 'here' earlier this week) is often 
quietly avoided by 'the average Python programmer'. It is unwieldy, yet 
that is, in-part, a function of its power and flexibility. Its 
explanation in the Library docs requires multiple pages - and even after 
sending us first to the 'HowTo', still many people turn away (vaguely 
promising to 'come back later'). For the nit-picky amongst us: it 
dramatically fails PEP-8* (and we won't even mention higher numbers).


Once the framework is learned, its flexibility appreciated, and its 
strictures accepted; (IMHO) the library comes into its own. Over the 
years, the range of output options ("handlers") has grown and become 
ever more sophisticated. Simple text files are now supplemented by 
"rotating" mechanisms; simple socket transmissions have formalised into 
SMTP (email), HTTP, queues, and datagrams; and both MS-Win and *nix 
syslog mechanisms are covered. Similarly, the traditional formatting of 
messages with ToD-clock, technicalIDs, and error-level preceding the 
'real content', whilst still standard, can be completely replaced to 
suit the application and circumstance.


The received-wisdom of text books and tutorials is that Python trainees 
should 'evolve' from using quick-and-dirty debug-print functionality, to 
logging. This idea(l) promotes the virtue of providing a full 
information flow when it is vitally-needed, but not cluttering-up the 
display with excessive and extraneous data, when not - especially when 
GUIs are involved! (plus obviating that pesky-business of going-through 
ensuring every debug-print is deleted or commented-out, before delivery 
to 'live'!) However, there's always a lot to learn - too many toys, too 
little time!


Recently, I was building a little "batch job"# for an author-friend 
who'd lost control of his extensive and burgeoning library of files, 
back-ups, half-dead disks, archives... Being a 'good boy'& I was 
throwing all the debug/test/demo info out to a log-file. Without (my) 
thinking too much, all the useful listings ended-up in the same place. 
Oops! Rather than bringing them 'back' out to the screen (which, because 
he prefers to work from paper rather than the screen - "now you tell 
me". Sigh!) would also have meant capturing sys.stdout to grant the user 
his (late-expressed) desire; I established another logger and made minor 
mods to the code so that it would instead emit the 'useful' output 
there. Hence, an "output report".


I was chuckling at how my 'mistake' turned into a 'plus', because 
without a lot of work to 'fix' things, the user was given exactly what 
he wanted! ("oh, and it would be nice if you could send the file to me 
by email..." - they're always, um, never, (quite) satisfied...)



In the more general case, when at least some of an application's output 
goes to file (or similar), is it a 'smart move'% to use the logging 
library to collect more than behind-the-scenes debugging, or 
application/syslog-level data?



* but then, so do I!
# https://en.wikipedia.org/wiki/Batch_processing
& if you believe that, you'll believe anything!
% 
https://www.quora.com/What-is-meant-by-the-Mark-Twain-quote-To-a-man-with-a-hammer-everything-looks-like-a-nail 



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Python list and Python Journeymen*

2019-04-13 Thread DL Neil

* and Journey(wo)men

TL;DR? Please scroll the bottom with a view to contributing advice


Hello Arup,

I appreciate your confidence and trust in writing to me personally. 
Hoping I have not betrayed that, but despite your concerns this reply is 
posted on-list. I trust it won't, but apologise if it feels 
embarrassing. Please allow me to explain...




Hello DL Neil,
Sorry if it feels like random. I need some advices about the Python. I am 
learning Python to learn basically Flask, because I am a web developer and 
understands it well. Having prior knowledge in Ruby, JS, I thought it will be 
quicker for me to get a control on this language. But it feels like vast so 
far, lot of concepts. Which books would you recommend to get to the 
intermediate position from beginner level? Also asides web development, how 
good the future is as a Python developer? Many people online, offline I heard 
to discuss about learning Functional programming. While I know Ruby, JS, do you 
think it is fine to learn another similar language, or learning something new 
like others says will be a good idea.
Again sorry if it sounds like irritating. You can have the rights to ignore 
this email 100%, I would not mind, as I understand people like you are really 
busy at your own work. I couldn’t post it in the ML, but have little hesitation 
  how others would react on this.
Thanks,
Arup Rakshit



If I have understood correctly, I detect five questions in-all:
1 Learning to apply Python
2 Python eco-system
3 Functional programming
4 "Good ideas", other people, and 'the next great thing'
5 This list and requesting assistance

I'll (attempt to) respond, but please excuse me if I do so in reverse 
sequence...



5 The list
The benefits the list brings (cf personal correspondence) is that your 
question is exposed to a larger number of "eyeballs" (that word sounds a 
bit crude, but if you've not seen the term used before, you will find 
context in error-hunting and code-proving throughout the Open Source 
world). Thus, better minds than mine (alone) can be brought to bear. 
Secondly, there are other readers, sometimes referred-to as "lurkers"; 
who subscribe to the list specifically to read and learn from 'good 
ideas'. Accordingly, whilst it might seem that you ask a question and it 
is answered, to your benefit/relief/advancement (eg last month we 
discussed "scope"); a number of other people probably also learned 
something about "scope" along-the-way*. So, when you ask a question, it 
is likely that you are not the only-one asking it. Thus answers to 
'your' question, will benefit more people than we can know!
* it is an interesting phenomenon that answering someone else's 
questions can cause 'the answerer' to advance his/her learning at the 
same time! (in fact, if I might put my cognitive-psychology 'hat' on for 
a moment, it is an excellent way to learn - and to prove that one has 
learned something)
Using the link at the foot of each posting, you can back-track to a 
web-page of Python discussion lists. There you will find details of 
"Tutor". If you feel a question might be 'embarrassing' posed to this 
list, try there...
However, my impression of the members of this list is that there is no 
such thing as a 'silly question'. Recollecting recent Q-s and A-s 
(sadly) evidences short/lazy/unhelpful ways to ask a question. 
Accordingly, people who expect help but fail to provide code, errmsgs, 
and the like; receive equally short replies addressing their 
*short*comings (hah!). Human nature is that people prefer to help people 
who are helping themselves: the more background-information that is 
given: 'here's my code', 'I tried this', 'the manual says...', 'my text 
book...' the more information the 'helpers' have to formulate a (useful) 
response - compare this with [I'm not telling you that this is my 
homework] "How do I pile all the round blocks on top of the rectangular 
ones?".
In this mode, I recall asking you, which book you were working from. 
When you replied, I was able to immediately look-up the problem-set - 
and thus gather more background. (we also started a side-conversation 
about 'resources', which appears to continue here!)
Most lists talk about "respect" (for other subscribers). If I may 
'indulge': respect for people's time is high on my list. (to my 
knowledge, no-one is specifically paid to be 'here' and to be 'helpful'; 
and a volunteer's time should be valued in $big (if you must) )
Another benefit of the list - which is often 'missed', even by 
'StackOverflow aficionados', is that the list is archived. Accordingly, 
there are likely similar questions, previously asked and answered. No 
need to ask aga

Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

(I know it's not Friday [exp], and after personal apologies[apo])


Do you bother with exception handling for import statements?


Most of the code I read, both in books and during code review, eschews 
any form of ImportError check. Even data science people who 'clean' 
every data field towards inclusion/exclusion in the analysis, take for 
granted that numpy, scipy, pandas, et al, will be available to their code.



Does such a check seem un-pythonic? [sto] (maybe 'forgiveness cf 
permission'?)


Can we assume that if such a catastrophic error occurs, it is quite 
acceptable for the code to fall-over in a tumbling-fumble?


Does it make a difference if operating in/out of a dev-ops environment?

Might such only occur once, because once the environment has been 
correctly-built, it will/can *never* happen again?


Can we assume Built-in and PSL modules *must* be present, so we only 
need to talk about covering in-house code and pip-ed (or similar) modules?


Is it more/less important in __main__ than in an imported module?

Do you handle each import separately, or all in a single try..except block?

Do you try to anticipate and cover every import in the system at the top 
of __main__, eg imports inside imported modules?


What about OpSys-specific imports (etc)?

Do modules import-ed only in specific situations, deserve more, or less, 
attention?



Refs:

[apo] Change of season coughs and sniffles, duly shared with the CO (oops!)

[exp] Explanation: in the Christian calendar, this Friday is "Good 
Friday" and thus a national/public holiday in much of the western world. 
Thus, also next ("Easter") Monday and possibly Tuesday. To continue the 
theme: next Thursday is also a holiday in New Zealand and Australia 
("ANZAC Day": equating to Veterans' Day, Memorial Day, Independence Day, 
etc)


[imp] 5. The import system https://docs.python.org/3.6/reference/import.html

[sto] A somewhat similar question: 
https://stackoverflow.com/questions/3131217/error-handling-when-importing-modules


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


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

On 18/04/19 8:53 AM, Larry Martell wrote:

On 2019-04-17 21:20, DL Neil wrote:

Do you bother with exception handling for import statements?


I often have to do something like this:

try:
 from settings import SITE_WAFER_DIAMETER
except ImportError:
 SITE_WAFER_DIAMETER = 300



That's an interesting application. Most of the multiple input 
configuration options examples (I've seen) start with a base of the 
least-prioritised values, and then 'add' higher-priority configuration 
option-values to that.


In this case we: import the config file, but if it's not available use 
the stated fall-back value(s).


Good one!
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

On 18/04/19 8:45 AM, MRAB wrote:

On 2019-04-17 21:20, DL Neil wrote:

Do you bother with exception handling for import statements?


Can we assume that if such a catastrophic error occurs, it is quite
acceptable for the code to fall-over in a tumbling-fumble?



[snip]
Catch only what you (well, the script) can fix.

If it needs numpy, but can't import numpy, then when can it do? Might as 
well just let it fail.


I suppose an alternative might be to try to download and install numpy 
and then retry, but what if it can't be downloaded, or the installation 
fails?


No, you have to give up at some point. It's better just to report the 
problem and leave it to the user to fix it.


Ah, but is that not the point - the user cannot fix it (and neither 
should he be allowed to do so: see later comments about Operations 
functions).


What the user faces (unless we more properly handle the exception) is:

import davids_brains
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'davids_brains'

You and I will think this fine - and 'here' on the list will even beg 
OPs to give us this much data.


However, despite users who have been known to make other comments about 
my (?lack of) brains, they will tend to offer such helpful advice as: 
"we need the missing module"...!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

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 Python3 and
 the program tries first one, then the other.


Excellent example - and a lot easier than interrogating os.environ (for 
example), ie permission cf forgiveness.




  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?



Most of the code I read, both in books and during code review,
eschews any form of ImportError check. Even data science people who
'clean' every data field towards inclusion/exclusion in the
analysis, take for granted that numpy, scipy, pandas, et al, will be
available to their code.


You've omitted the second thing assumed by the authors: without numpy,
scipy, pandas, et alia the program can do nothing useful.


but... what of the third inherent assumption: that the user(s) will be 
able to handle the situation (discussed in another msg 'here')?




Does such a check seem un-pythonic? [sto] (maybe 'forgiveness cf
permission'?)


It's probably rather unpythonic if you're not going to anything useful
in the exception handler.


Indisputable!



Can we assume that if such a catastrophic error occurs, it is quite
acceptable for the code to fall-over in a tumbling-fumble?


It's certainly OK with me.  I'm not sure why you refer to raising an
exception as "fall-over in a tumbling fumble".  Raising an exception
is the normal way to indicate failure in Python.


Apologies! Evidently a cultural reference that did not export well.

To understand "tumbling fumble" perhaps think of dropping something, 
attempting to catch it with one hand, then having to make a second try 
with the other, and probably failing to intercede before the floor... I 
could have used other terms, but likely to be considered 
'politically-INcorrect'.


No, "tumbling fumble" describes having no exception handling and merely 
allowing the program to "crash".


Thus the basic question: why do we (apparently) so seldom consider the 
possibility of an ImportError?




Does it make a difference if operating in/out of a dev-ops
environment?


I have no idea what "a dev-ops environment means", and I plan on
keeping it that way. :)


I see that you value your sanity. On the other hand you don't seem so 
worried about your physical safety - please note that I'll be hiding 
behind you, should the (ever-so nice) dev-ops lady on one of my projects 
happen to read this...


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

On 18/04/19 8:29 AM, Chris Angelico wrote:

On Thu, Apr 18, 2019 at 6:21 AM DL Neil  wrote:

Do you bother with exception handling for import statements?
Can we assume that if such a catastrophic error occurs, it is quite
acceptable for the code to fall-over in a tumbling-fumble?


I try/except around import statements only if it's possible for the
program to recover from the exception. For instance, something that

...

User reactions have been covered elsewhere 'here'.



For something that is absolutely required for the program to continue,
what would be in your exception handler? Print a message to stderr and
exit? That's exactly what not-catching-the-exception is for. I do
sometimes annotate the imports, though:


We disagree. Although I hasten to add, if the error is trapped, then 
there should be some added-value over what is system-provided.


Application's log? SysLog? Particularly in a centralised or server-based 
application especially web-services.




from dataclasses import dataclass # ImportError? Upgrade to Python 3.7
or pip install dataclasses

If that bombs out, the entire line will get printed, comment and all,
and there isn't really anything else that I would want to do with the
exception.
So I guess the best way to answer your question is with another
question: If such a catastrophic error occurs, what ELSE would your
code do than fall over? If there's an answer to that question, then
sure, catch the ImportError. Otherwise don't.


Kudos! To whom are you addressing such annotations?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-17 Thread DL Neil

On 18/04/19 1:24 PM, Cameron Simpson wrote:

On 17Apr2019 21:45, MRAB  wrote:

On 2019-04-17 21:20, DL Neil wrote:

Do you bother with exception handling for import statements?

[...]

Catch only what you (well, the script) can fix.

If it needs numpy, but can't import numpy, then when can it do? Might 
as well just let it fail.


I'm of this mind too, but...

I suppose an alternative might be to try to download and install numpy 
and then retry, but what if it can't be downloaded, or the 
installation fails?


As an example of what an open ended can of worms attempts recovery might 
be, yeah. How hard do you try? But also, "installation fails": that 
isn't always a clean situation: it can litter the install area with 
partial junk.


But this is also a bad example: it is something an _invoked_ programme 
should never try to do. Except by specific deliberate design and 
request, a running application shouldn't presume it has rights to 
install additional things, or even to try. I have personally (though 
metaphorically) clipped devs across the ear for doing themselves the 
moral equivalent of the above: try thing, then just "sudo try thing" 
when it was forbidden.

...

+1


Installing additional packages is the same as self modifying code: as a 
rule, the admins install packages, not the app.


+1



Sorry, ranting now over.


Not at all, an excellent point which needs to be taken out and 
dusted-off, every now-and-again - particularly for such ear-clipping 
training exercises!


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-17 Thread DL Neil

On 18/04/19 4:10 PM, Sayth Renshaw wrote:

I have created a function that takes a list as an argument.
Without using itertools I want to compare each item in the list to find the max.

However instead of the max I keep getting the  last item in the list. Where is 
my logic wrong here?

...


Seems like it should work but doesn't.




I'd recommend rethinking your algorithm first, and then thinking about
debugging your actual code. You should be able to find the largest in
a collection without making many many passes over the items - a single
pass should be sufficient.




Most I am finding either use the max function or itertools. Both of which I am 
trying not to use so that I actually do it myself.



Did you understand the advice? Have you simply dropped the first-attempt 
and gone looking for another canned-solution?


Whilst you seem to be on-the-right-track, there is a definite error in 
the algorithm/the code.


What debugging did you perform?

Do you only assume, or can you see example (pertinent) values during 
each "pass" (time through the loop)? If not, why not?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


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 it replaces the 
first item and comparison continues.



A good first effort!

Is it sufficiently-detailed to say "compare it to the rest"? Is it being 
compared with ALL of the other elements of the list at once?



How about this outline:

Set the first item in the list as the current largest.
Compare ...
if this element is larger, set ...

How could we fill in the gaps (...) of that description?


Also, what types of data are you expecting as elements within the list?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-19 Thread DL Neil

> On 19/04/19 7:23 PM, Sayth Renshaw wrote:


In English:

  Set the first item in the list as the current largest. 
Compare each subsequent integer to the first.
if this element is larger, set integer. 



Criticism: (because this does NOT match the code, below!)
- should the algorithm "Compare each subsequent integer to the first" or 
is the comparison with 'the current largest', ie 'the largest so-far'?


NB IIRC this was (likely) why it was suggested that you explain the 
method in English, first!



In code:


def maxitwo(listarg):
 myMax = listarg[0]
 for item in listarg:
 if item > myMax:
 myMax = item

 return myMax



Well done!

Now, what happens when the code is tested with various (different) sets 
of test-data?

(remember the last question from my previous msg!?)


Once you are happy with the various test-runs, do you have any ideas for 
making the code more efficient?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-19 Thread DL Neil

On 20/04/19 4:41 AM, Rob Gaddi wrote:

On 4/19/19 12:23 AM, Sayth Renshaw wrote:

On Friday, 19 April 2019 17:01:33 UTC+10, Sayth Renshaw  wrote:

Set the first item in the list as the current largest.
 Compare each subsequent integer to the first.
 if this element is larger, set integer.


def maxitwo(listarg):
 myMax = listarg[0]
 for item in listarg:
 if item > myMax:
 myMax = item

 return myMax


When you understand what it is you intend to write (barring DL Neil's 
comments), and THEN write it, you write the correct thing.  Thus endith 
the lesson.



+1, Rob's guidance saves time and embarrassment...

Upon opening a new module in one's text-editor/IDE one of the first 
steps should be to write an explanatory docstring. Similarly, after 
typing the letters "def" or "class"!


On the basis of this conversation, you might also benefit from reading 
about the use of doctests! (seeing we're talking docstrings - can always 
move to other test methods later)


I find this a useful habit, particularly if I am outlining an entire 
module or class, and only later coming back to flesh-out the code.


Further reading: Test-Driven Development


Of course all the comments in the world won't help if code != comment!!! 
Before congratulating ourselves that the code 'works': did you spot the 
difference in the better-developed 'English' description and the 
implementation in Python?



Regarding 'testing': Start with the scope and your objectives [as yet 
unstated, so we can only imagine what they might be]. When should it 
work, eg data-types. Why doesn't the code work with string data? Does it 
work if the list mixes different data-types? Should it work if a list 
element is itself a collection/class?


Regarding 'optimisation': rather than 'disappearing' into high-volume 
and 'exotic' situations (see earlier comment), why not stick with the 
simple stuff? For example, once 'max' is initialised, is there a need to 
compare max with 'list[ 0 ]'?



Extension: if, instead of merely finding the largest value in the list 
(cf which element of the list is the largest!), what if the code also 
'moved' that element to the end of the list? Then, what if that function 
was called again but this time to operate on all of the list EXCEPT the 
last (which we already know is the largest) - and if this 'outer loop' 
were repeated 'len( list )' number of times (either by loop or (perhaps 
a later coding exercise) by recursion; what would be the final condition 
of the 'list'?


--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   >