Test d'import depuis une classe|TP_3.9|ADD file1.py file2.py
This commit is contained in:
parent
bf2d5e50ca
commit
07e4c39586
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from file2 import Message
|
||||
|
||||
""" Single variable importation example """
|
||||
|
||||
WORD_LIST = ["hello","bonjour","ola"]
|
||||
|
||||
Message(1)
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Single variable importation example
|
||||
|
||||
:Example:
|
||||
>>> MyMessage = Message(0)
|
||||
|
||||
>>> type(MyMessage)
|
||||
<class '__main__.Message'>
|
||||
>>> print(MyMessage)
|
||||
hello world
|
||||
>>> repr(MyMessage)
|
||||
"phrase: hello world|wl: ['hello', 'bonjour', 'ola']"
|
||||
"""
|
||||
|
||||
class Message:
|
||||
|
||||
def __init__(self, index):
|
||||
from file1 import WORD_LIST
|
||||
|
||||
self._phrase = WORD_LIST[index] + " world"
|
||||
self._word_list = WORD_LIST
|
||||
|
||||
def __repr__(self):
|
||||
return "phrase: {}|wl: {}".format(self._phrase, self._word_list)
|
||||
|
||||
def __str__(self):
|
||||
return self._phrase
|
||||
|
||||
if __name__ == "__main__":
|
||||
""" Starting doctests """
|
||||
import doctest
|
||||
doctest.testmod()
|
Loading…
Reference in New Issue