Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Python Utility FuckIt.py

Shulou Source: shulou.com Published: 2022-06-03 17:03:34 10月06日 Update

This article mainly shows you the "sample analysis of the Python utility FuckIt.py", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of the Python utility FuckIt.py".

FuckIt.py uses the most advanced technology to make your code no matter what kind of errors, you just FuckIt, the program can be "normal" execution, soldiers to cover up the water.

Let's start with an example of how to use it.

Installation

Pip install fuckit

Suppose there is a target file: broke.py

Def f (): broken_codeprint ('fuckit chaining works') forlet's just assume this is a big module of shitty code.x = yy = x1 / 0 # Oh shhhiiiiiiivar = "Are you proud of what you've done?"

There are several obvious errors in broke.py, including syntax errors, the variable broken_code is not defined, and 0 is treated as a divisor.

If you go directly to import broke, you will definitely report an error.

> import brokeFile "broke.py", line 5 for ^ SyntaxError: invalid syntax

At this point you can use fuckit to import broke.

> > import fuckit > fuckit ("broke") > broke

An error will also be reported when calling the function f

> broke.f () NameError: global name 'broken_code' is not defined

You can use chained fuckit to call this problematic function

> fuckit (broke) .f () fuckit chaining works

Or

> fuckit (fuckit ("broke")) .f () fuckit chaining works

In addition, fuckit can also be used as a decorator and context manager.

Decoration function

> @ fuckit... Def broken_function ():... Non_existant_variable # Let's create a NameError... Return 'Function decorator works'... > > print (broken_function ()) None

Decorative category

> @ fuckit... Class BrokenClass (object):... Def f (self):... Self.black_hole = 1 / 0. Return 'Class decorator works'... > > print (BrokenClass () .f ()) None

Context Manager

> with fuckit:... Print ('Context manager works'). Raise RuntimeError ().

Equivalent to

Try:print ('Context manager works') except RuntimeError:pass

See here, do you feel that fuckit is very violent, so what scenarios can it be used in? Personally, I think this library is very chicken, because your code should not tolerate these errors, and if there are errors, you should fix them immediately, but one possible use scenario is that you have just taken over a piece of super-complex code with all kinds of code that you can't understand, and when there is an error in the fucking code from time to time, and you can't control it, you can use fuckit.

The above is all the content of the article "sample Analysis of the Python Utility FuckIt.py". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Error code utility utility tool example analysis content function article up and down context scene time report learn help manage complex obvious Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux macOS Apple Shulou Information