Re: How to cover connection exception errors, and exit

2020-03-29 Thread Peter Otten
[email protected] wrote:

> Hi,
> 
> I've tried urllib, requests, and some other options.  But I haven't found
> a way to trap certain urls that aren't possible to connect from, outside
> the office.  In those cases, I need to just output an error.
> 
> 
> So, the following code will cover the 404s and similar errors for most of
> the problem IPs and urls.  But for these particular problem urls, while
> debugging it keeps transferring control to adapters.py, and outputting
> 
>  requests.exceptions.ConnectionError:
>  HTTPSConnectionPool(host='xxx.state.gov', port=443): Max retries
>  exceeded with url: /xxx/xxx/xxx(Caused by
>  NewConnectionError('  object at 0x03934538>: Failed to establish a new connection: [Errno
>  11001] getaddrinfo failed'))
> 
> 
> How do I trap this error, without invoking adapters.py?

If requests catches the error -- I don't know. 

If you fail to catch the error in your code -- what happens if you use a 
bare except? Like

try:
...  # your code
except:
print(sys.exc_info())

This should print the type of exception you need to catch.


> I've tried many things, but the most recent is this code, from the web:
> 
> 
> 
> try:
> r = requests.get(url,timeout=3)
> r.raise_for_status()
> except requests.exceptions.HTTPError as errh:
> print ("Http Error:",errh)
> except requests.exceptions.ConnectionError as errc:
> print ("Error Connecting:",errc)
> except requests.exceptions.Timeout as errt:
> print ("Timeout Error:",errt)
> except requests.exceptions.RequestException as err:
> print ("OOps: Something Else",err)
> 
> 
> It seems like the error should be trapped by the exception above
> requests.exceptions.ConnectionError, but instead its' hitting adapters.py.


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


Re: mport pytorch fails on my windows 10 PC

2020-03-29 Thread Souvik Dutta
Since it is not in the control panel, go to windows app execution aliases
and scroll down till you find python. Now toggle both of them and see if
this works.

On Sun, Mar 29, 2020, 2:53 PM joseph pareti  wrote:

> All right, thx, but how to uninstall the 'other' python version?
>
> The control panel only shows python 3.7 which is what I am using.
>
> Am So., 29. März 2020 um 01:36 Uhr schrieb Souvik Dutta <
> [email protected]>:
>
>> Yes having two versions of python causes that problem.
>>
>> On Sat, 28 Mar, 2020, 11:53 pm joseph pareti, 
>> wrote:
>>
>>> apologies for asking here a presumably off-topic question:
>>>
>>> I have installed pytorch using (miniconda3) the following command:
>>>
>>> *conda install pytorch torchvision cpuonly -c pytorch*
>>>
>>> In the jupyter notebook, the 'import torch' fails:
>>>
>>> *ModuleNotFoundError: No module named 'torch._C'*
>>>
>>> I am not sure if having several python versions on the system could cause
>>> the issue:
>>>
>>> ./Users/joepareti/Miniconda3/envs/myenv/python.exe
>>> ./Users/joepareti/Miniconda3/envs/myenv1/python.exe
>>> ./Users/joepareti/Miniconda3/pkgs/python-3.6.8-h9f7ef89_0/python.exe
>>> ./Users/joepareti/Miniconda3/pkgs/python-3.6.8-h9f7ef89_1/python.exe
>>> ./Users/joepareti/Miniconda3/pkgs/python-3.7.1-h8c8aaf0_6/python.exe
>>> ./Users/joepareti/Miniconda3/python.exe
>>> --
>>> Regards,
>>> Joseph Pareti - Artificial Intelligence consultant
>>> Joseph Pareti's AI Consulting Services
>>> https://www.joepareti54-ai.com/
>>> cell +49 1520 1600 209
>>> cell +39 339 797 0644
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
>
> --
> Regards,
> Joseph Pareti - Artificial Intelligence consultant
> Joseph Pareti's AI Consulting Services
> https://www.joepareti54-ai.com/
> cell +49 1520 1600 209
> cell +39 339 797 0644
>
-- 
https://mail.python.org/mailman/listinfo/python-list


super not behaving as I expected

2020-03-29 Thread Antoon Pardon


I have the following program

class slt:
__slots__ = ()

def getslots(self):
print("### slots =", self.__slots__)
if self.__slots__ == ():
return []
else:
ls = super().getslots()
ls.extend(self.__slots__)
return ls

def __str__(self):
ls = []
attrs = self.getslots()
for attr in attrs:
ls.append(str(getattr( self, attr)))
return '->'.join(ls)


class slt1 (slt):
__slots__ = 'fld1', 'fld2'

def __init__(self, vl1, vl2):
self.fld1 = vl1
self.fld2 = vl2

class slt2(slt1):
__slots__ = 'fld3',

def __init__(self, vl1, vl2, vl3):
self.fld1 = vl1
self.fld2 = vl2
self.fld3 = vl3

rc1 = slt1(4, 7)
rc2 = slt2(11, 18, 29)

print(rc1)
print(rc2)

When I call this I would expect to see the following:

### slots = ('fld1', 'fld2')
### slots = ()
4->7
### slots = (fld3,)
### slots = ('fld1', 'fld2')
### slots = ()
11->18->29

What I actually get is:

### slots = ('fld1', 'fld2')
Traceback (most recent call last):
  File "slottest", line 39, in 
print(rc1)
  File "slottest", line 15, in __str__
attrs = self.getslots()
  File "slottest", line 9, in getslots
ls = super().getslots()
AttributeError: 'super' object has no attribute 'getslots'

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


Re: super not behaving as I expected

2020-03-29 Thread Peter Otten
Antoon Pardon wrote:

> 
> I have the following program
> 
> class slt:
> __slots__ = ()
> 
> def getslots(self):
> print("### slots =", self.__slots__)
> if self.__slots__ == ():
> return []
> else:
> ls = super().getslots()
> ls.extend(self.__slots__)
> return ls
> 
> def __str__(self):
> ls = []
> attrs = self.getslots()
> for attr in attrs:
> ls.append(str(getattr( self, attr)))
> return '->'.join(ls)
> 
> 
> class slt1 (slt):
> __slots__ = 'fld1', 'fld2'
> 
> def __init__(self, vl1, vl2):
> self.fld1 = vl1
> self.fld2 = vl2
> 
> class slt2(slt1):
> __slots__ = 'fld3',
> 
> def __init__(self, vl1, vl2, vl3):
> self.fld1 = vl1
> self.fld2 = vl2
> self.fld3 = vl3
> 
> rc1 = slt1(4, 7)
> rc2 = slt2(11, 18, 29)
> 
> print(rc1)
> print(rc2)
> 
> When I call this I would expect to see the following:
> 
> ### slots = ('fld1', 'fld2')
> ### slots = ()
> 4->7
> ### slots = (fld3,)
> ### slots = ('fld1', 'fld2')
> ### slots = ()
> 11->18->29
> 
> What I actually get is:
> 
> ### slots = ('fld1', 'fld2')
> Traceback (most recent call last):
>   File "slottest", line 39, in 
> print(rc1)
>   File "slottest", line 15, in __str__
> attrs = self.getslots()
>   File "slottest", line 9, in getslots
> ls = super().getslots()
> AttributeError: 'super' object has no attribute 'getslots'
> 

Well...

super().method

looks up method in the parent class of the class where it's used -- in your 
case the parent class of slt, or object.

self.attribute

looks up the attribute in the instance, and if that fails works its way up 
the inheritance tree follong the mro; here it succeeds in slt1. This leeds 
to execution of the else branch in getslots() which in turn tries to invoke 
object.getslots() -- and fails.

That would be the normal behaviour. The __slots__ attribute is special, so 
there may be subtle differences.


Anyway, here's my attempt to collect inherited slots:

@classmethod
def get_slots(cls):
all_slots = set()
for C in cls.__mro__:
try:
slots = C.__slots__
except AttributeError:
assert C is object
else:
all_slots.update(slots)
return all_slots


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


Re: How to uninstall Python3.7 in Windows using cmd ?

2020-03-29 Thread Terry Reedy

On 3/29/2020 12:17 AM, Mike Dewhirst wrote:

On 29/03/2020 5:06 am, Terry Reedy wrote:

On 3/27/2020 8:07 AM, deepalee khare wrote:


How to Uninstall Python3.7.3 using cmd ? i tried using cmd: Msiexec
/uninstall C:\Python37\python.exe But it gives me below error: enter
image description here


Python is not currently installed with msi, hence cannot use it to 
uninstall.  Images and attachments are not allowed.





In that case install that same version of Python to the same location 
using msi 


Just how do you propose that one do that?

- then remove it.

To clarify, the pydev/python.org installer does not use msi.  I don't 
know that anyone else does.  And if someone did, why do you think it 
would also uninstall the current installation?


--
Terry Jan Reedy


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


RE: Confusing textwrap parameters, and request for RE help

2020-03-29 Thread Steve Smith
I am having the same issue. I can either get the text to wrap, which makes all 
the text wrap, or I can get the text to ignore independent '/n' characters, so 
that all the blank space is removed. I'd like to set up my code, so that only 1 
blank space is remaining (I'll settle for none at this point), an the text 
wraps up to 100 chars or so out per line. Does anyone have any thoughts on the 
attached code? And what I'm not doing correctly?


#import statements
import textwrap
import requests
from bs4 import BeautifulSoup

#class extension of textwrapper
class DocumentWrapper(textwrap.TextWrapper):

def wrap(self, text):
split_text = text.split('\n')
lines = [line for para in split_text for line in 
textwrap.TextWrapper.wrap(self, para)]
return lines

#import statement of text.
page = requests.get("http://classics.mit.edu/Aristotle/rhetoric.mb.txt";)
soup = BeautifulSoup(page.text, "html.parser")

#instantiation of extension of textwrap.wrap.
d = DocumentWrapper(width=110,initial_indent='',fix_sentence_endings=True )
new_string = d.fill(page.text)

#set up an optional variable, even attempted applying BOTH the extended method 
and the original method to the issue... nothing has worked.
#new_string_2 = textwrap.wrap(new_string,90)

#with loop with JUST the class extension of textwrapper.
with open("Art_of_Rhetoric.txt", "w") as f:
f.writelines(new_string)

#with loop with JUST the standard textwrapper.text method applied to it.
with open("Art_of_Rhetoric2.txt", "w") as f:
f.writelines(textwrap.wrap(page.text,90))


-Original Message-
From: Python-list  On 
Behalf Of Dan Sommers
Sent: Friday, March 27, 2020 3:51 PM
To: [email protected]
Subject: Re: Confusing textwrap parameters, and request for RE help

On Fri, 27 Mar 2020 15:46:54 -0600
Michael Torrie  wrote:

> On 3/27/20 3:28 PM, Dan Stromberg wrote:

> > Back when I was a kid, and wordprocessors were exemplified by 
> > WordStar, I heard about a study the conclusion of which was that 
> > aligned right edges were harder to read - that it was better to 
> > align on the left and leave the right ragged.

I remember WordStar, and its text editor cousin WordMaster.

> > But one study doesn't establish truth.

> I've read poorly-typeset, self-published books that were really hard 
> to read due to the way the full justification worked out.  Not sure if 
> that's just due to the poor typesetting job (a word processor probably 
> did it), or the font, or what.  There must be some tricks that 
> publishers use to both justify and keep the text looking good and 
> readable ...

Ask Donald Knuth why he invented TeX, and why math is enclosed in literal $ 
(U+0024) characters.  ;-)

