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.2.2.tar.gz (8.3 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.2.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for noythp-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6b25f30368fca99dfc702987f94bed004cb977e0f6c0696cf53e6a68ee40caa7
MD5 1cf92c662530f9beebf82610e690acff
BLAKE2b-256 d3ec639ae1c7a5c55e0970d3ecf164242596b5605c6122f398f7a24397c86ea1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: noythp-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88c470ae4741e74fc43486c4b0d05bdf4f1f5300ccaa5e4de618f480b85f5134
MD5 3de68fec1c3b239df535c5de9ca8dff2
BLAKE2b-256 c2c230533e48674ca68e053ca07041b9fc7d124f1ad4883b17900f8937c3bbfe

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