[Python] execution environment-executable built-in functions

Source: Internet
Author: User
Document directory
  • Built-in function: BIFS
  • User Function: UDF
  • Built-in method: BIMs (only the corresponding bit has the corresponding BIM)
  • User method: UDM

Reference: First Half of chapter 14 of Python core programming

Built-in function knowledge:

Built-in function: BIFS

Attribute:
BIF. _ Doc __
BIF. _ name __
BIF. _ self __
BIF. _ module __
User Function: UDF

Attribute:
UDF. _ Doc _ document string
UDF. _ name _ function name
UDF. func_code byte compiled code object
UDF. func_globals global namespace dictionary
Name Space of UDF. func_dict function attribute
UDF. func_doc
UDF. func_name
UDF. func_closure

From the class perspective
Built-in method: BIMs (only the corresponding bit has the corresponding BIM) User method: UDM

Class instantiation is a "call" class.
Method binding and unbinding: Is there any instance to call the method?
Class method:
_ Init _ is equivalent to the constructor.

Executable object function: callable (OBJ) determines whether OBJ can be called, that is, whether the object can be called ().

def fun():    pass    callable(fun)Truefunc = fun()callable(func)False
Compile () allows programmers to quickly generate code objects at runtime, and then execute these objects using exec or eval ().
In [16]: help(compile)Help on built-in function compile in module __builtin__:compile(...)    compile(source, filename, mode[, flags[, dont_inherit]]) -> code object    Compile the source string (a Python module, statement or expression)    into a code object that can be executed by the exec statement or eval().    The filename will be used for run-time error messages.    The mode must be 'exec' to compile a module, 'single' to compile a    single (interactive) statement, or 'eval' to compile an expression.    The flags argument, if present, controls which future statements influence    the compilation of the code.    The dont_inherit argument, if non-zero, stops the compilation inheriting    the effects of any future statements in effect in the code calling    compile; if absent or zero these statements do influence the compilation,    in addition to any features explicitly specified.

The third parameter from the document is mode, which generally has three options.
'Eval' evaluable expression
'Singles' single executable statement
'Exec 'executable statement Group
Ex:

In [17]: eval_code = compile('3+3','','eval')In [18]: eval(eval_code)Out[18]: 6In [20]: single_code = compile('print "hello world"','','single')In [21]: exec single_codehello worldIn [24]: exec_code = compile("""   ....: print 'some num'   ....: for i in range(5):   ....:         print i   ....:     """,'','exec')In [25]: exec exec_codesome num01234

Eval (): evaluate the expression

In [26]: eval('100+100.0')Out[26]: 200.0
Exec (): accepts a parameter, executes the code object or string code, or obtains the code to open the program file for execution. Each execution reaches the end of the file.
In [28]: exec """   ....: print range(5)   ....: """[0, 1, 2, 3, 4]

Input (): A combination of eval and raw_input. eval (raw_input ())

In [30]: input('please a expression ')please a expression 3+3Out[30]: 6

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.