Python built-in help function throws an error - python

When I try to get help information on any of the built-in functions, it returns the following error:
Version: 3.7.4
>>> help(len)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\hgak\AppData\Local\Programs\Python\Python38-32\lib\_sitebuiltins.py", line 103, in __call__
return pydoc.help(*args, **kwds)
varchars = string.ascii_letters + string.digits + '_-'
AttributeError: module 'string' has no attribute 'ascii_letters'

Related

Unable to create owl:NamedIndividual on owlready2

I need to create a NamedIndividual (https://www.w3.org/TR/owl2-syntax/#Named_Individuals) but I am not seeing a way to do it.
The following example:
from owlready2 import *
onto = get_ontology("example")
class NamedIndividual(Thing): namespace = owl
print(NamedIndividual.iri)
print(NamedIndividual.name)
mini = NamedIndividual()
onto.save("minrep.rdf")
Gives the following error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual("example")
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 137, in __init__
if self.storid > 0: self.namespace.ontology._add_obj_triple_spo(self.storid, rdf_type, owl_named_individual)
TypeError: '>' not supported between instances of 'str' and 'int'
If I instantiate the class without a name, I get another error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual()
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 123, in __init__
iri = self.namespace.world._new_numbered_iri("%s%s" % (self.namespace._base_iri, self.generate_default_name()))
AttributeError: 'World' object has no attribute '_new_numbered_iri'
Any ideas on what is happening there? Thanks!

Why there is STAFRegister error in PySTAF.py?

I am getting the below error. I have used capital letters PYSTAF too, still getting the same error.
Traceback (most recent call last):
File "C:\Python27\STAFtest.py", line 16, in <module>
handle = STAFHandle("Lang/Python/Test/Basic")
File "D:\STAF\bin\PySTAF.py", line 137, in __init__
rc, self.handle = PySTAF.STAFRegister(handleNameOrNumber)
AttributeError: 'module' object has no attribute 'STAFRegister'

SystemError exception occurs when running click.confirm

I am trying to run a click.confirm() command. It works when I run the file stand-alone, but when I call the function from another module I get a SystemError
Traceback (most recent call last):
File "/home/usr/.local/lib/python3.6/site-packages/click/_compat.py", line 108, in __getattr__
return getattr(self._stream, name)
File "/home/usr/.vscode-server/extensions/ms-python.python-2022.6.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_io.py", line 59, in __getattr__
raise AttributeError(name)
AttributeError: closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/usr/.local/lib/python3.6/site-packages/click/termui.py", line 231, in confirm
echo(prompt.rstrip(" "), nl=False, err=err)
File "/home/usr/.local/lib/python3.6/site-packages/click/utils.py", line 298, in echo
file.write(out) # type: ignore
SystemError: <built-in method write of _NonClosingTextIOWrapper object at 0x7f20e85ea048> returned a result with an error set
I run my program on a computer over SSH using the vscode extension

NameError: global name 'imfilter' is not defined

I am trying to use imfilter and, despite of upgrading to 0.18.1 version, I cannot use it:
>>> import scipy
>>> blurred_arr = scipy.imfilter(arr, "blur")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'imfilter'
>>> blurred_arr = scipy.misc.imfilter(arr, "blur")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'misc'
>>> blurred_arr = imfilter(arr, "blur")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'imfilter' is not defined
>>> scipy.__version__
'0.18.1'
I am not an expert in Python, so I feel that I am asking something really silly here...Can you help please?
If scipy.misc is its own module, then it has to be imported explicitly.
Either:
import scipy.misc
...
scipy.misc.imfilter(...)
or
from scipy.misc import imfilter
...
imfilter(...)

Get socket for urllib2.urlopen return value for HTTP

I'm trying to do asynchronous downloading of files using urllib2 but have no succeeded in finding out the socket (or its fileno) to wait for new data for for HTTP requests. Here's what I've already tried.
>>> from urllib2 import urlopen
>>> from select import select
>>> r = urlopen('http://stackoverflow.com/')
>>> select([r], [], [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/socket.py", line 307, in fileno
return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>> r.fileno()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/socket.py", line 307, in fileno
return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>> r.fp.fileno()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/socket.py", line 307, in fileno
return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>> select([r.fp], [], [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/socket.py", line 307, in fileno
return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>>
See http://www.velocityreviews.com/forums/t512553-re-urllib2-urlopen-broken.html.
The problem is that urlib2 was changed to wrap an HTTPResponse object
in a socket._fileobject to get a few more file methods. Except (as
reported above) HTTPResponse doesn't have a fileno() method, so when
_fileobject tries to use it, it blows up.
The solution
Adding an appropriate method to HTTPResponse:
def fileno(self):
return self.fp.fileno()
Or, alternatively, use urllib.urlopen instead of urrlib2.urlopen.
There is a bug report for this issue; it was fixed in Python 3 and in Python 2.7.

Categories

Resources