Python's logging module misses "captureWarnings" function - python

Python's standard logging module is supposed to contain a useful captureWarnings function that allows integration between the logging and the warnings modules. However, it seems that my installation misses this function:
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.captureWarnings
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'captureWarnings'
>>> import logging.captureWarnings
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named captureWarnings
>>> import warnings
>>> import logging.captureWarnings
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named captureWarnings
>>>
What am I doing wrong?

Unfortunately, there is no such method in Python 2.6.5's logging module. You need Python 2.7.

Related

python-gnupg vs forked python-gnupg

I am trying to use the forked version of python-gnupg: https://pypi.org/project/gnupg/
rather than the original: https://pypi.org/project/python-gnupg/
When I install "gnupg" to my conda environment I see this:
$conda list | grep gnupg
gnupg 2.2.17 he1f381d_0
but when I try to import that module, I get this not found error:
(my_env) $python
Python 3.7.7 (default, May 7 2020, 21:25:33)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnupg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gnupg'
>>> import pretty_bad_protocol
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pretty_bad_protocol'
>>> from pretty_bad_protocol import gnupg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pretty_bad_protocol'
The docs for the forked version say to import gnupg and pretty-bad-protocol, but neither work for me. I can't figure out what I'm doing wrong. Has anyone else had success with this module? Thanks!

Python asyncio '_overlapped' is not imported

Could not import asyncio library in virtualenv.
Python 3.6.4 x32
Win 10 x64
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import asyncio
Traceback (most recent call last):
File "C:\Python36\Lib\asyncio\__init__.py", line 16, in <module>
from . import _overlapped
ImportError: cannot import name '_overlapped'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\Lib\asyncio\__init__.py", line 18, in <module>
import _overlapped # Will also be exported.
OSError: [WinError 0] The operation completed successfully
There is no module _overlapped in asyncio folder "C:\Python36\Lib\asyncio\". Also I know that asyncio is a part of Python from version 3.4.
What is wrong and what should i do? Could it be due to x64 Win and not x64 Python?

Why I can't import this module

Everything is obvious as the below image and the codes followed it :
I want to import a module that phycially there is in the D:\pyusb-1.0.0a2\usb, but I receive errors!
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> sys.path.append('d:\pyusb-1.0.0a2\usb')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 16-17: truncated \uXXXX escape
>>> sys.path.append('d:/pyusb-1.0.0a2/usb')
>>> from usb import core
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from usb import core
ImportError: No module named 'usb'
>>> import core
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import core
File "d:/pyusb-1.0.0a2/usb\core.py", line 44, in <module>
import usb.util as util
ImportError: No module named 'usb'
>>> import usb.core
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import usb.core
ImportError: No module named 'usb'
>>>
You need to append d:/pyusb-1.0.0a2/ to your Python path, and not d:/pyusb-1.0.0a2/usb/.
As you can see when trying to import core the error is no longer that your import failed, but that the usb.core module did not manage to import usb.util since there's no usb module available in your Python path, only modules inside usb, such as core or util.

Generating random integer in python fails using random library

Below is the snippet:
C:\APPS>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.seed()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'seed'
>>> random.randint(0,3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'randint'
>>>
You probably have a file called random.py in the APPS directory. Delete or rename that file.
Try something like this to see which random module you're using:
In [1]: import random
In [2]: print(random.__file__)
/usr/lib/python3.2/random.py

random module doesn't have randint() function

When I call random.randint(), I get the following error. Can anyone please explain what's happening?
$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "random.py", line 4, in <module>
print >>file,random.randint(100,10000)
AttributeError: 'module' object has no attribute 'randint'
>>> random.randint(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined
You've called a script "random.py". Rename it so that it isn't shadowing the stdlib module of the same name.

Categories

Resources