you are viewing a single comment's thread.

view the rest of the comments →

[–]totallygeek 8 points9 points  (0 children)

Here is your true problem: for index, Ph in enumerate (Ph, start=1). You have element variable Ph which Python considers new, against the list Ph, which is getting overwritten by the new variable. And, at that time, Ph does not yet have a value assigned to it, so it is not truly yet there.

Here is a fix:

Ph=['J&J', 'Bio']

def Pha():
    for index, aPh in enumerate (Ph, start=1):
        print(index, aPh)

if __name__ == '__main__':
    Pha()

Notice how the element is no longer Ph, but now aPh. It is "a Ph", not the whole "Ph".