Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
for element in self.table1.find({'ji': {'$ne': ""}}):
gongLiNian = int(element['gongLiNian'])
gongLiNianScope = [str(gongLiNian-1), str(gongLiNian), str(gongLiNian+1)]
res = self.table2.find_one({'guanZhi' : element['guanZhi'],
'gongLiNian' : {'$in', gongLiNianScope},
'name' : element['name']})
For this code, here is the error:
Traceback (most recent call last):
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 172, in <module>
oneJi.run()
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 158, in run
res1 = self.step1()
File "C:\Users\elqstux\Desktop\study\History\oneJi.py", line 44, in step1
'gongLiNian' : {'$in', gongLiNianScope},
TypeError: unhashable type: 'list'
But i can't find any clue from the error.Could you give me some advise?
See the comma here:
{'$in', gongLiNianScope}
that is a syntax to initialize a set and you can put only hashable data types into a set.
Instead, you meant to have a dictionary:
{'$in': gongLiNianScope}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
After fighting for hours, I need your help.
On a JSON response, I'd like to get ONE result from it.
Here how look the JSON file:
I want the result to be "Desnoss" only and only once.
data = json.loads(response)
print("%s" % (data["0"]["team"]["0"]["name"]))
Traceback (most recent call last):
File "c1.py", line 48, in <module>
print("%s" % (data["0"]["team"]["0"]["name"]))
TypeError: list indices must be integers or slices, not str
Thanks a lot
Pls. try following. 0 is the index and not "0"
print("%s" % (data[0]["team"][0]["name"]))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
im writing the code below:
def add_to_index(index,keyword,url):
i=0
while i<=len(index):
if keyword in index[i]:
index[i][1].append(url)
else:
index.append([keyword,[url]])
i=i+2
Im curious because when I define the index as
index = []
gives me the error list out of range, whats makes sense because there is no entry in my list, but when I define the index as
index=[['udacity',['http_qualquer'],['udacity',['http_any']]]
the error is:
Traceback (most recent call last):
File "vm_main.py", line 33, in <module>
import main
File "/tmp/vmuser_azqmlozsjr/main.py", line 18
def add_to_index(index,keyword,url):
^
SyntaxError: invalid syntax
And there is no error in the syntax of this specific line, if the syntax was wrong the error should have appeared when the index was empty.
use index this one
It should end with four brackets
check that number of open brackets should match number of closed brackets
index=[['udacity',['http_qualquer'],['udacity',['http_any']]]]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create packed binary data, using struct.pack() in python3.x
It is giving me the below error, but I am unable to understand.
packed1 = struct.pack('>i4', 7, 8)
errorTraceback (most recent call last)
<ipython-input-823-a27a6bc07ff4> in <module>()
----> 1 packed1 = struct.pack('>i4', 7, 8)
error: repeat count given without format specifier
The repeat count should be before the i
struct.pack('>4i', 7, 8, 3, 2)
Also you need 4 parameters not only 2
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to open websites in python. Lets cut to the chase.
import webbrowser
webbrowser.open('http://google.com')
(my code)
Traceback (most recent call last):
File "C:\Python27\webbrowser.py", line 1, in <module>
import webbrowser
File "C:\Python27\webbrowser.py", line 3, in <module>
webbrowser.open('http://google.com')
AttributeError: 'module' object has no attribute 'open'
PS C:\Users\ug>
(my error)
What did I do wrong?
import webbrowser
alink = 'http://eample.com'
new = 2
webbrowser.open(alink, new=new)
If this doesn't work, run this and post the output: dir(webbrowser)
webbrowser.py is the same name as the import module. Try renaming the file to wbrowser.py and see if this helps.
To summarize and clarify the comments:
Rename C:\Python27\webbrowser.py to webbrowser_test.py
Delete C:\Python27\webbrowser.pyc and C:\Python27\webbrowser.pyo
Run python webbrowser_test.py and you should get the desired results.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I run the following in Python 2.7
import numpy
a = numpy.ndarray(shape=(2,2), dtype=float, order='F')
print numpy.mean(a)
numpy.savetext('foo.txt', a)
and get this result
[me#foo bar]$ python f.py
8.79658981512e-317
Traceback (most recent call last):
File "f.py", line 4, in <module>
numpy.savetext('foo.txt', a)
AttributeError: 'module' object has no attribute 'savetext'
What's wrong?
It's numpy.savetxt, without the e.