Reputation: 183
I get a little confused by this code snippet to detect duplicate names why PyCharm detects an Unresolved Reference "Error" to my variable mp3.
while mp3.title.upper() in [mp3.title.upper() for mp3 in songs]:
mp3.title += str(n)
n += 1
print(mp3)
songs.append(mp3) # Unresolved Reference to mp3 her
The code is running fine.
But would actualli really like to know, what's causing this and how eventually to solve it.
Thanks in advance
Upvotes: 0
Views: 176
Reputation: 662
Yes because your mp3 variable is declared twice at two different places 1.
`while mp3.title.upper()`
2.
[mp3.title.upper() for mp3 in songs]:
in first case it is obvious that mp3 is declared previously but in second case you overshadow the first one in for loop because now each item of song will be held by mp3
Upvotes: 1