Count items in Infopath field - sharepoint-2010

I created a form in Infopath with a rich text box field. The field is used to keep a list of usernames (first and last). I want to be able to keep a of count each entry and keep a tally. I then want to use that total # of entries to add or subtract from other fields. Is there any way to do that?

Is the rich text box field just a large string? If so you could just use python's built in split function, and either split by ("\r\n"), or (",").
Example:
u = "Bob, Michael, Jean"
x = u.split(",")
X will be a list of usernames. If you are using line breaks for each new username, then replace (",") with ("\r\n").
Now to count the items in a list you just need to iterate on the list you created with a for loop.
Example:
b = 0
u = "Bob, Michael, Jean"
x = u.split(",")
for i in x:
b += 1 // b will be the number of usernames

Related

Python selenium get table values into List of Lists

I'm just trying to get the data from this table:
https://www.listcorp.com/asx/sectors/materials
and put all the values (the TEXT) into a list of lists.
I've tried so many different methods using--> xpath, getByClassName, By.tag
------------
rws = driver.find_elements_by_xpath("//table/tbody/tr/td")
---------------
table = driver.find_element_by_class_name("v-datatable v-table theme--light")
--------------
findElements(By.tagName("table"))
--------------
# to identify the table rows
l = driver.find_elements_by_xpath ("//*[#class= 'v-datatable.v-
table.theme--light']/tbody/tr")
# to get the row count len method
print (len(l))
# THIS RETURNS '1' which cant be right because theres hundreds of rows
And nothing seems to work to get the values in an easy way to understand the manner.
(EDIT SOLVED)
before doing the SOLVED solution below.
First do: time.sleep(10) this will allow the page to load so that the table can actually be retrieved. then just append all the cells to a new list. YOU WILL NEED MULTIPLE LISTS to fit all the rows.
So basically you can use find_elements_by_tag_name
and use this code
row = driver.find_elements_by_tag_name("tr")
data = driver.find_elements_by_tag_name("td")
print('Rows --> {}'.format(len(row)))
print('Data --> {}'.format(len(data)))
for value in row:
print(value.text)
Have proper wait to populate the data.

How to chose options in a while loop

My program --> I Will ask the user to introduce a number and I want to make that if the number is not in a random sequence (I choose 1,2,3) of numbers, the user need to write again a number until the number they enter is in the sequence:
a = (1,2,3)
option = int(input(''))
while option != a:
print('Enter a number between 1 and 3 !!')
option = int(input(''))
So as you can see I use the variable as a tuple but I don't know how to do it.. =(
Assuming the use of a tuple is obligatory, you will need to get input as a string, because it is iterable type. It will alow you easily convert to int, sign by sign, thru list comprehension. Now you have a list of ints, which you simply convert to a tuple. The final option variable looks:
option = tuple([int(sign) for sign in str(input(''))])
But consider keeping your signature in int instead of tuple. Int number is also unequivocal if its about sequence. In python 123 == 132 returns False. That way, you need only to replace:
a = (1,2,3)
by a:
a = 123
And script will works.

Web2py - SQLFORM.smartgrid: how to retrieve field name and value before submission

I use smartgrid with 'in the grid' edition of values. To do this, I use the .represent function to add the row_id to the variable name, so that I can retrieve what to update in request.post_vars, where I can retrieve the list of filed name, ids, with the submitted value.
But I'd like to identify what has been changed by the user in the smartgrid without making an additional I/O in the DB. Is there a global variable where the form fields and initial values are recorded before user change ? Or a function to extract form fields and values before sending it to the view?
db.define_table('cny',Field('f_cny'))
def tst():
tb = db.cny
if len(request.post_vars) >0:
d = {}
for k,v in request.post_vars.iteritems():
(f,sep,r) = k.partition('_r_')
if r:
if not r in d:
d[r] = {}
d[r][f] = v #should only be done if d[r][f] was changed!!!
for r in d:
if len(d[r]):
db(tb.id==r).update(**d[r])
tb.f_cny.represent=lambda v,r:string_widget(tb.f_cny, v, **{'_name':'f_cny_r_%s' % r.id})
f = SQLFORM.smartgrid(tb,
linked_tables=[],
selectable=(lambda ids:redirect(URL(request.controller,request.function,args=request.args))))
return dict(f=f)

Why does my text value not appear in matlab gui?

I've managed to retrieve 5 string values from my database whereby results = 'something1' 'something2' 'something3' 'something4' 'something5'. Now I want these values to display in my edit texts Matlab GUI. How do I do that? How to pass all values from results = curs.Data; to all 5 different set(handles.edit1,'String');?
%Assign data to output variable
results = curs.Data;
display(results);
%Diplay in edit texts matlab gui
set(handles.edit1,'String');
set(handles.edit2,'String');
set(handles.edit3,'String');
set(handles.edit4,'String');
set(handles.edit5,'String');
If results is a cell array then simply do:
set(handles.edit1,'String',results{1});
and repeat for each string. Or, if you wish, you can use arrayfun:
arrayfun(#(k) eval(['set(handles.edit' num2str(k) ',''String'',results{' num2str(k) '}); ']),1:5);

create unique Textboxes's control names

I have tried to create unique Textboxes control names for later use, i.e., assign corresponding values from datatables to each of textboxes. I have 128 questions of a survey in a datatable that are divided into group. For example, ABgroup.count = 4 meaning there are 4 questions for group AM. ACgroup.count = 18 and so on with total of 128 rows. Questions are categories into L (likeness), Y (yes/no), or C (comment). L has 4 possibilities of votes (strongly agree, agree, disagree, strongly disagree). I plan to create textboxes control name for AM group as following
datatable.count = 4
Q1: txtbx1.Name = AM100
L type: txtbx2.Name = AM100a; txtbx3.Name = AM100b; txtbx3.Name = AM100c; txtbx5.Name = AM100d
Q2: txtbox6.Name = AM101
Y type: txtbx7.Name = AM101y; txtbx8.Name = AM101n
Q3: similar as Q1
Q4 / C type: txtbx13.Name = AM103c
My question should I create textboxes controls separately for each group as described above? Or create something that dynamically create all textboxes control names? either way, can you please show me how to achieve it? Thank you.