Skip to content

Commit 636071a

Browse files
committed
26072025
1 parent f42d123 commit 636071a

15 files changed

Lines changed: 726 additions & 181 deletions

‎@F_Methods-FILE.py‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎@F_Python-key-words.py‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

Books/Python/PCAP/dokumen.pub_python-essentials-2-aligned-with-pcap-certified-associate-the-openedg-python-institutepdf.pdf renamed to Books/Python/python-essentials-2-aligned-with-pcap.pdf

File renamed without changes.

‎Files.py‎

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
# - write to the stream: the portions of the data from the memory (ex: a variable) are transferred to the file
5050

5151
# three basic modes used to open the stream:
52-
# - read mode: a stream opened in this mode allows read operations only; trying to write to the stream will cause an exception UnsupportedOperation
53-
# - write mode: a stream opened in this mode allows write operations only; attempting to read the stream will cause UnsupportedOperation again
54-
# - update mode: a stream opened in this mode allows both writes and reads
52+
# - READ mode: a stream opened in this mode allows read operations only; trying to write to the stream will cause an exception UnsupportedOperation
53+
# - WRITE mode: a stream opened in this mode allows write operations only; attempting to read the stream will cause UnsupportedOperation again
54+
# - UPDATE mode: a stream opened in this mode allows both writes and reads
5555

5656
# The stream behaves almost like a tape recorder
5757
# ==> read something from a stream? a virtual head moves over the stream according to the number of bytes transferred from the stream
@@ -71,7 +71,7 @@
7171

7272

7373

74-
#### OPEN()
74+
#### OPEN(FILE, MODE, ENCODING)
7575

7676
### to invoke the object (the file)
7777

@@ -80,63 +80,65 @@
8080

8181
### open()
8282
# - very first operation performed on the stream
83-
# - successful, the function returns a stream object
84-
# - otherwise, an exception is raised, ex:FileNotFoundError
83+
# - successful ? ==> the function returns a stream object
84+
# - otherwise ==> an exception is raised, ex:FileNotFoundError
8585

8686

87-
### file = specifies the name of the file to be associated with the stream
87+
### file
88+
# = specifies the name of the file to be associated with the stream
8889

8990

90-
### mode = specifies the open mode used for the stream
91+
### mode
92+
# = specifies the open mode used for the stream
9193
# - default opening mode is read in text mode
9294
# - string filled with a sequence of characters, and each of them has its own special meaning:
9395

94-
## ==> r = open mode: read
96+
## ==> R = open mode: READ
9597
# the stream will be opened in read mode
9698
# the file associated with the stream must exist and has to be readable, otherwise exception raised
9799

98-
## ==> w = open mode: write
100+
## ==> W = open mode: WRITE
99101
# the stream will be opened in write mode
100102
# the file associated with the stream doesn't need to exist
101103
# if it doesn't exist it will be created
102104
# if it exists, it will be truncated to the length of zero (erased)
103105
# if the creation isn't possible (ex: due to system permissions), exception
104106

