坚持Selenium+Python学习记录 DAY8

Posted flyin9

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了坚持Selenium+Python学习记录 DAY8相关的知识,希望对你有一定的参考价值。

2018/05/ 28

[来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html

继续敲类相关的代码

#No.1
class people:
    name = ‘‘
    age = 0
    __weight = 0

    def __init__(self, n, a, w):
        self.name = n
        self.age = a
        self.__weight = w

    def speak(self):
        print("%s 说:我 %d 岁。" %(self.name, self.age))

class student(people):
    grade = ‘‘
    def __init__(self, n, a, w, g):
        people.__init__(self, n, a, w)
        self.grade = g

    def speak(self):
        print("%s 说:我 %d 岁了,我在读 %d 年纪" %(self.name, self.age, self.grade))

s = student(‘ken‘, 10, 60, 3)
s.speak()
resut:
d:\fly\Python (master -> origin)
λ python test.py
ken 说:我 10 岁了,我在读 3 年纪
#No.2
class people:
    name = ‘‘
    age = 0
    __weight = 0

    def __init__(self, n, a, w):
        self.name = n
        self.age = a
        self.__weight = w

    def speak(self):
        print("%s 说:我 %d 岁。" %(self.name, self.age))

class student(people):
    grade = ‘‘
    def __init__(self, n, a, w, g):

        people.__init__(self, n, a, w)
        self.grade = g

    def speak(self):
        print("%s 说: 我 %d 岁了,我在读 %d 年级"%(self.name, self.age, self.grade))

class speaker():
    topic = ‘‘
    name = ‘‘
    def __init__(self, n, t):
        self.name = n
        self.topic = t

    def speak(self):
        print("我叫 %s, 我是一个演说家, 我演讲的主题是 %s" %(self.name, self.topic))

class sample(speaker, student):
    a = ‘‘
    def __init__(self, n, a, w, g, t):
        student.__init__(self, n, a, w, g)
        speaker.__init__(self, n, t)

test = sample("Tim", 25, 80, 4, "Python")
test.speak()
resut:
d:\fly\Python (master -> origin)
λ python test.py
我叫 Tim, 我是一个演说家, 我演讲的主题是 Python
#No.3
class parent:
    def myMethod(self):
        print(‘调用父类方法‘)

class child(parent):
    def myMethod(self):
        print(‘调用子类方法‘)

c = child()
c.myMethod()
super(child, c).myMethod()
resut:
d:\fly\Python (master -> origin)
λ python test.py
调用子类方法
调用父类方法
#No.4
class JustCounter:
    __secretCount = 0
    publicCount = 0

    def count(self):
        self.__secretCount += 1
        self.publicCount += 1
        print(self.__secretCount)

counter = JustCounter()
counter.count()
counter.count()
print(counter.publicCount)
print(counter.__secretCount)
resut:
d:\fly\Python (master -> origin)
λ python test.py
1
2
2
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    print(counter.__secretCount)
AttributeError: ‘JustCounter‘ object has no attribute ‘__secretCount‘
#No.5
class Site:
    def __init__(self, name, url):
        self.name = name
        self.__url = url

    def who(self):
        print(‘name : ‘, self.name)
        print(‘url : ‘, self.__url)

    def __foo(self):
        print("这是私有方法")

    def foo(self):
        print(‘这是公共方法‘)
        self.__foo()

x = Site(‘菜鸟教程‘, ‘www.runoob.com‘)
x.who()
x.foo()
x.__foo()
resut:
d:\fly\Python (master -> origin)
λ python test.py
name :  菜鸟教程
url :  www.runoob.com
这是公共方法
这是私有方法
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    x.__foo()
AttributeError: ‘Site‘ object has no attribute ‘__foo‘

以上是关于坚持Selenium+Python学习记录 DAY8的主要内容,如果未能解决你的问题,请参考以下文章

坚持Selenium+Python学习之从读懂代码开始 DAY6

坚持Selenium+Python学习之从读懂代码开始 DAY5

2016-11-1坚持学习Day16MongoDB复制集 分片

win10下的selenium + python环境搭建

python+selenium+unittest+pageobject学习记录

Python Selenium UI自动化学习记录