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

Uploaded Python 3

File details

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

File metadata

  • Download URL: noythp-0.2.1.tar.gz
  • Upload date:
  • Size: 7.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.1.tar.gz
Algorithm Hash digest
SHA256 c1546351042fd20fb6df16fc0d772e1a94f563d00270883be5091c107fa55180
MD5 16cea2cf2d33bb7d0cbf8b3db9acfe9b
BLAKE2b-256 f1e2f5b831d5bceb0ce2d852e4d5aedecc71e518f1f89f1aaf14949cdbfc02ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: noythp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0698b725b56dc2926c0ff272e9f6d454e1a8c45196c4d8d54156931c7453c578
MD5 2145802ba839e1fbad86f618337fe969
BLAKE2b-256 5d602c309c47f2db78d716ded40e7b58c4d9b95cecd87a5dde2f16850c8144e8

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