Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python: Bad Ideas

License

NotificationsYou must be signed in to change notification settings

seperman/bad-ideas

Repository files navigation

LicenseBuild Status

It is a good idea to install bad ideas!

Bad ideas include a collection of bad Python 3 ideas. This package is not compatible with Python 2.

Bad Ideas are prepared for PyCon 2017 talk:Magic Method, on the wall, who, now, is the__fairest__ one of all?. You can read the proposal for this talk on theZepworks blog

If you have any bad ideas that you want to be added here, let me know!

Disclaimer

This code is for educational purposes ONLY. Use it at your own risk.

Install

pip install bad-ideas

Usage

Type less by in-place editing of numbers

Avoid the carpal tunnels, use mutable integers!

>>>frombadimportnumber>>>num=number(10)>>>num+313>>>num13>>>3-num-10>>>num-10>>>2/num-0.2>>>num-0.2

Filter that returns list instead of generator when printed

>>>frombadimportfiltered>>>foo= [1,2,3,5,6,7]>>>filtered(lambdax:x%3==0,foo)[3,6]

Pipe and grep

>>>frombadimportgrep>>>LINES="""... Whether you're new to programming or... an experienced developer, it's easy... to learn and use Python.... Checkout jobs.python.org... for Python jobs.... """>>>LINES|grep('Python')['to learn and use python.','checkout jobs.python.org','for python jobs.']>>>LINES|grep('Python')|grep('jobs')['checkout jobs.python.org','for python jobs.']

Undeletable

Need some memory leaking? Subclass the Undeletable to introduce "persistent" objects that won't go away!

>>>frombadimportUndeletable>>>obj=Undeletable()>>>delobjYoucan'tdeleteme!>>>obj<undeletable:4127530384>

Note that you can have many references to the same object. You can still delete all the references except the last one:

>>>obj2=obj>>>delobj2>>>obj2Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>NameError:name'obj2'isnotdefined>>>obj<undeletable:4127530384>

Contribute

Have a bad idea? Let me know!

Make a PR or open a ticket!


[8]ページ先頭

©2009-2025 Movatter.jp