Os.path.isfile (Imgpath) = = False problem in Python due to Chinese path

Source: Internet
Author: User

Yesterday in the use of Python script processing files, encountered the problem, clearly the file exists, but in the Os.path.isfile (imgpath) = = False Judgment is always set up, In the first thought is the front and reverse slash windows and Linux caused by different, and later found because the Chinese path caused.

The following solutions have been consulted on the Internet:

Imgpath = Unicode (Imgpath, "UTF8")

Using the above statement to convert the encoding of the Imgpath, and then the judgment and subsequent image reading (using the CV2 module), there is no problem.

Os.path.isfile (Imgpath) = = False problem in Python due to Chinese path

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.