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.
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 3 months ago.
Improve this question
I tried running this basic python script to print something, and it doesn't seem to be executing properly.
name = "Tyler";
print{name};
I am getting this error:
File "C:\Users\tyler\main.py", line 2
print{name};
^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
I tried changing line 2 to:
print(...)
but it prints out
Ellipsis, not my name.
You don't need semicolons in Python
The issue was the use of curly braces. Call your variable name with print() like this:
name = "Tyler"
print(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 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 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 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}
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.