How does Python automatically determine the type of input parameters
This article mainly introduces "how to automatically judge the type of input parameters by Python". In daily operation, I believe that many people have doubts about how to automatically judge the type of input parameters by Python. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to automatically judge the type of input parameters by Python". Next, please follow the editor to study!
Directly through the decorator @ typic.al, and then automatically determine the input parameter type according to the annotation function of Python3.
Example:
> import typic
> > >
> @ typic.al
> def multi (a: int, b: int):
... Return a * b
...
> multi ('2percent,' 3')
six
> class DuckRegistry:
... "" A Registry for all the ducks "
...
... @ typic.al
... Def _ _ init__ (self, * duck: Duck):
... Self._reg = {x.name: x for x in duck}
...
... @ typic.al
... Def add (self, duck: Duck):
... Self._ regs [duck.name] = duck
...
... @ typic.al
... Def find (self, name: str):
... Try to find a duck by its name. Otherwise, try with type. ""
... If name not in self._reg:
... Matches = [x for x in self._reg.values () if x.type = = name]
... If matches:
... Return matches [- 1] if len (matches) = = 1 else matches
... Return self._ reg[name]
...
> registry = DuckRegistry ({'type':' black', 'name':' Daffy'})
> registry.find ('Daffy')
Duck (type=, name='Daffy')
> registry.add ({'type':' white', 'name':' Donald'})
> registry.find ('Donald')
Duck (type=, name='Donald')
> registry.add ({'type':' goose', 'name':' Maynard'})
Traceback (most recent call last):
...
ValueError: 'goose' is not a valid DuckType
Python makes it easier to use ffmpeg to process video files, such as
Ffmpeg-I input.mp4-I overlay.png-filter_complex "[0] trim=start_frame=10:end_frame=20 [v0];\
[0] trim=start_frame=30:end_frame=40 [v1]; [v0] [v1] concat=n=2 [v2]; [1] hflip [v3];\
[v2] [v3] overlay=eof_action=repeat [v4]; [v4] drawbox=50:50:120:120:red:t=5 [v5] "\
-map [v5] output.mp4
Change to:
Import ffmpeg
In_file = ffmpeg.input ('input.mp4')
Overlay_file = ffmpeg.input ('overlay.png')
(
Ffmpeg
.concat (
In_file.trim (start_frame=10, end_frame=20)
In_file.trim (start_frame=30, end_frame=40)
)
.overlay (overlay_file.hflip ())
.drawbox (50,50,120,120, color='red', thickness=5)
.output ('out.mp4')
.run ()
At this point, the study on "how to automatically determine the type of input parameters by Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!