attributeerror

Python3 AttributeError: 'list' object has no attribute 'clear'

一个人想着一个人 提交于 2019-12-18 20:14:09
问题 I am working on a Linux machine with Python version 3.2.3. Whenever I try to do list.clear() I get an exception >>> l = [1, 2, 3, 4, 5, 6, 7] >>> l.clear() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list' object has no attribute 'clear' At the same time on my Mac with Python 3.4.3 the same code runs smoothly. Can it be due to the difference between Python versions or is there something I'm missing? 回答1: list.clear was added in Python 3.3. Citing

AttributeError: 'NoneType' object has no attribute 'get_text'

放肆的年华 提交于 2019-12-18 13:50:35
问题 I am parsing HTML text with Telephone = soup.find(itemprop="telephone").get_text() In the case a Telephone number is in the HTML after the itemprop tag, I receive a number and get the output ( "Telephone Number: 34834243244" , for instance). Of course, I receive AttributeError: 'NoneType' object has no attribute 'get_text' in the case no telephone number is found. That is fine. However, in this case I would like Python not to print an error message and instead set Telephone = "-" and get the

AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'

微笑、不失礼 提交于 2019-12-18 05:37:46
问题 Following on from my last question Error: No module named psycopg2.extensions, I have updated my mac OS to Mountain Lion and installed Xcode. I have also installed psycopg2 using 'sudo port install py27-psycopg2'. I am now trying to run 'python manage.py runserver' but am receiving this error AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF' Any help on how to fix this and get my localhost running? 回答1: From django docs: A Django settings file contains all the configuration of

AttributeError: 'Tensor' object has no attribute '_keras_history'

岁酱吖の 提交于 2019-12-18 04:34:23
问题 I looked for all the "'Tensor' object has no attribute ***" but none seems related to Keras (except for TensorFlow: AttributeError: 'Tensor' object has no attribute 'log10' which didn't help)... I am making a sort of GAN (Generative Adversarial Networks). Here you can find the structure. Layer (type) Output Shape Param # Connected to _____________________________________________________________________________ input_1 (InputLayer) (None, 30, 91) 0 _____________________________________________

AttributeError: 'Tensor' object has no attribute 'numpy'

谁说胖子不能爱 提交于 2019-12-17 20:43:17
问题 How can I fix this error I downloaded this code from GitHub. predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].numpy() throws the error AttributeError: 'Tensor' object has no attribute 'numpy' Please help me fix this! I used: sess = tf.Session() with sess.as_default(): predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval() And i get this error. Someone help me i just want it to work why is this so hard? D:\Python>python TextGenOut.py File

Python SQLAlchemy: AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema'

岁酱吖の 提交于 2019-12-17 19:33:22
问题 I tried creating a new database in my project, but I got this error when I run the script, I have another project using similar definition, it worked before, but now it get the same error now. I am using Python 2.7.8 and the version of SQLAlchemy module is 0.9.8. By the way, a project used Flask-SQLAlchemy, it works well. I am confused. The traceback information is following: Traceback (most recent call last): File "D:/Projects/OO-IM/db_create.py", line 4, in <module> from models import Base

Why is Tkinter widget stored as None? (AttributeError: 'NoneType' object …)(TypeError: 'NoneType' object …) [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-17 02:51:33
问题 This question already has an answer here : Why do my Tkinter widgets get stored as None? [duplicate] (1 answer) Closed 2 years ago . #AttributeError: 'NoneType' object has no attribute ... Example try: # In order to be able to import tkinter for import tkinter as tk # either in python 2 or in python 3 except ImportError: import Tkinter as tk root = tk.Tk() widget = tk.Label(root, text="Label 1").grid() widget.config(text="Label A") root.mainloop() Above code produces the error: Traceback

Python Json with returns AttributeError: __enter__

半世苍凉 提交于 2019-12-14 03:45:47
问题 Why does this return AttributeError: __enter__ Sorting method is just a string created based on how the list is sorted, and current time uses stfttime current_time = strftime("%Y-%m-%d %H-%M-%S", gmtime()) filename = f"Komplett-{str(sorting_method)}-{str(current_time)}.txt" if not os.path.exists(f'C:/Users/tagp/OneDrive/Dokumenter/Python/{filename}'): open(str(filename), "w+") with (filename, "w+") as json_data: my_list = {} my_list["products"] = [] for thing in my_products: my_list["products

Parse HTML file using Python without external module

允我心安 提交于 2019-12-14 02:50:31
问题 I am trying to Parse a html file using Python without using any external module. The reason is I am triggering a jenkins job and running into some import issues with lxml and BeautifulSoup (tried resolving it and I think somewhere I am doing over engineering to get my stuff done) Input : <tr class="test"> <td class="test"> <a href="a.html">BA</a> </td> <td class="duration"> 0.000s </td> <td class="zero number">0</td> <td class="zero number">0</td> <td class="zero number">0</td> <td class=

AttributeError: 'nt.stat_result' object has no attribute 'S_IWRITE'

南笙酒味 提交于 2019-12-13 18:02:06
问题 I am trying to delete a files. I check the date and delete if it is older than I want. I noticed that one .zip file was not deleting. It was read only, so in a bit of test code, I used the os.chmod(path, stat.S_IWRITE) and then os.remove(path) and it worked. I put this code into my main code and got the error. I import the os and stat module in both. Below is the test code that works, but when I put this into the bigger code I got the error and the full code this is just a def as well: