[issue38863] Improve is_cgi() in http.server

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue38863>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24764] cgi.FieldStorage can't parse multipart part headers with Content-Length and no filename in Content-Disposition

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue24764>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21705] cgi.py: Multipart with more than one file is misparsed

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue21705>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1047397] cgitb failures

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue1047397>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39727] cgi.parse() fatally attempts str.decode when handling multipart/form-data

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue39727>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10879] cgi memory usage

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue10879>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9968] Let cgi.FieldStorage have named uploaded file

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue9968>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41140] cgitb uses the locale encoding for log files

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue41140>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41139] cgi uses the locale encoding for log files

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue41139>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27777] cgi.FieldStorage can't parse simple body with Content-Length and no Content-Disposition

2020-07-20 Thread Rhodri James


Change by Rhodri James :


--
nosy:  -Rhodri James

___
Python tracker 
<https://bugs.python.org/issue2>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: An I connected here?

2020-07-17 Thread Rhodri James

On 17/07/2020 20:12, J. Pic wrote:

And Hollidays ;)


Nah, that's next week ;-)



Le ven. 17 juil. 2020 à 21:03, Rhodri James  a écrit :


On 17/07/2020 19:33, Steve wrote:

Sorry folks, I really messed that one up.  I tried to doctor up a reply

to

get the address correct but failed to delete enough to own the message...


Yeah, don't do that.  Just start a new message, otherwise you'll end up
with all the threading for the old message thread, irritating those of
us who sort by thread so that we aren't chopping and changing subject
all the time :-/


My message did not have anything to do with the "Fake News Detect"

subject.


I posted a request for assistance about a week ago, no response.  I also

see

very little traffic here, less than there used to be.  Has something gone
wrong with my set up?


No, nothing's wrong.  I can't answer for anyone else and I can't recall
your specific question, but I suspect you were asking about something I
know nothing about and wasn't sufficiently intrigued to go find out about.

I think there are fewer experts with time lurking around here (and I
don't count myself as one of those, TBH).  Recent controversies and the
attempts to moderate them have probably upset quite a lot of people one
way or another.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list






--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: An I connected here?

2020-07-17 Thread Rhodri James

On 17/07/2020 19:33, Steve wrote:

Sorry folks, I really messed that one up.  I tried to doctor up a reply to
get the address correct but failed to delete enough to own the message...


Yeah, don't do that.  Just start a new message, otherwise you'll end up 
with all the threading for the old message thread, irritating those of 
us who sort by thread so that we aren't chopping and changing subject 
all the time :-/



My message did not have anything to do with the "Fake News Detect" subject.

I posted a request for assistance about a week ago, no response.  I also see
very little traffic here, less than there used to be.  Has something gone
wrong with my set up?


No, nothing's wrong.  I can't answer for anyone else and I can't recall 
your specific question, but I suspect you were asking about something I 
know nothing about and wasn't sufficiently intrigued to go find out about.


I think there are fewer experts with time lurking around here (and I 
don't count myself as one of those, TBH).  Recent controversies and the 
attempts to moderate them have probably upset quite a lot of people one 
way or another.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-05 Thread Rhodri James

On 04/07/2020 16:38, Random832 wrote:

On Fri, Jul 3, 2020, at 08:48, Rhodri James wrote:

As I said in my preamble, it doesn't matter whether you believe that is
true or think it's utter bollocks.  I asked the question to get the
Steering Council's opinion, not anyone else's.  If you collectively
really must rehash the arguments again, please have the decency to do so
in a different thread.


The idea that the statement was in any way related to one of the authors being named 
"White" was an *obvious factual mistake* in your post.


Nope.  It was a factual mistake in someone else's post.  I hesitate to 
say "obvious" because I have in fact known people to genuinely think 
things like that.  It is *still* irrelevant to what was asked of the 
Steering Council.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: New to python - Just a question

2020-07-03 Thread Rhodri James

On 03/07/2020 11:09, Daley Okuwa via Python-list wrote:


Please can someone help

Write an algorithm (choose the language you prefer) that given a character 
string, for instance {‘c’,’a’,’i’,’o’,’p’,’a’}, will print out the list of 
characters appearing at least 2 times. In this specific example, it would 
return {‘a’}. Afterwards, comment out the cost in terms of space and time.


The first thing to do with any problem is to break it down into bits. 
In the case of Python, writing them out as "pseudo-code" instructions 
often helps.  In this case you have:


Set up something to count letters with
For each letter in the string:
If we haven't seen this letter before:
Set the counter for the letter to 1
Else:
Add 1 to the counter for the letter

For each counter:
If the count is 2 or more:
Print the letter

Now there are a lot of possible ways to write that, but they mostly come 
down to deciding what data structure to use to count letters with.  Have 
a browse through a tutorial (or the standard library if you are feeling 
adventurous) and see what you think might work, then try it.



Write a bash/python script that takes a directory as an argument and output the 
total lines of code in *.cpp files recursively.


In bash, what existing commands count things?  If you don't know, how 
might you find out?  Then you have to figure out how to do that for each 
*.cpp file in a directory, and add the totals together.


In Python, you can read a file one line at a time, so how to count the 
number of lines in a file should be pretty obvious.  Figuring out how to 
do that for every *.cpp file in a directory will involve looking through 
the standard library, or getting a bash script to do it for you :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-03 Thread Rhodri James

On 03/07/2020 15:28, Jon Ribbens via Python-list wrote:

On 2020-07-03, Rhodri James  wrote:

On 02/07/2020 23:46, Random832 wrote:

On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote:

Come again?  I can see no other link in the verbage with the
"relics of white supremacy" that she referred to.  If there are
other links, they should be included in the commit message.  I
agree with Rhodri that an explanation would be interesting.  Far be
it from me to demand one.  So whatever.


It's possible that this wasn't explained clearly enough in the commit
message itself (though I would argue it was definitely adequately
explained in the ensuing on-list discussion, and wonder how much of
that discussion you've actually read), but the point is that the
*whole idea* of "standard English" is tied to white supremacy, not
any particular standard whether via its authors or otherwise.


As I said in my preamble, it doesn't matter whether you believe that is
true or think it's utter bollocks.  I asked the question to get the
Steering Council's opinion, not anyone else's.


You don't get to decide whose opinions are offered.


But I do get to decide whose opinions are solicited.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-03 Thread Rhodri James

On 02/07/2020 23:46, Random832 wrote:

On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote:

Come again?  I can see no other link in the verbage with the
"relics of white supremacy" that she referred to.  If there are
other links, they should be included in the commit message.  I
agree with Rhodri that an explanation would be interesting.  Far be
it from me to demand one.  So whatever.


It's possible that this wasn't explained clearly enough in the commit
message itself (though I would argue it was definitely adequately
explained in the ensuing on-list discussion, and wonder how much of
that discussion you've actually read), but the point is that the
*whole idea* of "standard English" is tied to white supremacy, not
any particular standard whether via its authors or otherwise.


As I said in my preamble, it doesn't matter whether you believe that is 
true or think it's utter bollocks.  I asked the question to get the 
Steering Council's opinion, not anyone else's.  If you collectively 
really must rehash the arguments again, please have the decency to do so 
in a different thread.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-02 Thread Rhodri James

On 02/07/2020 18:11, Dieter Maurer wrote:

I am no member of the Council. Thus, your questions are not directed
to me. **BUT** you made your questions public and thus you are
likely prepared to receive public comments.


Fortunately you don't answer any of the questions, so I don't need to 
have an opinion on that :-)



The commit message tries to provide the motivation for
the change. In my view, it is good to document change motivations
and a commit message is not a bad place for that.


True.  However, the motivation as appeared in the discussions was 
(approximately) that many people, especially those whose first language 
is not English, find being given a list of writing guidelines like 
Strunk and White's "The Elements of Style" intimidating.  That's fair 
enough, though a bit more consideration suggests that many people have 
exactly the opposite problem.  The wording could be amended to reassure 
both, and I've been contemplating doing so.


The political diatribe about the linguistic contribution to white 
supremacy of standardized English appeared nowhere in the discussion. 
Had it done so, I suspect Keala would have realised quite quickly that 
using it would be (and has been) controversial and divisive, the exact 
opposite of her stated intentions.


All of which is quite beside the point for the questions I raised.  As I 
said, it doesn't matter whether you agree with that political opinion 
raised, disagree with it, or do not give a monkey's, should _any_ 
political opinion be in the repo?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Formal Question to Steering Council (re recent PEP8 changes)

2020-07-02 Thread Rhodri James
We've had the requested 24 hour cooling off, and I don't imagine anyone 
is surprised that the situation remains unchanged.  The commit message 
that caused the controversy is still in the PEP repository, and is still 
controversial.  Whether you think it's the best thing since the last 
best thing or the biggest load of bollocks since the last biggest load 
of bollocks is irrelevant.  It's there, it espouses a political stance, 
and by implication the Steering Council support it.


Since explicit is better than implicit :-), I would like to formally ask 
the Steering Council to answer the following questions.


1. Does the Steering Council think political statements have any place 
in the Python repositories?


2. If so, for the avoidance of doubt does the Steering Council support 
the statements in commit 0c6427d? 
(https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4)


3. If not, what do they intend to do about the above commit?

If the answer to question 1 is a qualified yes or no, both follow-up 
questions apply.


If the answer to question 1 is a prevarication, non-answer or silence, 
people will still draw their own conclusions.  I mention this merely to 
reinforce the idea that these things are still answers as well as 
hostages to fortune.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Code of Conduct address "hold message"

2020-06-30 Thread Rhodri James

On 30/06/2020 15:25, Rhodri James wrote:
Having just had occasion to use the code of conduct link 
(conduct...@python.org), I got back the message:


   Your mail to 'conduct...@python.org' with the subject

     

   Is being held until the list moderator can review it for approval.


Ah, it looks like the message I was expecting is generated when the 
moderator actually picks up the complaint, so that's OK.  The generic 
moderation message is still rather off-putting, though.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Code of Conduct address "hold message"

2020-06-30 Thread Rhodri James
Having just had occasion to use the code of conduct link 
(conduct...@python.org), I got back the message:


  Your mail to 'conduct...@python.org' with the subject



  Is being held until the list moderator can review it for approval.

etc.  I know this is the standard moderation message, but it seems 
rather out of place for the CoC address.  It's not the least bit 
reassuring if you feel uncomfortable about making such reports, as some 
people (myself included) are.  If I were emailing a commercial company's 
complaints line I would expect something more in the nature of


  Thank you for your email about "".  We will deal with
  it as soon as we can."

Plus the usual platitudes about valuing my input and appreciating my 
custom which don't necessarily apply here ;-/


Any chance of getting the message altered to something a bit more friendly?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pycharm offers only implementation of an abstract getter but not an abstract setter

2020-06-25 Thread Rhodri James

On 24/06/2020 22:46, zljubi...@gmail.com wrote:

Why Pycharm didn't offer a setter as well as getter?


This is a general Python mailing list.  If you have specific 
questions/complaints about PyCharm, they are probably better addressed 
directly to the makers of PyCharm.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 201, Issue 9

2020-06-09 Thread Rhodri James

On 09/06/2020 18:31, Joseph Jenne via Python-list wrote:

On 2020-06-09 09:00, zljubi...@gmail.com wrote:

Well the problem that I am facing with is, that I have to establish 
interface between python and outer system.


Original question was about creation of input object (data that I have 
received from outer system). If I accept recommendation to use "from_" 
instead of "from", it could work, for processing input, because 
processing is under my control.


However, my process will create output object that I should json 
serialize and return back to outer system as a response to the input. 
If I will have "from_" object property instead of "from", I believe 
that I should write a custom object to json serializer in order to 
support changing names from "from_" to "from".


It should be possible to name it from_ and then insert it into the 
__dict__ as 'from', although a custom serializer

would probably be preferable from a design standpoint.


Might it be simpler to use a dict from the start?  You could have a 
dictionary key of "from" without any problems.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Can't download Pygame and Pgzero

2020-06-05 Thread Rhodri James

On 05/06/2020 11:54, Lily Sararat via Python-list wrote:

I have trouble installing the Pygame and Pgzero on Window.  I based
on the instruction on the "Computer Coding Python Games for Kids" by
Carol Vorderman.  Nothing works.



I tried Python 3.6.2 as describe in the book and the latest version
3.8.3 still encounter on the same problem.  I really need to get this
sorted so my kid can spend his summer break mastering the coding.


Hi there Lily.  We aren't Pygame specialists, but we can give it a go. 
However to do that you're going to need to give us some details.  Which 
version of Windows are you using?  What exactly did you do to install 
Pygame and Pgzero, in order, and what exactly went wrong.  Please copy 
and paste any error messages, don't send screenshots because the mailing 
list will strip them off and we won't see them.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Imports, Namespaces, Poisoning, Readability

2020-06-05 Thread Rhodri James

AFAIKT the "three" are readability, naming conflicts and source location.

On 05/06/2020 01:15, DL Neil via Python-list wrote:

- how do you like to balance these three (and any other criteria)?


Readability is king.  Or queen, if you prefer.  Anything that damages 
readability drops dramatically in its desirability.  One consequence of 
that is that I rarely use "import ... as", since as you mentioned, 
renamed libraries are a rich source of WTF moments.  I would use "import 
numpy as np" (if I ever used numpy) because it seems to be standard, but 
I wouldn't type "import pygame as pg" despite having used PyGame 
extensively in the past.


I tend to use "from xxx import yy_yy, " when I'm not importing many 
things from a library and their names are sufficiently obvious.  The 
definitions of "not many" and "sufficiently obvious" are pretty 
flexible.  In particular, I'll list more items as the qualified names 
get longer, as you noted.  Source location is a non-issue; it's trivial 
to jump to the imports at the top of the file, look it up and jump back 
again.  Or have two buffers viewing the same file; that's a technique I 
use quite a lot anyway.  If I need to know the signature, that's what 
documentation is for.


I would never rename an object I've imported using "as".  It's just not 
worth the inevitable heartache.  If that means I have namespace 
collisions, that's either a vote to use the qualified name or to change 
the name of whatever I wrote that clashes with it.


- is your preference (or selection) influenced by the facilities offered 
by your favorite editor/IDE?


Not really.  I'm an EMACS user, so any of the "fancy" IDE handiwork is 
immediately out.  The only reason you need an IDE is if your support 
tools suck (sorry, Windows users).


- does your decision differ according to whether the 'target module' is 
one of yours, from the PSL, from some third party, corporate, ...?


I'm more likely to change my own module to fit :-)

- do you prefer PSL's importlib over Python's native import-s, for one 
of these (or any other) reason?


Um, why would I?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Binary Sort on Python List __xor__

2020-06-01 Thread Rhodri James

On 31/05/2020 18:01, Evan Schalton wrote:

I think you're arguing both sides of the argument -- numpy arrays do
have a lot of similar, related operations (because numpy uses them
internally -- since they're more efficient) which means they're not
fringe.

I'm advocating that the built-in list class add the efficient,
convenience methods -- especially since it wouldn't be overriding
other methods, it would be leveraging standard methods that are
currently unimplemented



Those methods make perfect sense in the bit-twiddling lists that you are 
using.  They make no sense whatsoever for lists like ["The", "quick", 
"brown", "fox"].  There's a decent purpose for a class implementing the 
features you want, but I honestly don't think the generic list class is it.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: .dll problem

2020-05-29 Thread Rhodri James

[Re-ordered because top-posting is evil ]:-)

On 29/05/2020 17:38, Souvik Dutta wrote:

On Fri, 29 May, 2020, 9:50 pm Preetha M,  wrote:


Hello. Warm regards from india. I am a kid who is currently learning
python. Hope you are doing well. I know that it is not a problem that you
can fix but whenever i try to open the software it shows that
api-ms-win-crt-runtime-l1-0-0.dll is missing. I tried reinstalling but it
is not working. Every application i install shows that something.dll is
missing. Please help.



Do you have DirectX installed. It must solve the problem.



DirectX is highly unlikely to be involved, as you have been told before 
Souvik.  What the OP actually needs is the missing Windows runtime, 
which can be obtained straightforwardly from Microsoft.  Here's the 
link: https://www.microsoft.com/en-in/download/details.aspx?id=48145


Incidentally, the first link Google turns up when you search for 
"windows runtime missing" explains what's going on and points to this link.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 17:39, BlindAnagram wrote:

I believe by attempting to make the directory I send absolute with
abspath() and then copying a file to this path.  They expected this to
copy the file into the directory with its original name but instead it
copies it to the file that abspath 'kindly' converts my directory into.

I did complain about their lack of knowledge but I also have a right to
complain about a function that converts an explicitly specified
directory into a file:-)


Well, they're getting exactly the behaviour I'd expect them to get (and 
not getting what they expect).  I'm faintly gobsmacked that anyone 
expects something like that to work.  If you want a directory, create 
it.  That's what os.mkdir (and the pathlib equivalent) is for.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 16:12, BlindAnagram wrote:

I'm sorry that you don't believe me but all I know is how I intend the
path to be used.  And the os.path functions aren't helpful here when
they actually_change_  the meanings of paths on Windows:


fp= "C:\\Documents\finance\\"
abspath(fp)

'C:\\Documents\\finance'

If you believe these 'before' and 'after' paths are the same I can only
assume that you don't work on Windows (where one refers to a directory
and the other a file without an extension).


More accurately, one is not a legal filename but both are legal 
directory names.


I entirely believe that you have a problem, but I'm inclined to think 
it's of your own making.  You seem to have decided how paths work 
without checking whether the language agrees with you.  It doesn't, and 
hasn't for over a decade without a significant number of complaints (as 
in I can't remember the last one, and I've been around here for a while 
-- it's too hot for me to want to go hunt in the archives :-).


How are these unexpected extensionless files getting created?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 14:41, BlindAnagram wrote:

That is true if you know for sure how your path will be used.

But if you don't, there is a world of difference between passing the
paths 'name' and 'name\\' on for others to use. And in this situation it
doesn't help when os.path functions strip the directory separator off.


Only if you impose meaning externally, which implies you do know how 
your path will be used after all.  If you want to know whether a given 
path corresponds to a file or a directory on a filing system, there's no 
real substitute for looking on the filing system.  Anything else is, as 
you have discovered, error-prone.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-26 Thread Rhodri James

On 26/05/2020 18:07, BlindAnagram wrote:

On 26/05/2020 17:46, MRAB wrote:

On 2020-05-26 16:48, BlindAnagram wrote:

On 26/05/2020 16:22, Ben Bacarisse wrote:

BlindAnagram  writes:


I came across an issue that I am wondering whether I should report
as an
issue.  If I have a directory, say:

   base='C:\\Documents'

and I use os.path.join() as follows:

   join(base, '..\\..\\', 'build', '')


It rather defeats the purpose of os.sep if you include it in a part of
the path.  What you mean is better expressed as

   join(base, '..', '..', 'build', '')

