V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
MarioLuisGarcia

将你输入的任何话自动转化成代码的 Python 小玩具,适合吐槽、装 X、示爱(误)

  •  
  •   MarioLuisGarcia · Nov 21, 2017 · 3620 views
    This topic created in 3084 days ago, the information mentioned may be changed or developed.

    Coding environment: Python3.6

    import unicodedata as ud
    
    code_doc = """
    import unicodedata as ud
    
    init_str = ''
    for unicode_name in %r:
        unicode = ud.lookup(unicode_name)
        init_str += unicode
    
    print(init_str)
    """
    
    def easy_coding(string):
        """将你输入的任何句子(字符串)转化成更 fancy 的 python 代码!"""
        name_list = []
        for i in string:
            name_list.append(ud.name(i))
    
        print(code_doc % name_list)
    

    使用方法:

    将源代码复制到空白 py 文件并用 Python3 运行后,调用 easy_coding 函数,并将你想要转化的字符串作为参数传进去。
    easy_coding 将自动打印一段可再次 implicitly 打印该字符串的代码。将该打印出来的代码复制到另一个空白 py 文件并用 Python3 运行后,可以打印出你刚才输入的字符串。 (^__^)

    #示例:
    In [4]: easy_coding('兽人永不搞基!')
    
    import unicodedata as ud
    init_str = ''
    for unicode_name in ['CJK UNIFIED IDEOGRAPH-517D', 'CJK UNIFIED IDEOGRAPH-4EBA', 'CJK UNIFIED IDEOGRAPH-6C38', 'CJK UNIFIED IDEOGRAPH-4E0D', 'CJK UNIFIED IDEOGRAPH-641E', 'CJK UNIFIED IDEOGRAPH-57FA', 'FULLWIDTH EXCLAMATION MARK']:
        unicode = ud.lookup(unicode_name)
        init_str += unicode
    
    print(init_str)
    
    6 replies    2017-11-22 10:43:30 +08:00
    mYYnSmiTEQWcCwAr
        1
    mYYnSmiTEQWcCwAr  
       Nov 21, 2017 via Android
    感谢分享,感觉 ctf 的 misc 题又有得出了
    MarioLuisGarcia
        2
    MarioLuisGarcia  
    OP
       Nov 21, 2017
    @cy97cool ctf 的 misc 题是什么东东啊?
    jadec0der
        3
    jadec0der  
       Nov 21, 2017
    就是那种给个线索找谜底的黑客竞赛
    xubeiyan
        4
    xubeiyan  
       Nov 21, 2017   ❤️ 1
    不如直接生成某个 py 文件……而且丝毫不考虑 cmd 下换行的问题……(摊手
    MarioLuisGarcia
        5
    MarioLuisGarcia  
    OP
       Nov 22, 2017
    @xubeiyan 好建议,受教啦!
    goodryb
        6
    goodryb  
       Nov 22, 2017
    所以这和 print("兽人永不搞基!") 有啥区别

    类似于自己编译自己解释?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 19:26 · PVG 03:26 · LAX 12:26 · JFK 15:26
    ♥ Do have faith in what you're doing.