Home > Backend Development > Python Tutorial > Is python process-oriented?

Is python process-oriented?

anonymity
Release: 2019-06-14 09:55:18
Original
7385 people have browsed it

Is python process-oriented?

Is python process-oriented?

1. Process-oriented: The core is the word process. The process refers to the steps to solve the problem. For example, designing an assembly line is a kind of Mechanical way of thinking.

means that the program is executed step by step from top to bottom, and the problem is solved step by step from top to bottom, from beginning to end. The basic design idea is that the program starts with solving a large problem, and then decomposes the large problem into many small problems or sub-processes. These sub-processes are then executed and then continue to be decomposed until the small problems are simple enough to be solved in one Solved in small steps.

2, Advantages and Disadvantages:

Advantages: Streamline complex problems and simplify them.

Disadvantages: Poor scalability

3, Example: Procedural-oriented login and registration program

import json,re
def login():
    '''
    用户输入
    :return:
    '''
    usename = input('用户名:').strip()
    pwd = input('密码:').strip()
    tel = input('电话:').strip()
    mail = input('邮箱:').strip()
    return {
        'usename':usename,
        'pwd':pwd,
        'tel':tel,
        'mail':mail
    }
def authentication(use_info):
    '''
    判断用户名和密码等信息是否合法
    :return:
    '''
    is_valid = True # 默认合法
    if len(use_info['usename'])==0:
        print('用户名不能为空!')
        is_valid = False
    if len(use_info[&#39;pwd&#39;])< 6:
        print(&#39;密码长度不得小于6位!&#39;)
        is_valid = False
    if len(re.findall(&#39;1[0-9]{10}&#39;,use_info[&#39;tel&#39;]))==0:
        print(&#39;电话格式不对!&#39;)
        is_valid = False
    if not re.search(r&#39;@.*?.com$&#39;,use_info[&#39;mail&#39;]).group(): # 使用Python的r前缀,就不用考虑转义的问题,&#39;*&#39;加个?就可以让&#39;.&#39;采用非贪婪匹配
        print(&#39;邮箱格式不对&#39;)
        is_valid = False
    return {
        &#39;valid&#39;:is_valid,
        &#39;info&#39;:use_info
    }
def register(auth):
    &#39;&#39;&#39;
    若输入信息合法则注册,写入文件或数据库
    :param auth:
    :return:
    &#39;&#39;&#39;
    if auth[&#39;valid&#39;]==True:
        with open(&#39;data.json&#39;,&#39;w&#39;,encoding=&#39;utf-8&#39;) as f:
            json.dump(auth[&#39;info&#39;],f)
def main():
    &#39;&#39;&#39;
    主逻辑程序
    :return:
    &#39;&#39;&#39;
    use_info = login()
    auth = authentication(use_info)
    register(auth)
if __name__==&#39;__main__&#39;: # 直接调用时执行下列程序,被调用时不执行
    main()
Copy after login

Note : It is generally believed that if you just write some simple scripts to do some one-time tasks, it is excellent to use a process-oriented approach, but if the tasks you want to handle are complex and require continuous iteration and maintenance, then It is most convenient to use object-oriented.

The above is the detailed content of Is python process-oriented?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template