105-
## ==>a = open mode: append
106-
# the stream will be opened in append mode
107-
# the file associated with the stream doesn't need to exist
108-
# if it doesn't exist, it will be created
109-
# if it exists the virtual recording head will be set at the end of the file, the previous content of the file remains UNTOUCHED !
110-
111-
## ==> r+ = open mode: read and update
112-
# the stream will be opened in read and update mode
113-
# the file associated with the stream MUST EXIST and has to be WRITEABLE, otherwise exception
114-
# both read and write operations are allowed for the stream
115-
116-
## ==> w+ open mode: write and update
117-
# the stream will be opened in write and update mode
118-
# the file associated with the stream doesn't need to exist
119-
# if it doesn't exist, it will be created
120-
# the previous content of the file remains UNTOUCHED
121-
# both read and write operations are allowed for the stream.
122-
123-
# If there is a letter b at the end of the mode string it means that the stream is to be opened in binary mode
124-
# If the mode string ends with a letter t the stream is opened in text mode
107+
## ==> A = open mode: APPEND
108+
# the stream will be opened in append mode
109+
# the file associated with the stream doesn't need to exist
110+
# if it doesn't exist, it will be created
111+
# if it exists the virtual recording head will be set at the end of the file, the previous content of the file remains UNTOUCHED !
112+
113+
## ==> R+ = open mode: READ and UPDATE
114+
# the stream will be opened in read and update mode
115+
# the file associated with the stream MUST EXIST and has to be WRITEABLE, otherwise exception
116+
# both read and write operations are allowed for the stream
117+
118+
## ==> W+ open mode: WRITE and UPDATE
119+
# the stream will be opened in write and update mode
120+
# the file associated with the stream doesn't need to exist
121+
# if it doesn't exist, it will be created
122+
# the previous content of the file remains UNTOUCHED
123+
# both read and write operations are allowed for the stream.
124+
125+
# If there is a letter B at the end of the mode string it means that the stream is to be opened in BINARY mode
126+
# If the mode string ends with a letter T the stream is opened in TEXT mode
125127
# TEXT MODE is the DEFAULT behaviour assumed when no binary/text mode specifier is used
126128
# the successful opening of a file will set the current file position (the virtual reading/writing head) before
127129
# the first byte of the file if the mode is not a and after the last byte of the file if the mode is set to a
128130

129131
## encoding = specifies the encoding type, ex:UTF-8 when working with text files
130132
# - default encoding depends on the platform used
133+
131134
# all the streams are divided into text and binary streams:
132135
# - TEXT streams are structured in lines, they contain typographical characters (letters, digits, punctuation, etc),
133136
# arranged in rows (lines), as seen with the naked eye when you look at the contents of the file in the editor
134-
# - BINARY streams don't contain text but a sequence of bytes of any value, ex: an executable program, an image,
135-
# an audio or a video clip, a database file, etc.
137+
# - BINARY streams don't contain text but a sequence of bytes of any value
138+
# ex: an executable program, an image, an audio or a video clip, a database file, etc.
136139
# Because these files don't contain lines, the reads and writes relate to portions of data of any size.
137140
# Hence the data is read/written byte by byte, or block by block, where the size of the block usually ranges from one to an arbitrarily chosen value
138141

139-
140142
# ! In Unix/Linux systems, the line ends are marked by a single character named LF (ASCII code 10) designated in Python programs as \n.
141143
# Other operating systems, especially these derived from the prehistoric CP/M system (which applies to Windows family systems, too)
142144
# use a different convention: the end of line is marked by a pair of characters, CR and LF (ASCII codes 13 and 10) which can be encoded as \r\n.
@@ -162,20 +164,21 @@
162164
# the source code run in a Windows environment will work properly
163165

164166

167+
165168
### 3 Exceptions where open() is not needed
166-
import sys # 3 processes included int he sys module
169+
import sys # 3 processes included int the SYS MODULE
167170

168-
## ==> sys.stdin = standard input
171+
## ==> SYS.STDIN = standard input
169172
# stdin stream is normally associated with the keyboard, pre-open for reading and regarded as the primary data source for the running programs
170173
# the well-known input() function reads data from stdin by default
171174

172175

173-
## ==> sys.stdout = standard output
176+
## ==> SYS.STDOUT = standard output
174177
# stdout stream is normally associated with the screen, pre-open for writing, regarded as the primary target for outputting data by the running program
175178
# the well-known print() function outputs the data to the stdout stream
176179

177180

178-
# #==> sys.stderr = standard error output
181+
# #==> SYS.STDERR = standard error output
179182
# stderr stream is normally associated with the screen, pre-open for writing, regarded as the primary place
180183
# where the running program should send information on the errors encountered during its work
181184

@@ -199,19 +202,19 @@
199202
except Exception as exc:
200203
print("Cannot open the file:", exc)
201204
# ---
202-
203205
### 1. **Airbyte**
204206
# - **Ressources en ligne** :
205207
# - [Site officiel](https://airbyte.com/) — Documentation, guides d’utilisation.
206208
# - [Tutoriel YouTube](https://www.youtube.com/watch?v=H6D3pWwX1JA) — Introduction à Airbyte.
207209
# - [Blog Airbyte](https://airbyte.com/blog) — Cas d’usage, nouveautés.
208210
# - **Ouvrages** : Aucun ouvrage dédié, mais la documentation est très complète.
209211
# ...
210-
#etc
212+
# etc
211213
# ==> OK
212214

