Python core programming version 2, 437th page, Chapter 2 exercises continued 2-answers to Python core programming-self-developed-

Source: Internet
Author: User

This is a self-made exercise and may be incorrect. You are welcome to discuss and discuss various optimization and reconstruction solutions.
Based on feedback or code review, the updated answers or related content of this article will be added to the comments of this blog.
We will try to ensure that the answer code for each question is complete, not just functions, classes, or just a rough idea. We strive to open the Python 2.7 IDLE and copy the complete code to debug and run it.
Welcome to Balian's blog home. Http://www.cnblogs.com/balian

[This blog may be disappointing. Sorry]

14-9.
Shells. Create a shell (Operating System Interface) program. Provides the command line interface (any platform) for receiving operating system commands ).
Additional Question 1: pipelines are supported (see dup (), dup2 (), and pipe () functions in the OS module ). The MPs queue process allows standard inputs of a process to be connected to another process.
Additional Question 2: brackets are used to support reverse-order pipelines. A functional programming interface is provided for shell. In other words, it supports more functional styles, such as sort (grep (ps (-ef), root),-n, + 1 ), instead of ps-ef | grep root | sort-n + 1.
[Unfinished]
I feel difficult. I am temporarily suspended.

14-10.
Comparison Between fork ()/exec * () and spawn. What is the difference between the fork ()-exec * () pair and the spawn * () family function? Which group has better functions?
[Unfinished]
I feel difficult. I am temporarily suspended. However, you can reference the 429th page table 14.6 and
Http://blog.csdn.net/small_tina/article/details/8071791

14-11.
Generate and execute Python code. Use the funcAttrs. py script (for example, 14.4-Actually it should be 14.2, page 425th) to add the test code to the functions of the existing program. Create a test framework. Every time you encounter a special function attribute, it will run your test code.
[Unfinished]
I feel difficult. I am temporarily suspended. The funcAttrs. py script code is as follows:

def foo():    return Truedef bar():    'bar() does not do much'    return Truefoo.__doc__ = 'foo() does not do much'foo.tester='''if foo():    print 'PASSED'else:    print 'FAILED''''for eachAttr in dir():    obj = eval(eachAttr)    if isinstance(obj, type(foo)):        if hasattr(obj, '__doc__'):            print '\nfunction "%s" has a doc string:\n\t%s' % (eachAttr, obj.__doc__)        if hasattr(obj, 'tester'):            print 'function "%s" has a tester... executing' % eachAttr            exec obj.tester        else:            print 'Function "%s" has no tester... skip ping' % eachAttr    else:        print '"%s" is not a function' % eachAttr

[Execution result]

"__builtins__" is not a function"__doc__" is not a function"__file__" is not a function"__name__" is not a function"__package__" is not a functionfunction "bar" has a doc string:bar() does not do muchFunction "bar" has no tester... skip pingfunction "foo" has a doc string:foo() does not do muchfunction "foo" has a tester... executingPASSED

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.