Also, there are word processors and there are word processors.  From an 
aesthetics perspective, TeX has been producing beautiful printed pages (and 
pairs and sequences of pages) for decades, Word still didn't the last time I 
looked (maybe 8 or 10 years ago?), and there are dozens or more in between.

> ... At one point in the print world, the majority of what I read is 
> fully justified, yet still quite readable.  Even now I think most 
> published books I've seen recently are fully justified. These days, 
> seems like more and more is ragged-right, such as magazines, which is 
> probably due to the prevalence of digital media where it's probably 
> easier to generate and easier to read on small screens.

If content producers did their job well, a 2540 pixel per inch printed page, a 
desktop 72 or 96 pixel per inch display screen, and a handheld
320 pixel per inch screen would all be optimized separately (through one sort 
of style sheet mechanism or another).  But these days, they spend more time and 
money on ads and SEO than typesetting.

Dan

--
“Atoms are not things.” – Werner Heisenberg Dan Sommers, 
http://www.tombstonezero.net/dan
--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Unable to install or operate PIP on Windows 10

2020-03-29 Thread Steven Hobbs


Hi all,

I have installed Python 3.7.7 on Windows 10 and I understood that pip came 
installed. However when I try using pip I get an unrecognised command error.

I tried following the instructions on this website:
https://docs.python.org/3/installing/index.html

