Example of _ call _ usage in Python and python _ call _

Source: Internet
Author: User

Example of _ call _ usage in Python and python _ call _

This article describes the usage of _ call _ in Python and shares it with you for your reference. The specific method is as follows:

Let's take a look at the following sample code:

# Call. py when a class is loaded. Class Next: List = [] def _ init _ (self, low, high): for Num in range (low, high): self. list. append (Num ** 2) def _ call _ (self, Nu): return self. list [Nu]

If you use this method:

b = Next(1,7)print b.Listprint b(2)

The feedback is normal:

[1, 4, 9, 16, 25, 36]9

However, if you use:

b = Nextb(1,7)print b.Listprint b(2)$python ./call.py[1, 4, 9, 16, 25, 36]Traceback (most recent call last): File "cal.py", line 17, in <module>  print b(2) TypeError: __init__() takes exactly 3 arguments (2 given)

_ Init _ is an initialization function that is executed when the class instance is generated.

While _ call _ is a simulated () call and needs to be applied on the instance. Therefore, the instance has already executed _ init.

The following example:

b = Next

This is not to create an instance, but to assign the class to a variable. Therefore, the subsequent operations using B are for the Next class, which is actually:

Next(1,7)print Next.Listprint Next(2)

I hope this article will help you with Python programming.


** Prefix usage in python. Here is an example (with points)

Def fun (p, ** args ):
Print args

Fun (1, a = 2, B = 3, c = 4, d = 5)

Call usage in batch processing is described in detail with examples,

Call another batch processing program from the batch processing program.

CALL [drive:] [path] filename [batch-parameters]

Batch-parameters specifies the command line information required by the batch processing program.

If the command extension is enabled, the CALL will change as follows:

The CALL command now accepts the volume label as the CALL target. Syntax:

CALL: label arguments

A new batch file context is created by a specified parameter and controlled by the volume label
And then passed to the statement. You must "exit" twice by reaching the last two times of the batch script file.
When a file is read for the first time, the control will return to the end of the CALL statement. Second
Will exit the batch script. Type GOTO /?, See GOTO: Description of the EOF extension,
This description allows you to return from a batch of scripts.

In addition, the batch script text parameter reference (% 0, % 1, etc.) has changed as follows:

% * In the batch script indicates all parameters (for example, % 1% 2% 3% 4% 5 ...)

The substitution of the batch parameter (% n) has been enhanced. You can use the following syntax:

% ~ 1-delete quotation marks (") and expand % 1
% ~ F1-extended % 1 to a fully qualified path name
% ~ D1-only expand % 1 to one drive letter
% ~ P1-only expand % 1 to one path
% ~ N1-only expand % 1 to one file name
% ~ X1-only expand % 1 to one file extension
% ~ S1-expanded path refers to short name
% ~ A1-extended % 1 to file attributes
% ~ T1-extend % 1 to the date/time of the file
% ~ Z1-expand % 1 to the file size
% ~ $ PATH: 1-find the directory of the PATH environment variable and set % 1
Extended to the first fully qualified name found. If the environment
The variable name is not defined, or the file is not found.
Extended to a null string

You can combine the modifier to obtain multiple results:

% ~ Dp1-extend % 1 to drive letter and path only
% ~ Nx1-only extend % 1 to the file name and extension
% ~ Dp $ PATH: 1-find % 1 in the directory column in the PATH environment variable,
And extend to the drive letter and path of the first file.
% ~ Ftza1-extend % 1 to output rows similar to DIR.

In the preceding example, % 1 and PATH can be replaced by other valid values.
% ~ The syntax is terminated by a valid parameter number. % ~ The modifier cannot match % *
Use

From: cmd --> call /? > Xxx.txt

Respondent: bmgeng-Level 3

Report the Call statement to Call another program and wait until it is executed to return correct or wrong results.
The returned position is C... the remaining full text>
 

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.