(and base includes it too, but I can't suggest an alternative because I
don't know your intent is far as defaults go.)


Thanks for your input but while that part of my path may not be to your
liking, it works fine and does not seem to be relevant to my concern,
which is that join appears to treat os.sep as an absolute path, which it
is not.


If it starts with the path separator, then it's absolute (well, absolute
on that drive).


Agreed.  I did not think that I needed to add this exception to my
comment as I thought from the the context that it would be clear that I
was questioning how it worked at the end of a path, not when used at its
  start.


But you aren't talking about the end of the (finished) path, you are 
talking about the start of the final path component you pass to 
os.path.join(), "\\".  As the documentation says, "If a component is an 
absolute path, all previous components are thrown away and joining 
continues from the absolute path component."  Since "\\" is an absolute 
path component, all the previous components are thrown away and you are 
left with just "\\".


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-26 Thread Rhodri James

On 26/05/2020 18:01, BlindAnagram wrote:

On 26/05/2020 17:09, Stefan Ram wrote:

Mats Wichmann  writes:

an absolute path is one that starts with the pathname separator.


   The Python Library Reference does not use the term
   "pathname separator". It uses "directory separator"
   (os.sep) and "filename separator" ('/' on Unix).

   On Windows:

|>>> import pathlib
|>>> import os
|>>> pathlib.PureWindowsPath('\\').is_absolute()
|False
|>>> pathlib.PureWindowsPath(os.sep).is_absolute()
|False
|>>> pathlib.PureWindowsPath('/').is_absolute()
|False


Thanks, that seems to suggest that there is an issue and that I should
hence submit this as an issue.


It is indeed most curious as to why this obviously absolute path is not 
recognised as such :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: stderr writting before stdout

2020-05-25 Thread Rhodri James

On 24/05/2020 05:27, Souvik Dutta wrote:

Is there any precedence or priority order by which sys.stderr.write() and
sys.stdout.write() works.


No.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strings: double versus single quotes

2020-05-23 Thread Rhodri James

On 22/05/2020 20:57, Manfred Lotz wrote:

I also believe that transferring habits from C, Rust or whatever to
Python doesn't make much sense as Python does not distinguish between a
character and string from a type perspective.


From a logical perspective, you are correct.  From the point of view of 
someone who writes more C code than Python, not having to remember a new 
set of habits for Python makes life a lot simpler.


Chacun à son goût and all that.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: why no camelCase in PEP 8?

2020-05-19 Thread Rhodri James

On 18/05/2020 22:07, Eli the Bearded wrote:

camelCase   ->noCamelCase
snake_case  ->no_snake_case

One of those is easier to "grep" for than the other.


Eh.  A changed case in the one, an extra character in the other; that's 
pretty much the same difficulty really.  I certainly don't find it 
"hard" to grep for _snake_case.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Installation Problem

2020-05-05 Thread Rhodri James

On 05/05/2020 05:34, Adolf Yoshua Marbun wrote:

Dear Python,

I am currently learning about Python. First thing first, I need to install
the interpreter Python 3.8.2 before I get to the IDE. But, I have problem
during running command.

The installation was successful. When I try to run the command prompt,
typing "python --version", it always shows me an error message as attached
below this message. I tried to follow the message (reinstalling the
program), but didn't work. I don't know what it is and I have tried few
times to solve the problem from the internet.


Unfortunately this is a text-only mailing list, and your attachment was 
stripped off before any of us had the chance to see it.  Could you copy 
and paste the error message into a message, please?  Also if you could 
let us know what operating system you are using, some people may be able 
to offer more detailed advice.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: python Netcdf and ncdump

2020-04-30 Thread Rhodri James

On 30/04/2020 18:55, J Conrado wrote:

Please,

Please can someone explain to me why I have this difference: in Python 
int16 SST(y, x) and with ncdump -h short SST(y, x)


Presumably on your computer a (signed) short integer is a (signed) 
sixteen bit integer.  That's rather unhelpful of ncdump.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.9.0a6 is now available for testing

2020-04-29 Thread Rhodri James

On 29/04/2020 20:23, Schachner, Joseph wrote:

 norm=lambda m: m+(m and(m[-1]!= '\n'and'\n'or'  ')or'\n')

Parentheses   1  2  
  1 0
quotes 1  0 1   
0   1 01  0

OK I don't see any violation of quoting or parentheses matching.   Still trying 
to figure out what this lambda does.


Presumably it's something to do with recognising string prefixes?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 22:27, dcwhat...@gmail.com wrote:

On Friday, April 17, 2020 at 2:11:17 PM UTC-4, Rhodri James wrote:

And people wonder why I stick to gdb when at all possible :-)

Never worked with it.  Is it a debugger for compiled code, i.e. it steps 
through the executable while displaying the source?  Or interpreted code?


The GNU project debugger has been around for quite a few decades now. 
It's a debugger for compiled code, covering about a dozen source 
languages (I can't be bothered to count at this time of night).  It is 
ridiculously flexible, command-line driven, and most importantly it does 
what you tell it to do.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 17:18, dcwhat...@gmail.com wrote:

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE
will interject here, to argue for the sake of arguing). But when I
worked with Groovy in Intellij about 5 years ago, there were times
when the IDE was confused, during a debugging sessions. I don't
remember the exact details, but that anomaly happened only with DEFed
variables ; it didn't happen when the data type was specified.


This is a general problem for IDEs, and type information isn't always 
helpful.  The number of times I have had to add useless bits of code to 
cast something to (uint8_t *) because I want to see the bytes and the 
IDE will not give up on trying to interpret them for me.


And people wonder why I stick to gdb when at all possible :-)

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Rhodri James

On 17/04/2020 12:40, Aakash Jana wrote:

I am running python 3.8 only but my issue is I need more zeroes after my
result.
I want 2/5 = 0.40
But I am only getting 0.4


When you just print or display a floating point number, Python only uses 
as many digits as needed if the answer happens to be a (small enough) 
exact decimal [*].


>>> foo = 2/5
>>> print(foo)
0.4

If you want the number displayed differently, you have to format it 
yourself.


>>> print("{:6f}".format(foo))
0.40


[*]: Since floats are stored internally in the standard IEEE *binary* 
format, what constitutes an *exact* decimal may be a little surprising!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: RFC: For Loop Invariants

2020-04-11 Thread Rhodri James

On 10/04/2020 21:44, Elliott Dehnbostel wrote:

Hello Everyone,

I've also posted this to the python-ideas mailing list, but I thought to
post here as well for a more general audience.

If I've done this incorrectly, please let me know so that I can
improve/revise. I'm new to the Python community and quite enjoy the more
functional features of Python 3, but have I have a peeve about it. I'd like
to propose and discuss the following enhancement to Python 3:

*Consider the following trivial for-loop:*

chars = "abcaaabkjzhbjacvb"
seek = {'a','b','c'}
count = 0for a in chars:
  if a in seek:
   count += 1

Gross. Twice nested for a simple count.


a) I don't personally think that's gross (apart from the missing 
newline, which is just an email artefact I assume).


b) If it's simple like this and you care enough, refactor it as a 
comprehension:


  count = sum(1 for a in chars if a in seek)

It it's not so simple, neither the comprehension nor your proposal are 
going to be as readable as the twice nesting.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How To Change Package Representation on Shell?

2020-04-01 Thread Rhodri James

On 01/04/2020 21:22, Abdur-Rahmaan Janhangeer wrote:

Greetings list,

I have a custom package.


import package
package

'>

what do i have to modify from my package to have like


package

Hi!


Do you mean "How do I override the str() or repr() of a module"?  I 
don't think you can.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 18:24, Musbur wrote:

Am 01.04.2020 15:01 schrieb Rhodri James:

I believe you do it in C as you would in Python: you call the Series 
class!


pyseries = PyObject_CallObject((PyObject *)_type, NULL);


Well, that dumps core just as everything else I tried.

What does work, however, is calling PyType_Ready first:

     PyType_Ready(_type);
     pyseries = PyObject_New(Series, _type);
     PyObject_Init((PyObject *)pyseries, _type);o

I don't understand, though, why I have to do that and when. Didn't that 
already happen when the module was imported? Do I need to do it whenever 
I create a new instance in C?


It should have happened on your module being imported, the line was 
there in your code.  Stick a breakpoint on your module init function and 
see if it is being called.


(The "from thingy import *" always makes me nervous, but it shouldn't be 
responsible for this.)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 13:42, Musbur wrote:
So when created from C, neither the "new" nor the "init" functions are 
called on the object, only "finalize". No wonder I get segfaults in the 
real life application.


So how is this done right? Here's the C module:


I believe you do it in C as you would in Python: you call the Series class!

pyseries = PyObject_CallObject((PyObject *)_type, NULL);

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Like c enumeration in python3

2020-03-23 Thread Rhodri James

On 23/03/2020 02:18, Paulo da Silva wrote:

Hi!

Suppose a class C.
I want something like this:

class C:
KA=0
KB=1
KC=1
...
Kn=n

def __init__ ...
...


These constants come from an enum in a .h (header of C file).
They are many and may change from time to time.
Is there a way to somehow define them from inside __init__ giving for
example a list of names as strings?


It sounds like what you want is a separate script to process your .h 
file into a Python module containing an enum, then import that module 
into your program.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James

On 19/03/2020 14:47, Peter J. Holzer wrote:

On 2020-03-19 14:24:35 +, Rhodri James wrote:

On 19/03/2020 13:00, Peter J. Holzer wrote:

