7
Hello, I have the following module (did not want to put all the code here) in Python >= 3.6. It is already functional in the current state, although it does not handle all possible errors. But I want to, to practice, change some things. I’m not a programming professional, I’m actually a biologist, rsrs. But I use a lot of Python and mainly R in research. So I apologize if the code is not as efficient and clean as possible.
The module renames video files that are with their absolute number of episodes (25) instead of the standard per season (S02E03). Basically, he uses the package pymediainfo to detect videos in a folder and then uses the package tvdb_api to identify the series and import information about it. This information will be used in the process of changing the file name with absolute episode number to the default Season/Episode.
I’ve been trying to replace the links for creating the initial lists by list comprehension. I got for two of the lists (Season and episodes), but the third (absoluteNumbers) I have tried many ways and failed.
Basically I want to turn the following links for into list or Dict comprehension:
for key in show:
for value in show[key]:
absoluteNumbers.append(show[key][value]['absoluteNumber'])
Similar to the one done with the other two lists:
seasons = [key for key in show for value in show[key]]
episodes = [value for key in show for value in show[key]]
My initial attempt was:
[absNum for k in show for v in show[k] for absNum in show[k][v]['absoluteNumber']]
But the result is not what was expected, something like a list containing the sequence of absolute numbers of the series' episodes. For example, if we had two seasons of 10 episode the list would have the numbers from 1 to 20. What I get is an error:
TypeError: 'int' object is not iterable
Any suggestions?
Have you tried debugging and seeing what’s coming out, like printing out every value of that
for
? because this error occurs when you try to integer a whole type, make afor
with the numeral 1, then any language is half lost, because you can only know if it is a list,Arry dics . in this link can help you understand better.– Tmilitino
So, I did a debug and error is this same, in my version it tries to iterate a type None, the problem is that I can not get around it, the logic of this list comprehension is escaping me beautiful.
'NoneType' object is not iterable
– Rodrigo
can you give me an example of filename? See if I test here and give you a better answer
– Tmilitino
Dude, I went around here and put the file name of 'Leverage' a series. I see that there are some
absolutenumber
that this asNone
. What you can do to get around this is an accountant, since he goes through all the seasons and every time he passes is a new episode there will add up every step.– Tmilitino