r/pythonhelp • u/Farzy0 • Aug 16 '22
UndefinedVariable issue in code.
Currently unable to run code due to throwing an undefined variable error. The "mod_emp_list" is whats giving the error, I'm relatively new to programming and would appreciate the help or tips to getting this figured out. I also added a link to show what the issue as well.
def main():
mod_emp_list = to_mod_list(employee_list)
print("Modified employee list: " + mod_emp_list + "\n")
print(f"List of usernames: {generate_usernames(mod_emp_list)}\n")
print(f"Initials and ids: {map_id_to_initial(employee_list)}")
if __name__ == "__main__":
main()
3
Upvotes
2
u/Goobyalus Aug 16 '22
Your print statements are not indented, so they are not part of the main function, they are part of the top level code. They execute before
if __name__ ...and there is nomod_emp_listin scope at the top level of the file.