Re: Multiplication

2024-04-01 Thread D'Arcy Cain via Python-list

On 2024-04-01 12:35, Joel Goldstick via Python-list wrote:

On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list

  ^^^


from math import *

a = 2
b = 3
print( a * b )


I guess the operator "*" can be imported from any module... :-)

No import is necessary.


Of course not.  Check the date on the message.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-07 Thread D'Arcy Cain via Python-list

On 2023-11-07 08:40, Grant Edwards via Python-list wrote:

If you, as a web developer, want the user to enter a text-message
capable phone number, then ASK FOR THAT!


And you may as well ask if they even want you to send texts whether they 
can technically receive them or not.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-05 Thread D'Arcy Cain via Python-list

On 2023-11-05 06:48, Jon Ribbens via Python-list wrote:

Sometimes I think that these sorts of stupid, wrong, validation are the
fault of idiot managers. When it's apostrophes though I'm suspicious
that it may be idiot programmers who don't know how to prevent SQL
injection attacks without just saying "ban all apostrophes everywhere".
Or perhaps it's idiot "security consultancies" who make it a tick-box
requirement.


https://xkcd.com/327/


OK, now that I am started, what else?  Oh yah.  Look at your credit
card.  The number has spaces in it.  Why do I have to remove them.  If
you don't like them then you are a computer, just remove them.


Yes, this is also very stupid and annoying. Does nobody who works for
the companies making these sorts of websites ever use their own, or
indeed anyone else's, website?


Gotta wonder for sure.  It could also be the case of programmers 
depending on user input but the users insist on living with the bugs 
and/or working around them.  We made crash reporting dead simple to 
report on and still users didn't bother.  We would get the traceback and 
have to guess what the user was doing.



Honestly I don't understand why every web application platform doesn't
automatically strip all leading and trailing whitespace on user input
by default. It's surely incredibly rare that it's sensible to preserve
it. (I see Django eventually got around to this in version 1.9.)


Yes, I have done that forever.  Never had a complaint about it dropping 
characters.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-05 Thread D'Arcy Cain via Python-list

On 2023-11-05 00:39, Grant Edwards via Python-list wrote:

Definitely. Syntactic e-mail address "validation" is one of the most
useless and widely broken things on the Interwebs.  People who do
anything other than require an '@' (and optionally make you enter the
same @-containing string twice) are deluding themselves.


And don't get me started on phone number validation.  The most annoying 
thing to me, though, is sites that reject names that have an apostrophe 
in them.  I hate being told that my name, that I have been using for 
over seventy years, is invalid.


OK, now that I am started, what else?  Oh yah.  Look at your credit 
card.  The number has spaces in it.  Why do I have to remove them.  If 
you don't like them then you are a computer, just remove them.


When do we stop working for computers and have the computers start 
working for us?


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-02 Thread D'Arcy Cain via Python-list

On 2023-11-02 00:18, AVI GROSS via Python-list wrote:

Yes, it would be nice if there was a syntax for sending a test message sort
of like an ACK that is not delivered to the recipient but merely results in
some status being sent back such as DELIVERABLE or NO SUCH USER or even
MAILBOX FULL.


It used to do that.  The facility was very quickly turned off.


I note earlier iterations of email had addressed like
mach1!mach2!mach3!ihnp4!mach5!mach6!user or even mach1!mach2!user@mach3 and
I remember tools that analyzed what other machines various machines claimed
to have a direct connection to and tried to figure out a connection from
your source to destination, perhaps a shorter one or maybe a less expensive
one. Hence machines like ihnp4 and various universities that were densely
connected to others got lots of traffic. In that scenario, validity had
another meaning.


Yep.  It's called UUCP.  It still exists.  You can even do UUCP over TCP/IP.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-02 Thread D'Arcy Cain via Python-list

On 2023-11-02 02:04, Chris Angelico via Python-list wrote:

On Thu, 2 Nov 2023 at 15:20, AVI GROSS via Python-list
 wrote:


Yes, it would be nice if there was a syntax for sending a test message sort
of like an ACK that is not delivered to the recipient but merely results in
some status being sent back such as DELIVERABLE or NO SUCH USER or even
MAILBOX FULL.



Yes, it would! Spammers would be able to use this syntax to figure out
exactly which addresses actually have real people connected to it. It
would save them so much trouble! Brilliant idea.


Which is exactly why we stopped doing it.  In fact, mailing software may 
even have a control to turn it back on but definitely it doesn't reply 
to the request as delivered.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net

--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking if email is valid

2023-11-01 Thread D'Arcy Cain via Python-list

On 2023-11-01 17:17, Chris Angelico via Python-list wrote:

On Thu, 2 Nov 2023 at 08:09, Grant Edwards via Python-list
 wrote:

Make sure it has an '@' in it.  Possibly require at least one '.'
after the '@'.


No guarantee that there'll be a dot after the at. (Technically there's
no guarantee of an at sign either, but email addresses without at
signs are local-only, so in many contexts, you can assume there needs
to be an at.)


druid!darcy - doesn't work any more but not because it is syntactically 
incorrect.


Remember the good old days when we were able to test if an address 
existed without sending?  That was before the black hats discovered the 
Internet.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net

--
https://mail.python.org/mailman/listinfo/python-list


Re: Information about Dying kernel

2022-08-08 Thread D'Arcy Cain

On 2022-08-07 21:38, Paul Bryan wrote:

Have you tried turning it off and back on again?


Thank you, Roy.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Replacement for Mailman

2021-06-08 Thread D'Arcy Cain
Given that mailman still runs under 2.7 and that's being deprecated, does
anyone have a suggestion for a replacement?

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Please

2021-03-28 Thread D'Arcy Cain

On 2021-03-26 12:42 p.m., Igor Korot wrote:

On top of that - usual stanza applies:

1. OS - Windows, Linux, Mac?
2. OS version?
3. Python version?
4. Are you able to run python interpretor?
5. Socks version you are trying to install?
6. Was install successful?


7. Use a subject that describes the actual issue.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Please don't feed the trolls

2021-03-08 Thread D'Arcy Cain

On 2021-03-06 4:24 p.m., Terry Reedy wrote:
Trolling, among other things, is fishing with a moving line, especially 
with a revolving lure, as from a moving boat.  A troll, among other 
things, is that method or the lure used.


You are confusing "troll" with "trawl"

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot marshal objects

2020-11-27 Thread D'Arcy Cain

On 11/27/20 4:05 PM, Skip Montanaro wrote:

I am getting this error.


I assume you mean the email subject. It doesn't work in 3.8 either:


Yes I do and that's too bad.


but that's not surprising to me. The marshal module is more-or-less
meant to serialize Python byte code. Pickle is more generally used for
object serialization. Why not use it?


Because the marshaling is happening in the guts of xmlrpc.

I may have solved it anyway.  The code I was running was spitting out that 
error but I think it was actually happening in the server that it was 
connecting to.  I just added that same code to the server.  Have to wait 
until Monday to test.  I will update the list if it fixes it.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Cannot marshal objects

2020-11-27 Thread D'Arcy Cain

I am getting this error.  I found this recipe to fix it:

from xmlrpclib import Marshaller
from decimal import Decimal

def dump_decimal(self, value, write):
 write("")
 write(str(value))
 write("\n")

Marshaller.dispatch[Decimal] = dump_decimal

That seems to be for Python 2.  I am running Python 3.5 (I know but I am 
stuck there for the moment).  I tried changing the import to "from 
xmlrpcl.client import Marshaller" which didn't raise an error but the 
problem still persists.  Do I need to do something different for Python 3?


TIA.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com




OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dataframe to postgresql - Saving the dataframe to memory using StringIO

2020-10-22 Thread D'Arcy Cain

On 10/22/20 7:23 AM, Marco Sulla wrote:

I would add that usually I do not recommend saving files on databases. I
usually save the file on the disk and the path and mime on a dedicated
table.


I used to do that because backing up the database became huge.  Now I use 
ZFS snapshots with send/receive so the backup only copies the changed blocks 
so I keep it in the database.  That way the data is available from any 
client with database access without the need to give access to the server.


PostgreSQL can handle it.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: File Name issue

2020-10-18 Thread D'Arcy Cain

On 10/18/20 5:55 AM, Steve wrote:

I am not sure if what I did to repair it but the problem is gone.
A copy/paste/rename was performed on the original code file and now I do not
get the error. No need for "r" or "\"...

WTH? I hate it when that happens.


Could that original hyphen have been a unicode character?

--
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What might cause my sample program to forget that already imported datetime?

2020-10-13 Thread D'Arcy Cain
On 10/12/20 7:20 AM, Chris Angelico wrote:
> This is yet another reason that "from MODULE import *" is a bad idea.
> Instead, just import the module itself, and take whatever you need.

