how to make a command in kivy with a variable? - image

I have been using kivy but need help with a problem. I try to run this
def go(self, value, value2):
self.value2.source = 'Graphics\\Tiles\\' + value + '.png'
But every time it tells me value2 is not a property for newgame(my class). It works if I give the image name but I need to make it identify value2 as an argument. How do I do this?

If you are sending value2 as parameter you shouldn't use self, like this:
def go(self, value, value2):
value2.source = 'Graphics\\Tiles\\' + value + '.png'
The error you are getting is because value2 is not defined anywhere else on your class.

Related

Unable to locate element by giving variable name inside XPATH

brand_name = 'LACOSTE'
element = browser.find_element_by_xpath("//*[text()= brand_name]")
This is giving error. However, if i do like this:
element = browser.find_element_by_xpath("//*[text()= 'LACOSTE']")
then element is found.
But i dont want to hardcode the value. Please help.enter image description here
The XPath needs apostrophe's around the search-string, so I think you need to concatenate the XPath expression like this
element = browser.find_element_by_xpath("//*[text()='" + brand_name + "']")

Evaluate String value in jmeter

I want to evaluate the value of SEATID.
Find my code below.
String res2[0] = "40B";
vars.put("SEAT_ID",res2[0]);
When i am trying the get the value of SEATID in a string i am not getting the actual value of SEATID.
String otherSampler = vars.get("{"seatCode":"${SEAT_ID}");
Output is coming as : {"seatCode":"${SEAT_ID}
Expected output : {"seatCode":"40B"}
I am wring the code in Beanshell pre processor. Please help.
You need to use vars.get on SEAT_ID
String otherSampler = "{\"seatCode\":\"" + vars.get("SEAT_ID") + "\"}"
Your code is wrong. Try using this for declaring SEAT_ID variable:
vars.put("SEAT_ID","{\"seatCode\":\"" + res2[0] + "\"}");
Then you could use:
String otherSampler = vars.get(SEAT_ID);
To get:
{"seatCode":"40B"}

After performing string.slice() return string with part removed

Im sure this is very obvious but I cant seem to get it work.
I have a Pathname instance and Im attempting to remove the first directory from it and then return the rest of the string, but because slice returns the part removed it seems there is no way of getting the smaller string back.
filepath = Pathname.new("this_folder_needs_to_go/another_folder/file.html")
filedir = filepath.to_s.slice("this_folder_needs_to_go/")
newfilepath = filedir
I would hope newfilepath would be another_folder/file.html but instead it just returns this_folder_needs_to_go/
So how on earth to I get the string that has had the part removed?
Using String#split:
"this_folder_needs_to_go/another_folder/file.html".split('/', 2)[1]
# => "another_folder/file.html"
You can also use .slice! instead of .slice if you're trying to modify your string
filepath = Pathname.new("this_folder_needs_to_go/another_folder/file.html")
filepath.to_s.slice!("this_folder_needs_to_go/")
puts filepath ==> "another_folder/file.html"
Though that will affect your filepath variable irreversibly.
#partition will also work in a similar manner to #split
filepath = Pathname.new("this_folder_needs_to_go/another_folder/file.html")
file_dir = filepath.partition("this_folder_needs_to_go/")[-1]
file_dir
#=> "another_folder/file.html"
#partition returns [head,sep,tail] so this will look like ["","this_folder_needs_to_go","/another_folder/file.html"] the [-1] says get the last element.

How to modify the value of a variable whose name is given

I wish to have a method that takes in a string, and then updates a variable with the name of that string. This is an example of my attempt:
#other_class = OtherClass.new()
def change_variable(variable_string)
self.#other_class.send.variable_string += 1
end
I am getting the error:
syntax error, unexpected tIVAR
with the pointer just before 'send' in the method above. Does anyone have any suggestions to make this work?
You probably want instance_variable_set http://ruby-doc.org/core-2.0/Object.html#method-i-instance_variable_set
The syntax using your variables is I think:
other_var = ('#' + variable_string).to_sym
#other_class.instance_variable_set( other_var, #other_class.instance_variable_get( other_var ) + 1 )
The immediate syntatic error is that you're using self and # wrongly.
Either one is fine but not in conjunction with each other.
So in your case self.other_class.send... would be fine but then you cant declare it as #.
As would # be but then you cant do self.
These are meant to do different things and these are that
# is an instance variable and so is self but the difference is that using # calls the attribute other_class directly as to where self calls the method other_class.
So # is both a getter and setter in one so you can do
#other_class = my_milk_man as to where
self.other_class -> self.other_class (as getter),
self.other_class = my_milk_man -> self.other_class= (as setter).

Adding conditional attributes with Builder::XmlMarkup

Say I have two variables (value1 and value2) and either could be nil, how can I create an element using XmlMarkup and only add the attributes that are not nil?
If I do this
xm = Builder::XmlMarkup.new
xm.item(:attribute1=>value1, :attribute2=>value2)
and both value1 and value2 are nil, I still get
<item attribute1="", attribute2=""/>
I have also tried to add the attributes after creating the element but had no success and I cannot figure out if this is even supported.
If it is not already apparent, I am a complete ruby beginner so any input would be appreciated.
I think something like this could work:
xm = Builder::XmlMarkup.new
attributes = {}
attributes[:attribute1] = value1 if value1
attributes[:attribute2] = value2 if value2
xm.item(attributes)
If you have more than a couple of attributes I can show you a way to minimize duplication with a similar method too.

Resources