猫史档案馆


【Python作品分享】仿Javascript-Console对象(氵作品)

用户:Fox_AwaFox_Awa查看:0 回复:3 评论:0 创建时间:2020-08-18T13:46:19


【作品展示】

center_image

 

【作品介绍】

随便玩玩

 

【作品源代码】

# libjs-py
# 随便写写
import os;
import prettytable as pt;
class Console:
    def __init__(self):
        self.__count={};
    def log(self,obj):
        print(obj);
    def warn(self,obj):
        print("[Warning]"+obj);
    def error(self,obj):
        print("[Error]"+obj);
    def count(self,obj):
        if obj not in self.__count:
            self.__count[obj]=1;
        print(obj+":"+self.__count[obj]);
    def countReset(self,obj):
        if obj not in self.__count:
            self.warn("Count for '"+obj+"' does not exist");
        self.__count[obj]=0;
    def table(self,obj):
        if type(obj) != dict and type(obj) != list:
            self.log(obj);
        else:
            tb=pt.PrettyTable();
            tb.field_names = ["(index)","Value"];
            if type(obj) == dict:
                for awa in obj:tb.add_row([str(awa),obj[awa]]);
            else:
                for awa in range(0,len(obj)):tb.add_row([str(awa),obj[awa]]);
            print(tb);
    def debug(self,obj):
        pass
    #info:非标准的(如dir,dirxml)在此不会实现。
    def info(self,obj):
        print(obj);
    def js_assert(self,obj):#assert是关键字无法定义,这里用js_assert代替。
        if obj == False:
            self.error("Assert Failed.");
            exit();
        else:
            return;
    def clear(self):
        os.system("clear");
typeof=type;
Array=list;#可变
Object=dict;#可变
number=int;
string=str;
console=Console();

#your code here
console.log("Hello World!");

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
Fox_AwaFox_Awa

我才学2天Python,兄弟萌,我写的对吗?

点赞0


评论


一个STUB用户_6923702一个STUB用户_6923702

我也是一开始从JS转过来的哈哈

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

az

 

点赞0


评论