PySide.QtGui.QListWidget' object has no attribute 'setItemSelected' - python

Extremely confused here... trying to select all items in a QListWidget. Strangely enough I have done this before fine with this code, but this time it is barking back at me?
# Error: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected'
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# ...............
# self.locListWidget.setItemSelected(item, True)
# AttributeError: 'PySide.QtGui.QListWidget' object has no attribute 'setItemSelected' #
if (sizeDimensionLocators > 0):
for loc in dimensionLocators:
self.locListWidget.addItem(loc)
for i in range(self.locListWidget.count()):
item = self.locListWidget.item(i)
self.locListWidget.setItemSelected(item, True) <---------- Issue Here

QListWidget doesn't have a setItemSelected:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QListWidget.html#PySide.QtGui.QListWidget
http://doc.qt.io/archives/qt-4.8/qlistwidget.html#selectedItems
You can do this though:
item.setSelected(true)
http://doc.qt.io/qt-5/qlistwidgetitem.html#setSelected
You might also need to review the selection mode:
https://srinikom.github.io/pyside-docs/PySide/QtGui/QAbstractItemView.html#PySide.QtGui.PySide.QtGui.QAbstractItemView.setSelectionMode

Related

Python-pycharm-oemof: Attribute Error with processing.results()

I have a problem with executing the function processing.results() in oemof.
It was working before, but after an update it didn't work any more.
Does anyone know how to fix it or which interpreter I need for oemof - oemof test says all is installed correct. Or is my code wrong?
Code:
64/# OPTIMIZATION MODEL
65/equipmentList = (electricity_bus, heat_bus, electricity_grid, electricity_supply,
electricity_storage, heat_supply, heat_storage, heat_pump, photovoltaics, excess_electricity)
66/for item in equipmentList:
67/ optimizationSystem.add(item)
68/model = solph.Model(optimizationSystem)
69/model.write('optimizationSystem_model.lp', io_options={'symbolic_solver_labels': True})
70/model.solve(solver='gurobi', solve_kwargs={'tee': True})
71/results = solph.processing.results(model)
Failure-Message:
Traceback (most recent call last):
File "C:/Users/TKurz/Desktop/NEFI Hackathon/Main.py", line 71, in <module>
results = solph.processing.results(model)
File "C:\Users\TKurz\AppData\Local\Programs\Python\Python38\lib\site-packages\oemof\solph\processing.py", line 125, in results
df = create_dataframe(om)
File "C:\Users\TKurz\AppData\Local\Programs\Python\Python38\lib\site-packages\oemof\solph\processing.py", line 89, in create_dataframe
for i in getattr(bv, "_index"):
AttributeError: 'IndexedVar' object has no attribute '_index'
THX for any help!
Yours Thomas

TypeError: NoneType object is not iterable

When I am iterating through my variable it gives me an error which I show as below.
Traceback (most recent call last):
File "C:\Users\ZHEN YUAN\Desktop\东航第一步\wen2.py", line 13, in <module>
for i in Names:
TypeError: 'NoneType' object is not iterable
Your function wenjian() does not have any return statements, so it will always return None, by default. That's why Names = wenjian(file) assigns the value None to Names, and so you can't iterate over Names with the for loop.
import os
def wenjian(file):
for root,dirs,files in os.walk(file):
for file in files:
filename = os.path.join(root,file)
print (filename[-28:])
file = ("C:\Users\ZHEN YUAN\Desktop\东航try")
Names = wenjian(file)
for i in Names:
print (i[1])
PS C:\Users\ZHEN YUAN> & python "c:/Users/ZHEN YUAN/Desktop/东航第一步/wen2.py"
\Desktop\东航try\C2002455.xlsx
Traceback (most recent call last):
File "c:/Users/ZHEN YUAN/Desktop/东航第一步/wen2.py", line 14, in <module>
for i in Names:
TypeError: 'function' object is not iterable

Why am I getting "TypeError: '_gdbm.gdbm' object is not iterable"?

This is my first time looking into the 'dbm' module as part of an exercise in a book and I can't figure out why I'm getting this error.
import dbm
db = dbm.open('chapt14/dbtest/captions', 'c')
db['cleese.png'] = 'Photo of John Cleese'
db['testeroni.png'] = 'Photo of Cohn Jleese'
for key in db:
print(key, db[key])
db.close()
Traceback (most recent call last):
File "/home/individuation/Documents/Code/ThinkPython/chapt14/dbtest/db_test.py", line 7, in <module>
for key in db:
TypeError: '_gdbm.gdbm' object is not iterable

AttributeError: 'builtin_function_or_method' object has no attribute 'split' 3.7

I need help to fix this code:
import urllib.request,urllib.parse,urllib.error
fhand = urllib.request.urlopen("http://data.pr4e.org//romeo.txt")
counts = dict ()
for line in fhand:
lines = line.decode.split()
for words in lines:
counts[words] = counts.get(words,0)+1
print(counts)
I am getting this error while running this code:
C:\Users\g.p\AppData\Local\Programs\Python\Python37-32>py urllib2.py
Traceback (most recent call last):
File "urllib2.py", line 5, in <module>
lines = line.decode.split()
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
you should run decode function, otherwise, it will be the built-in function not str, so you cannot split the function
You should write like this:
lines = line.decode().split()
For more info: Link

TypeError: 'numpy.int64' object is not iterable

Sorry I'm not that good at StackOverflow.
I'm trying to make a game bot with universe and i got an error saying:
[2018-09-14 07:28:33,723] Making new env: Taxi-v2
Traceback (most recent call last):
File "d:\pacmantest.py", line 8, in <module>
action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]
TypeError: 'numpy.int64' object is not iterable
The code is:
import gym
import universe
env = gym.make('Taxi-v2')
observation_n = env.reset()
while True:
action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]
observation_n, reward_n, done_n, info = env.step(action_n)
env.render()
If you execute print(type(observation_n)) immediately after observation_n = env.reset() it will likely print 'numpy.int64'. You can only iterate on iterable objects, such as lists, single values such as int64 are not iterable.
Switch the first two lines of your while loop. env.reset returns an int, while env.step returns a tuple.

Categories