Python creates a Chinese folder in the current directory

Source: Internet
Author: User

Whim, did a picture crawler downloader, because no time have to manually set up the picture directory, so Baidu the next Chinese directory establishment method, helpless before a few answers are not completely correct, so here want to integrate under.

In order to set up the Chinese directory, it is of course to find the current directory, two lines

1 Import OS 2 Cur_path = Os.path.abspath (Os.curdir)

In fact, there are several ways to output the current directory, please Baidu, we do not repeat here. The rest is to set up a Chinese directory, in plain language to establish a Chinese directory or coding problems, Python can not directly output Chinese characters, so want to set up a Chinese directory to the Chinese character string encoding as gb2312, the code is as follows

 1  import   sys  2  reload (SYS)  3  sys.setdefaultencoding ( " utf-8  "  )  4  word = "  Chinese blahblah   " 5  goal_path = Cur_path +  " \\   " + word.encode ("   gb2312   " )   6  Os.mkdir (Goal_path) 

The Chinese catalogue has been built here.

Python creates a Chinese folder in the current directory

Related Article

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.