It's more compact, especially, if "d" isn't a one-character variable,
but an expression:

  fname, lname = db[people].employee.object.get(pk=1234)[['first_name', 
'last_name']]

vs.

  fname = db[people].employee.object.get(pk=1234)['first_name']
  lname = db[people].employee.object.get(pk=1234)['last_name']


I have to say I don't think that's more compact at all.  It's too wide
to be compact.


But 83 characters is still more compact than 121 characters.


Only if your sole metric is a strict character count.  Width matters in 
perception; two shorter lines are easier to take in than one long line, 
even if the long line contains fewer characters.


Besides, terseness isn't one of Python's objectives.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why is the program not printing three lines?

2020-03-19 Thread Rhodri James

On 19/03/2020 13:58, Souvik Dutta wrote:

I should have been more clear
class first():
 print("from first")
 def second():
 print("from second")
first()

When I run the above code the output is
"from first"
(2ND CODE)

class first():
 print("from first")
 def second():
 print("from second")
first.second()

When I run this code the output is
"from first"
"from second"

Thus going by the above logic

class first():
 print("from first")
 def second():
 print("from second")
first()
first.second()

This should have given the following output
from first
from first
from second


Nope.  You haven't made your logic clear, but I think you are still 
confused about when the code in the class suite is run, and still think 
of it as running when an instance is created.


Try running this code:

class first:
print("from first")

Just that.  No instantiation, no "first()", nothing else.  Just the 
class suite itself.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James

On 19/03/2020 13:00, Peter J. Holzer wrote:

On 2020-03-19 18:22:34 +1300, DL Neil via Python-list wrote:

On 19/03/20 3:28 PM, Santiago Basulto wrote:

myself missing A LOT features from NumPy, like fancy indexing or
boolean arrays.
So, has it ever been considered to bake into Python's builtin list and
dictionary types functionality inspired by NumPy? I think multi indexing
alone would be huge addition. A few examples:

[snip]>> I fear that I'm missing your point.


How is
l[[0, -1]] or fname, lname = d[['first_name', 'last_name']]
any better than
l[ 0 ], l[ -1 ] or
fname = d[ 'first_name' ]
lname = d[ 'last_name' ]


It's more compact, especially, if "d" isn't a one-character variable,
but an expression:

 fname, lname = db[people].employee.object.get(pk=1234)[['first_name', 
'last_name']]

vs.

 fname = db[people].employee.object.get(pk=1234)['first_name']
 lname = db[people].employee.object.get(pk=1234)['last_name']


I have to say I don't think that's more compact at all.  It's too wide 
to be compact.  I think the second version is more readable (and the 
third version, where you factored out the common lookup is better still).


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python question

2020-03-11 Thread Rhodri James

On 11/03/2020 04:06, Michael Torrie wrote:

On 3/10/20 6:49 PM, Souvik Dutta wrote:

What about moving on to a social media app completely made in pythoj for
python?

No thanks. I don't want to be on yet another web forum.  I don't need
"social media" or a "social media app."  Email works exceedingly well
for this sort of thing, despite Google's antics.


+10

The best response to "This system breaks when I abuse it" is almost 
always "Well stop abusing it then."


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-26 Thread Rhodri James

On 25/02/2020 15:06, BlindAnagram wrote:

My interest in this stems from wanting to keep the dictionary only
available to the function that uses it and also a worry about being
called from threaded code.


Hiding your dictionary away inside a class or instance isn't going to 
protect it from threading disasters by itself, though it will make it 
easier to protect it as you need.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 15:20, BlindAnagram wrote:

class GetIt:
   seen = dict()

   def __call__(self, piece):
     return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not
actually any better than a global dictionary.

This doesn't work for me since get_it(piece) returns the error:

builtins.TypeError: get_it() takes no arguments


It works for me (pace sticking something in GetIt.seen to avoid getting 
a KeyError).  You aren't muddling up the class name and instance name 
are you?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 12:38, BlindAnagram wrote:

I would appreciate advice on whether it is possible to avoid the use of
a global variable used in a function by encapsulating it in a class
without maaking any changes to the call interface (which I cannot change).

I have:


seen = dict()

def get_it(piece):
...
return seen[piece]


and I am wondering if it is possible to use a class something like


class get_it(object):

   seen = dict()

   def __call__(piece):
 return seen[piece]


to avoid the global variable.


I wouldn't.  Calling the class name creates an instance of the class, so 
won't actually do what you want.  You could rewrite the class and create 
an instance to call instead:


class GetIt:
  seen = dict()

  def __call__(self, piece):
return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not 
actually any better than a global dictionary.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: time.localtime add a parameter for timezone

2020-02-24 Thread Rhodri James

On 24/02/2020 17:21, Dieter Maurer wrote:

qbit wrote at 2020-2-24 05:18 -0800:

How about adding a time zone parameter to time.localtime?

A  offset just like the form: ± hh[:mm[:ss]].


Why should this be necessary? `localtime` returns the time
in the "local timezone" -- and the "local timezone" usually
does not change between different calls to `localtime`.


It can if your calls to localtime() happen either side of a daylight 
saving time switch.


That said, I agree that the timezone doesn't really belong in the output 
of localtime().  There are a very few occasions when you want it, but 
more often you should be working in UTC not local time.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Paper Print Help

2020-02-20 Thread Rhodri James

On 20/02/2020 15:08, Duram wrote:

On 19/02/2020 12:17, Rhodri James wrote:

On 19/02/2020 14:22, Duram via Python-list wrote:
I have a drawing in a .gif file with (a,b) pixels and want to 
paperprint it in a position (x,y), what would be the code?


What have you tried?


Nothing, I did not find the module that make to print to the paper


Please don't reply to me directly; if it's a question worth asking in 
public then it's worth answering in public too!


OK, let's backtrack a bit.  First off, what operating system are you using?

Second, do you have this GIF file in any sort of program at the moment, 
or do you want advice on how to write a program to handle the image?  I 
suspect your question is a bit too specific at the moment, and you have 
some mistaken assumptions about how images and (most especially) 
printing work.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Paper Print Help

2020-02-19 Thread Rhodri James

On 19/02/2020 14:22, Duram via Python-list wrote:
I have a drawing in a .gif file with (a,b) pixels and want to paperprint 
it in a position (x,y), what would be the code?


What have you tried?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James

On 12/02/2020 17:46, Python wrote:

On Wed, Feb 12, 2020 at 01:16:03PM +, Rhodri James wrote:

On 12/02/2020 00:53, Python wrote:

In pretty much every job I've ever worked at, funding work (e.g. with
humans to do it) with exactly and precisely the resources required is
basically impossible, and management prefers to underfund the work
than to overfund it, for cost-savings reasons.  This basically means
that any non-trivial work you do inevitably will become technical debt



s/become/accrue/.  The work itself isn't the debt, but its sub-optimality
creates debt (or future headaches, if you prefer to think of it that way).



I think it's a purely semantic distinction without a practical
difference...which was the point I was trying to make.  The work is
the direct cause of the debt, and at the time it is performed the debt
is realized.  Without the work, that particular debt is not incurred.
You may have eliminated some old debt when the work is done, but your
new debt replaces your old debt.  Depending on the resources you can
devote, that debt may or MAY NOT be less than the other, and sometimes
the truth of this can not be discovered until you're already knee deep
in it.


Here's where the "purely semantic" distinction matters.  You are 
equating the work with the debt, but ignoring the benefit the work 
presumably brings (otherwise you wouldn't have done it at all).  Either 
you should be rolling it all together or separate both, surely.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James

On 12/02/2020 00:53, Python wrote:

In pretty much every job I've ever worked at, funding work (e.g. with
humans to do it) with exactly and precisely the resources required is
basically impossible, and management prefers to underfund the work
than to overfund it, for cost-savings reasons.  This basically means
that any non-trivial work you do inevitably will become technical debt


s/become/accrue/.  The work itself isn't the debt, but its 
sub-optimality creates debt (or future headaches, if you prefer to think 
of it that way).



IMMEDIATELY, because you will not be given the time to do the job
completely in the first place, there will inevitably be bugs which are
minor enough to ignore indefinitely, and most likely, in order to meet
arbitrary-but-nevertheless-real time constraints you will find
yourself obliged to take shortcuts.  So conceptually "costs" may be
different from "debt" but in practice, you never have one without the
other, and "debt" is really just "costs" you haven't paid yet.


It's that last bit, "you haven't paid yet", that's the important part. 
Project managers and accountants alike are very much in favour of 
putting off paying for things if they can.  Sometimes they can be 
persuaded that the interest on the debt (the extra cost that the code 
structure imposes on fixing bugs) is too much, and then you get the 
opportunity to refactor and reduce the overall debt (at a cost, 
obviously) and the interest you will pay in the future.


Sometimes, and this is the bit that bean counters really like, you can 
get away without paying the debt by ditching the project entirely before 
the debt is paid off.  If you don't want to piss your customers off you 
need to pay the cost of a replacement project, which will accrue its own 
technical debt...


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ERROR in loading data

2020-02-04 Thread Rhodri James

On 04/02/2020 14:49, laiba.zubai...@gmail.com wrote:

