Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: range expected at most 3 arguments, got 4

from selenium import webdriver
import openpyxl as excel


def bacaKontak(namafile):
    # Load File Excel 
    file = excel.load_workbook(namafile, data_only=True)


    # Load Data 
    setting = file['Setting']
    colNomor = setting['B2'].value
    colPesan = setting['B3'].value
    jedaKirim = setting['B4'].value
    jumlahKirim = setting['B5'].value


    print(jedaKirim)

    # Load Database
    database = file['Database']
    dataKontak = database[colNomor]
    dataPesan = database[colPesan]

    # Pengulangan
    for cell in range(1, jumlahKirim+1):
        kontak = dataKontak[cell].value

        print (kontak)

    targets = bacaKontak("./Sett.xlsx")

I got 2 errors :

  1. File "C:\Users\Jtresst\Desktop\WAbot\kirimwa.py", line 32, in
    targets = bacaKontak("./Sett.xlsx")
  2. File "C:\Users\Jtresst\Desktop\WAbot\kirimwa.py", line 26, in bacaKontak
    for cell in range(1,jumlahKirim,1):
    TypeError: ‘float’ object cannot be interpreted as an integer

how to resolve them please? I use py ver 3.9

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You probably want to coerce to int, as range won’t accept a float

for value in range(1, int(some_input) + 1):
    ...
>>> range(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
>>> range(int(10.0))
range(0, 10)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading