Python Practice book A small program for the No. 0002 question every day

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2 __author__='Deen' 3 " "4 Title Description:5 Save the 200 activation codes (or coupons) generated by the 0001 questions to the MySQL relational database. 6 " "7 """8 import MySQLdb as MDB9 Ten config = { One ' host ': ' 127.0.0.1 ', A ' Port ': 3306, - ' user ': ' Root ', - ' passwd ': ', the ' db ': ' Student ', - ' charset ': ' UTF8 ' - } - conn = Mdb.connect (**config) + cursor = conn.cursor (cursorclass=mdb.cursors.dictcursor) -  +  A  at cursor.execute (' Set names GBK ') -  -  -  - n=0 - num=list () in  -  to For line in open ("Student12.txt"): + line=line.decode (' GBK '). Encode (' Utf-8 ') -  the n=n+1 *  $ if n%6==1:Panax Notoginseng Cursor.execute (' INSERT into student12 (SNO) VALUES (%s) '% (line)) -  the """ +  A ImportMySQLdb as MDB the  +Config = { -     'Host':'127.0.0.1', $     'Port': 3306, $     'User':'Root', -     'passwd':"', -     'DB':'ctf_test', the     'CharSet':'UTF8' - }Wuyiconn = Mdb.connect (* *config) thecursor = Conn.cursor (cursorclass=mdb.cursors.DictCursor) -Cursor.execute ('Set names GBK') Wu  -Cursor.execute ('CREATE TABLE codes (ID int (5), code char )') AboutWith open ('Poll_codes.txt','R') as FP: $      forLineinchfp.readlines (): -line = Line.strip ('\ n'). Split (':') -Cursor.execute ('INSERT into Codes VALUES (%s,%s)', line) -  A  + Conn.commit () the cursor.close () -Conn.close ()

Python Practice book A small program for the No. 0002 question every day

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.