Could you please check the code. Why does it give me an error.
figure()
vals = []
dieVals = [1,2,3,4,5,6]
for i in range(10000):
vals.append(random.choice(dievals)+random.choice(dievals))
hist(vals, bins=11)
show()
and following is the error
Traceback (most recent call last):
python files\lec18.py", line 25, in <module>
vals.append(random.choice(dievals)+random.choice(dievals))
NameError: name 'dievals' is not defined
Variable names are case sensitive. You have dieVals and further you try to access dievals.
You have a typo between
dieVals
and
dievals
^
^
the error message is giving you a big clue about this. Change dievals to dieVals in both places it appears in the code inside your loop.
Related
I used a new notebook within colab, and the same code worked just fine. This probably is a colab-related issue. 1: https://i.stack.imgur.com/zzamQ.png
I'm still curious as to why it happened though.
def function(a,b,c):
temp = a
for i in (b,c):
if i > temp:
temp = i
return temp
function(43,54,12)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-127543af6285> in <module>()
----> 1 function(43,54,12)
NameError: name 'function' is not defined
[1]: https://i.stack.imgur.com/atmRn.png
Call to function should be done after the function is declared and defined as the interpreter first interpret the function and then evaluate the function call.
Make sure you call function(43, 54, 12) after the function itself is defined.
Also make sure you change the indentation from 2 space to 4 spaces when pressing Tab by going in Tools > Setting > Editor and changing:
Other than that after installing new packages, the kernel needs to be restarted. Sometimes just restarting the kernel refreshes the environment and fixes the issues.
Excuse the debugging question, new to coding in general. Cannot understand why my code suddenly wont run.
I have checked for typos which seems to not be my problem.
filepath = '/proper_noun.txt'
def pluralize(word):
proper_nouns = [line.strip() for line in open (filepath)]
for item in proper_nouns: ### print out the list once.
if (item==[-1]):
break;
currently working in google colab.
At this point, I'm just trying to return the items from 'proper_nouns' into a list to get the ball rolling. Any ideas?
print (proper_nouns)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-29-c6832e0493e8> in <module>()
----> 1 print (proper_nouns)
NameError: name 'proper_nouns' is not define
Thanks guys. I hope this question follows SOF etiquette
Since you are working on Google Colab, my guesss is that you accidentally don't run the code from the beginning (from example if you selected the code starting from for item in proper_nouns: and only run the selected part, or if you split your program in different cells), and therefore proper_nouns is not defined yet.
Please make sure you run everything and tell us if that was it.
EDIT: I just thought of another option: is the line print(proper_nouns) in the pluralize function? If not, the scope of proper_nouns being the function, it's normal that it is not defined outside of the function. To access it from the outside, you must either declare it outside the function, or return it.
I tried to add a new node following the example but:
myitems = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
myitems['abc'].append('test')
gives me an error:
Traceback (most recent call last):
File "item_updater.py", line 148, in <module>
myitems['wohnung'].append('test')
AttributeError: 'CommentedMap' object has no attribute 'append'
I am using ruamel.yaml v0.13.7
What am I doing wrong?
Your error doesn't come from the example you indicated, as in the inp of the example there is no wohnung that shows up in your error.
You probably forgot a - somewhere:
wohnung:
a: 1
instead of:
wohnung:
- a: 1
only on the latter you can append using myitems['wohnung'].append('test').
The example works, but without showing your real YAML input it is difficult to see what is the exact cause of your error.
I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.
I have a problem with using DLL function in python.
I looked the name of function by dint of "dumpbin".
For example
_xGraphics3D#20
I tried to call the function like this:
from ctypes import *
xorsLib = cdll.LoadLibrary("Xors3D.dll")
width = c_int(800)
height = c_int(600)
depth = c_int(32)
mode = c_int(0)
vsync = c_int(0)
xGraphics3D = getattr(xorsLib,"_xGraphics3D#20")
xGraphics3D(width, height, depth, mode, vsync)
but it's cause the error:
Traceback (most recent call last):
File "D:/Coding/Python/pyASG/main", line 11, in <module>
xGraphics3D(width, height, depth, mode, vsync)
ValueError: Procedure called with not enough arguments (20 bytes missing) or wrong calling convention
what am i doing wrong?
p.s. i haven't know python, but i learn it. i read ctype-manual and tried to find answer...
p.p.s sorry for my awful english.
Try use windll instead of cdll.
xorsLib = windll.LoadLibrary("xors3d.dll")
http://docs.python.org/release/3.1.5/library/ctypes.html
The reason is the same as martineau commented.