Or just import the objects that you need;

from datetime import datetime, SYMBOL, etc...

I use Decimal a lot.  I would hate to have to write "decimal.Decimal(str)"
for example.

Whichever method you use the most important thing is to be consistent as
much as possible.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com


OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread D'Arcy Cain
On 2020-08-28 08:30, Richard Damon wrote:
> This might be one of the cases where Python 2's lack handling of string
> vs bytes was an advantage.

For English speaking Americans.

> Python2 handled that sort of case quite easily. Python 3 on the other
> hand, will have issue converting the byte message to a string, since
> there isn't a single encoding that you could use for all of it all the
> time. This being 'fussier' does make sure that the program is handling
> all the text 'properly', and would be helpful if some of the patterns
> being checked for contained 'extended' (non-ASCII) characters.
> 
> One possible solution in Python3 is to decode the byte string using an
> encoding that allows all 256 byte values, so it won't raise any encoding
> errors, just give your possibly non-sense characters for non-ASCII text.

Or simply handle the errors in the way that makes sense for your
requirements.  Check the section on error handling here:

https://www.askpython.com/python/string/python-encode-and-decode-functions

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I do this in Python 3 (string.join())?

2020-08-26 Thread D'Arcy Cain
On 2020-08-26 09:22, Chris Green wrote:
> I have the following line in Python 2:-
> 
> msgstr = string.join(popmsg[1], "\n")  # popmsg[1] is a list 
> containing the lines of the message
> 
> ... so I changed it to:-
> 
> s = "\n"
> msgstr = s.join(popmsg[1])  # popmsg[1] is a list containing the 
> lines of the message
> 
> However this still doesn't work because popmsg[1] isn't a list of
> strings, I get the error:-
> 
> TypeError: sequence item 0: expected str instance, bytes found
> 
> So how do I do this?  I can see clumsy ways by a loop working through
> the list in popmsg[1] but surely there must be a way that's as neat
> and elegant as the Python 2 way was?

Well, the simple fix is to set s to b"\n" but that may not solve all of your
problems.  The issue is that popmsg[1] is a list of bytes.  You probably
want a list of strings.  I would look further back and think about getting a
list of strings in the first place.  Without knowing how popmsg was created
we can't tell you how to do that.

Of course, if a bytes object is what you want then the above will work.  You
can also convert to string after the join.

Cheers.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vybenetworks.com VoIP: sip:da...@vybenetworks.com



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exiting a while loop

2020-05-22 Thread D'Arcy Cain
On 2020-05-22 7:49 a.m., John Yeadon via Python-list wrote:
> Am I unreasonable in expecting this code to exit when required?

Yes.

> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
> 
> while True:
>     x = 2 ** (n - 1)
>     sum += x
>     print(n, sum)
>     if sum >= target:
>     print("Target met.")
>     exit
>     n += 1
> 
> print("\n", n, "terms are required.")

I think that you meant "break", not "exit".

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Print formatting

2019-10-18 Thread D'Arcy Cain

On 10/18/19 5:00 PM, D'Arcy Cain wrote:

Finally, if this is in a loop do this.

FMT = '{0[0]:<12s}{0[3]:>12s}'.format
for temp_list in GetLists(): print FMT(temp_list)


Oops.  Time warp.  I meant "print(FMT(temp_list))

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Print formatting

2019-10-18 Thread D'Arcy Cain

On 10/18/19 2:21 PM, Jagga Soorma wrote:

I seem to have found a way to do this with the following:

  print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3])))

Still let me know if there is a better way to format this output :)


I would start with removing the redundant parens.

print('{:<12s}{:>12s}'.format(temp_list[0],temp_list[3]))

But then I would simplify it further.

print('{0[0]:<12s}{0[3]:>12s}'.format(temp_list))

You can do a similar thing with dictionaries.

print('{0[data0]:<12s}{0[data3]:>12s}'.format(temp_dict))

You can even mix and match.

print('{0[0]:<12s}{1[data3]:>12s}'.format(temp_list, temp_dict))

Finally, if this is in a loop do this.

FMT = '{0[0]:<12s}{0[3]:>12s}'.format
for temp_list in GetLists(): print FMT(temp_list)

Cheers.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: FDs will be closed after exception automatically in python2.7?

2019-06-10 Thread D'Arcy Cain
On 2019-06-10 15:46, Alan Bawden wrote:
> D'Arcy Cain  writes:
>> with open("file","w+") as fd:
> 
> That makes the window smaller, but it doesn't actually eliminate it.  Look
> at the generated byte code.  In both cases the call to open() is over and
> the open file is created _before_ the SETUP_WITH instruction is executed.

Am I correct in assuming that the window is there for process interrupts
but not threads?

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: FDs will be closed after exception automatically in python2.7?

2019-06-10 Thread D'Arcy Cain
On 2019-06-10 10:48, Michael Torrie wrote:
> Probably you should be using Python 3, which uses a print() function.
> But even in Python 2.7, the recommended way to do this is like this:
> 
> fd = open("file","w+")
> with fd:

There is still a small window there if there are asynchronous events
happening.  Use this instead:

with open("file","w+") as fd:

*rest of good advice elided.*

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 594 cgi & cgitb removal

2019-05-24 Thread D'Arcy Cain
On 2019-05-22 03:51, Robin Becker wrote:
> In PEP 594 t has been proposed that cgi & cgitb should be removed. I
> suspect I am not the only person in the world that likes using cgi and
> cgitb.

I use both heavily.  Just another data point.  I wasn't going to respond
with a "Me too" except that I saw posts suggesting that few people are
chiming in.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python indentation (3 spaces)

2018-10-15 Thread D'Arcy Cain
On 10/15/18 5:54 PM, Gregory Ewing wrote:
> Cameron Simpson wrote:
>> I can't express how pleasing it is to see the traditional vi-vs-emacs
>> wars supplanted by emacs-vs-emacs :-)
> 
> We're the People's Front of Emacs, not the Emacs People's Front!

I thought we were the People's Emacs Front.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] master/slave debate in Python

2018-09-26 Thread D'Arcy Cain
On 9/26/18 3:58 AM, David Palao wrote:
> Hello,
> My opinion is that the terms "master/slave" describe well some situations.
> They could be seen by some people as offensive (although unfortunately
> sometimes true, even today) when applied to persons. But it is not
> offensive when applied to processes in a computer. They are not living
> entities.

Exactly.  It's like the word "bitch".  It's a perfectly good word when
used correctly but extremely offensive when applied to women.  Maybe we
should change the name of the language because calling someone a snake
is pejorative.  I bet the PC police could find many words in the
language that are offensive when applied to people.

Where is Lenny Bruce when we need him?

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cross platform mutex to prevent script running more than instance?

2018-09-05 Thread D'Arcy Cain
On 09/03/18 09:45, Malcolm Greene wrote:
> Use case: Want to prevent 2+ instances of a script from running ...
> ideally in a cross platform manner. I've been researching this topic and
> am surprised how complicated this capability appears to be and how the
> diverse the solution set is. I've seen solutions ranging from using
> directories, named temporary files,  named sockets/pipes, etc. Is there
> any consensus on best practice here?

Here's my simple method which works in pure Python so I guess that makes it
cross-platform.  Well, as long as it has process IDs anyway.  There's a small
window between reading the file and writing the new one but for most purposes
that should be OK.  If you have to worry about those nano-second situations you
 will need to use one of those more complicated methods.

import os, sys

def ok2run(lockfile):
mypid = os.getpid()

try: pid = int(open(lockfile).read())
except FileNotFoundError: pass
else:
try: os.kill(pid, 0)
except OSError: pass
else: return False

print(mypid, file=open(lockfile, 'w'))
return True

if not ok2run("/tmp/lockfile"): sys.exit(0)

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cross platform mutex to prevent script running more than instance?

2018-09-03 Thread D'Arcy Cain
On 09/03/18 09:45, Malcolm Greene wrote:
> Use case: Want to prevent 2+ instances of a script from running ...
> ideally in a cross platform manner. I've been researching this topic and
> am surprised how complicated this capability appears to be and how the
> diverse the solution set is. I've seen solutions ranging from using
> directories, named temporary files,  named sockets/pipes, etc. Is there
> any consensus on best practice here?

Here's my simple method which works in pure Python so I guess that makes
it cross-platform.  Well, as long as it has process IDs anyway.  There's
a small window between reading the file and writing the new one but for
most purposes that should be OK.  If you have to worry about those
nano-second situations you will need to use one of those more
complicated methods.

import os, sys

def ok2run(lockfile):
mypid = os.getpid()

try: pid = int(open(lockfile).read())
except FileNotFoundError: pass
else:
try: os.kill(pid, 0)
except OSError: pass
else: return False

