gitmyhub

stack-overflow-import

Python ★ 3.7k updated 4y ago

Import arbitrary code from Stack Overflow as Python modules.

A satirical Python library that fulfills the joke of 'importing from Stack Overflow' literally, it searches Stack Overflow at import time and injects the top-voted answer's code as a real Python module.

Pythonsetup: easycomplexity 2/5

This is a joke Python library that takes the common developer habit of copying code from Stack Overflow and makes it literal. Instead of manually searching, copying, and pasting, you write a regular Python import statement and the library does the searching for you.

When you write something like from stackoverflow import quick_sort, the library searches Stack Overflow for the query "[python] quick sort", finds the highest-voted question, looks at the highest-voted answer, and pulls out the largest code block that does not throw a syntax error. That code block is then returned as a Python module you can call directly.

The resulting module has a few extra attributes: __author__ contains the link to the Stack Overflow answer the code came from, and __license__ shows the license (Stack Overflow content is under CC BY-SA 3.0). The README demonstrates this with a quick sort and a chunk-splitting function, both of which work in the example shown.

This is clearly a satirical project rather than something meant for production use. The README's license note is self-aware: the project is licensed under "whatever license you want it to be as long as the license is compatible with the fact that I blatantly copied multiple lines of code from the Python standard library." The star count suggests the joke landed well.

Where it fits