However usage of pip as described at this website receives an unrecognised 
command error. I have also tried adding the python directory to the Path 
variable and running commands in the Python directory.

I have also tried this website without success:

https://pip.pypa.io/en/stable/installing/
Installation — pip 20.0.2 
documentation
Warning. Be cautious if you are using a Python install that is managed by your 
operating system or another package manager. get-pip.py does not coordinate 
with those tools, and may leave your system in an inconsistent state.
pip.pypa.io


Can I please have step by step instructions that have been verified to work 
with Windows 10 and Python 3.7.7 that list all requirements, dependencies and 
processes to install and run pip and then install libraries such as numpy and 
pillow.


Any help would be greatly appreciated.

Regards,

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


Re: Unable to install or operate PIP on Windows 10

2020-03-29 Thread MRAB

On 2020-03-29 23:34, Steven Hobbs wrote:


Hi all,

I have installed Python 3.7.7 on Windows 10 and I understood that pip came 
installed. However when I try using pip I get an unrecognised command error.

I tried following the instructions on this website:
https://docs.python.org/3/installing/index.html

However usage of pip as described at this website receives an unrecognised 
command error. I have also tried adding the python directory to the Path 
variable and running commands in the Python directory.

I have also tried this website without success:

https://pip.pypa.io/en/stable/installing/
Installation — pip 20.0.2 
documentation
Warning. Be cautious if you are using a Python install that is managed by your 
operating system or another package manager. get-pip.py does not coordinate 
with those tools, and may leave your system in an inconsistent state.
pip.pypa.io


