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
Related
im trying to disable auto update in Circutpython 8.0 beta on the pico W and every time I run
import supervisor supervisor.disable_autoreload()
I always get this error
>>> supervisor.disable_autoreload() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'disable_autoreload'
how can I fix this
I had the same issue and I'm not sure why because this function is still in the official documentation. Anyways, this worked for me on en_US-8.0.0-rc.2.
supervisor.runtime.autoreload = False
I am trying to generate QR code in python. My code is working fine in another python file but throws an error when I tried to use it in Flask webapp.
I've already installed pillow and qrcode.
#app.route('/qr')
def qrcode():
img = qrcode.make('https://youtube.com')
img.save('first-image1.png')
return 'all good'
Inside your function qrcode() refers to the local function, not to the external qrcode module/function/object. Your qrcode() function does not have any attribute named make, therefore an exception is raised. Here's an example:
def f():
print(f.make)
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
AttributeError: 'function' object has no attribute 'make'
To fix this, rename your function so that it does not clash with qrcode:
#app.route('/qr')
def qr():
img = qrcode.make('https://youtube.com')
img.save('first-image1.png')
return 'all good'
Here I simply renamed your function to qr() so that it will no longer shadow qrcode.
I am trying to load my json file. I am new to MacOS,but that should be the problem. My code
from terminal
import json
>>> with open('ticr_calculated_3_2020-05-27T11-01-30.json','r+', encoding='utf-8') as f:
data=json.load(f)
I got error
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: '_io.TextIOWrapper' object has no attribute 'load'
The same error happens with json example from Python docs
json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '_io.TextIOWrapper' object has no attribute 'dumps'
Why?
Have you written everything into one Python interpreter session? It seems to me that you defined the name json before.
Try opening a new Python interpreter or writing your script into a file.
for some reason I get an error at the line containing this piece of code:
t1 = threading.Thread(target=socket)
this is the error:
Traceback (most recent call last):
File "D:/04 - Media/Python Projects/4 - Networking/Send_Variable_Test/Server.py", line 33, in <module>
t1 = threading.Thread(target=socket)
AttributeError: 'module' object has no attribute 'Thread'
Exception AttributeError: "'module' object has no attribute '_shutdown'" in <module 'threading' from 'D:\04 - Media\Python Projects\4 - Networking\Send_Variable_Test\threading.pyc'> ignored
its obvious from this error that apparently there is no "Thread" module in the threading library, why is this? is the fact that I'm using python 2 the reason?
It looks like you have a file in your path that is called threading.py. Rename that and also delete the .pyc file and it should work.
In particular at this location: D:\04 - Media\Python Projects\4 - Networking\Send_Variable_Test\threading.pyc
I have written the simplest python code (module) :
def newplus(x, y):
return x*y
This is stored in a folder sabya (which is my package). The folder has _init_ and newplus.py files.
In my IDLE I can open the module sabya.newplus. When I give import sabya.newplus there is no error. but when I issue :
>>> sabya.newplus(2, 3)
I am getting this error
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
sabya.newplus(2, 3)
TypeError: 'module' object is not callable
You need to qualify the function as follow:
sabya.newplus.newplus(2, 3)