Use python to change the SQL format file to the desired format,

Source: Internet
Author: User

Use python to change the SQL format file to the desired format,

Insert into ttt (NSAME, ID, AGE) VALUES ('aaa', '20140901', '22 ');


Change the preceding SQL format to the following format.


AAA | 201023210816 | 22

Import oslists = [] paths = OS. getcwd () for root, dirs, files in OS. walk ('wfyh'): for fn in files: lists. append (fn) for nmb in lists: dfile = open ("wfyh \" + nmb, 'R') nmbb = nmb. replace ('. SQL ', '') ofile = open (" wf_test \ "extends nmbb1_'.txt', 'w') lists = [] for line in dfile: m = line. split (') [2]. replace (');',''). replace (',', '| '). replace ('\ '','') t = ''. join (m. split () lists. append (t) for linet in lists: ofile. write (linet + '\ n') dfile. close () ofile. close ()

Write the converted txt file into a folder.




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.