Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
single range function
#1
Hey I need help to create multiple loops in a single statement as:

'''for n1,n2,n3 in range(1,501):
........code'''

**TypeError: cannot unpack non-iterable int object**
Reply
#2
What exactly do you mean? What would you expect that code to do if it were possible to write it? Also, why do you need to do something like this? Please give details so people can help you find appropriate solutions.
Reply
#3
(Oct-05-2020, 08:04 AM)ndc85430 Wrote: What exactly do you mean? What would you expect that code to do if it were possible to write it? Also, why do you need to do something like this? Please give details so people can help you find appropriate solutions.
I need the code to extract data from the web, however the problem is related to creating a single range statement.

for n1, n2 , n3, n4, n5 in range(1,501):
  buyer=browser.find_element_by_xpath('/html/body/form/div[4]/div[5]/div/div[4]/table/tbody/tr['f'{n1}'']/td[4]/a')
    buyer=buyer.text
    seller=browser.find_element_by_xpath('/html/body/form/div[4]/div[5]/div/div[4]/table/tbody/tr['f'{n2}'']/td[5]/a')
    seller=seller.text
and so on
Reply
#4
range will yield one number at a time (i.e. per each iteration). That said it's still not clear what you want to achieve.
Is it correct to assume you actually want to get
1, 2, 3, 4, 5
then
6, 7, 8, 9, 10
and so on?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 3,502 Aug-31-2021, 08:08 PM
Last Post: joelbeater992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020