Can I please have step by step instructions that have been verified to work 
with Windows 10 and Python 3.7.7 that list all requirements, dependencies and 
processes to install and run pip and then install libraries such as numpy and 
pillow.


Any help would be greatly appreciated.


I'd recommend using the pip module via the Python launcher instead:

py -m pip install numpy

If you have multiple Python versions installed, then you can specify 
which one you want to use, e.g. for Python 3.7:


py -3.7 -m pip install numpy
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to uninstall Python3.7 in Windows using cmd ?

2020-03-29 Thread Mike Dewhirst

On 29/03/2020 10:24 pm, Terry Reedy wrote:

On 3/29/2020 12:17 AM, Mike Dewhirst wrote:

On 29/03/2020 5:06 am, Terry Reedy wrote:

On 3/27/2020 8:07 AM, deepalee khare wrote:


How to Uninstall Python3.7.3 using cmd ? i tried using cmd: Msiexec
/uninstall C:\Python37\python.exe But it gives me below error: enter
image description here


Python is not currently installed with msi, hence cannot use it to 
uninstall.  Images and attachments are not allowed.





In that case install that same version of Python to the same location 
using msi 


Just how do you propose that one do that?


I would first determine whether it is the 32 or 64 bit version which is 
installed. I would then visit www.python.org and download the exact same 
python executable installer. Don't know what msi is but it doesn't 
matter. I think it just means microsoft installer.


If you launch the installer in Windows and choose the custom install it 
will let you select the location. You should choose C:\Python37 as you 
have already noted.


It is possible/probable that the installer will detect your existing 
Python 3.7.x and offer to repair it. Some parts of Python may have been 
omitted from the original installation. With a custom installation the 
msi installer lets you tick boxes to decide which components to install. 
To cover the uninstallation bases I would tick them all and proceed to 
completion.


In (my) theory that will do the install and hopefully let you do an 
ordinary Windows uninstall.


I assume (?) the original installation put the usual Python components 
including dll libraries in the conventional places for Windows and the 
python.org executable installer will follow suit.


The uninstallation probably won't delete the C:\Python37 directory but 
you can do that yourself.


If all the above fails, you can delete C:\Python37 and all its content 
as a precursor and then go through the installation again and try 
uninstalling again.