print(mypid, file=open(lockfile, 'w'))
return True

if not ok2run("/tmp/lockfile"): sys.exit(0)

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unexpected behaviour with DeprecationWarning, Python 3.7 and escape codes

2018-08-23 Thread D'Arcy Cain
On 2018-08-23 06:08 AM, Peter via Python-list wrote:
> I understand that Python 3.7 now issues DeprecationWarning for code
> entered in the interactive shell and also for single-module programs. I
> see this behaviour with:
> 
> C:\wrk> python
> python 3.7.0 (v3.7.0:...
 import imp
> __main__:1: DeprecationWarning: the imp module is deprecated...

Valid warning.

> But if I use an unknown escape code, then the expected warning doesn't
> issue:
> 
 print('Hello \world')
> Hello \world
> 
> But if I explicitly turn on default warnings, then I do get it:
> 
> C:\wrk> python -Wd
 print('Hello \world')
> :1: DeprecationWarning: invalid escape sequence \w
> Hello \world

I don't know why it issues DeprecationWarning but this is not the same
as the previous line.  In this case \w is invalid and, as far as I know,
 has always been invalid.  I think it should be a different warning but
I do understand why it is in a different code path in Python.

It doesn't issue any warning in 2.7 by the way.  It still prints the
same thing so it is still an invalid escape sequence.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New books by O’Reilly

2018-08-19 Thread D'Arcy Cain
On 2018-08-18 09:40 PM, Larry Martell wrote:
> https://imgur.com/gallery/tW1lwEl

I think I have met the people who studied those books.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint false positives

2018-08-16 Thread D'Arcy Cain
On 2018-08-14 04:58 AM, Frank Millman wrote:
> "D'Arcy Cain"  wrote in message
>> I am also getting a funny smell from your description.  Are you sure
>> that you need to redefine the methods?  Perhaps you just need to define
>> some class variables and use one method.  You can also define your own
>> method and call the classA method inside it for common functionality.
> 
> As an example, I have a master class defining a unit of data (i.e. the
> value of a column) retrieved from a database. I have separate
> sub-classes for each data type - text, integer, date, etc. To ensure
> that a value is valid before storing it as an instance attribute, I call
> a method called 'check_value'. The details of check_value vary according
> to the data type, but that is transparent to the piece of code that
> calls check_value().

class classA:
  DATATYPE = None # Or default type

  def check_value(self, v)
if not isinstance(v, self.DATATYPE):
  raise RuntimeError("Invalid data type for '%s'" % v)

class classB(classA):
  DATATYPE = int

Very simplistic and untested but does that give you any ideas?
Hopefully your email client doesn't mess up the formatting.  You can
fill out check_value to do more than simply check the the type matches
and you can also do further checks based on the type.  Also, you can
have more than one sub-class doing the same check without having to cut
and paste code from another class.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint false positives

2018-08-14 Thread D'Arcy Cain
On 2018-08-14 03:38 AM, Frank Millman wrote:
> Hi all
> 
> Pylint is flagging a lot of lines as errors that I would consider to be
> acceptable.
> 
> I have an abstract class ClassA with a number of concrete sub-classes.
> ClassA has a method which invokes 'self.method_b()' which is defined
> separately on each sub-class. Pylint complains that "Instance of
> 'ClassA' has no  'method_b' member".
> 
> First question - as a matter of style, is Pylint correct? If so, I could
> define 'method_b' in ClassA and raise NotImplementedError. Is this
> considered more pythonic? The downside is that I have quite a few of
> them, so it would add some clutter.

I would add the method.  It's one line:

  def method_b(self): raise NotImplementedError

When you say that you have quite a lot of them, what is "them"?  Many
master classes or many methods in the class?  If the latter, one line
each isn't so bad.  If the former I wonder if a master, master class is
called for.

I am also getting a funny smell from your description.  Are you sure
that you need to redefine the methods?  Perhaps you just need to define
some class variables and use one method.  You can also define your own
method and call the classA method inside it for common functionality.

Just my 2¢ based on no information about your actual application.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 can find cairo libs but not Python 3.6

2018-07-17 Thread D'Arcy Cain
On 2018-07-17 10:22 AM, Peter Otten wrote:
> D'Arcy Cain wrote:
> 
>> I just realized that my subject was backwards.  It's 2.7 that can find
>> the libs and 3.6 than cannot.  Just in case that makes a difference.
> 
> Not for me, I believed the pasted shell session rather then the subject 
> line. 

Good plan.  :-)

So, I rebuilt and reinstalled a bunch of packages and now it works.  I
don't even know which packages made the difference.  I had already
reinstalled all of the obvious ones.

Still not working for 3.7 on my HEAD system.  Need to work on that.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 can find cairo libs but not Python 3.6

2018-07-16 Thread D'Arcy Cain
I just realized that my subject was backwards.  It's 2.7 that can find
the libs and 3.6 than cannot.  Just in case that makes a difference.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Kindness

2018-07-13 Thread D'Arcy Cain
On 2018-07-13 05:45 PM, Marko Rauhamaa wrote:
> Yeah, that is cult behavior. Here's a few boxes to tick on:
> 
>http://www.csj.org/infoserv_cult101/checklis.htm>

I couldn't find a single item that applies to this group.  What's your
point?


-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread D'Arcy Cain
On 2018-07-13 10:28 AM, Peter Otten wrote:
> As far as I can see -- without having access to a netbsd machine -- this 

Would it help if I gave you a login on one?

Interestingly, I don't have this issue on my NetBSD machine built from
HEAD.  Maybe it is something that was fixed but not pulled up to 7.

More weirdness - I do have the issue on my HEAD system but only with
3.7.  I can give you an account on that server as well.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread D'Arcy Cain
On 2018-07-13 08:05 AM, Peter Otten wrote:
> D'Arcy Cain wrote:
>> Nope.  Both are 64 bit.
> 
> Just to be 100% sure, what does
> 
> $ python2.7 -c 'import struct; print(struct.calcsize("l"))'
> 
> $ python3.6 -c 'import struct; print(struct.calcsize("l"))'
> 
> print? 

$ python2.7 -c 'import struct; print(struct.calcsize("l"))'
8
$ python3.6 -c 'import struct; print(struct.calcsize("l"))'
8

> If both print 8, what is sys.platform? (This is just that I can look at the 
> right branch of the ctypes.util source for differences)?

$ python2.7 -c 'import sys; print(sys.platform)'
netbsd7
$ python3.6 -c 'import sys; print(sys.platform)'
netbsd7

Thanks for checking this.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread D'Arcy Cain
On 2018-07-12 07:41 PM, Peter Otten wrote:
> Wild guess: one Python is 64 bit and the other is 32 bit, and you have only 
> one version of the library installed.

Nope.  Both are 64 bit.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread D'Arcy Cain
On 2018-07-12 04:17 PM, Terry Reedy wrote:
> On 7/12/2018 3:52 PM, D'Arcy Cain wrote:
>> $ python2.7 -c "import ctypes.util;
>> print(ctypes.util.find_library('cairo'))"
>> libcairo.so.2
>> $ python3.6 -c "import ctypes.util;
>> print(ctypes.util.find_library('cairo'))"
>> None
>>
>> I have the 3.6 version of py-cairo installed.  Any thoughts?
>>
>> NetBSD 7.1.2
> 
> what is sys.path?  Where in py-cairo installed?

For 3.6 it includes '/usr/pkg/lib/python3.6/site-packages' and for 2.7
it includes '/usr/pkg/lib/python2.7/site-packages'.  The py-cairo files
are in the 3.6 site-packages.  There are no Cairo files in the 2.7
Python directory.

I'm not sure why that matters though.  It's the system libraries that it
can't find unless having py-cairo installed is somehow blocking the
search for the libraries.

Of course, my actual use depends on a cairo package.  In fact, the
failure that led me to the above issue happens when I load cairocffi.