#load the training and testing data, then scale it into the
# range [0, 1]
print("[INFO] loading  ADNI data...")
((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
Drive/3_Classes/'.loads_data()
trainX = trainX.astype("float") / 255.0
testX = testX.astype("float") / 255.0
  
	# initialize the label names for the  ADNI dataset

labelNames = ["outAD", "outCN", "outMCI"]
When i try to run this code I got the following error.

[INFO] loading  ADNI data...
---
AttributeErrorTraceback (most recent call last)
 in ()
   1 print("[INFO] loading  ADNI data...")
> 2 ((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
Drive/3_Classes/'.loads_data()
   3 trainX = trainX.astype("float") / 255.0
   4 testX = testX.astype("float") / 255.0
   5


So that error is saying that something on line 2 is trying to use an 
attribute incorrectly, probably one that doesn't exist (there really 
should be more explanatory information in the error, by the way).  The 
only thing on line 2 that tries to access an attribute is the string 
'/content/gdrive/My Drive/3_Classes/', which tries to run the method 
loads_data().  Fair enough.  A quick test on the interactive command 
line or a look in the documents will tell you that strings indeed do not 
have a loads_data() method.


I don't know what library you are intending to use, but you need to open 
your file with that first.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: when uses time.clock,there are always mistakes

2020-02-03 Thread Rhodri James

On 03/02/2020 08:04, 石盼 wrote:

Hello !
 The problem like this:
     RESTART: Shell 

  >>> import time
  >>> t = time.clock()
  Traceback (most recent call last):
    File "", line 1, in 
  t = time.clock()
  AttributeError: module 'time' has no attribute 'clock'


It is correct, there is no time.clock() function.  The documentation is 
here: https://docs.python.org/3/library/time.html


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Data type assignment

2020-01-28 Thread Rhodri James

On 28/01/2020 12:03, sushma ms wrote:

Hi

Please find below example and the compiler error,

when i'm assigning value dynamically and when we comparing in "if" loop it
is throwing compiler error. It should not throw error


It absolutely should throw an error.


it should assign and
act as int why it is thinking as string.


Because it is a string.  The documentation of "input" is quite explicit 
about this:


 input([prompt])

If the prompt argument is present, it is written to standard output 
without a trailing newline. The function then reads a line from input, 
converts it to a string (stripping a trailing newline), and returns 
that. When EOF is read, EOFError is raised.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Enum by gum

2020-01-24 Thread Rhodri James

On 24/01/2020 04:26, DL Neil via Python-list wrote:

Questions:

Have I made proper sense of this? (please don't laugh too much)


Um.

My basic take on enums is that they provide a convenient namespace to 
collect together related constants.  API flags and opcodes are an 
obvious example of related constants you would want to keep together, 
but Python enums can be more complex than that both as structured data 
and associated functions.


Is the above 'interfacing' an appropriate use of enum-s; or is it really 
'overkill' or posturing?


I think it's an entirely appropriate use of enums.  In fact it's pretty 
much my only use of them.  One caveat: when you care about the value of 
a constant, set it explicitly.  Don't rely on auto() to come up with the 
right number for you, because the documentation really gives you no 
guarantees.


Python v3.6+ brings Flag-enums into the game. These seem better for 
interface use, as described. Do you prefer them to the 'plain-vanilla' 
enum, and for what reason?


I prefer them when the interface calls for flags, because they behave 
like flags.  I use plain enums when I don't require that behaviour. 
It's horses for courses, as ever.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: Enhancing Zipapp

2020-01-08 Thread Rhodri James

On 08/01/2020 18:08, many people wrote lots of stuff...

Folks, could we pick one list and have the discussion there, rather than 
on both python-list and python-ideas?  Getting *four* copies of Andrew's 
emails is a tad distracting :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold!

2020-01-06 Thread Rhodri James

On 01/01/2020 07:22, Abdur-Rahmaan Janhangeer wrote:

-- Self-updating Python distributions


Microsoft have proved time and again that this is a really good thing if 
you want to piss off your customer base.  Let's not.



-- Distributions which notify about new releases


Surely this is the OS's package management system's job?


-- Easy compilation to python-specific executable (.pyz is a good candidate)


Don't we already have .pyc files?


-- More robust native Gui facilities


Why is this a core Python issue?  GUIs are inherently OS-specific 
(including those OSes -- or lack of OSes -- which have no graphical 
interface).


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold! - The Draft

2020-01-06 Thread Rhodri James

On 06/01/2020 10:21, Abdur-Rahmaan Janhangeer wrote:

Before we begin, we'd like to define the term executable used in the context
of this draft. It means an archive that is run by double-clicking.


I'm an embedded systems programmer.  Congratulations, you have just 
rendered your draft utterly irrelevant to me and those like me.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dataset training using Kmeans

2020-01-06 Thread Rhodri James

On 05/01/2020 12:56, hanan lamaazi wrote:

Dear all,

I'm actually using the K-means algorithm for clustering, and scikit-learn
machine learning in python.

when I want to print my "score_accuarcy" using this command


print(metrics.accuracy_score(y_test, y_pred))


I get the following error :

"Classification metrics can't handle a mix of continuous-multioutput and
binary targets"


This is probably an exception from metrics.accuracy_score() (you've 
shorn off too much context for me to be certain).  Googling the text 
gives me no shortage of links; you are far more likely than me to 
recognise which of them are relevant to your circumstances.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 12:43, tommy yama wrote:

Thanks for your quick response i did not expect.
I hope you see the error below in my response as i just copy and paste it.

"no module named 'hexdump'."

In addition, i tried to execute python3 hexdump.py. However, no such file
directory.

from hexdump import hexdump

ModuleNotFoundError: No module named 'hexdump'

user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
can't open file 'hexdump.py': [Errno 2] No such file or directory

user@USERnoMacBook-Air LibraBrowser %


Huh.  You've done a "pip3 install hexdump" so I don't know what might be 
happening here.  Sorry.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 11:23, tommy yama wrote:

Thanks for your kind response.
The error was simply "module Hexdump was not found".


Several things:

a) Did it really say "module Hexdump was not found"?  "hexdump" and 
"Hexdump" are not the same things; module names are case-sensitive.


b) There will have been a whole load more stack trace that might be 
useful to us.  I should have been clearer when I asked you to copy and 
paste the error that I really meant the whole of the complaint that 
Python made to you, not just the final error message!  Apologies for that.


c) I would much prefer it if you didn't top-post, but interleaved your 
replies like I've done here.  I find it hard to follow top-posted 
messages because they reverse the normal flow of conversation.





On Wed, Dec 18, 2019 at 11:39 PM Rhodri James  wrote:


On 18/12/2019 02:23, tommy yama wrote:

Hi,

This sounds familiar to somebody?
After upgrading my mac OS to Catalina, this persists even after pip3
install hexdump.

[image: image.png]


I'm afraid this is a text-only mailing list.  Your screenshot has been
stripped out before any of us saw it.  Could you copy and paste (DON'T
retype!) the error instead, so we can all read it?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list






--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-18 Thread Rhodri James

On 18/12/2019 02:23, tommy yama wrote:

Hi,

This sounds familiar to somebody?
After upgrading my mac OS to Catalina, this persists even after pip3
install hexdump.

[image: image.png]


I'm afraid this is a text-only mailing list.  Your screenshot has been 
stripped out before any of us saw it.  Could you copy and paste (DON'T 
retype!) the error instead, so we can all read it?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-12 Thread Rhodri James

On 11/12/2019 21:32, mus...@posteo.org wrote:

On Tue, 10 Dec 2019 14:56:10 -0500
Dennis Lee Bieber  wrote:


It is called when the language IMPLEMENTATION decides to call
it. That time is not specified in the language description/reference
manual.

Yes it is:

"Note: del x doesn’t directly call x.__del__() — the former decrements
the reference count for x by one, and the latter is only called when
x’s reference count reaches zero."

Plain and simple: When the refcount reaches zero.
You are assuming that "when" implies "immediately on the occurence."  It 
doesn't.  This happens to be the behaviour in CPython, but other 
implementations vary as Chris has explained several times now.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-11 Thread Rhodri James

On 11/12/2019 14:17, Musbur wrote:

Am 10.12.2019 22:33 schrieb Paul Moore:


You do understand that the reference counting garbage collector is an
implementation detail of the CPython implementation *only*, don't you?


I don't think that's true. Here's a sentonce from near the top of the 
"gc" module documentation of Python 3:

https://docs.python.org/3/library/gc.html#module-gc

"Since the collector supplements the reference counting already used in 
Python, you can disable the collector if you are sure your program does 
not create reference cycles."


The way I read this is that Python automatically and immediately deletes 
objects once their refcount goes to zero, and the garbage collector only 
kicks in case of circular references or other obscure circumstances. The 
documentation makes no reference to the specific Python implementation, 
so I believe this is true for CPython as well as others.


That's a bug in the documentation, and needs fixing; thanks for pointing 
it out!  It is certainly true that some other Python implementations 
(Jython for example) do not use reference counting, and disabling the 
collector may have further-reaching implications for those 
implementations.  I can't speak to the details; the only other 
implementation I use is Micropython, and I don't use that often enough 
to have cared about the details of garbage collection beyond noting that 
it's different to CPython.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:25, R.Wieser wrote:

And to repeat, you have*no*  guarantee*at all*  in the language spec that
this will happen.

There is also absolutily no guarantee in those specs that my 'puter will not
suddenly transform into a bonzai tree.   Should I now expect it to happen ?


That's an implementation detail of your computer.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:00, R.Wieser wrote:

MRAB,


You merely disabled the mark-and-sweep collector.


Nope.   Go check the docs on "gc"


Yep.  Go and check the docs on "gc" *carefully*

*plonk*


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 17:18, R.Wieser wrote:

Chris,


Okay. What should happen when you do this?

x = 5
del x

Should the integer 5 be deleted?


Yep.

What do you think happens instead ?   I've not seen you explain or support
anything in that regard, not even now.


As it happens, the object that is the integer 5 *isn't* deleted.  Once 
again, you are making assertions based on what you believe to be true, 
despite having been told otherwise.  That's fair enough, but you then 
give those assertions the weighting of fact.



There is a bit of a problem with the above though: It has got zero to do
with the __del__ I was talking about.


On the contrary, it's exactly the point.  You are asserting behaviour 
that you are not guaranteed.  It happens that current versions of 
CPython conform to your expectations.  I have a vague and unreliable 
recollection that earlier versions didn't.  Other Python interpreters 
may or may not.  The language description does not give you that 
guarantee, so relying on it is at best foolish.



 I've not seen you point out any
mistake with my example (pointing out race contition problems) either.


Greg Ewing did:

"In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared. That happens to be
true currently in CPython (which uses reference counting), but it's
not guaranteed by the language."

Unless you're referring to some other example.  It's a bit hard to tell 
without the context.



Not a smooth move bro.  Not a smooth move /at all/ :-(


Words fail me.


So the language designers couldn't possibly have been so stupid
as to do things this way, but you're going to ignore what they did?


Actually, they didn't.

Did you know you can disable the garbage collector ?  Well, you can.   Guess
what I saw when I disabled it, created a class instance and than deleted it
again.  Yup, the "print" command I placed in the "__del__" method did
actually show output - something that, according to you, could/should never
happen ...


What you disabled wasn't the garbage collector, it was the garbage 
collector's periodic background run to detect reference cycles and 
delete them when they have no external references.  The garbage 
collector itself ran just fine when your instance's reference count 
reached zero, exactly as everyone has been saying to you.


And to repeat, you have *no* guarantee *at all* in the language spec 
that this will happen.  The garbage collector could have waited until it 
was short of space before deleting the object, for example, which might 
not happen until your script terminates.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Rhodri James

On 10/12/2019 03:35, Tim Daneliuk wrote:

On 12/9/19 8:50 PM, Paul Rubin wrote:

Tim Daneliuk  writes:

- Imagine an environment in which there may be multiple instances of a given
   microservice written in Python.


Decide the maximum number of microservice instances, say 1000.  Chop up
the 10 digit range into 1000 pieces, so 0..99, 100-199, etc.
Give one range to each microservice instance.  Then have the
microservices give out the numbers sequentially, but treating them as 10
digit numbers and encrypting each one under a 10 digit pseudorandom
permutation shared by all the instances.  Look up "format preserving
encryption" for how to do this.

Obvious variants of the above are obvious, and maybe you need some way
to hand around chunks of range if some instance gives out more than a
million numbers.




The problem here is that the services are ephemeral and the number of said
services is not fixed.


Hm.  Normally I'd mash together the MAC address of the interface and the 
process ID of the service (or whatever individual identifier 
microservices have -- indeed, whatever microservices *are* :-), but ten 
digits is a bit few for that.  So you want some variant of Paul's approach.


* I assume there are a number of machines providing these services. 
Give them unique numbers -- I'm guessing three digits should be enough 
for that, but you know your own setup better.  How you assign those 
numbers is up to you; a config file in /etc, a Windows registry key, or 
some broadcast protocol that the machines use to dynamically configure 
themselves are all options that spring to mind.


* On each machine, something must spin up services when they are needed. 
 That something will be in a position to assign a unique number (within 
an individual machine) to each service.  So do that, using whatever 
digits you have left after the unique machine number.


* Mash these two numbers into a single ten digit identifier.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regarding problem in python 3.8.0 installation

2019-12-09 Thread Rhodri James

On 08/12/2019 18:08, alok singh wrote:

Sir,

My system is windows 7 SP1 32-bit . after installing python in my
system,when i try to launch it using command prompt then a message is
shown. I am attaching a screenshot of the following.
kindly look seriously into my problem and tell me the solution..


I'm afraid this is a text-only mailing list, so your screenshot has been 
stripped off before any of us could see it.  Please could you copy and 
paste the text of the error message you receive.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-05 Thread Rhodri James

On 05/12/2019 19:30, Rhodri James wrote:

On 05/12/2019 18:49, RobH wrote:

Update:
I did python3 Internet.py
and now only get this error:

pi@raspberrypi:~/Downloads $ python3 Internet.py
   File "Internet.py", line 24
 font = ImageFont.truetype( 'Minecraftia.ttf', 35)
 ^
TabError: inconsistent use of tabs and spaces in indentation

I cannot see what is wrong, as the text is all lined up with that 
above and below:


The problem will be that you have a mix of tabs and spaces in your 
indentation.  This causes problems because some people don't think that 
the One True Tab Width is 8 characters ;-) so to them the indentation 
looks ragged.  Worse, when they mix tabs and spaces, code that looks to 
be at the same indentation level to them looks different to the 
interpreter.  The decision was taken a while ago that Python should put 
its foot down about this, and demand that we use either all tabs or all 
spaces for our indentation.  That's what you've fallen foul off; there 
must be a mix of tabs and spaces in that line!


Or more likely you've used tabs on that line and spaces elsewhere, or 
vice versa.  I should have remember to say that, sorry.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-05 Thread Rhodri James

On 05/12/2019 18:49, RobH wrote:

Update:
I did python3 Internet.py
and now only get this error:

pi@raspberrypi:~/Downloads $ python3 Internet.py
   File "Internet.py", line 24
     font = ImageFont.truetype( 'Minecraftia.ttf', 35)
     ^
TabError: inconsistent use of tabs and spaces in indentation

I cannot see what is wrong, as the text is all lined up with that above 
and below:


The problem will be that you have a mix of tabs and spaces in your 
indentation.  This causes problems because some people don't think that 
the One True Tab Width is 8 characters ;-) so to them the indentation 
looks ragged.  Worse, when they mix tabs and spaces, code that looks to 
be at the same indentation level to them looks different to the 
interpreter.  The decision was taken a while ago that Python should put 
its foot down about this, and demand that we use either all tabs or all 
spaces for our indentation.  That's what you've fallen foul off; there 
must be a mix of tabs and spaces in that line!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-14 Thread Rhodri James