If that fails just delete C:\Python37 and its contents and hope for the 
best.


Good luck

Mike



- then remove it.

To clarify, the pydev/python.org installer does not use msi.  I don't 
know that anyone else does.  And if someone did, why do you think it 
would also uninstall the current installation?




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


Re: Unable to install or operate PIP on Windows 10

2020-03-29 Thread Mike Dewhirst

On 30/03/2020 9:34 am, Steven Hobbs wrote:

Hi all,

I have installed Python 3.7.7 on Windows 10 and I understood that pip came 
installed. However when I try using pip I get an unrecognised command error.

I tried following the instructions on this website:
https://docs.python.org/3/installing/index.html

However usage of pip as described at this website receives an unrecognised 
command error. I have also tried adding the python directory to the Path 
variable and running commands in the Python directory.

I have also tried this website without success:

https://pip.pypa.io/en/stable/installing/
Installation � pip 20.0.2 
documentation
Warning. Be cautious if you are using a Python install that is managed by your 
operating system or another package manager. get-pip.py does not coordinate 
with those tools, and may leave your system in an inconsistent state.
pip.pypa.io


Can I please have step by step instructions that have been verified to work 
with Windows 10 and Python 3.7.7 that list all requirements, dependencies and 
processes to install and run pip and then install libraries such as numpy and 
pillow.


I don't know about numpy but pillow on Windows is a pain because it is 
only available as source and pip want's to compile it. That is the pain. 
Pip needs to use a C compiler and Windows was never designed to make 
life easy for developers out of the box. You need to set up a dev 
environment yourself for that. HOWEVER all is not lost ...


Visit https://www.lfd.uci.edu/~gohlke/pythonlibs/ which is Christoph 
Gohlke's page of pre-compiled binaries for Windows. I couldn't use 
Windows without it. That man deserves a Nobel prize for generosity.


You will find a suitable Pillow installer there. To install all you do 
is execute it in the venv. But there is a better way if you need to 
install it only in particular venvs.


Use pip!

If you download the Pillow installer to your Windows downloads 
directory, here is a pip install incantation which works for me in an 
activated venv ...


python -m pip install 
D:\Users\mike/downloads/Pillow-6.0.0-cp37-cp37m-win_amd64.whl


Don't worry about my slashes and backslashes. That part of the above 
line is copied from a requirements file assembled by batch file. Pip 
doesn't care about the angle of the slash.


I think numpy people use Anaconda to install stuff. Not sure about that.

Good luck

Mike






Any help would be greatly appreciated.

Regards,

Steven Hobbs


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


Re: How to uninstall Python3.7 in Windows using cmd ?

2020-03-29 Thread Michael Torrie
On 3/29/20 6:41 PM, Mike Dewhirst wrote:
> I would first determine whether it is the 32 or 64 bit version which is 
> installed. I would then visit www.python.org and download the exact same 
> python executable installer. Don't know what msi is but it doesn't 
> matter. I think it just means microsoft installer.

I think you misread both Terry and the original poster.

What Terry was trying to say is that there is no MSI installer available
for python, so you cannot use the Microsoft MSI command line tool
(msiexec), which was what the original poster was asking about.  Thus
you cannot use msiexec.exe to remove Python by way of a batch file or
script. He'll have to do it a different way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to uninstall Python3.7 in Windows using cmd ?

2020-03-29 Thread Mike Dewhirst

On 30/03/2020 2:55 pm, Michael Torrie wrote:

On 3/29/20 6:41 PM, Mike Dewhirst wrote:

I would first determine whether it is the 32 or 64 bit version which is
installed. I would then visit www.python.org and download the exact same
python executable installer. Don't know what msi is but it doesn't
matter. I think it just means microsoft installer.

I think you misread both Terry and the original poster.


Maybe so but the method I suggested should install Python in a way which 
Windows should be able to uninstall and clear out what was there 
previously. That is why I said "it doesn't matter".


I hope.



What Terry was trying to say is that there is no MSI installer available
for python, so you cannot use the Microsoft MSI command line tool
(msiexec), which was what the original poster was asking about.  Thus
you cannot use msiexec.exe to remove Python by way of a batch file or
script. He'll have to do it a different way.


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