Printing docstrings in Python 3 - python

How do you print doc strings in python 3.1.x?
I tried with the re and sys modules as a test and I keep getting errors. Thanks
import re
print(re._doc_)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
print(re._doc_)
AttributeError: 'module' object has no attribute '_doc_'

It's called __doc__, not _doc_.
import re
print(re.__doc__)
Works just fine.

Related

After setting __import__ to None why I can still import?

If I do this:
__import__ = None
Then import a module:
import random
I still can. Why?
It doesn't call the reference in your module. It uses the one in builtins. Try:
import builtins
builtins.__import__ = None
import random
And you'll see it fail with:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

When I import fileinput module, use the input method , it report AttributeError: 'module' object has no attribute 'input'

The version of python is 2.7.13.
The content of 3.txt is:
this is a river
that is a cloud
the world is beatiful
I write a python script:
import fileinput
def process(string):
print 'Processing: ', string
for line in fileinput.input(r'E:\Python\3.txt'):
process(line)
When I run this script , it report error:
====================== RESTART: E:\Python\fileinput.py ======================
Traceback (most recent call last):
File "E:\Python\fileinput.py", line 1, in <module>
import fileinput
File "E:\Python\fileinput.py", line 7, in <module>
for line in fileinput.input(r'E:\Python\3.txt'):
AttributeError: 'module' object has no attribute 'input'
--------------------------------------------------------------------------------
What is the reason cause this problem ?
How can I slove this problem ?
Don’t name your script “fileinput.py”. It conflicts with the library module of the same name.

I can't start successfully boa constructor in windows7

When I start boa-constructor(boa-constructor-0.6.1.src.win32.exe) from the command line by starting the script "Boa.py", I got the message says
My python version is "python-2.7.7.msi" and I download wxPyton "wxPython3.0-win32-3.0.0.0-py27.exe"
O searched for files that contains the string "NO_3D " but I didn't get any can you help me pleaze and thanks
Actually you will require wxPython 2.8.12.1 to not get this error.
>>> import wx
>>> wx.__version__
'2.8.12.1'
>>> wx.NO_3D
0
This is a pity, because the operation …|wx.NO_3D is actually a No-Op. So you could fix this particular issue by defining wx.NO_3D somewhere.
On 2.9.5:
>>> import wx
>>> wx.__version__
'2.9.5.0'
>>> wx.NO_3D
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'NO_3D'

AttributeError: 'module' object has no attribute 'TextCalendar'

When I copy the below code in Ideone then it runs fine but it is not running in the text editor and showing the error mentioned in the subject of this post:
import calendar
c = calendar.TextCalendar(calendar.SUNDAY)
c.prmonth(2007, 7)
The complete error is:
Traceback (most recent call last):
File "calendar.py", line 1, in <module>
import calendar
File "/home/shl/Desktop/calendar.py", line 2, in <module>
c = calendar.TextCalendar(calendar.SUNDAY)
AttributeError: 'module' object has no attribute 'TextCalendar'
change the program name from calendar.py to something like calendar_code.py
This wold work properly.
Importing from builtin library when module with same name exists

Mkdir typeerror in Python 2.7

I am trying to write a simple script to create a directory in my C drive called Cake using Python. I followed a tutorial and can't figure out why I am getting an error.
os.mkdir("C:\\Cake")
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
os.mkdir("C:\\Cake")
TypeError: 'str' object is not callable
There is no Cake folder that already exists and it is on my personal PC so I do have administrative access. Any help would be appreciated.
Python lets you shoot yourself in the foot rather easily sometimes. You replaced the os.mkdir() function with a string somewhere.
You must've rebound the os.mkdir name to a string earlier in your code:
os.mkdir = 'some string'
or
os.mkdir = some_name_referring_to_a_string
Find that line and correct it. If you are seeing this in the shell, reload the module with:
reload(os)
Demo:
>>> import os
>>> os.mkdir = 'Hello world!'
>>> os.mkdir('/tmp/test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>> reload(os)
<module 'os' from '/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/os.pyc'>
>>> os.mkdir('/tmp/test')
after importing os,
you must have set os.mkdir to a string, which is shortened to str in the error.
To fix, reload the os module.
As an example,
import os
os.mkdir "stringing along playfully"
reload(os)
os.mkdir(r"C:\Cake")

Categories

Resources