On 14/11/2019 17:11, R.Wieser wrote:

Rhodri,


MyVar is a global here, so nonlocal explicitly doesn't pick it up.

I do not agree with you there (the variable being global).  If it where than
I would have been able to alter the variable inside the procedure without
having to resort to a "global" override (an override which is only valid for
the context its used in by the way, not anywhere else)

Than again, that is how it works in a few other languages, so I might have
been poisonned by them.:-)


You have been.

  # This is at the top level of a module
  # I.e. it's a global variable
  my_global_variable = 5

  # You can read globals from within a function without declaring them
  def show_my_global():
print(my_global_variable)

  # If you try setting it, you get a local instead
  def fudge_my_global(n):
my_global_variable = n

  show_my_global()  # prints '5'
  fudge_my_global(2)
  show_my_global()  # prints '5'

  # If you read the variable before setting it, you get an exception
  def mess_up_my_global(n):
print(my_global_variable)
my_global_variable = n

  mess_up_my_global(2) # UnboundLocalError!

  # ...because it must be a local because of the assignment, but it
  # doesn't have a value at the time print() is called.

  # To do it right, declare you want the global from the get go
  def love_my_global(n):
global my_global_variable
print("It was ", my_global_variable)
my_global_variable = n

  love_my_global(3) # prints 'It was 5'
  show_my_global()  # prints '3'

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-14 Thread Rhodri James

On 14/11/2019 13:06, R.Wieser wrote:

Hello all,

I've just tried to use a "nonlocal MyVar" statement in a procedure
defenition, but it throws an error saying "Syntax error: no binding for
nonlocal 'MyVar' found.

According to platform.python_version() I'm running version 3.8.3

Why am I getting that error ? (already googeled ofcourse)

Testcode:
- - - - - - - - - - - -
Def Proc1()
 nonlocal MyVar
 MyVar = 5

MyVar = 7
Proc1()
print(MyVar)
- - - - - - - - - - - -
I've also tried moving "MyVar = 7" to the first line, but that doesn't
change anything.  Using "global MyVar" works..


The Language Reference says 
(https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement):


"The nonlocal statement causes the listed identifiers to refer to 
previously bound variables in the nearest enclosing scope *excluding 
globals.*"  (my emphasis.)


MyVar is a global here, so nonlocal explicitly doesn't pick it up.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Launching a Script on the Linux Platform

2019-11-12 Thread Rhodri James

On 12/11/2019 18:25, Rob Gaddi wrote:

On 11/12/19 10:06 AM, Wildman wrote:

What is the best approach for launching a Python GUI program
on a Linux platform.  The program will be distributed in .deb
format.  So the .deb will contain a menu file as well as a
.desktop file.  The post install script will update the system
menu.

My question is how should the program be executed?  Here are
two choices for the "command=" entry in the menu file...

command="/path/to/program.py"

In this case the hash-bang would have to be included in the
program script... #!/usr/bin/env python3

The other choice is this...

command="python3 /path/to/program.py"

(Of course, the Exec command in the .desktop file should match.)

Is one method better than the other or does it acutally matter?



I will note that without the shebang (and setting the execute bit), the 
program is only executable from the GUI menu, not the command prompt.  I 
personally start even GUI programs far more often from a prompt.


To follow Linux conventions you'd put the shebang, make the file 
executable, and put the executable somewhere on the PATH.  I'd stick to 
those conventions barring a particular reason not to.


Wildman is talking about launching his program from a menu, so putting 
it on the PATH is unnecessary.  It may even be a bad idea, depending on 
exactly what he's done :-)


As to the original question, there shouldn't really be much of a 
difference.  The original idea of the shebang line invoking env, as far 
I recall, was that you'd get the "proper" system python3 wherever it had 
been put rather than something random and possibly malicious.  I guess 
that means to go for your first option.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-12 Thread Rhodri James

On 11/11/2019 19:05, Bill Deegan wrote:

You could use SCons (native python... )


I could.  But I'd have to learn how to first, and particularly for 
complex cross-platform working that involves learning a lot of stuff I 
already know how to do in Make.  The time investment has never seemed 
that worthwhile.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-11 Thread Rhodri James

On 11/11/2019 17:55, Thomas Jollans wrote:
I'm sure it's possible to write Makefiles that work with both GNU make 
and NMake, but I imagine it's a rather limiting and thankless enterprise.


Is that something you actually do? (Maybe it's great, I really wouldn't 
know. Do tell!)


Trying to work cross-platform with NMake/GNU make is every bit as horrid 
as you're imagining when you start getting clever, and I haven't tried 
doing it for years.  Generally when I'm working on both Windows and 
Linux, Cygwin is involved anyway so I just use GNU make and be done with it.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-11 Thread Rhodri James

On 09/11/2019 23:50, Thomas Jollans wrote:

On 09/11/2019 21:30, Chris Angelico wrote:

On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans  wrote:

On 07/11/2019 20:20, Vitaly Potyarkin wrote:

What do you think of using Makefiles for automating common chores in
Python projects? Like linting, type checking and testing?

I've come up with a reusable Makefile for automating virtual 
environment

management in Python projects. I think it can be useful for simplifying
the onboarding of new developers (both new to project and new to 
Python)

and for documenting project's development practices.

Here it is:
- Repo: https://github.com/sio/Makefile.venv
- Demo screencast: https://asciinema.org/a/279646

What do you think? Is this useful or I'm just unaware of some tool that
abstracts venv chores away better?


As others have said, make is a useful tool and many people use it for
different purposes in their Python projects. Nothing wrong with that.

HOWEVER, at risk of stating the obvious, using Makefiles written for/on
*nix systems on Windows is a bit of a hassle. If, for some reason, your
software is *nix-only anyway, that's fine. If not, using make means
sacrificing some portability.

If your software runs on Windows, of you think it might run on Windows
in the future, maybe consider writing simple Python scripts for
platform-independent tasks rather than makefiles and shell scripts.


Are you assuming that every Windows system has Python, but that you
can't get make or bash? Because neither half of that is true. I've
happily used makefiles on Windows, and these days, bash is as easy to
get hold of as Python is.

ChrisA


That's why I say "a bit of a hassle". You can get a MSYS set up (whether 
from Git for Windows or otherwise). You can get it to play nice with the 
right Python installation and the Python scripts you presumably want to 
call from the Makefile. But all of that is a bit of a hassle.


If you've got almost any development environment for Windows, you've got 
a version of make.  I quite like the NMake that comes with Visual 
Studio, for example, and use it in preference to the IDE when I can. 
Yes, it's a hassle, but it's a hassle you're going to go through anyway.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-11 Thread Rhodri James

On 07/11/2019 13:36, Stephen Waldron wrote:

This is how it is at the moment, however it may be more agreeable, especially 
if that is the only purpose of the function, for python users to be able to 
define new functions inside of function calls.


No, not seeing it.  Sorry, I don't think "I don't want to use up a 
precious, precious name in this namespace" is a good enough reason to do 
anything, never mind something with a lot of implicit naming going on. 
Suppose you had been good and made a module of your Book example.  What 
is someone reading your code supposed to make of this?


import books

my_books = [
books.Book("Triplanetary", 'E.E. "Doc" Smith'),
books.Book("Foundation", "Isaac Asimov")
]

books.doToBooks(my_books):
print(book.name, ":", book.author)
then:
if book.name == "Foundation":
print("READ THIS FIRST!")

The name "book" has just appeared out of thin air, and without stopping 
and reading the code of your module they will have to guess at what it 
is.  Now in this case their first guess is probably right, but this is a 
toy example and just as easily written with lambdas if you're that 
worried about using up names.


-10 from me.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How execute at least two python files at once when imported?

2019-11-06 Thread Rhodri James

On 06/11/2019 16:02, Spencer Du wrote:

Why is importing modules in parallel bad?


To put it as simply as I can:

1. The import mechanism is complicated, even the bits that are 
user-visible.  Fiddling with it has a high chance of going wrong.


2. Multi-threading is less complicated than import, but still requires a 
lot of careful thought.  For example you've asserted that the modules 
you want to import simultaneously, but you also need to consider the 
import mechanism itself.


Put 1 and 2 together, and multi-threaded import sounds like a nightmare.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How execute at least two python files at once when imported?

2019-11-06 Thread Rhodri James

On 06/11/2019 11:42, Rhodri James wrote:

On 06/11/2019 09:51, Spencer Du wrote:

On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James  wrote:

On 05/11/2019 18:33, Spencer Du wrote:

I want to execute at least two python files at once when imported but
I dont know how to do this. Currently I can only import each file one
after another but what i want is each file to be imported at the same
time.


That is a very odd requirement.  Why would you want to do this?  What
exactly does "at the same time" mean here?

These are modules/files which are independent of each other and have 
no dependencies with one another. Because of this I want to run 
modules all at once.




"All at once" still isn't a very meaningful phrase.  If you want to 
import modules in parallel, don't.  Not only is it hard work to do, it 
will come back and bite you.


Also posting exactly the same answer word for word four different times 
isn't a very helpful thing to do.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How execute at least two python files at once when imported?

2019-11-06 Thread Rhodri James

On 06/11/2019 09:51, Spencer Du wrote:

On Tuesday, 5 November 2019 19:44:46 UTC+1, Rhodri James  wrote:

On 05/11/2019 18:33, Spencer Du wrote:

I want to execute at least two python files at once when imported but
I dont know how to do this. Currently I can only import each file one
after another but what i want is each file to be imported at the same
time.


That is a very odd requirement.  Why would you want to do this?  What
exactly does "at the same time" mean here?


These are modules/files which are independent of each other and have no 
dependencies with one another. Because of this I want to run modules all at 
once.



"All at once" still isn't a very meaningful phrase.  If you want to 
import modules in parallel, don't.  Not only is it hard work to do, it 
will come back and bite you.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How execute at least two python files at once when imported?

2019-11-05 Thread Rhodri James

On 05/11/2019 18:33, Spencer Du wrote:

I want to execute at least two python files at once when imported but
I dont know how to do this. Currently I can only import each file one
after another but what i want is each file to be imported at the same
time.


That is a very odd requirement.  Why would you want to do this?  What 
exactly does "at the same time" mean here?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-05 Thread Rhodri James

On 04/11/2019 22:23, Peter J. Holzer wrote:

On 2019-11-04 14:54:23 +, Rhodri James wrote:

On 04/11/2019 14:33, Veek M wrote:

__metaclass__ = whatever; # is python2.x syntax


But not Python3: see PEP 3115


Doesn't "X is python2.x syntax" imply "X is not python3 syntax"?


Not necessarily, the OP might have (and apparently was) assuming that it 
was also Python3 syntax.  Also it gave me an opportunity to point him to 
the appropriate PEP.  That said, we've reached the limits of my 
knowledge here and I'm bowing out of the discussion.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James

On 04/11/2019 14:33, Veek M wrote:


Aha.  You're trying to fix up the metaclass after the fact, which is not
the right way to do it.  If you change the class definitions to:


__metaclass__ = whatever; # is python2.x syntax


But not Python3: see PEP 3115


then you get the prints from MyMeta.__instancecheck__().  The
isinstance() still returns True, though, and I don't know why.  Then
again, your definition of MyMeta is really weird.


weird how..?
(I'm just trying to figure out what's going on with __instancecheck__ -
no further higher purpose :p)

example, when we do: isinstance(x, (A, B, C))
you expect from the docs that
A.__instancecheck__(cls, x) is passed but x = []
also, B and C.__instancecheck__ is not called when I return False

Also if I interchange (Bar, Foo), expecting that Foo.__instancecheck__
will be called, it's completely bypassed


That must be what's responsible for the True result.  Logically the 
problem must be to do with your MyzMeta class then.  I have no idea what.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: __instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

2019-11-04 Thread Rhodri James

On 04/11/2019 11:30, Veek M wrote:

1. Why do I get True whenever i tuple the
isinstance(f, (Bar, Foo))
(and why don't the print's run)


I'm not very familiar with metaclasses, but I can answer the second part 
of your question.




The docs say that you can feed it a tuple and that the results are OR'd


The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for
isinstance(x, A) or isinstance(x, B) or ... (etc.).
-
which implies that the metaclasses are called for each class?


class MyzMeta(type):
 def __instancecheck__(cls, other):
 print('MyzzMeta', other)
 return 0


class MyMeta(MyzMeta, object):
 def __instancecheck__(cls, other):
 print('MyMeta')
 print(cls, other)
 return 0

 
class Foo(list):

 __metaclass__ = MyzMeta
 pass

class Miaow(object):
 pass

class Bar(Foo, Miaow):
 __metaclass__ = MyMeta
 pass



Aha.  You're trying to fix up the metaclass after the fact, which is not 
the right way to do it.  If you change the class definitions to:


class Foo(list, metaclass=MyzMeta):
pass

class Bar(Foo, Miaow, metaclass=MyMeta):
pass

