Search code examples
pythonlistcycle

In the 'for' cycle, when using '.append', it turns out 'none'


When adding new information to the list using '.append', I get none.

data = []
for e in movie:
    ru_name = print(e.find('div', class_='base-movie-main-info_mainInfo__ZL_u3').find('span', class_='styles_mainTitle__IFQyZ styles_activeMovieTittle__kJdJj').text)
    original_name = print(e.find('span', class_='desktop-list-main-info_secondaryTitle__ighTt').text)
    remain = print(e.find('div', class_='styles_main__Y8zDm styles_mainWithNotCollapsedBeforeSlot__x4cWo').find('span', class_='desktop-list-main-info_truncatedText__IMQRP').text)
    rate = print(e.find('span', class_='styles_kinopoiskValuePositive__vOb2E styles_kinopoiskValue__9qXjg styles_top250Type__mPloU').text)
    link = print("https://www.kinopoisk.ru"+e.find('a',class_= 'base-movie-main-info_link__YwtP1').get('href'))
    
    data.append([ru_name, original_name, remain, rate, link])

I don't understand why none is on the list. I looked at a lot of topics on this question, and it seems like I have everything right, at the end of the cycle without a 'print', just adding a 'date.append' to the list. If I add to the list before the cycle, then everything is displayed correctly. I can't understand why this is happening.


Solution

  • The print function returns None so any value given to the print function just returns None. So ru_name = print(e.find(...) also return the None. Means ru_name is set to None.

    data = []
    for e in movie:
        ru_name = e.find(...
        original_name = e.find(...
        remain = e.find(...
        rate = e.find(...
        link = "https://ww.kinopoisk.ru" + e.find(...
    
        ## if you also want to print these then
    
        print(ru_name)
        print(original_name)
        print(remain)
        print(rate)
        print(link)
    
        ## Append to the list
        data.append([ru_name, original_name, remain, rate, link])