Python filename conflicts with module name, error ' module ' object has no attribute ' strftime '

Source: Internet
Author: User

Import timeprint time.strftime ('%y%m%d%h%m%s')

The above applet is named time.py

Error message at run time:

Print time.strftime ('%y%m%d%h%m%s ')

Attributeerror: ' Module ' object has no attribute ' strftime '

After confirming that strftime is really a function of time, I thought it was a bug.

Then directly with the console run the above code, found that the correct results, the code is not a problem, it may be the name of the problem, the thought of here just suddenly found that the import module is time, and I give this Python file named time, is estimated to be a conflict.

The name of the test program that you wrote was changed from time.py to something else and then it worked.

Python filename conflicts with module name, error ' module ' object has no attribute ' strftime '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.