213215

214216

217+
215218
#### CLOSE()
216219
stream.close()
217220
# to get rid of the object
@@ -228,6 +231,7 @@
228231

229232

230233

234+
231235
#### DIAGNOSIS
232236

233237
# IOError object is equipped with a property named errno = error number
@@ -286,9 +290,10 @@
286290

287291

288292

293+
289294
#### Gestion de l'erreur
290295

291-
### try/exept + errno
296+
### try/exept + ERRNO
292297
# errno fournit des constantes pour représenter différents codes d'erreur
293298
# Quand une erreur survient lors de l'ouverture d'un fichier, une exception IOError (ou OSError dans Python 3) est levée
294299
# cette exception possède un attribut errno qui indique le type précis d'erreur
@@ -323,7 +328,7 @@
323328
# The file doesn't exist.
324329

325330

326-
### strerror()
331+
### STRERROR()
327332
# comes from the os module
328333
# 1 * argument = error number
329334
# returns a string describing the meaning of the error

‎Functions-BUILT-IN.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,42 @@ def __init__(self):
193193
# {'x': 10, 'y': 20}
194194

195195

196-
### dir() # Returns a list of the specified object's properties and methods
197-
# can be a variable, a module, etc
196+
### dir()
197+
# returns a list of the specified object's properties and methods
198+
# PARAMETER can be a variable, a module, (), None
199+
# RETURN can be a list of:
200+
# the module's attribute
201+
# names of class attributes
202+
# names of object attributes
203+
# names of the base class attributes
198204

205+
206+
# object/class
199207
class Person:
200208
name = "John"
201209
age = 36
202210
country = "Norway"
203211
print(dir(Person))
204-
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'age', 'country', 'name']
212+
# ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'age', 'country', 'name']
205213

214+
# module
206215
import math
207216
for name in dir(math):
208217
print(name, end=" ")
209218
# __doc__ __loader__ __name__ __package__ __spec__ acos acosh asin asinh atan atan2 atanh cbrt ceil comb copysign cos cosh degrees dist e erf erfc exp exp2 expm1 fabs factorial floor fma fmod frexp fsum gamma gcd hypot inf isclose isfinite isinf isnan isqrt lcm ldexp lgamma log log10 log1p log2 modf nan nextafter perm pi pow prod radians remainder sin sinh sqrt sumprod tan tanh tau trunc ulp
210219

211220

221+
# current local
222+
print(dir())
223+
# ['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
224+
225+
# None
226+
print(dir(None))
227+
# ['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__',
228+
# '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
229+
# '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
230+
231+
212232
### divmod() # Returns the quotient and the remainder when argument1 is divided by argument2
213233

214234
x = divmod(5, 2)

Lambda.py renamed to Functions-LAMBDA.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
# 2 ==> exécution de la fonction
3939

4040

41+
## lambda n'accepte PAS de RETURN
42+
# Lambda functions are single expressions, and return is not allowed inside them
43+
44+
lambda x, y: return x + y
45+
46+
# Correct way:
47+
lambda x, y: x + y
48+
49+
4150
## cas d'usage
4251

4352
def print_function(args, fun):
@@ -54,6 +63,19 @@ def poly(x):
5463
# f(1)=0
5564
# f(2)=2
5665

66+
67+
## mélande de lambda et de fonction
68+
69+
def f(a, b):
70+
return a(b)
71+
# La fonction f prend deux arguments : a (une fonction) et b (une valeur)
72+
73+
print(f(lambda x: x and True, 1 > 0))
74+
# 1er argument a est une lambda : lambda x: x and True == True + True
75+
# 2ème argument b est 1 > 0, ce qui retourne True
76+
# True
77+
78+
5779
# ==> avec LAMBDA
5880
# pas besoin de créer la fonction poly() ==> remplacée par lambda x: 2 * x**2 - 4 * x + 2
5981

0 commit comments

Comments
 (0)