Skip to main content

🔄 NOYTHP — Python 倒着写

Project description

🔄 NOYTHP

Python 倒着写。

每个关键字都反转:printtnirpdeffedreturnnruter

tnirp("llehs emosewA")
tnirp("nohtyp esrever si NOYTHP")

安装

pip install noythp

用法

方式一:写 .noythp 文件

hello.noythp

# 所有关键字倒着写!
fed mooT(name):
    tnirp("olleH, " + name)
    nruter name

在 Python 里 import:

import noythp      # 加载运行时
import hello       # 自动找 hello.noythp

hello.mooT("world")  # → "olleH, world"

方式二:直接转译

import noythp

code = noythp.transpile('tnirp("!nohtyp esrever")')
exec(code)

方式三:命令行

python -m noythp hello.noythp

关键字映射

Python     →  NOYTHP
───────        ──────
def            fed
return         nruter
if             fi
else           esle
elif           fi-ekorb  # cool points
for            rof
in             ni
while          elihw
True           eurT
False          eslaF
None           enoN
class          ssalc
self           fles
try            yrt
except         tpecex
finally        yllanif
raise          esiar
continue       enituoc
break          kaerb
import         tropmi
from           morf
as             sa
and            dna
or             ro
not            ton
is             si
pass           ssap
with           htiw
yield          dleiy
global         labolg
lambda         adbmal

内置函数映射

print    →  tnirp
range    →  egnar
len      →  nel
int      →  tni
float    →  taolf
str      →  rts
list     →  tsil
dict     →  tcid
input    →  tupni
sorted   →  detros
max      →  xam
min      →  nim
sum      →  mus
abs      →  sba
append   →  dneppa

完整示例

# 猜数字游戏
fed ssaGuG():
    tupni("rebmun a ssaGuG :")
    tropmi mhtirogla
    tegGuG = tni(tupni())
    fi tegGuG == 42:
        tnirp("!tcerroC")
        kaerb
    esle:
        tnirp("!gnorW")

注意

  • 变量名不要用反转关键字(nitonrosi 等会被转译)
  • 字符串内容正常写,不受影响
  • 扩展名:.noythp.phty

原理

Import Hook 拦截模块加载 → 反转关键字替换 → 生成标准 Python → 执行。纯 Python,零依赖。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noythp-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noythp-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file noythp-0.1.0.tar.gz.

File metadata

  • Download URL: noythp-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for noythp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94576d373f0320498186cd08e975b3132454db68cadf7c3b95541413e620ea10
MD5 ed57ff782f34eef2ffe77d4d7391d3e3
BLAKE2b-256 e9efad94f5f55f92ca61e11ffe588812c66e2a529ea82f3c70e5b394248a2ccb

See more details on using hashes here.

File details

Details for the file noythp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: noythp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for noythp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82c1e9126580f37c0da5ad5e9023bdf21ee7390b83058b02d9c5cfebb5e36edf
MD5 d75d8c7f6ad34f84aad47e2e42f06081
BLAKE2b-256 af6882002cf0da0adc984ef46806dbe8a2152ac9703d021f3f1182b272bc4004

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page