Forum Discussion
Hi baxatob. I was asking like how to print only the first value?
Like from ['TC1138', 'TC996', 'TC1135', 'TC1138', 'TC1140'] i need to print only 'TC1138'.
Can you help with this problem?
my_list = [1, 2, 3, 4, 5] my_list[0] == 1 my_list[-1] == 5
etc...
You ask very fundamental questions. I believe you need to open Python's Tutorial where you will find all answers and more.
It's impossible to code something without that knowledge.
- Rajesh28 years agoContributor
baxatob I know to print the values from the list.
my_list = [1, 2, 3, 4, 5] my_list[0] == 1 my_list[-1] == 5
But i am not able to print using the script which you have sent
test_case_container = DDT.ExcelDriver("C:\\TestCases.xls", "Sheet1") def get_test_suite(test_case_container): tests_to_run = [] # creating an empty list
while not test_case_container.EOF(): if test_case_container.Value["ExecutionFlag(Y/N)"] == "Y": tests_to_run.append(test_case_container.Value["TCID"])
test_case_container.Next() return tests_to_runWhen i call this method inside a script i will get the result as ['TC1138', 'TC996', 'TC1135', 'TC1138', 'TC1140'].
Now i need to fetch the first value from the list.
I have tried with this code:
test_case_container = DDT.ExcelDriver("C:\\Users\\TESTPC\\Desktop\\TestDoc.xlsx", "Sheet1", True)
def get_test_suite():
tests_to_run = [] # creating an empty list
while not test_case_container.EOF():
if(test_case_container.Value["Execute-Flag(Y/N)"] == "Y"):
test=tests_to_run.append(test_case_container.Value["TCID"])
test_case_container.Next()
return tests_to_run
def test():
Log.Message(str(get_test_suite()))
A=[get_test_suite()]
Log.Message(str(A[1]))But i am not able to fetch the values. Can you please help with this problem?
- baxatob8 years agoCommunity Hero
Your code:
A = [get_test_suite()]
will provide the following result:
[ ["Value1", "Value2", "Value3"] ]
If you call A[0] it will return ["Value1", "Value2", "Value3"]
If you call A[1] it will raise an IndexError
However if you call A[0][0] it will return "Value1"
Try simply:
A = get_test_suite()
- Rajesh28 years agoContributor
baxatob Thank you for the answer. But I am getting the result as []
I tried with following ways
1. def test():
A=[get_test_suite(test_case_container)]
Log.Message(str(A[0]))2. def test():
A=[get_test_suite(test_case_container)]
Log.Message(A[0])3.def test():
A=[get_test_suite(test_case_container)]
Log.Message(str(A[0][0]))4.def test():
A=[get_test_suite(test_case_container)]
Log.Message(A[0][0])But i am not getting the values in Result. Can you please help me with this Baxatob.
Related Content
Recent Discussions
- 4 days ago
- 4 days ago