D
D
Denis99992015-12-22 20:37:38
Python
Denis9999, 2015-12-22 20:37:38

Working with strings and types in Python 3?

I need to get a string in a loop, while the counter should be embedded in the middle of the string. As it turned out in python, even the data type cannot be changed. How then to solve such a problem?

i = 1
while i < 11:
  t = driver.find_element_by_xpath(".//*[@id='header']/li[" . i(счетчик)  .  "]/div[2]/div/cite")
  print(t)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-12-22
@sim3x

In [1]: for counter in range(1, 11):
   ...:         print(".//*[@id='b_results']/li[{}]/div[2]/div/cite".format(counter))
   ...:     
.//*[@id='b_results']/li[1]/div[2]/div/cite
.//*[@id='b_results']/li[2]/div[2]/div/cite
.//*[@id='b_results']/li[3]/div[2]/div/cite
.//*[@id='b_results']/li[4]/div[2]/div/cite
.//*[@id='b_results']/li[5]/div[2]/div/cite
.//*[@id='b_results']/li[6]/div[2]/div/cite
.//*[@id='b_results']/li[7]/div[2]/div/cite
.//*[@id='b_results']/li[8]/div[2]/div/cite
.//*[@id='b_results']/li[9]/div[2]/div/cite
.//*[@id='b_results']/li[10]/div[2]/div/cite

funny guys

V
Vladimir, 2015-12-22
@vintello

yes, I agree, some kind of misunderstanding. but pretty :)

for i in xrange(1,11,1):
            t = driver.find_element_by_xpath(".//*[@id='b_results']/li[%s]/div[2]/div/cite" %str(i))
            print(t)

G
GhoWh, 2015-12-22
@GhoWh

for i in range(1, 11):
    t = driver.find_element_by_xpath(".//*[@id='b_results']/li[" + str(i) +  "]/div[2]/div/cite")
    print(t)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question