then you get the prints from MyMeta.__instancecheck__().  The 
isinstance() still returns True, though, and I don't know why.  Then 
again, your definition of MyMeta is really weird.





f = Foo()
b = Bar()

print(isinstance(f, (Bar, Foo)))



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: OOP - iterable class: how to delete one of its objects ?

2019-11-04 Thread Rhodri James

On 02/11/2019 06:30, R.Wieser wrote:

Rhodri,


Use weak references.  A WeakSet
(https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is
probably what you want.


Most likely!As a fresh freshling in regard to python I was not even
aware that a "copy object, but do not increment the reference count"
existed.Thank you.

Could cause some interresting "the object has disappeared!" problems when
you're not carefull with it though ... :-)


Yes, it can.  That's why you want to create a finalizer to tidy up.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: OOP - iterable class: how to delete one of its objects ?

2019-11-01 Thread Rhodri James

On 01/11/2019 19:15, R.Wieser wrote:

Hello all,

I've created a class from which I can iterate all its instanciated objects
(using an "instances" list).The problem is that I now cannot seem to
delete an object anymore, AFAIK as a copy of its "self" is still inside the
"instances" list.

Object in question:
- - - - - - - - - - - - - - - -
class TheObject:
 instances = []

 def __init__(self):
 self.instances.append(self)

 def __del__(self):
 print("Deleted!")
- - - - - - - - - - - - - - - -

The question: How can I keep the class iterable, but still have it delete
itself when asked.


Use weak references.  A WeakSet 
(https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is 
probably what you want.


The idea is that the reference to the instance kept by the WeakSet 
doesn't contribute to the reference count.  This won't automatically 
delete the reference from the WeakSet when the instance goes away, 
you'll want to set a finalizer for that, but the documentation covers 
what you want to know fairly clearly.  Trust me, I was doing exactly 
this a week or so ago, and it's pretty straightforward.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Calculations and Variables

2019-11-01 Thread Rhodri James

On 01/11/2019 17:07, MRAB wrote:

On 2019-11-01 12:36, Rhodri James wrote:

On 31/10/2019 20:14, MRAB wrote:

On 2019-10-31 18:46, ferzan saglam wrote:
The code below which I have written should print the result of 43.6 
with the given values I have included at the end of this question, 
but for some odd reason I get the result of 44.44.



bill = (input("Enter the total cost of the meal: \n"))
tip = (input("Enter how much the tip is: \n"))
split = (input("Enter how many people there are: \n"))


Why are there parentheses around the inputs? Have you omitted the 
conversion to numbers?


My guess is the OP is using Python2 rather than Python3.  So my first
piece of advice would be to switch to Python3 now so you don't have to
re-learn oddities like input(), print() and string handling.


The OP says it prints 44.44.

In Python 2, / does integer division, so it would print 44.00.


Well, it's inconsistent one way or the other.  We'll have to wait for 
more information.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Calculations and Variables

2019-11-01 Thread Rhodri James

On 31/10/2019 20:14, MRAB wrote:

On 2019-10-31 18:46, ferzan saglam wrote:
The code below which I have written should print the result of 43.6 
with the given values I have included at the end of this question, but 
for some odd reason I get the result of 44.44.



bill = (input("Enter the total cost of the meal: \n"))
tip = (input("Enter how much the tip is: \n"))
split = (input("Enter how many people there are: \n"))


Why are there parentheses around the inputs? Have you omitted the 
conversion to numbers?


My guess is the OP is using Python2 rather than Python3.  So my first 
piece of advice would be to switch to Python3 now so you don't have to 
re-learn oddities like input(), print() and string handling.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Black

2019-10-21 Thread Rhodri James

On 21/10/2019 15:18, lizhollinshe...@gmail.com wrote:

What do people think about black?


It's the new orange?

Seriously, some context would be good.  I take it from a quick Google 
that black is a Python code formatter that makes some frankly rather 
dubious claims for what it will do to your coding.



I'm asking because one of my personal preferences is to use spaces for clarity:


If your personal preference is not the same as black's, it looks like 
you shouldn't use black.  Just asking the question indicates that you 
are intending to fight with it, and that's bound to be a waste of energy.




1.  right = mystr[ start : ]

  black version right=mystr[start:]

2.  mtime = time.asctime( time.localtime( info.st_mtime ) )

  black version mtime = time.asctime(time.localtime(info.st_mtime))

Is there a reason why PEP8 doesn't like these spaces?


All I can offer is my personal opinion that brackets of all sorts are 
their own spacing, and additional spaces reduce clarity rather than 
increase it.  On the other hand I do put extra spaces around everything 
other than ":" and ".". But like I said, that's my personal preference. 
(Which indicates that I too shouldn't consider using black!)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Instantiating sub-class from super

2019-10-15 Thread Rhodri James

On 14/10/2019 21:55, DL Neil via Python-list wrote:
Is there a technique or pattern for taking a (partially-) populated 
instance of a class, and re-creating it as an instance of one of its 
sub-classes?



In a medically-oriented situation, we have a Person() class, and start 
collecting information within an instance (person = Person(), etc).


During the data-collection process the person's sex may become obvious, 
eg few males have become/been pregnant.


We could stick with Person() and implement specific methods therein, 
rather than separate Man and Woman sub-classes, but...


It seemed better (at the design-level) to have Man( Person ) and Woman( 
Person ) sub-classes to contain the pertinent attributes, source more 
detailed and specific questions, and collect such data; by gender.


Knowing a lot of Trans people as I do, may I gently suggest that this 
solution will find many and varied ways of coming back to bite you?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Curious about library inclusion

2019-10-15 Thread Rhodri James

On 15/10/2019 12:38, Antoon Pardon wrote:

On 11/10/19 15:48, Rhodri James wrote:

On 10/10/2019 12:40, Antoon Pardon wrote:

About including piped iterators:
 
http://code.activestate.com/recipes/580625-collection-pipeline-in-python/


On 10/10/19 13:00, Paul Moore wrote:

As another measure, look at various other libraries on PyPI and ask
yourself why *this* library needs to be in the stdlib more than those
others. The answer to that question would be a good start for an
argument to include the library.


Well my answer would be that this library wouldn't add functionality
but rather would allow IMO for a more readable coding style.

If you split the work to be done over mulitple generators I find it
easier to understand when I read something like:

  for item in some_file | gen1 | gen2 | gen3:
  ...

than when I read something like:

  for item in gen3(gen2(gen1(somefile))):
  ...


With my ever-so-reactionary hat on, I have to say I'm the other way
round.  With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's
going on -- nested function or generator calls, probably the latter
from the name.  With "somefile|gen1|gen2|gen3" I need more context to
kick my expectations out of the more common meaning of "|" as "or".

Yes, context demands that the "|" in your first example can't actually
be an "or".  It still causes a moment of logical disconnect (currently
a long moment) that throws me out of understanding what your code is
doing overall into what this line means in particular.  It's exactly
like coming across an unusual phrasing or iffy grammar in a piece of
writing; you get thrown out of the reading experience by having to
concentrate on the individual words.


But isn't this just a matter of experience? For example does it still
causes a moment of logical disconnect when you see a '+' used for
concatenation? For me the use of '|' is very similar to how it is used
by unix shells. Would the use of an other operator ease this disconnect
for you, maybe '>>', or wouldn't that make a difference?


I *could* get used to any syntax, but why should I?  We have syntax that 
works perfectly well already.  Making me go to the extra effort of 
importing shell-style pipes or C++-style streams into my mental 
construct of Python doesn't really seem necessary.


(As it happens, I don't think the use of "+" for concatenation did cause 
me a moment of disconnection, because it already fitted into my mental 
model.  I do recall that's Perl's choice of "." as the concatenation 
operator *did* cause me to stop and reevaluate quite a lot.  People are 
weird :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t

2019-10-11 Thread Rhodri James

On 11/10/2019 15:13, Prabakaran Hadoop wrote:

Thanks for your reply. Any work around or any other way to achieve from python 
to prestosql .


If there is, it'll be in the GitHub issue I linked to.  I just applied 
Google to your question.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Curious about library inclusion

2019-10-11 Thread Rhodri James

On 10/10/2019 12:40, Antoon Pardon wrote:

About including piped iterators:
 http://code.activestate.com/recipes/580625-collection-pipeline-in-python/

On 10/10/19 13:00, Paul Moore wrote:

As another measure, look at various other libraries on PyPI and ask
yourself why *this* library needs to be in the stdlib more than those
others. The answer to that question would be a good start for an
argument to include the library.


Well my answer would be that this library wouldn't add functionality
but rather would allow IMO for a more readable coding style.

If you split the work to be done over mulitple generators I find it
easier to understand when I read something like:

 for item in some_file | gen1 | gen2 | gen3:
 ...

than when I read something like:

 for item in gen3(gen2(gen1(somefile))):
 ...


With my ever-so-reactionary hat on, I have to say I'm the other way 
round.  With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's 
going on -- nested function or generator calls, probably the latter from 
the name.  With "somefile|gen1|gen2|gen3" I need more context to kick my 
expectations out of the more common meaning of "|" as "or".


Yes, context demands that the "|" in your first example can't actually 
be an "or".  It still causes a moment of logical disconnect (currently a 
long moment) that throws me out of understanding what your code is doing 
overall into what this line means in particular.  It's exactly like 
coming across an unusual phrasing or iffy grammar in a piece of writing; 
you get thrown out of the reading experience by having to concentrate on 
the individual words.


Heh.  Literary criticism as applied to programming.  Only in Python...

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   >