-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule-SYS.py
More file actions
121 lines (87 loc) · 5 KB
/
Module-SYS.py
File metadata and controls
121 lines (87 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
########## MODULE SYS ##########
## sys.argv
# liste des arguments de la ligne de commande
import sys
print(sys.argv)
# ['c:/PythonLearning/bac-à-sable.py']
## sys.path
# liste des chemins d’accès où Python recherche les modules à importer
print(sys.path)
# ['c:\\PythonLearning', 'C:\\Python313\\python313.zip', 'C:\\Python313\\DLLs', 'C:\\Python313\\Lib', 'C:\\Python313',
# 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages', 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\win32',
# 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\win32\\lib',
# 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\Pythonwin', 'C:\\Python313\\Lib\\site-packages']
## sys.modules
# Dictionnaire contenant tous les modules déjà importés
print(sys.modules)
# {'sys': <module 'sys' (built-in)>, 'builtins': <module 'builtins' (built-in)>, '_frozen_importlib': <module '_frozen_importlib' (frozen)>, '_imp': <module '_imp' (built-in)>,
# '_thread': <module '_thread' (built-in)>, '_warnings': <module '_warnings' (built-in)>, '_weakref': <module '_weakref' (built-in)>, 'winreg': <module 'winreg' (built-in)>,
# '_io': <module '_io' (built-in)>, 'marshal': <module 'marshal' (built-in)>, 'nt': <module 'nt' (built-in)>, '_frozen_importlib_external': <module '_frozen_importlib_external' (frozen)>,
# 'time': <module 'time' (built-in)>, 'zipimport': <module 'zipimport' (frozen)>, '_codecs': <module '_codecs' (built-in)>, 'codecs': <module 'codecs' (frozen)>,
# 'encodings.aliases': <module 'encodings.aliases' from 'C:\\Python313\\Lib\\encodings\\aliases.py'>, 'encodings': <module 'encodings' from 'C:\\Python313\\Lib\\encodings\\__init__.py'>,
# 'encodings.utf_8': <module 'encodings.utf_8' from 'C:\\Python313\\Lib\\encodings\\utf_8.py'>, 'encodings.cp1252': <module 'encodings.cp1252' from 'C:\\Python313\\Lib\\encodings\\cp1252.py'>,
# '_signal': <module '_signal' (built-in)>, '_abc': <module '_abc' (built-in)>, 'abc': <module 'abc' (frozen)>, 'io': <module 'io' (frozen)>, '__main__': <module '__main__' from 'c:\\PythonLearning\\bac-à-sable.py'>,
# '_stat': <module '_stat' (built-in)>, 'stat': <module 'stat' (frozen)>, '_collections_abc': <module '_collections_abc' (frozen)>, 'genericpath': <module 'genericpath' (frozen)>, '_winapi': <module '_winapi' (built-in)>,
# 'ntpath': <module 'ntpath' (frozen)>, 'os.path': <module 'ntpath' (frozen)>, 'os': <module 'os' (frozen)>, '_sitebuiltins': <module '_sitebuiltins' (frozen)>,
# 'encodings.utf_8_sig': <module 'encodings.utf_8_sig' from 'C:\\Python313\\Lib\\encodings\\utf_8_sig.py'>, '_distutils_hack': <module '_distutils_hack' from 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\_distutils_hack\\__init__.py'>,
# 'pywin32_system32': <module 'pywin32_system32' (namespace) from ['C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\pywin32_system32']>,
# 'pywin32_bootstrap': <module 'pywin32_bootstrap' from 'C:\\Users\\bfrerot\\AppData\\Roaming\\Python\\Python313\\site-packages\\win32\\lib\\pywin32_bootstrap.py'>, 'site': <module 'site' (frozen)>}
## sys.version
# Version de Python sous forme de chaîne de caractères
print(sys.version)
# 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
## sys.platform
# Plateforme (système d'exploitation) sur laquelle Python tourne
print(sys.platform)
# win32
# sys.maxsize
# valeur numérique max que peut prendre une int
print(sys.maxsize)
# 9223372036854775807
## sys.exit([arg])
# Exit le programme
# Peut prendre un code de sortie (par défaut 0)
print(sys.exit(0))
## sys.getsizeof(object[, default])
# Retourne la taille en octets d’un objet
print(sys.getsizeof(42))
# 28
## sys.stdin, sys.stdout, sys.stderr
# Flux standard d'entrée, sortie et erreur
# peuvent être redirigés
print("Tapez quelque chose :")
ligne = sys.stdin.readline()
print("Vous avez tapé :", ligne)
# Tapez quelque chose :
# hello (input clavier)
# Vous avez tapé : hello
sys.stdout.write("Bonjour, ceci est un message sur la sortie standard.\n")
# Bonjour, ceci est un message sur la sortie standard
try:
x = int(input("Entrez un nombre : "))
except ValueError:
print("Ce n'est pas un nombre valide.", file=sys.stderr)
# Entrez un nombre : un
# Ce n'est pas un nombre valide.
## sys.setrecursionlimit(limit)
# Modifie la limite de récursion (par défaut, 1000).
sys.setrecursionlimit(2000)
## sys.getrecursionlimit()`**
# Retourne la limite actuelle de récursion.
print(sys.getrecursionlimit())
# 1000
import sys
print(sys.getrecursionlimit())
# 1000
sys.setrecursionlimit(2000)
print(sys.getrecursionlimit())
# 2000
## sys.path.append(path)
# Ajoute un nouveau chemin pour la recherche de modules.
sys.path.append('/mon/nouveau/chemin')
import sys
import os
zip_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'packages', 'extrapack.zip'))
sys.path.append(zip_path)
## sys.path.insert(index, path)
# Insère un chemin à une position spécifique dans sys.path