| 
 
 
 
 hash, sum, super, idlen, max, min, next, sumdelattr, dir, getattr, globals, locals, setattr, varsascii, format, reprinput, open, print __import__breakpoint, @classmethod, compile, eval, exec, help, @staticmethod 
Draft for Information Only ContentPython Built-in Conversion Functions
 breakpoint()Parameters
 Remarks
 
 @classmethodParameters
 Remarks
 
 compile()Parameters
 Remarks
 
 eval()Parameters
 Remarks
 
 exec()Parameters
 Remarks
 
 help()Parameters
 Remarks
 
 @staticmethodParameters
 Remarks
 Source and Reference
 
Python Built-in Conversion Functions
The Python interpreter has some built-in conversion functions.
     breakpoint()
breakpoint(*args, **kws)Parametersbreakpoint()to drop into the debugger at the call site.*argsto specify the arugments**kwsto specify the keyword arugmentsRemarksSpecifically, it calls sys.breakpointhook(), passingargsandkwsstraight through.By default, sys.breakpointhook()callspdb.set_trace()expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly import pdb or type as much code to enter the debugger. However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice.Raises an auditing event builtins.breakpoint with argument breakpointhook.
 @classmethod
@classmethodParameterstype()to transform a method into a class method.RemarksA class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
            class C:
    @classmethod
    def f(cls, arg1, arg2, ...): ...The @classmethod form is a function decoratorA class method can be called either on the class (such as C.f()) or on an instance (such as C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.Class methods are different than C++ or Java static methods. If you want those, see staticmethod()
 compile()
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)Parameterscompile()to compile the specifiedsourceinto a code or AST object.sourceto specify thesourceto be returned from.filenameto specify the file from which the code was readmodeto specify what kind of code must be compiledflagsto control which future statements affect the compilation ofsource.dont_inheritto control which future statements affect the compilation ofsource.optimizeto specifies the optimization level of the compiler.RemarksCode objects can be executed by exec()oreval()sourcecan either be a normal string, a byte string, or an AST objectfilenamepass: some recognizable value if it wasn't read from a file ('<string>"is commonly used).modecan be'exec'ifsourceconsists of a sequence of statements;'eval'if it consists of a single expression; or'single'if it consists of a single interactive statement (in the latter case, expression statements that evaluate to something othe thanNonewill be printed.If neither flagsnordont_inheritis present (or both are zero), the code is compiled with those future statements that are in effect in the code that is callingcompile()If flagsis given anddont_inheritis not (or is zero) then the future statements specified by theflagsargument are used in addition to those that would be used anyway.If dont_inheritis a non-zero integer then theflagsargument is it -- the future statements in effect around the call to compile are ignored.Future statements are specified by bits which can be bitwise ORed together to specify multiple statements. The bitfield required to specify a given feature can be found as the compiler_flagattribute on the_Featureinstance in the__future__module.The optional argument flagsalso controls whether the compiled source is allowed to contain top-levelawait,async forandasync with. When the bitast.PyCF_ALLOW_TOP_LEVEL_AWAITis set, the return code object hasCO_COROUTINEset inco_code, and can be interactively executed viaawait eval(code_object)The default value of optimizeis -1.optimizeselects the optimization level of the interpreter as given by-ooptions. Explicit levels are 0, (no optimization;__debug__is true), 1 (asserts are removed,__debug__is false), or 2 (docstrings are removed too).If the compiled source is invalid, compileraisesSyntaxErrorIf the source contains null bytes, compileraisesValueErrorRaises an auditing event compilewith argumentssourceandfilename. This event may also be raised by implicit compilation.When compiling a string with multi-line code in 'single'or'eval'mode, input must be terminated by at least one newline character. This is to facilitate detection of incomplete and complete statements in thecodemoduleIt is possible to crash the Python interpreter with a sufficiently large/complex string when compiling to an AST object due to stack depth limitations in Python’s AST compiler.
 eval()
