Python implementation of the file in the picture generated with tagged TXT file __python

Source: Internet
Author: User
Tags python script

In depth learning you often need to generate a list of tagged picture names, xxxlist.txt files, and write a simple Python script to generate the file list below.

Import OS
def generate (Dir,label):
    files = Os.listdir (dir)
    files.sort ()
    print ' **************** '
    print ' input: ', dir
    print ' Start ... '
    listtext = open (dir+ ' \ \ ' + ' list.txt ', ' W ') for
    file in files:
        FileType = os.path.split (file)
        if filetype[1] = = ' txt ':
        name = file + ' + str (int (label)) + ' \ n ' C12/>listtext.write (name)
    listtext.close ()
    print ' down! '
    print ' **************** '    

if __name__ = = ' __main__ ':  
    generate (' C:\\users\\desktop\\image ', 1)    

Running the script generates a list.txt file in the image folder, and each picture has a label of 1.

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: 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.