$ python3.6 -c "import cairocffi"
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/pkg/lib/python3.6/site-packages/cairocffi/__init__.py",
line 41, in 
cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/usr/pkg/lib/python3.6/site-packages/cairocffi/__init__.py",
line 38, in dlopen
raise OSError("dlopen() failed to load a library: %s" % ' /
'.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.6 can find cairo libs but not Python 2.7

2018-07-12 Thread D'Arcy Cain
$ python2.7 -c "import ctypes.util;
print(ctypes.util.find_library('cairo'))"
libcairo.so.2
$ python3.6 -c "import ctypes.util;
print(ctypes.util.find_library('cairo'))"
None

I have the 3.6 version of py-cairo installed.  Any thoughts?

NetBSD 7.1.2

Cheers.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Feeding the trolls

2018-06-20 Thread D'Arcy Cain
On 2018-06-20 08:10 AM, Tim Golden wrote:
> [... snip discussions about Bart's language ...]
> 
> Wearing my moderator hat
> 
> Can we take the "Bart's language vs Python Show" to some other forum,
> please? We've already gone over this ground again and again and it isn't
> helping the signal-to-noise ratio here on the Python list /
> comp.lang.python

Thank you.  Many of us have blocked rick and bart years ago.  If you are
just going to feed the trolls we have to see their nonsense anyway.
Just email them privately if you really feel the need to vent.

One of these days I will have to figure out how to block replies to the
trolls as well.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Proper email etiquette

2018-05-20 Thread D'Arcy Cain
On 2018-05-18 06:24 PM, José María Mateos wrote:
> And another one I learned recently on a similar conversation on another 
> mailing list (that of the e-mail client I'm using right now): it is very 
> useful for searches. Every e-mail contains just the right amount of text 
> necessary to be properly read, as opposed to a more or less complete 
> copy of the current thread.
Another good idea is to change the subject when the topic changes.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread D'Arcy Cain
On 2018-05-10 07:28 AM, Skip Montanaro wrote:
> https://www.python.org/dev/peps/pep-3127/#removal-of-old-octal-syntax

Funny stuff:

Python could either:

1. silently do the wrong thing...
2. immediately disabuse him...
3. let him continue to think...

Some people passionately believe that (c) is the correct answer

I guess  uses letters in the writer's browser.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Leading 0's syntax error in datetime.date module (Python 3.6)

2018-05-10 Thread D'Arcy Cain
On 2018-05-10 07:39 AM, AK wrote:
> Try (should work from both PY2 and PY3):
> 
> d0 = date(2018,0o2,0o1)

Bad advice.  Those numbers are decimal, not octal,  You should use
"date(2018,2,1)" here.  Works in PY2, PY3 and for my birthday, Sept 4.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


PyGreSQL 5.0.5

2018-05-01 Thread D'Arcy Cain
We are pleased to announce the release of PyGreSQL 5.0.5.  The main
changes in this release are;

- This version officially supports the new PostgreSQL 10.
- The memory for the string with the number of rows affected by
  a classic pg module query() was already freed (bug report and
  fix by Peifeng Qiu).

It is available at: http://pygresql.org/files/PyGreSQL-5.0.5.tar.gz.

If you are running NetBSD, look in the packages directory under
databases.  There is also a package in the FreeBSD ports collection.

Please refer to `readme.txt `_
for general information.

This version has been built and unit tested on:
 - NetBSD
 - FreeBSD
 - openSUSE
 - Ubuntu
 - Windows 7 and 10 with both MinGW and Visual Studio
 - PostgreSQL 9.0 to 9.6 and 10 (32 and 64bit)
 - Python 2.6, 2.7 and 3.3 to 3.6 (32 and 64bit)

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org IM:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Using object as a class

2018-03-26 Thread D'Arcy Cain
It's called a super class but it doesn't quite work like a normal class.

>>> OBJ = object()
>>> OBJ.x = 3
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'object' object has no attribute 'x'

I can fix this by creating a NULL class.

>>> class NullObject(object): pass
...
>>> OBJ = NullObject()
>>> OBJ.x = 3
>>> OBJ.x
3
>>>

Is this behaviour (object not quite like a class) documented anywhere?
Does anyone know the rationale for this if any?

In case anyone wants to know why I am doing this, sometimes I simply
want an object to hold values that I can pass around.  I don't need
methods and I don't always know what variables I am going to need.

And yes, I know that dict is the usual way to do this.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String formatting

2018-03-25 Thread D'Arcy Cain
Was "Accessing parent objects."

On 03/25/2018 12:26 PM, Jugurtha Hadjar wrote:
>> print("I am {0.__class__.__name__} foo".format(self))
> 
> I prefer keyword arguments, but if I used it that way I'd do:
> 
> print("I am {0} foo".format(self.__class__.__name__))

These are contrived examples.  In real code I might do something like this:

fmt_class_name = "I am {0.__class__.__name__} foo".format
...
for x class_list:
  print(fmt_class_name(x))

IOW when I define the format string I want it clear what it is supposed
to print.  The actual use of the format could happen in a completely
different place.

> self.__class__.__name__ looks better (+ makes more sense to me) than
> 0.__class__.__name__.
> 
>> print(f"I am {self.__class__.__name__} foo")
> 
> f-strings are only available in python 3.6 as far as I know and.

I'm not even sure if I am a big fan of f-strings but I do like to run
current versions of Python so they are there for me.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing parent objects

2018-03-25 Thread D'Arcy Cain
On 03/24/2018 06:54 PM, Steven D'Aprano wrote:
>> On Saturday, March 24, 2018 at 1:20:24 PM UTC-5, D'Arcy Cain wrote:
>>> I tried various forms of super() but that didn't seem to work.
> 
> Define "doesn't see to work".

It accesses the parent class.  I want to access the parent object.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing parent objects

2018-03-25 Thread D'Arcy Cain
On 03/25/2018 05:10 AM, Jugurtha Hadjar wrote:
>     print("I am {self.__class__.__name__} foo".format(self=self))

Unrelated to the original issue but why not one of the following?

print("I am {0.__class__.__name__} foo".format(self))
print(f"I am {self.__class__.__name__} foo")

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing parent objects

2018-03-25 Thread D'Arcy Cain
On 03/25/2018 04:37 AM, Jugurtha Hadjar wrote:
> On 03/24/2018 07:14 PM, D'Arcy Cain wrote:
>> class C1(dict):
>>    class C2(object):
>>  def f(self):
>>    return X['field']
>>
>> O1 = C1()
>> O1['field'] = 1
>> O2 = O1.C2()
>> print(O2.f())
> 
> I prefer to *feed* the child to the parent or vice versa. Simplifies
> things like testing.

That was my original solution but it seems clumsy.

O2 = O1.C2(O1)

IOW passing the parent object to the child class.  It just seems like
there should be some way to access the parent object in C2.

> Something like this:
> 
> class C1(object):
...
> class C2(object):
>     def __init__(self, parent=None):
> self.parent = parent

Perhaps your email client is collapsing leading spaces but that isn't
what I wrote.  The C2 class is supposed to be a member of C1.  That's
why I called it as O1.C2() instead of just C2().  I was hoping that by
doing so that the data in O1 would somehow be available without having
to explicitly pass it as an argument.

However, I would have made the parameter required.  I don't see the
point of calling another method to add it in later.  Of course, if I do
that there's no point in making C2 part of C1.  What you wrote would be
just fine and obvious.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Accessing parent objects

2018-03-24 Thread D'Arcy Cain
I'm not even sure how to describe what I am trying to do which perhaps
indicates that what I am trying to do is the wrong solution to my
problem in the first place but let me give it a shot.  Look at the
following code.

class C1(dict):
  class C2(object):
def f(self):
  return X['field']

O1 = C1()
O1['field'] = 1
O2 = O1.C2()
print(O2.f())

I am trying to figure out what "X" should be.  I know how to access the
parent class but in this case I am trying to access the parent object.
I tried various forms of super() but that didn't seem to work.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What F strings should have been

2018-02-15 Thread D'Arcy Cain
On 02/15/18 02:56, Peter Otten wrote:
>> class FSTR(str):
>>   def __call__(self, *args):
>> return self.format(*args)
>>
>> And here is how it could be used.
>>
>> s = FSTR("ABC {1} {0} {2[x]}")
> 
> This can be simplified to
> 
> s = "ABC {1} {0} {2[x]}".format

Hmm.  Hadn't thought of that.

>> print(s(1, 2, dict(x=3)))
>>
>> Too bad that it is too late to assign f'' to that function.
> 
> I must be missing something. How would you simplify or improve the 
> readability of the above with your version of f"..."? 

s = f"ABC {1} {0} {2[x]}"

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


What F strings should have been

2018-02-14 Thread D'Arcy Cain
A recent post by Terry Jan Reedy got me thinking about formatting.  I
like the new(ish) format method for strings and I see some value in F
strings but it only works well with locals.  Anything more starts
getting messier than format() and it is supposed to be cleaner.  Also, I
find that I tend to re-use format strings and wish there was a
formatting string option.  Here is what I came up with.

class FSTR(str):
  def __call__(self, *args):
return self.format(*args)

And here is how it could be used.

s = FSTR("ABC {1} {0} {2[x]}")
...
print(s(1, 2, dict(x=3)))

Too bad that it is too late to assign f'' to that function.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is more Pythonic: subclass or adding functionality to base class?

2018-02-11 Thread D'Arcy Cain
On 02/11/18 06:30, Victor Porton wrote:
> What is more pythonic?
> 
> 1. Create its subclass PredicateParserWithError and add the additional field 
> on_error to this class.
> 
> 2. Add on_error field to the base class, setting it to None by default, if 
> the class's user does not need this field.

Personally I would go with #1.  It just seems cleaner.  Not sure what
the Python gods would do.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Where has the practice of sending screen shots as source code come from?

2018-01-29 Thread D'Arcy Cain
On 01/29/2018 01:43 PM, John Ladasky wrote:
> On Sunday, January 28, 2018 at 7:07:11 AM UTC-8, Steven D'Aprano wrote:
>>
>> (The day a programmer posts a WAV file of themselves reading their code 
>> out aloud, is the day I turn my modem off and leave the internet forever.)
> 
> What's a... modem?

That would be a MOdulator-DEModulator device.  It's what you plug your
DSL phone line or cable coax into.  At one time it simply plugged into a
regular phone line but there aren't many of those around any more.

You may be connecting directly to a provider's Wifi AP but 90% of the
people still use modems.  And even if you connect directly to an AP that
device still needs to talk to a modem so you are still connected to a
modem at some point.

Modems are still around.  They have simply evolved from the 300 baud
acoustic coupler.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dunder variables

2018-01-09 Thread D'Arcy Cain
On 01/09/2018 07:30 AM, Steven D'Aprano wrote:
> If you have a class with only data, and you access the attributes via the 
> instance's __dict__, why not use an ordinary dict?

Or even subclass dict.

class MyClass(dict):
  VAR = 5

m = MyClass()
m['newvar'] = "Something"

I do this and wrap things like __getitem__, __call__, __del__, etc. with
my own methods.  For example...

def __getitem__(self, key):
  # return self.attribute if given "_attribute_" mapping
  if key[0] == '_' and key[-1] == '_' and key[1] != '_':
k = key[1:-1]
if hasattr(self, k): return getattr(self, k)
  return dict.__getitem__(self, key)

So, in the above example...

>>>print("newvar = '%(newvar)s', VAR = '%(_VAR_)s'" % m
newvar = 'Something', VAR = '5'

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Goto

2017-12-29 Thread D'Arcy Cain
On 12/29/2017 02:25 PM, Chris Angelico wrote:
>> PHP also added goto to a later version.
> 
> Ahh, great choice of example. "It's okay - PHP does it."

I thought that that was a reason to not do it.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python homework

2017-12-06 Thread D'Arcy Cain

On 12/05/2017 07:33 PM, nick.martinez2--- via Python-list wrote:

I have a question on my homework. My homework is to write a program in which 
the computer simulates the rolling of a die 50
times and then prints
(i). the most frequent side of the die
(ii). the average die value of all rolls.
I wrote the program so it says the most frequent number out of all the rolls for example 
(12,4,6,14,10,4) and will print out "14" instead of 4 like I need.


How did you come up with 4?  I come up with 3.36 with those numbers.


This is what I have so far:
import random

def rollDie(number):
 rolls = [0] * 6


For a small efficiency use "[0] * 7".  See below for reason.


 for i in range(0, number):
 roll=int(random.randint(1,6))
 rolls[roll - 1] += 1


Use "rolls[roll] += 1" here.  You save one arithmetic instruction each 
time through the loop.  Fifty times isn't much saving but imagine fifty 
million.



 return rolls


return rolls[1:].  No matter how many rolls you only need to do the 
slice once.  However, you really need a lot of iterations before it 
really affects the total run time.


You need one more thing though.  Create a new variable called "total" 
and set it to 0.0.  Add "total += roll" to your loop.  your return 
statement is now "return rolls[1:], total/number".




if __name__ == "__main__":
 result = rollDie(50)


Now "result, average = ..."


 print (result)
 print(max(result))


This is why you get 14.  The maximum number of rolls for any one side is 
14 for side 4.  Is that where you got "4"?


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-06 Thread D'Arcy Cain

On 10/05/2017 05:42 PM, Fetchinson . via Python-list wrote:

On 10/5/17, Chris Angelico  wrote:

On Fri, Oct 6, 2017 at 8:06 AM, Fetchinson . via Python-list
 wrote:

 import mystuff
 mystuff.some_more_expensive_stuff( x )
 del mystuff
 del x

You're not actually deleting anything. When you say "del x", all
you're doing is removing the *name* x. Especially, deleting an
imported module basically does nothing; it's a complete waste of time.
Modules are kept in their own special cache.


Meaning that if mystuff has some leaky stuff in it, there is no way
for me to recover?


Even if deleting mystuff actually removed it the objects that it created 
would still exist.  Import mystuff once at the top of your script. 
Importing over and over just costs CPU and could, in fact, be 
contributing to your leak.


Also, I am pretty sure that the two del statements don't do anything 
that ending the loop doesn't already do anyway.  Your best option is to 
find the leak.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Beginners and experts (Batchelder blog post)

2017-09-29 Thread D'Arcy Cain

On 09/29/2017 03:15 AM, Steve D'Aprano wrote:

"Carefully-designed experiments" -- yeah, that is so totally how the coders I've
worked with operate *wink*

I think that's an awfully optimistic description of how the average programmer
works :-)


Better not hire average programmers then.  I do "Carefully-designed 
experiments" to find non-obvious bugs so I guess I am not average.  I 
get the impression that many people here are above average too.


Personally I think you are being pessimistic about "average" 
programmers.  Perhaps you just know the sloppy kind.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Even Older Man Yells At Whippersnappers

2017-09-19 Thread D'Arcy Cain

On 09/19/2017 03:07 AM, Steven D'Aprano wrote:

How relevant is the "people use calculators to do arithmetic" argument
today?  Okay, so I'm old and cynical, but I know [young] people who
don't (can't?) calculate a gratuity without an app or a web page.


Which is a form of calculator. People still learn to use calculators at
school, they still use them at work. They use Excel, which is prone to


Wow.  I still remember decrying the use of calculators in school.  It 
seemed like the loss of actual math understanding.  When I was young 
(and not running from dinosaurs) we learned the addition and 
multiplication tables by heart (and received a few sore knuckles while 
we struggled) and then learned to do math by paper and pencil.  When it 
was time for a mechanical aid we got a slide rule.  I truly believe that 
doing so gave me the best understanding of math that I could get.  Now, 
of course, I use calculators and computers but I still understand the 
theory behind what I am doing.


To this day while writing code I will actually put pen to paper in order 
to check that my program is doing the correct calculations.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: python list name in subject

2017-08-22 Thread D'Arcy Cain

On 08/22/2017 10:14 AM, Grant Edwards wrote:

Please don't. It wastes space which is better used on the subject.  If
you want the mailing list prepended, then configure procmail (or
whatever) to do it for you.


Better yet, put it in its own folder.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic python understanding

2017-07-27 Thread D'Arcy Cain

On 07/27/2017 09:59 AM, Grant Edwards wrote:

If they have only ever used a single language, that may be a warning
sign.


Or if they list every language that they have ever smelled.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic python understanding

2017-07-27 Thread D'Arcy Cain

On 07/27/2017 09:34 AM, Rhodri James wrote:

On 27/07/17 13:24, D'Arcy Cain wrote:
Lesson: Look for programmers, not Python (or Perl or C or C++ or Java 
or...) programmers.


This isn't universally true, I'm afraid.  A friend of mine who is a very 
good C/assembler programmer simply cannot get his head around Python's 
mindset.  If you want bullet-proof Flash programming code, he's your 
man.  If you want Python-based unit tests for it, don't ask him.


As I said, look for programmers, not  programmers.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic python understanding

2017-07-27 Thread D'Arcy Cain

On 07/27/2017 02:31 AM, Gregory Ewing wrote:

I'd like to add that what you should really be looking for is
not a Python programmer as such, but simply a good, competent
programmer.

Any decent programmer will be able to quickly pick up what
they need to know about Python on the job. If they can't,
then they're not good enough, and you shouldn't hire them.


I'll second that.  I once had to build a team of Python developers for a 
major project.  The pool of actual Python programmers was small so we 
just advertised for programmers.  In the interviews we used a test that 
used C to determine their problem solving skills.  We also looked for 
new grads so that they didn't have to un-learn a bunch of stuff.  We 
wound up with an amazing team that managed to build the project in 
record time.


Lesson: Look for programmers, not Python (or Perl or C or C++ or Java 
or...) programmers.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: A Good Tutorial on Python Decorators

2017-06-28 Thread D'Arcy Cain

On 06/28/17 17:59, Steve D'Aprano wrote:

On Thu, 29 Jun 2017 01:56 am, Peter Pearson wrote:


(Blushing) Thanks.  Life is getting difficult for us JavaScript paranoids.


Its not paranoia if they're really out to get you.

https://www.cnet.com/news/javascript-opens-doors-to-browser-based-attacks/

https://www.proofpoint.com/us/corporate-blog/post/adgholas-malvertising-campaign

http://www.pcworld.com/article/2604480/malicious-advertising-hits-amazon-youtube-and-yahoo-cisco-says.html


Anyone else find it sad that all of these sites us Javascript?

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Checking for an exception

2017-06-25 Thread D'Arcy Cain

On 06/25/17 12:10, Steve D'Aprano wrote:

py> isinstance(KeyboardInterrupt(), Exception)
False
py> isinstance(ValueError, Exception)
False


That's because KeyboardInterrupt is not a subclass of Exception.  If you 
want to catch that as well you need to check against BaseException.


https://docs.python.org/3.6/library/exceptions.html#exception-hierarchy

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-18 Thread D'Arcy Cain

On 2017-03-18 11:18 AM, Mikhail V wrote:

On 18 March 2017 at 05:02, Ben Finney  wrote:

Feel free to start your own discussion forum for your new programming
language that forbids spaces for indentation. That language will never
be Python, so please don't ask us to discuss it here.


Slight note of aggression in you words makes me think you
are a ... spacist?


As are just about everyone on this list except you.


So you are the opinion it would be more productive to
invent a new language instead of just cleaning up spaces?


No, he thinks it would be more productive for us if you went away and 
invented your own language.



Interesting idea indeed, but that is ok.
I think it still helps to realize that in the future this will
become more noticable problem than it seems now, so
at least making up a strategy for converting to tabs
could be way more productive on a long term basis,
than replacing tabs and spaces back and forth, like pouring
water from one glass to another.


At one point I couldn't decide if you were just a troll or not.  Thanks 
for clearing it up.


*plonk*

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-18 Thread D'Arcy Cain

On 2017-03-18 09:46 AM, Mikhail V wrote:

Not to judge, but usually such opinions come from determined


And he probably wasn't being facetious.

Butyouareprobablyright.Spaceisawasteofspace.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-18 Thread D'Arcy Cain

On 2017-03-17 10:09 PM, Joel Goldstick wrote:

This is not a useful conversation.  It has been had over and over in
the past.  Some people like tabs, some like spaces.  In python you can
use either, but you must stick to one or the other


s/must/should/

Technically you can use both if you are careful but life is so much 
easier if you pick one or the other.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dynamically replacing an objects __class__; is it safe?

2017-03-16 Thread D'Arcy Cain

On 2017-03-16 09:45 AM, Robin Becker wrote:

On 15/03/2017 13:53, Steve D'Aprano wrote:

You probably can't make a whale fly just by changing the class to
bird. It
will need wings, and feathers, at the very least.


the whale in the Hitchhiker's Guide found itself flying without feathers
or wings


Falling is not the same as flying unless you accidentally miss the ground.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: str.title() fails with words containing apostrophes

2017-03-07 Thread D'Arcy Cain

On 2017-03-06 06:33 PM, Steve D'Aprano wrote:

If you read "title case" as *literally* as being only for titles (of books,


I believe there is only one conclusion to be drawn from this thread - 
There is still a place for human proofreaders.  I'm taking that as good 
news.


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: str.title() fails with words containing apostrophes

2017-03-06 Thread D'Arcy Cain

On 2017-03-06 05:04 AM, Peter Otten wrote:

Won't Steve D'aprano And D'arcy Cain Be Happy Now :)


Perhaps one could limit the conversion to go from lower to upper only, as
names tend be in the desired case in the original text.


That would help with acronyms as well.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Who still supports recent Python on shared hosting

2017-03-05 Thread D'Arcy Cain

On 2017-03-05 09:39 PM, John Nagle wrote:

I'm looking for shared hosting that supports
at least Python 3.4.


http://www.VybeNetworks.com/

We have Python 2.7 and 3.6 installed.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: str.title() fails with words containing apostrophes

2017-03-05 Thread D'Arcy Cain

On 2017-03-05 03:40 PM, Terry Reedy wrote:

import re

def title(string):
return re.sub(r"\b'\w", lambda m: m.group().lower(), string.title())


Nice.  It lowercases a word char that follows an "'" that follows a word
without an intervening non-word char. It passes this test:
print(title("'time' isn't 'timeless'!"))
'Time' Isn't 'Timeless'!

It guess the reason not to bake this exception into str.title is that it
is language specific and could even be wrong if someone used "'" to
separate words (perhaps in a different alphabet).


Or, it doesn't handle exceptions.

print title("My name is D'Arcy")

Oops.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.6.1rc1 is now available

2017-03-05 Thread D'Arcy Cain

On 2017-03-05 07:01 AM, Ned Deily wrote:

On behalf of the Python development community and the Python 3.6 release
team, I would like to announce the availability of Python 3.6.1rc1.
3.6.1rc1 is the first release candidate for Python 3.6.1, the first
maintenance release of Python 3.6.  3.6.0 was released on 2017-12-22


from __future__ import 3.6.0

Did Guido finally get that time machine working?

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.6.1rc1 is now available

2017-03-05 Thread D'Arcy Cain

On 2017-03-05 07:01 AM, Ned Deily wrote:

On behalf of the Python development community and the Python 3.6 release
team, I would like to announce the availability of Python 3.6.1rc1.
3.6.1rc1 is the first release candidate for Python 3.6.1, the first
maintenance release of Python 3.6.  3.6.0 was released on 2017-12-22


from __future__ import 3.6.0

Did Guido finally get that time machine working?

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.6.1rc1 is now available

2017-03-05 Thread D'Arcy Cain

On 2017-03-05 07:01 AM, Ned Deily wrote:

On behalf of the Python development community and the Python 3.6 release
team, I would like to announce the availability of Python 3.6.1rc1.
3.6.1rc1 is the first release candidate for Python 3.6.1, the first
maintenance release of Python 3.6.  3.6.0 was released on 2017-12-22


from __future__ import 3.6.0

Did Guido finally get that time machine working?

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Need reviews for my book on introductory python

2017-01-27 Thread D'Arcy Cain

On 2017-01-27 11:01 PM, Terry Reedy wrote:

This is a run-on sentence, which is to say, two sentences.  Change
'suntax,' to 'syntax.' and 'in' to ' In'.

   ^^
I can't believe how many typos and grammar errors there are in this 
thread by people correcting typos and grammar.


And please don't say "suntax".  The government hasn't thought of that 
one yet.  Don't give them ideas.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Need reviews for my book on introductory python

2017-01-27 Thread D'Arcy Cain

On 2017-01-27 03:17 PM, bob gailer wrote:

sudo apt-get won't work on Windows. Tell the reader that this is how to
do it in Unix, and show the Windows equivalent.


Actually it doesn't work on Unix either.  It only works on Linux.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extended ASCII [solved]

2017-01-13 Thread D'Arcy Cain

On 2017-01-13 05:44 PM, Grant Edwards wrote:

On 2017-01-13, D'Arcy Cain <da...@vybenetworks.com> wrote:


Here is the failing code:

with open(sys.argv[1], encoding="latin-1") as fp:
   for ln in fp:
 print(ln)

Traceback (most recent call last):
   File "./load_iff", line 11, in 
 print(ln)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in
position 132: ordinal not in range(128)

I don't understand why the error says "ascii" when I told it to use
"latin-1".


That can't be the failing code, since it's failing at line 11, and
that's only 5 lines. It helps if we can tell which line generated the
error.  ;)


I didn't think that the part leading up to it was relevant.  Here it is.

#! /usr/bin/python

import sys, os

if len(sys.argv) < 2:
print("No file named", file=sys.stderr)
sys.exit(1)


I'm _guessing_ that line 11 is the print(), and it's barfing because


Of course.  That's why the error is listed right below it.


stdout is using ascii encoding, and there's no way to encode that
character in ascii so that it can be printed to an ascii output
stream.


Thank you!  I know all about that but for some reason I did not have 
PYTHONIOENCODING=utf8 set on that particular machine.  I have it set on 
every other machine I work on an never thought to check.  My Unicode 
universe is all right again.


Cheers.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Extended ASCII

2017-01-13 Thread D'Arcy Cain
I thought I was done with this crap once I moved to 3.x but some 
Winblows machines are still sending what some circles call "Extended 
ASCII".  I have a file that I am trying to read and it is barfing on 
some characters.  For example:


  due to the Qu\xe9bec government

Obviously should be "due to the Québec government".  I can't figure out 
what that encoding is or if it is anything that can even be understood 
outside of M$.  I have tried ascii, cp437, cp858, cp1140, cp1250, 
latin-1, utf8 and others.  None of them recognize that character.  Can 
someone tell me what encoding includes that character please.


Here is the failing code:

with open(sys.argv[1], encoding="latin-1") as fp:
  for ln in fp:
print(ln)

Traceback (most recent call last):
  File "./load_iff", line 11, in 
print(ln)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in 
position 132: ordinal not in range(128)


I don't understand why the error says "ascii" when I told it to use 
"latin-1".


--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 07:07 PM, Deborah Swanson wrote:
> D'Arcy Cain wrote, on Wednesday, January 04, 2017 5:03 AM
>> In all the messages in this thread I still don't understand what this
>> "teensy advantage" is supposed to be.  Do you want to be able
>> to do this:
>>
>>make_web_link(http://...)
>>
>> instead of:
>>
>>make_web_link("http://...;)

[...]

> Is make_web_link("http://...;) valid python code? That's exactly the

It's just a made up name.  My point was that the first was syntactically 
incorrect and the second, while not a real method, was at least parseable.

I think I saw someone else mention this but it bears repeating.  When you ask a 
question make sure you are presenting the problem and not your solution to a 
secret problem.  Always tell us the actual problem you are trying to solve.  
You will get much better answers.

Think of it this way.  You drop a ring down a drain.  You can ask two 
questions, "How do I remove a drain trap?" or "How do I recover a ring that I 
dropped down the drain?"  If you ask the first question you will get lots of 
advice on tools and buckets, etc.  People will assume that the drain is 
blocked.  Ask the second question and someone might mention a magnet and a 
piece of string.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net VoIP: sip:da...@vex.net

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 05:58 PM, Deborah Swanson wrote:
>> the user to go and authenticate, you can simply
>> webbrowser.open("http://.../;) and it'll DTRT.
>
> Thank you, thank you! Finally, at least one person on this list knows
> about something (anything) in the python world that is internet aware.

Lots of things in Python are Internet aware.  That's not the question you asked 
though.

> It's also occurred to me that Beautifulsoup downloads data from a url,
> so that code must have access to some kind of an internet engine too.

Nope.  You have to feed it HTML.  You either need to generate that or capture 
it from somewhere.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net VoIP: sip:da...@vex.net

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
Deborah - please trim your quoted text.

On 2017-01-04 04:32 AM, Deborah Swanson wrote:
> Thanks, Steven. Yes, of course if you want to print strings you must
> enclose them in quotes. I think you learn that in Week 1 of any
> introductory course on Python.

Closer to minute one.  When I investigated Python years ago the first thing I 
learned was;

  print "Hello, world"

> But we aren't trying to print strings here, the point is to produce
> clickable links. I didn't enclose them with quotes because I didn't see
> any point in printing plain text when I wanted clickable links. I

I'm not sure what your links are composed of but mine all look like sequences 
of characters or "strings."  It sounds like you are trying to make URL a first 
class type like strings. integers, floats, etc.  I can't think of any language 
that treats URLs as first class objects. Even HTML needs quotes:

   http://...;>Go here

> actually didn't understand why you thought I should print them, but it

You want to output them to something.  That often involves printing them to a 
particular handler.

> never would have occurred to me that you wanted me to print out a bunch
> of silly plain text strings, apparently just for the heck of it.

Is that really what you got from his message?

> At this point, if I pursue this any farther, it will be to look into how
> Firefox takes webpage titles and urls out of its sqlite database and
> makes objects you can click on to open the webpages. That's the basic
> technology I'd need to find a way to talk (write) python into doing.

I can assure you that FF prints the string at some point.  It may wrap it in 
HTML tags first but printing is what it does.  Also, the URLs are stored as 
strings.  SQLite has no URL type.  If it did then it would still store it as a 
string somewhere.  PostGreSQL would let you create a URL type if you wanted but 
you would still need to wrap it in quotes
(single in this case) when you created the entry.

> If it's even worth it. On a practical level it's not worth it, way too
> much work for the teensy advantage of having it to use. It might be some
> giggles to figure out how to do it and maybe I will sometime just for
> funsies.

In all the messages in this thread I still don't understand what this "teensy 
advantage" is supposed to be.  Do you want to be able to do this:

   make_web_link(http://...)

instead of:

   make_web_link("http://...;)

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net VoIP: sip:da...@vex.net

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-06 Thread D'Arcy Cain
On 2017-01-04 08:44 AM, Rodrigo Bistolfi wrote:
> 2017-01-04 7:39 GMT-03:00 Steve D'Aprano :
>> Aside: you've actually raised a fascinating question. I wonder whether
>> there
>> are any programming languages that understand URLs as native data types, so
>> that *source code* starting with http:// etc is understood in the same way
>> that source code starting with [ is seen as a list or { as a dict?
>
> Some Smalltalk implementations have something that comes close:
>
> st> 'https://python.org' asUrl retrieveContents

But notice that even here the URL has to be defined as a string.  To be a first 
class object you would need to do something like this:

   url = https://python.org/

The only time you would see that is in config files and languages like shell 
where everything is a string so no quotes necessary.  They are implied.

> `asUrl` would be a string method returning a URL instance, which also has a
> convenient method `retrieveContents` wrapping an http client. Not hard to
> do with Python, I think this could be an interesting exercise for a learner.

Sure but the issue is, what to do with it.  In any case, it's still just a 
wrapper around various string methods.  You still need to give the class a 
string to create the object.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net VoIP: sip:da...@vex.net

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-04 Thread D'Arcy Cain

On 2017-01-04 07:07 PM, Deborah Swanson wrote:

D'Arcy Cain wrote, on Wednesday, January 04, 2017 5:03 AM

In all the messages in this thread I still don't understand what this
"teensy advantage" is supposed to be.  Do you want to be able
to do this:

   make_web_link(http://...)

instead of:

   make_web_link("http://...;)


[...]


Is make_web_link("http://...;) valid python code? That's exactly the


It's just a made up name.  My point was that the first was syntactically 
incorrect and the second, while not a real method, was at least parseable.


I think I saw someone else mention this but it bears repeating.  When 
you ask a question make sure you are presenting the problem and not your 
solution to a secret problem.  Always tell us the actual problem you are 
trying to solve.  You will get much better answers.


Think of it this way.  You drop a ring down a drain.  You can ask two 
questions, "How do I remove a drain trap?" or "How do I recover a ring 
that I dropped down the drain?"  If you ask the first question you will 
get lots of advice on tools and buckets, etc.  People will assume that 
the drain is blocked.  Ask the second question and someone might mention 
a magnet and a piece of string.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-04 Thread D'Arcy Cain

On 2017-01-04 05:58 PM, Deborah Swanson wrote:

the user to go and authenticate, you can simply
webbrowser.open("http://.../;) and it'll DTRT.


Thank you, thank you! Finally, at least one person on this list knows
about something (anything) in the python world that is internet aware.


Lots of things in Python are Internet aware.  That's not the question 
you asked though.



It's also occurred to me that Beautifulsoup downloads data from a url,
so that code must have access to some kind of an internet engine too.


Nope.  You have to feed it HTML.  You either need to generate that or 
capture it from somewhere.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-04 Thread D'Arcy Cain

On 2017-01-04 08:44 AM, Rodrigo Bistolfi wrote:

2017-01-04 7:39 GMT-03:00 Steve D'Aprano :

Aside: you've actually raised a fascinating question. I wonder whether
there
are any programming languages that understand URLs as native data types, so
that *source code* starting with http:// etc is understood in the same way
that source code starting with [ is seen as a list or { as a dict?


Some Smalltalk implementations have something that comes close:

st> 'https://python.org' asUrl retrieveContents


But notice that even here the URL has to be defined as a string.  To be 
a first class object you would need to do something like this:


  url = https://python.org/

The only time you would see that is in config files and languages like 
shell where everything is a string so no quotes necessary.  They are 
implied.



`asUrl` would be a string method returning a URL instance, which also has a
convenient method `retrieveContents` wrapping an http client. Not hard to
do with Python, I think this could be an interesting exercise for a learner.


Sure but the issue is, what to do with it.  In any case, it's still just 
a wrapper around various string methods.  You still need to give the 
class a string to create the object.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-04 Thread D'Arcy Cain

Deborah - please trim your quoted text.

On 2017-01-04 04:32 AM, Deborah Swanson wrote:

Thanks, Steven. Yes, of course if you want to print strings you must
enclose them in quotes. I think you learn that in Week 1 of any
introductory course on Python.


Closer to minute one.  When I investigated Python years ago the first 
thing I learned was;


 print "Hello, world"


But we aren't trying to print strings here, the point is to produce
clickable links. I didn't enclose them with quotes because I didn't see
any point in printing plain text when I wanted clickable links. I


I'm not sure what your links are composed of but mine all look like 
sequences of characters or "strings."  It sounds like you are trying to 
make URL a first class type like strings. integers, floats, etc.  I 
can't think of any language that treats URLs as first class objects. 
Even HTML needs quotes:


  http://...;>Go here


actually didn't understand why you thought I should print them, but it


You want to output them to something.  That often involves printing them 
to a particular handler.



never would have occurred to me that you wanted me to print out a bunch
of silly plain text strings, apparently just for the heck of it.


Is that really what you got from his message?


At this point, if I pursue this any farther, it will be to look into how
Firefox takes webpage titles and urls out of its sqlite database and
makes objects you can click on to open the webpages. That's the basic
technology I'd need to find a way to talk (write) python into doing.


I can assure you that FF prints the string at some point.  It may wrap 
it in HTML tags first but printing is what it does.  Also, the URLs are 
stored as strings.  SQLite has no URL type.  If it did then it would 
still store it as a string somewhere.  PostGreSQL would let you create a 
URL type if you wanted but you would still need to wrap it in quotes 
(single in this case) when you created the entry.



If it's even worth it. On a practical level it's not worth it, way too
much work for the teensy advantage of having it to use. It might be some
giggles to figure out how to do it and maybe I will sometime just for
funsies.


In all the messages in this thread I still don't understand what this 
"teensy advantage" is supposed to be.  Do you want to be able to do this:


  make_web_link(http://...)

instead of:

  make_web_link("http://...;)

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reading python list as a newsgroup (was ...)

2016-12-16 Thread D'Arcy Cain

On 2016-12-16 08:16 PM, Dennis Lee Bieber wrote:

Unfortunately, my client can only "pre filter" on subject and author; I
could kill all @gmail.*, but could not focus on just Google Groups
submissions...


I don't know what client you use but perhaps you can adapt this procmail 
recipe.


:0 Hir
* ^List-Id:.*python-list.python.org
* ^From:.*@gmail.com
* ^Newsgroups:.*
/dev/null


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Reading python list as a newsgroup (was ...)

2016-12-16 Thread D'Arcy Cain

On 2016-12-16 10:11 AM, Grant Edwards wrote:

I didn't notice much spam on c.l.p (but then again, I filter out all
posts from google-groups).  The problem on c.l.p that caused me to


Yes, blocking GG was the biggest improvement to my reading this list 
(mailing list in my case).  That and a few judicious PLONKs and it is 
now useful.


Al I need to do now is figure out how to filter out the almost daily 
Windows installer questions.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread D'Arcy Cain

On 2016-12-15 12:06 PM, Steve D'Aprano wrote:

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.


There isn't enough info in your post to be sure but if those values are 
constant then you might be able to subclass dict and write a new 
__getitem__ that checks for specific ranges and calls the superclass 
only if not in the known ranges.  For example:


class MyDict(dict):
  def __getitem__(self, key):
if isinstance(key, int) and key >= 1 and key <= 100:
  return "foo"
return dict.__getitem__(self, key)

Obviously that middle section can be as complex as you need.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


PyGreSQL 5.0.3 released

2016-12-11 Thread D'Arcy Cain

Release 5.0.3 of PyGreSQL.

It is available at: http://pygresql.org/files/PyGreSQL-5.0.3.tar.gz.

If you are running NetBSD, look in the packages directory under databases.
There is also a package in the FreeBSD ports collection.

Please refer to the changelog.txt file for things that have changed in 
this version.


Please refer to `readme.txt for general information.

This version has been built and unit tested on:
 - NetBSD
 - FreeBSD
 - openSUSE
 - Ubuntu
 - Windows 7 with both MinGW and Visual Studio
 - PostgreSQL 9.0 to 9.5 32 and 64bit
 - Python 2.6, 2.7, 3.3, 3.4 and 3.5 32 and 64bit

--
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org IM:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Call a shell command from Python

2016-11-01 Thread D'Arcy Cain

On 2016-11-01 01:23 AM, Ben Finney wrote:

Wildman via Python-list  writes:
So the way your script was invoked has no bearing on whether Bash will
get involved in what your script does. Your script is *directly*
invoking programs, and if you don't ask for a shell to be involved you
won't get it.


In other words, the OP's script *is* bash in this scenario or a 
reasonable facsimile thereof.


The subject probably should have been "Emulating a shell in Python."  Of 
course, if the OP knew to use that subject he probably would have 
already had the answer.  :-)


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to use two threads (GUI and backend)

2016-10-27 Thread D'Arcy Cain

On 2016-10-27 07:33 AM, jmp wrote:

On 10/27/2016 12:22 PM, pozz wrote:

(blocking) thread. The blocking function read returns *immediately* when
all the bytes are received.  And I think during blocking time, the
thread isn't consuming CPU clocks.


Threads do consume CPU clocks.


Sometimes they do but read what pozz wrote.  "during blocking time, the 
thread isn't consuming CPU clocks".  That means that if you have two 
threads with one computing π and the other blocked waiting for user 
input then the first one is using CPU cycles - as many as it can get - 
and the other is using none until the user enters something.  This is 
kind of the point of threads - only things that need cycles get cycles.



An operation within a thread will not consume less CPU clocks, however,


It will if it blocks for something.  A simple sleep will also give up 
the processor.



From what I understand of your context, you don't want you GUI to
"freeze" when waiting for the remote application. That's a valid concern.


And that's why you use threads.  You can also use select in a state 
machine loop.  Depends on your model and somewhat on your preferences.



What you should not do is focus on gaining "CPU clocks". You just don't
care. It's probably not an issue. If it is, drop python and implement
your app in C.


In fact, going to C often is less of a win than you may think.  Python 
is pretty damn efficient if you write good code.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread D'Arcy Cain

On 2016-10-27 03:05 AM, Terry Reedy wrote:

When I used unix in the 1980s, the full screen ran csh until one started
another full screen application.  MSDOS was the same. Every contemporary
photo of modern Linux or Mac I have seen has a desktop with windows just
like Windows.  Do people on Linux still commonly use full-screen, no
window text editors like the one I had?  On Windows, there are full
screen games, but I have never seen a full-screen, no-window text
application.


You must lead a sheltered life then.


Since modern screen are pixel graphics screens, rather than character


Not always.  I have many Unix systems that don't run X.  A GUI is not 
essential to running a useful Unix server.


You may be correct that Linux systems tend to run GUIs but even then it 
isn't mandatory.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to handle errors?

2016-10-20 Thread D'Arcy Cain

On 2016-10-20 08:03 PM, Wildman via Python-list wrote:

Using a direct path to the Python interpreter can cause problems
on some systems because it is not always installed to the same
directory.  On my Debian-based system Python is installed in
/usr/bin.  So your code as written will not run on my system.
A workaround for this is to use env in the shebang/hashbang.

For Python 2:  #!/usr/bin/env python


Which would fail on my system because that's Python 3.5.


For Python 3:  #!/usr/bin/env python3

It will not matter where Python is installed.  'env' will always
know where it is.


Nothing is perfect.  I have just started linking /usr/bin/python* to 
wherever the actual one is on all my systems.  If I distribute something 
I expect the package manager on the target system to rewrite it as 
necessary.  I use NetBSD pkgsrc (which runs on many systems besides 
NetBSD) and it rewrites the HB line.


--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Re: #!/usr/bin/env python vs. #!/usr/bin/python?

2012-09-28 Thread D'Arcy Cain
On Fri, 28 Sep 2012 06:57:28 -0400
Roy Smith r...@panix.com wrote:
  I've seen both shebang lines to run a Python script on a *nix host:
  
  #!/usr/bin/env python
  #!/usr/bin/python
  
  What's the difference?
 
 The first one looks through your PATH to find the right python 
 interpreter to run.  The second one is hard-wired to run /usr/bin/python.
 
 If you only have a single copy of python installed, it doesn't really 
 matter which you use.  But, you might as well get into the habit of 
 using the /usr/bin/env flavor because it's more flexible.

Not just flexible but portable.  On various systems I have Python
in /usr/bin, /usr/local/bin and /usr/pkg/bin.  #!/usr/bin/env python
finds it in each case so I only need one version of the script.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Stop feeding the trolls (Was: which a is used?)

2012-09-25 Thread D'Arcy Cain
On Tue, 25 Sep 2012 08:44:18 +0100
Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 25/09/2012 06:07, Thomas Rachel wrote:
  Am 25.09.2012 04:37 schrieb Dwight Hutto:
[...usual nonsense]

 someone had the audacity to protect his stance.  I am sure that people 
 have seen enough of his behaviour in the last few hours to see the real 
 Dwight Hutto so I'll leave it at that.

Now if only people would stop feeding the troll, those of us who have
already *plonked* him can stop seeing his ramblings in the responses.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >