class

How are methods, `classmethod`, and `staticmethod` implemented in Python?

倖福魔咒の 提交于 2020-04-05 13:42:55
问题 At what point do methods in Python acquire a get property? —As soon as they're defined in the class? Why does Python let me define a method without any arguments (not even a first self argument)? I know how to use classmethod and staticmethod , and I know that they're built-in functions, but what happens to a function that is so-decorated? Essentially, I'm wondering about the "magic" that happens between class definition and class construction. 回答1: Check this out. http://docs.python.org

How are methods, `classmethod`, and `staticmethod` implemented in Python?

人走茶凉 提交于 2020-04-05 13:41:04
问题 At what point do methods in Python acquire a get property? —As soon as they're defined in the class? Why does Python let me define a method without any arguments (not even a first self argument)? I know how to use classmethod and staticmethod , and I know that they're built-in functions, but what happens to a function that is so-decorated? Essentially, I'm wondering about the "magic" that happens between class definition and class construction. 回答1: Check this out. http://docs.python.org

python学习之继承

走远了吗. 提交于 2020-04-04 09:44:35
class P(object): 'P class' def __init__(self): print('created an instance of',self.__class__.__name__) def foo(self): print('Hi,I am P-foo()')class C(P): def foo(self): P.foo(self) #子类的重写方法显式地调用基类方法 super(C,self).foo() #P.foo(self)等价super(C,self).foo()等价super().foo() super().foo() print('Hi,I am C-foo()')p=P()c=C()# print(p.__class__) # p所属的类名# print(P.__bases__) # 父类的父类# print(P.__doc__) # 父类的文档字符串# print('-'*50)# print(c.__class__) # c所属的类名# print(C.__bases__) # 子类的父类print('-'*50)# p.foo() #实例调用方法# c.foo() #子类调用基类的覆盖方法# P.foo(c) #调用未绑定的基类方法,把子类实例传参进去c.foo() 来源: https://www.cnblogs.com

抽屉新热榜页面之html

时光怂恿深爱的人放手 提交于 2020-04-04 08:45:17
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>抽屉新热榜-聚合每日热门、搞笑、有趣资讯</title> <link rel="stylesheet" href="css/indextwo.css"> </head> <body> <div class="bottom"> <div class="centor"> <div class="drawer"> <a> <img style="margin-top: 11px;" src="http://dig.chouti.com/images/logo.png" alt="抽屉新热榜"> </a> </div> <div class="classification"> <a class="item">全部</a> <a class="item">42区</a> <a class="item">段子</a> <a class="item">图片</a> <a class="item">挨踢1024</a> <a class="item">你问我答</a> </div> <div class="solr"> <from> <input type="text" class="search-txt-s" autocomplete="off" style

类的私有成员,类方法与静态方法,属性,isinstance、issubclass,异常处理

安稳与你 提交于 2020-04-01 04:32:25
1.类的私有成员 类中的私有成员: 私有类的静态属性, 私有对象属性,私有方法 =>类外部、派生类不可访问,内部可以访问 以私有属性为例: class B: school_name = '老男孩教育' __consc_edu = '良心教育' class A(B): class_name = 'python23' __girlnum = '1个' def func(self): print(self.__girlnum) def func1(self): print(self.__consc_edu) obj = A() print(obj.__girlnum) #类外部不可访问 print(A.__girlnum) #类外部不可访问 obj.func1() #派生类不可访问 obj.func() #内部可以访问 拓展: class A: __girlnum = '1个' print(A.__dict__) python中所有的私有成员: 就是在私有成员前面加上 _类名而已 print(A._A__girlnum) #千万不要这么去访问! 2.类方法与静态方法 class A: def func(self): print('实例方法') @classmethod # 类方法: 由类名直接调用的方法,会自动的将类名传给cls def a_func(cls): print('这是类方法

饿汉模式单例模板

老子叫甜甜 提交于 2020-03-30 19:37:22
使用c11的std::call_once实现饿汉模式的单例模板 #ifndef SINGLETON_H #define SINGLETON_H #include <memory> #include <mutex> //单例模板 template <typename T> class Singleton { public: static T& GetInstance(); private: static std::unique_ptr<T> instance; }; template <typename T> std::unique_ptr<T> Singleton<T>::instance; template <typename T> T& Singleton<T>::GetInstance() { std::once_flag sflag; std::call_once(sflag, [&](){ instance.reset(new T()); }); return *instance; } #define SINGLETON(Class) \ public: \ ~Class() = default; \ private: \ Class() = default; \ Class(const Class &other) = delete; \ Class& operator=

Android The content of the adapter has changed but ListView did not receive a notification

老子叫甜甜 提交于 2020-03-30 03:08:29
The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread 原因:没有在主线程里通知。。。。 1、bug 出现的地方 listView.class 1487行 if (mItemCount == 0) { resetList(); invokeOnItemScrollListener(); return; } else if ( mItemCount != mAdapter.getCount( )) { throw new IllegalStateException("The content of the adapter has changed but " + "ListView did not receive a notification. Make sure the content of " + "your adapter is not modified from a background thread, but only " + "from the UI

ES6中class的继承

人走茶凉 提交于 2020-03-27 23:08:20
ES6中class的继承 父类(基类) 子类 extends 关键字 //父类 class Human{ //父类的构造函数 constructor(name,age,sex,hobby){ this.name=name this.age=age this.sex=sex this.hobby=hobby } desc(){ const {name,age,sex,hobby}=this console.log(`我的名字是${ name },我今年${ age }岁,我的性别是:${ sex },我的爱好是:${ hobby }`) } eat(){ console.log("吧唧吧唧") } } //子类 前端工程师类 class FEEnginner extends Human{ constructor(name,age,sex,hobby,skill,salary){ super(name,age,sex,hobby)//在this之前调用super,实际上就是调用父类的构造函数 this.skill=skill this.salary=salary } say(){ console.log(this.skill.join(",")) } } const feer=new FEEnginner( "cyy", 18, "女", "study", ["es6","vue",

hadoop2.2.0 MapReduce分区

女生的网名这么多〃 提交于 2020-03-25 00:52:05
 package com.my.hadoop.mapreduce.partition; import java.util.HashMap; import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Partitioner; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class ParCount { public static class ParMap

Android 利用SAX解析XML

天涯浪子 提交于 2020-03-24 05:57:30
进入正题: 1、待解析的XML : <?xml version="1.0" encoding="utf-8"?> <mobile> <Response> <list> <item> <id>39</id> <username>user1</username> <content>content1</content> <flag>1</flag> <urlstr>20140103013946_jygy.amr</urlstr> </item> <item> <id>38</id> <username>user2</username> <content>content2</content> <flag>3</flag> <urlstr>20140103013621_jygy.jpg</urlstr> </item> </list> </Response> </mobile> 2、根据上面的XML定义实体 Item.java public class Item { private String id; private String username; private String content; private String flag; private String urlstr; public String getId() { return id; } public void