Python Basics-Day 4 assignment-employee Information Sheet Program

Source: Internet
Author: User

operational requirements and preliminary thinking

Employee Information Form procedures, to achieve additions and deletions to check the operation:

① can be used for fuzzy query , the syntax supports at least the following 3 kinds :

Select Name,age from staff_table where > 22select * from staff_table where dept = ' IT ' select * from Staff_table whe Re enroll_date like "2013" ②
    • solution : A python parsing problem with SQL statements that will convert the SQL statements entered by the user into actions that our code can perform correctly. For keywords where, values, limit, set, and like, create a new dictionary as the key value. After parsing the SQL statement, assign the appropriate information to value. For the table field name and age, use the For loop to print the dictionary to get the value of key for name and ages.

② find the information, after printing , the last side to show the number of found

    • Solution : read the JSON file into the dictionary, satisfy the conditional query to add new_dict, and use Len () to calculate the key value.

③ can create a new employee record , with the phone to do a unique key, staff_id need to increase

    • solution : Use phone number as the unique key, that is, the format in which the main dictionary is created in JSON is: {1390000000: {' name ': ' May Lol ', ' age ': All, ' staff_id ': xxxxxx, ' Enroll_date ': xxxxxxxx}}
    • staff_id self-increment, need to build in an ordered dictionary, import collection module, collections. Ordereddict

④ can delete specified employee information record, enter employee ID, delete

    • Delete the dictionary key and value

⑤ can modify employee information, the syntax is as follows:

UPDATE staff_table SET dept= "Market" where dept = "IT"
    • With ①

⑥ above requirements, to fully use the function, please do your utmost to reduce duplication of code

The approximately designed functions are:

    • Loaded_from_file: Reading JSON file
    • Write_into_file: Writing JSON files
    • Sql_parse:sql Statement Parsing
    • Add, delete, update, search: Add to search
    • Main: Inbound function

Knowledge points

1. Python parsing the execution of the SQL language: This is a very troubling question, this article is written in brief. The code is as follows:

Example

Sample 1

Sample 2

Sample 3

Detailed description Reference http://www.cnblogs.com/alex3714/articles/5740985.html

Python Basics-Day 4 assignment-employee Information Sheet Program

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.