I face a problem below.When I run another function related to this 'if',type error is "int() argument must be a string or a number, not 'Vec2D' ",then I cut off the int(),and the type error changes to "slice indices must be integers or None or have an index method ",wtf,waiting for someone's brilliant help.
def singleOrder(argument):
global position
global direction
if argument==']':
lastPosition=position[len(position)-1]
lastDirection=direction[len(direction)-1]
turtle.setposition(lastPosition)
turtle.setheading(lastDirection)
position=position[:int(lastPosition)]
direction=direction[:int(lastDirection)]
Removing the last element of a list is easy:
del L[-1]
Related
I read this
But when i'm passing string value in the variable at that time i'm getting error
Code :
type(${value}).__name__
Error:
Evaluating expression 'type(Robot).__name__' failed: NameError: name 'Robot' is not defined
String value converting as a variable
Please help me.
You should remove brackets {} around value and leave only $value.
Update to comment:
Robotframework treats everything as string unless you explicitly convert it to other datatype.
${value_str} Set Variable 4
${value_number} Convert To Number ${value_str}
${type1} Evaluate type($value_str).__name__
${type2} Evaluate type($value_number).__name__
Log ${type1}
Log ${type2}
I'm doing an introductory iOS developer's course, and am doing a cat-years calculator as an exercise. The following code returns the error:
Int(AgeInCatYears.text!) = CatsROld!
Error - Cannot assign to value: function call returns immutable value
In case it's important, the var CatsROld was set equal to Int(humanYears.text!)! * 7 one line earlier.
Any advice?
If you are setting value to the Label or textField then you need to simply set value (as String) to its property text, but you are try to convert the value to Int and then you assigning value of CatsROld to it, that is the reason you are getting this error. So simply write like AgeInCatYears.text = "\(CatsROld!)"
AgeInCatYears.text = "\(CatsROld!)"
Note: You are force wrapping CatsROld value with !, if you are 100% sure that it will not nil then its ok other wise you need to use if let or guard for optional wrapping.
This is the code I have written so far:
I am very new to python so am trying to use the most basic ways of accomplishing goals as possible as I currently don't know how to make it more efficient etc.
def simulateBeamRun(personlist, beam, times):
times = np.linspace(0,35,500)
templist = []
maxdeflectionlist = []
for t in times:
for i in personlist: #for each person instance
Tuple = personModel.person.loadDisplacement(t)
if 0 < Tuple(1) < beamModel.beam.L:
templist.append(Tuple)
else:
pass
return templist
File "beamSimulation.py", line 40, in simulateBeamRun
Tuple = personModel.person.loadDisplacement(t)
The error I am getting is:
TypeError: unbound method loadDisplacement() must be called with person instance as first argument (got float64 instance instead)
personlist is a list of lists each containing arrivalTime, weight, gait, speed for a given "person". This is so that it gives values to the constructor. Load displacement is the only other function in the person class:
class person(object):
"""This class models the displacement of a person's load as they run at
'speed' in one dimension. It assumes that the load is always concentrated
in a single point and that the displacement of that point is less than or
equal to the displacement of the person's centre of mass. Also the
displacement of the load will always be a multiple of 'gait'.
"""
def __init__(self, arrivalTime, weight, gait, speed):
"""This constructor function defines the person's weight, gait and
running speed as well as the time that they arrive at the position of
zero displacement.
"""
how do I fix this?
Given the limited code presented, some of this is just guessing, but it might point you in the right direction, at least:
There's no need to pass in the times argument if you're just going to immediately overwrite it with times = ....
You're not using maxdeflectionlist for anything, so it's not really needed (although maybe you're planning to later...).
Inside your for i in ... loop, i is your iteration variable, and should take each value successively from personlist. Guessing from variable names, these might be the person instances that you need to get displacements from, so the line that you're getting the error on should maybe be Tuple = i.loadDisplacement(t). If that's not the case, given your later comments, perhaps you need to instantiate a person object from the data in i - something like p = personModel.person(some, arguments, extracted, from, i), and then follow that with Tuple = p.loadDisplacement(t). Calling loadDisplacement() as you have is more appropriate for a class method or static method, not for an instance method, which is the essential meaning behind the error message you get. It's telling you that personModel.person is not a person instance - it's probably a class object.
The else: pass bit is sort of pointless.
I have a named tuple with values [x,y].
Both fields will hold strings.
My problem is ,I want to match the contents of the 'x' field and access the 'y' field of that index.
name_array_tuple_list
is the name of the list which holds the named tuples.
So far I have got this
print([x[0] for x in name_array_tuple_list].index('SNVT'))
Which prints the index of the matched value.
My question is how to access the y value of lets say the index 3.
You were very close. Try this:
print([point.y for point in name_array_tuple_list if point.x == 'SNVT'])
Interpret the code as follows:
print
a list of
y field contents
for every named tuple in a list
but only if the named tuple's x field matches SVNT
I need to access to items stored in a parameter that represents selected elements in a multiselect. I pass selected items from gsp to controller with the following code into the remoteFunction:
params: '\'receiptItemsSelected=\' + jQuery(this).val()'
Now, following the code found in discussion here, I use the closure to get each value, but if I perform a multiselect, the size of receiptItemsSelected is always 1, but value is, for example, 1,2. To get values as a list I've done the following in the controller
params.list("receiptItemsSelected")
but it does not give me two elements if I select two items in the multiselect, but always one element.
The question is: if I select two elements, how can I get each element and use it in the controller? And how can I have that elemnts as Long and not as String?
Thanks
If you're parameters are being passed with string representation of a list, e.g.:
http://yoursite.com/?receiptItemsSelected=1,2,3
You have to split the value using normal Groovy string manipulation and perform the type conversion yourself:
def receiptsAsLongs = params.receiptItemsSelected.split(',')*.toLong()
If your parameters are passed with the convention of repeated parameters makes a list, e.g.:
http://yoursite.com/?receiptItemsSelected=1&receiptItemsSelected=2
Then grails can convert this to a list for you using params.list(), but you must do the final String to Long conversion:
def receiptsAsLongs = params.list('receiptItemsSelected')*.toLong()
params.list() is intended for multi-valued parameters, i.e. it will work if you have
receiptItemsSelected=1&receiptItemsSelected=2
You may have more luck using serialize() rather than val() to build the request body.