corrections cours poo

This commit is contained in:
gwen
2017-10-05 09:18:23 +02:00
parent b73e7c85ff
commit 2214b33090
17 changed files with 67 additions and 4655 deletions

View File

@ -1,4 +1,4 @@
Ojets en python
Objets en python
=================
un object est une entité possédant une identité, un état, et un comportement.

View File

@ -0,0 +1,29 @@
types implicites et catégories
==============================
Sometimes it is a good choice to use strings as implicit types.
Some times not. Let us have some types :
::
types = ["booltype", "stringtype", "floattype"]
if "booltype" in types:
print type
But we loose an information there : all these string are the same type
and not a string type.
::
class NormalizeType(str):
pass
typenames = ("booltype", "stringtype", "floattype")
globs = globals()
for typename in typenames:
globs[typename] = NormalizeType(typename)
# and for example
if type(obj) == NormalizeType:
print type
Now we don't rely on a list, the type names present here are just for the
types's build. We rely on classes as sets.

View File

@ -4,6 +4,8 @@ Annexes
.. toctree::
:maxdepth: 2
types
categorie
ojbML
ConstructionParFermeture
cli

View File

@ -0,0 +1,33 @@
type et d'objet en python
=========================
et voir la confusion qui est faite avec le mélange classe et objets en python
In python, base types cannot be inherited, for example:
<pre>
>>> class MyType(int):
... pass
...
</pre>
But, they are not types any more, but objects. They can have attributes (types
cannot have attributes). They cannot return anything at the init (a type has to
return something at the init, it is the instance itself).
<pre>
>>> t = MyType(2)
>>> t
2
>>> isinstance(t, MyType)
True
>>> isinstance(t, int)
True
>>> isinstance(MyType, type)
True
>>>
>>> isinstance(t, object)
True
</pre>
So MyType is a type but has the notation behavior of an object.

View File

@ -37,8 +37,8 @@ def setup(app):
app.add_config_value('correction', False, 'env')
app.add_config_value('exercice', False, 'env')
exercice = False
correction = False
exercice = True
correction = True
todo_include_todos = True
# Add any paths that contain templates here, relative to this directory.