eval(expression[, globals[, locals]])Parameterseval()to return the result of the evaluated expression.expressionto specify the expression to be evaluated[globals]optional, to specify the globals to be used[locals]optional, to specify the locals to be usedRemarksglobalsmust be a dictionary.localscan be any mapping object.expressionis parsed and evaluated as a Python expression using theglobalsandlocalsdictionaries as global and local namespace.If the globalsdictionary is present and does not contain a value for the key__builtins__, a reference to the dictionary of the built-in modulebuiltinsis inserted under that key beforeexpressionis parsed. This means that expression normally has full access to the standardbuiltinsmodule and restricted environments are propagated. If thelocalsdictionary is omitted it defaults to theglobalsdictionary. If both dictinaries are omitted, the expression is executed with theglobalsandlocalsin the environment whereeval()is called.eval()does not have access to the nested scopes (non-locals) in the enclosing environment.The return value is the result of the evaluated expression. Syntax errors are reported as exceptions.This function can also be used to execute arbitrary code objects (such as those created by compile(). In this case pass a code object instead of a string. If the code object has been compiled with'exec'as themodeargument,eval()'s return value will beNone.Dynamic execution of statements is supported by the exec()function. Theglobals()andlocals()functions returns the current global and local dictionary, respectively, which may be useful to pass around for use byeval()orexec().See ast.literal_eval()for a function that can safely evaluate strings with expressions containing only literals.Raises an auditing event execwith the code object as the argument. Code compilation events may also be raised.
 exec()
exec(object[, globals[, locals]])Parametersexec()toobjectto specify the code to be executed[globals]optional, to specify the globals to be used[locals]optional, to specify the locals to be usedRemarksTo supports dynamic execution of Python code.objectmust be either a string or a code object.If objectis a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs).If objectis a code object, it is simply executed.In all cases, the code that's executed is expected to be valid as file input.Be aware that the returnandyieldstatements may not be used outside of function definitions even within the context of code passed to theexec()function.The return value is None.In all cases, if the optional parts are omitted, the code is executed in the current scope. If only globalsis provided, it must be a dictionary (and not a subclass of dictionary), which will be used for both the global and the local variables. Ifglobalsandlocalsare given, they are used for the global and local variables, respectively. If provided,localscan be any mapping object. Remember that at module level, globals and locals are the same dictionary. Ifexecgets two separate objects asglobalsandlocals, the code will be executed as if it were embedded in a class definition.If the globalsdictionary does not contain a value for the key__builtins__, a reference to the dictionary of the built-in modulebuiltinsis inserted under that key. That way you can control what builtins are available to the executed code by inserting your own__builtins__dictionary intoglobalsbefore passing it toexec().Raises an auditing event execwith the code object as the argument. Code compilation events may also be raised.The built-in functions globals()andlocals()return the current global and local dictionary, respectively, which may be useful to pass around for use as the second and third argument toexec().The default localsact as described for functionlocals()below: modifications to the defaultlocalsdictionary should not be attempted/ Pass an explicitlocaladictionary if you need to see effects of the code onlocalsafter functionexec()returns.
 help()
help([object])Parametershelp()to invoke the built-in help system.[object]optional, to specify theobjectto be returned fromRemarkshelp()is intended fro interactive use.If objectis omitted, the interactive help system starts on the interpreter console.if objectis a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console.If the argument is any other kind of object, a help page on the object is generated.If a slash /appears in the parameter list of a function, when invokinghelp(), it means that the parameters prior to slash are positional-only.help()is added to the built-in namespace by thesitemodule.
 @staticmethod
@staticmethodParameters@staticmethodto transform a method into a static method.RemarksA static method does not receive an implicit first argument. To declare a static method, use this idiom:
class C:
    @staticmethod
    def f(arg1, arg2, ...): ...The @staticmethod form is a function decorator – see Function definitions for details.
A static method can be called either on the class (such as C.f()) or on an instance (such as C().f()).
Static methods in Python are similar to those found in Java or C++. Also see classmethod() for a variant that is useful for creating alternate class constructors.
Like all decorators, it is also possible to call staticmethod as a regular function and do something with its result. This is needed in some cases where you need a reference to a function from a class body and you want to avoid the automatic transformation to instance method. For these cases, use this idiom:class C:
    builtin_open = staticmethod(open)
 Source and Reference©sideway
 
 ID: 201202902 Last Updated: 12/29/2020 Revision: 0 |  |