简体   繁体   中英

Working in PyDev console , But not when running in eclipse

I am learning python with PythonCook Book. I came across a scenario and i dont know why this happens. The below code is working fine when i run it in PyDev console.

>>> user_record =('Dave', 'dave@example.com', '773-555-1212', '847-555-1212')
>>> name, email, *phone_numbers = user_record
>>> name
'Dave'
>>> email
'dave@example.com'
>>> phone_numbers
['773-555-1212', '847-555-1212']

But when i run the code in Eclipse , i get the following error like 'undefined variable name'

Whats the concept here ? i am really new to python

This is the file I ran. It works. I don't know why it is giving you an error unless you put ">>>" in the file.

def main():
    user_record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212')
    name, email, *phone_numbers = user_record
    print(name)
    print(email)
    print(phone_numbers)
# end main

if __name__ == "__main__":
    main()

output:

Dave
dave@example.com
['773-555-1212', '847-555-1212']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM