11-pythonファイルの操作とパッケージ

1666 ワード

皆さんの理解を容易にするために、私が書いたコードのすべての関数名と変数名は中国語で命名されています.ちなみにpythonの中国語への互換性をテストします.
1.関数パッケージの部分:
# coding=utf-8 
# Time    : 2018/7/26 19:24
# Author  :    
# Email   : [email protected]
# File    :     .py
# Software: PyCharm
import json

def    (  ):
    try:
        with open(  ,"r",encoding="utf-8") as f:
               = f.read()
    except:
           = ""
        with open(  ,"w",encoding="utf-8") as f:
            f.write(  )
    return   

def    (  ,  ):
    with open(  , "w", encoding="utf-8") as f:
        f.write(str(  ))
        print("    !")
    return "    !"

def json   (  ):
    try:
        with open(  ,"r",encoding="utf-8") as f:
               = json.load(f)
    except:
           = ""
        with open(  ,"w",encoding="utf-8") as f:
            json.dump(  ,f)
    return   
def json   (  ,  ):
    with open(  , "w", encoding="utf-8") as f:
        json.dump(  ,f)
        print("    !")
    return "    !"

2.モジュール参照とテストの部分
# coding=utf-8 
# Time    : 2018/7/26 19:50
# Author  :    
# Email   : [email protected]
# File    :         .py
# Software: PyCharm

import     

if __name__ == '__main__':
       = {"aaa":123}
        .   ("./3.txt",  )

      2 =     .   ("./3.txt")

        .json   ("./3.json",  )

      3 =     .json   ("./3.json")
    print(  3,type(  3))
    print(  2,type(  2))

    :
    !
    !
{'aaa': 123} 
{'aaa': 123}