-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcmdline.html
More file actions
1810 lines (1685 loc) · 157 KB
/
Copy pathcmdline.html
File metadata and controls
1810 lines (1685 loc) · 157 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="fa" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="1. Command line and environment" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/cmdline.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="The CPython interpreter scans the command line and the environment for various settings. جزئیات پیادهسازی در CPython: Other implementations' command line schemes may differ. See Alternate Imp..." />
<meta property="og:image" content="_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="The CPython interpreter scans the command line and the environment for various settings. جزئیات پیادهسازی در CPython: Other implementations' command line schemes may differ. See Alternate Imp..." />
<meta name="theme-color" content="#3776ab">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<title>1. Command line and environment — مستندات Python3.14.6</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=4365c8fe" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=0fc419ee" />
<script src="../_static/documentation_options.js?v=e254dbbb"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/translations.js?v=5df48d09"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="جستجو در مستندات Python3.14.6"
href="../_static/opensearch.xml"/>
<link rel="author" title="درباره این مستندات" href="../about.html" />
<link rel="index" title="فهرست" href="../genindex.html" />
<link rel="search" title="جستجو" href="../search.html" />
<link rel="copyright" title="حق چاپ" href="../copyright.html" />
<link rel="next" title="2. Using Python on Unix platforms" href="unix.html" />
<link rel="prev" title="Python Setup and Usage" href="index.html" />
<link rel="canonical" href="https://docs.python.org/3/using/cmdline.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg">
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo">
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<input placeholder="جستجو سریع" aria-label="جستجو سریع" type="search" name="q">
<input type="submit" value="برو">
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">فهرست عناوین</a></h3>
<ul>
<li><a class="reference internal" href="#">1. Command line and environment</a><ul>
<li><a class="reference internal" href="#command-line">1.1. Command line</a><ul>
<li><a class="reference internal" href="#interface-options">1.1.1. Interface options</a></li>
<li><a class="reference internal" href="#generic-options">1.1.2. Generic options</a></li>
<li><a class="reference internal" href="#miscellaneous-options">1.1.3. Miscellaneous options</a></li>
<li><a class="reference internal" href="#controlling-color">1.1.4. Controlling color</a></li>
</ul>
</li>
<li><a class="reference internal" href="#environment-variables">1.2. Environment variables</a><ul>
<li><a class="reference internal" href="#debug-mode-variables">1.2.1. Debug-mode variables</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<h4>موضوع قبلی</h4>
<p class="topless"><a href="index.html"
title="فصل قبلی">Python Setup and Usage</a></p>
</div>
<div>
<h4>موضوع بعدی</h4>
<p class="topless"><a href="unix.html"
title="فصل بعدی"><span class="section-number">2. </span>Using Python on Unix platforms</a></p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('meta[property="og:title"]').content;
const elements = document.querySelectorAll('.improvepage');
const pageurl = window.location.href.split('?')[0];
elements.forEach(element => {
const url = new URL(element.href.split('?')[0].replace("-nojs", ""));
url.searchParams.set('pagetitle', title);
url.searchParams.set('pageurl', pageurl);
url.searchParams.set('pagesource', "using/cmdline.rst");
element.href = url.toString();
});
});
</script>
<div role="note" aria-label="source link">
<h3>این صفحه</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">گزارش یک اشکال</a></li>
<li><a class="improvepage" href="../improve-page-nojs.html">بهبود این صفحه</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/cmdline.rst?plain=1"
rel="nofollow">نمایش منبع
</a>
</li>
<li>
<a href="https://github.com/python/python-docs-fa/blob/3.14/using/cmdline.po?plain=1"
rel="nofollow">نمایش منبع ترجمه</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>ناوبری</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="فهرست کلی"
accesskey="I">فهرست</a></li>
<li class="right" >
<a href="../py-modindex.html" title="نمایه ی ماژول های پایتون"
>ماژول ها</a> |</li>
<li class="right" >
<a href="unix.html" title="2. Using Python on Unix platforms"
accesskey="N">بعدی</a> |</li>
<li class="right" >
<a href="index.html" title="Python Setup and Usage"
accesskey="P">قبلی</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.14.6 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> »</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">1. </span>Command line and environment</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="جستجو سریع" aria-label="جستجو سریع" type="search" name="q" id="search-box">
<input type="submit" value="برو">
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="command-line-and-environment">
<span id="using-on-general"></span><h1><span class="section-number">1. </span>Command line and environment<a class="headerlink" href="#command-line-and-environment" title="Link to this heading">¶</a></h1>
<p>The CPython interpreter scans the command line and the environment for various
settings.</p>
<div class="impl-detail compound">
<p><strong>جزئیات پیادهسازی در CPython:</strong> Other implementations' command line schemes may differ. See
<a class="reference internal" href="../reference/introduction.html#implementations"><span class="std std-ref">Alternate Implementations</span></a> for further resources.</p>
</div>
<section id="command-line">
<span id="using-on-cmdline"></span><h2><span class="section-number">1.1. </span>Command line<a class="headerlink" href="#command-line" title="Link to this heading">¶</a></h2>
<p>When invoking Python, you may specify any of these options:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span><span class="o">[</span>-bBdEhiIOPqRsSuvVWx?<span class="o">]</span><span class="w"> </span><span class="o">[</span>-c<span class="w"> </span><span class="nb">command</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>-m<span class="w"> </span>module-name<span class="w"> </span><span class="p">|</span><span class="w"> </span>script<span class="w"> </span><span class="p">|</span><span class="w"> </span>-<span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">[</span>args<span class="o">]</span>
</pre></div>
</div>
<p>The most common use case is, of course, a simple invocation of a script:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>myscript.py
</pre></div>
</div>
<section id="interface-options">
<span id="using-on-interface-options"></span><h3><span class="section-number">1.1.1. </span>Interface options<a class="headerlink" href="#interface-options" title="Link to this heading">¶</a></h3>
<p>The interpreter interface resembles that of the UNIX shell, but provides some
additional methods of invocation:</p>
<ul class="simple">
<li><p>When called with standard input connected to a tty device, it prompts for
commands and executes them until an EOF (an end-of-file character, you can
produce that with <kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">D</kbd> on UNIX or <kbd class="kbd docutils literal notranslate">Ctrl</kbd>-<kbd class="kbd docutils literal notranslate">Z,</kbd> <kbd class="kbd docutils literal notranslate">Enter</kbd> on Windows) is read.
For more on interactive mode, see <a class="reference internal" href="../tutorial/appendix.html#tut-interac"><span class="std std-ref">حالت تعاملی</span></a>.</p></li>
<li><p>When called with a file name argument or with a file as standard input, it
reads and executes a script from that file.</p></li>
<li><p>When called with a directory name argument, it reads and executes an
appropriately named script from that directory.</p></li>
<li><p>When called with <code class="docutils literal notranslate"><span class="pre">-c</span> <span class="pre">command</span></code>, it executes the Python statement(s) given as
<em>command</em>. Here <em>command</em> may contain multiple statements separated by
newlines. Leading whitespace is significant in Python statements!</p></li>
<li><p>When called with <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">module-name</span></code>, the given module is located using the standard
import mechanism and executed as a script.</p></li>
</ul>
<p>In non-interactive mode, the entire input is parsed before it is executed.</p>
<p>An interface option terminates the list of options consumed by the interpreter,
all consecutive arguments will end up in <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> -- note that the first
element, subscript zero (<code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code>), is a string reflecting the program's
source.</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-c">
<span class="sig-name descname"><span class="pre">-c</span></span><span class="sig-prename descclassname"> <span class="pre"><command></span></span><a class="headerlink" href="#cmdoption-c" title="Link to this definition">¶</a></dt>
<dd><p>Execute the Python code in <em>command</em>. <em>command</em> can be one or more
statements separated by newlines, with significant leading whitespace as in
normal module code.</p>
<p>If this option is given, the first element of <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> will be
<code class="docutils literal notranslate"><span class="pre">"-c"</span></code> and the current directory will be added to the start of
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> (allowing modules in that directory to be imported as top
level modules).</p>
<p class="audit-hook">Raises an <a class="reference internal" href="../library/sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">cpython.run_command</span></code> with argument <code class="docutils literal notranslate"><span class="pre">command</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span><em>command</em> is automatically dedented before execution.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-m">
<span class="sig-name descname"><span class="pre">-m</span></span><span class="sig-prename descclassname"> <span class="pre"><module-name></span></span><a class="headerlink" href="#cmdoption-m" title="Link to this definition">¶</a></dt>
<dd><p>Locate the module using the standard import mechanism and execute its contents
as the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module.</p>
<p>Since the argument is a <em>module</em> name, you must not give a file extension
(<code class="docutils literal notranslate"><span class="pre">.py</span></code>). The module name should be a valid absolute Python module name, but
the implementation may not always enforce this (e.g. it may allow you to
use a name that includes a hyphen).</p>
<p>Package names (including namespace packages) are also permitted. When a
package name is supplied instead
of a normal module, the interpreter will execute <code class="docutils literal notranslate"><span class="pre"><pkg>.__main__</span></code> as
the main module. This behaviour is deliberately similar to the handling
of directories and zipfiles that are passed to the interpreter as the
script argument.</p>
<div class="admonition note">
<p class="admonition-title">توجه</p>
<p>This option cannot be used with built-in modules and extension modules
written in C, since they do not have Python module files. However, it
can still be used for precompiled modules, even if the original source
file is not available.</p>
</div>
<p>If this option is given, the first element of <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> will be the
full path to the module file (while the module file is being located, the
first element will be set to <code class="docutils literal notranslate"><span class="pre">"-m"</span></code>). As with the <a class="reference internal" href="#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> option,
the current directory will be added to the start of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
<p><a class="reference internal" href="#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> option can be used to run the script in isolated mode where
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> contains neither the current directory nor the user's
site-packages directory. All <code class="docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment variables are
ignored, too.</p>
<p>Many standard library modules contain code that is invoked on their execution
as a script. An example is the <a class="reference internal" href="../library/timeit.html#module-timeit" title="timeit: Measure the execution time of small code snippets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">timeit</span></code></a> module:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>timeit<span class="w"> </span>-s<span class="w"> </span><span class="s2">"setup here"</span><span class="w"> </span><span class="s2">"benchmarked code here"</span>
python<span class="w"> </span>-m<span class="w"> </span>timeit<span class="w"> </span>-h<span class="w"> </span><span class="c1"># for details</span>
</pre></div>
</div>
<p class="audit-hook">Raises an <a class="reference internal" href="../library/sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">cpython.run_module</span></code> with argument <code class="docutils literal notranslate"><span class="pre">module-name</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">همچنین ملاحظه نمائید</p>
<dl class="simple">
<dt><a class="reference internal" href="../library/runpy.html#runpy.run_module" title="runpy.run_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">runpy.run_module()</span></code></a></dt><dd><p>Equivalent functionality directly available to Python code</p>
</dd>
</dl>
<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0338/"><strong>PEP 338</strong></a> -- Executing modules as scripts</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.1: </span>Supply the package name to run a <code class="docutils literal notranslate"><span class="pre">__main__</span></code> submodule.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>namespace packages are also supported</p>
</div>
</dd></dl>
<dl class="describe" id="cmdarg-dash">
<dt class="sig sig-object">
<span class="sig-name descname"><span class="pre">-</span></span></dt>
<dd><p>Read commands from standard input (<a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>). If standard input is
a terminal, <a class="reference internal" href="#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> is implied.</p>
<p>If this option is given, the first element of <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> will be
<code class="docutils literal notranslate"><span class="pre">"-"</span></code> and the current directory will be added to the start of
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
<p class="audit-hook" id="audit_event_cpython_run_stdin_0">Raises an <a class="reference internal" href="../library/sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">cpython.run_stdin</span></code> with no arguments.</p>
</dd></dl>
<dl class="describe" id="cmdarg-script">
<dt class="sig sig-object">
<span class="sig-name descname"><span class="pre"><script></span></span></dt>
<dd><p>Execute the Python code contained in <em>script</em>, which must be a filesystem
path (absolute or relative) referring to either a Python file, a directory
containing a <code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> file, or a zipfile containing a
<code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> file.</p>
<p>If this option is given, the first element of <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> will be the
script name as given on the command line.</p>
<p>If the script name refers directly to a Python file, the directory
containing that file is added to the start of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>, and the
file is executed as the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module.</p>
<p>If the script name refers to a directory or zipfile, the script name is
added to the start of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> and the <code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> file in
that location is executed as the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module.</p>
<p><a class="reference internal" href="#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> option can be used to run the script in isolated mode where
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> contains neither the script's directory nor the user's
site-packages directory. All <code class="docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment variables are
ignored, too.</p>
<p class="audit-hook" id="audit_event_cpython_run_file_0">Raises an <a class="reference internal" href="../library/sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">cpython.run_file</span></code> with argument <code class="docutils literal notranslate"><span class="pre">filename</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">همچنین ملاحظه نمائید</p>
<dl class="simple">
<dt><a class="reference internal" href="../library/runpy.html#runpy.run_path" title="runpy.run_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">runpy.run_path()</span></code></a></dt><dd><p>Equivalent functionality directly available to Python code</p>
</dd>
</dl>
</div>
</dd></dl>
<p>If no interface option is given, <a class="reference internal" href="#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> is implied, <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> is
an empty string (<code class="docutils literal notranslate"><span class="pre">""</span></code>) and the current directory will be added to the
start of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Also, tab-completion and history editing is
automatically enabled, if available on your platform (see
<a class="reference internal" href="../library/site.html#rlcompleter-config"><span class="std std-ref">Readline configuration</span></a>).</p>
<div class="admonition seealso">
<p class="admonition-title">همچنین ملاحظه نمائید</p>
<p><a class="reference internal" href="../tutorial/interpreter.html#tut-invoking"><span class="std std-ref">فراخوانی مفسر</span></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>Automatic enabling of tab-completion and history editing.</p>
</div>
</section>
<section id="generic-options">
<span id="using-on-generic-options"></span><h3><span class="section-number">1.1.2. </span>Generic options<a class="headerlink" href="#generic-options" title="Link to this heading">¶</a></h3>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-0">
<span class="sig-name descname"><span class="pre">-?</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-0" title="Link to this definition">¶</a></dt>
<dt class="sig sig-object std" id="cmdoption-h">
<span class="sig-name descname"><span class="pre">-h</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-h" title="Link to this definition">¶</a></dt>
<dt class="sig sig-object std" id="cmdoption-help">
<span class="sig-name descname"><span class="pre">--help</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-help" title="Link to this definition">¶</a></dt>
<dd><p>Print a short description of all command line options and corresponding
environment variables and exit.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-help-env">
<span class="sig-name descname"><span class="pre">--help-env</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-help-env" title="Link to this definition">¶</a></dt>
<dd><p>Print a short description of Python-specific environment variables
and exit.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-help-xoptions">
<span class="sig-name descname"><span class="pre">--help-xoptions</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-help-xoptions" title="Link to this definition">¶</a></dt>
<dd><p>Print a description of implementation-specific <a class="reference internal" href="#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> options
and exit.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-help-all">
<span class="sig-name descname"><span class="pre">--help-all</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-help-all" title="Link to this definition">¶</a></dt>
<dd><p>Print complete usage information and exit.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-V">
<span class="sig-name descname"><span class="pre">-V</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-V" title="Link to this definition">¶</a></dt>
<dt class="sig sig-object std" id="cmdoption-version">
<span class="sig-name descname"><span class="pre">--version</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-version" title="Link to this definition">¶</a></dt>
<dd><p>Print the Python version number and exit. Example output could be:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python 3.8.0b2+
</pre></div>
</div>
<p>When given twice, print more information about the build, like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python 3.8.0b2+ (3.8:0c076caaa8, Apr 20 2019, 21:55:00)
[GCC 6.2.0 20161005]
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.6: </span>The <code class="docutils literal notranslate"><span class="pre">-VV</span></code> option.</p>
</div>
</dd></dl>
</section>
<section id="miscellaneous-options">
<span id="using-on-misc-options"></span><h3><span class="section-number">1.1.3. </span>Miscellaneous options<a class="headerlink" href="#miscellaneous-options" title="Link to this heading">¶</a></h3>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-b">
<span class="sig-name descname"><span class="pre">-b</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-b" title="Link to this definition">¶</a></dt>
<dd><p>Issue a warning when converting <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> or <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> to
<a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> without specifying encoding or comparing <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code> or
<code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code> with <code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code> or <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code> with <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.
Issue an error when the option is given twice (<code class="xref std std-option docutils literal notranslate"><span class="pre">-bb</span></code>).</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.5: </span>Affects also comparisons of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> with <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-B">
<span class="sig-name descname"><span class="pre">-B</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-B" title="Link to this definition">¶</a></dt>
<dd><p>If given, Python won't try to write <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files on the
import of source modules. See also <span class="target" id="index-1"></span><a class="reference internal" href="#envvar-PYTHONDONTWRITEBYTECODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDONTWRITEBYTECODE</span></code></a>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-check-hash-based-pycs">
<span class="sig-name descname"><span class="pre">--check-hash-based-pycs</span></span><span class="sig-prename descclassname"> <span class="pre">default|always|never</span></span><a class="headerlink" href="#cmdoption-check-hash-based-pycs" title="Link to this definition">¶</a></dt>
<dd><p>Control the validation behavior of hash-based <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files. See
<a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">Cached bytecode invalidation</span></a>. When set to <code class="docutils literal notranslate"><span class="pre">default</span></code>, checked and unchecked
hash-based bytecode cache files are validated according to their default
semantics. When set to <code class="docutils literal notranslate"><span class="pre">always</span></code>, all hash-based <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, whether
checked or unchecked, are validated against their corresponding source
file. When set to <code class="docutils literal notranslate"><span class="pre">never</span></code>, hash-based <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files are not validated
against their corresponding source files.</p>
<p>The semantics of timestamp-based <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files are unaffected by this
option.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-d">
<span class="sig-name descname"><span class="pre">-d</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-d" title="Link to this definition">¶</a></dt>
<dd><p>Turn on parser debugging output (for expert only).
See also the <span class="target" id="index-2"></span><a class="reference internal" href="#envvar-PYTHONDEBUG"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDEBUG</span></code></a> environment variable.</p>
<p>This option requires a <a class="reference internal" href="configure.html#debug-build"><span class="std std-ref">debug build of Python</span></a>, otherwise
it's ignored.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-E">
<span class="sig-name descname"><span class="pre">-E</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-E" title="Link to this definition">¶</a></dt>
<dd><p>Ignore all <code class="docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment variables, e.g.
<span class="target" id="index-3"></span><a class="reference internal" href="#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> and <span class="target" id="index-4"></span><a class="reference internal" href="#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a>, that might be set.</p>
<p>See also the <a class="reference internal" href="#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> and <a class="reference internal" href="#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> (isolated) options.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-i">
<span class="sig-name descname"><span class="pre">-i</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-i" title="Link to this definition">¶</a></dt>
<dd><p>Enter interactive mode after execution.</p>
<p>Using the <a class="reference internal" href="#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> option will enter interactive mode in any of the following circumstances:</p>
<ul class="simple">
<li><p>When a script is passed as first argument</p></li>
<li><p>When the <a class="reference internal" href="#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> option is used</p></li>
<li><p>When the <a class="reference internal" href="#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> option is used</p></li>
</ul>
<p>Interactive mode will start even when <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a> does not appear to be a terminal. The
<span class="target" id="index-5"></span><a class="reference internal" href="#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a> file is not read.</p>
<p>This can be useful to inspect global variables or a stack trace when a script
raises an exception. See also <span class="target" id="index-6"></span><a class="reference internal" href="#envvar-PYTHONINSPECT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONINSPECT</span></code></a>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-I">
<span class="sig-name descname"><span class="pre">-I</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-I" title="Link to this definition">¶</a></dt>
<dd><p>Run Python in isolated mode. This also implies <a class="reference internal" href="#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a>, <a class="reference internal" href="#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a>
and <a class="reference internal" href="#cmdoption-s"><code class="xref std std-option docutils literal notranslate"><span class="pre">-s</span></code></a> options.</p>
<p>In isolated mode <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> contains neither the script's directory nor
the user's site-packages directory. All <code class="docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment
variables are ignored, too. Further restrictions may be imposed to prevent
the user from injecting malicious code.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-O">
<span class="sig-name descname"><span class="pre">-O</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-O" title="Link to this definition">¶</a></dt>
<dd><p>Remove assert statements and any code conditional on the value of
<a class="reference internal" href="../library/constants.html#debug__" title="__debug__"><code class="xref py py-const docutils literal notranslate"><span class="pre">__debug__</span></code></a>. Augment the filename for compiled
(<a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a>) files by adding <code class="docutils literal notranslate"><span class="pre">.opt-1</span></code> before the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>
extension (see <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a>). See also <span class="target" id="index-8"></span><a class="reference internal" href="#envvar-PYTHONOPTIMIZE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONOPTIMIZE</span></code></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.5: </span>Modify <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> filenames according to <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a>.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-OO">
<span class="sig-name descname"><span class="pre">-OO</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-OO" title="Link to this definition">¶</a></dt>
<dd><p>Do <a class="reference internal" href="#cmdoption-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> and also discard docstrings. Augment the filename
for compiled (<a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a>) files by adding <code class="docutils literal notranslate"><span class="pre">.opt-2</span></code> before the
<code class="docutils literal notranslate"><span class="pre">.pyc</span></code> extension (see <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a>).</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.5: </span>Modify <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> filenames according to <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a>.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-P">
<span class="sig-name descname"><span class="pre">-P</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-P" title="Link to this definition">¶</a></dt>
<dd><p>Don't prepend a potentially unsafe path to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">module</span></code> command line: Don't prepend the current working
directory.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">script.py</span></code> command line: Don't prepend the script's directory.
If it's a symbolic link, resolve symbolic links.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-c</span> <span class="pre">code</span></code> and <code class="docutils literal notranslate"><span class="pre">python</span></code> (REPL) command lines: Don't prepend an
empty string, which means the current working directory.</p></li>
</ul>
<p>See also the <span class="target" id="index-12"></span><a class="reference internal" href="#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable, and <a class="reference internal" href="#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a>
and <a class="reference internal" href="#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> (isolated) options.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-q">
<span class="sig-name descname"><span class="pre">-q</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-q" title="Link to this definition">¶</a></dt>
<dd><p>Don't display the copyright and version messages even in interactive mode.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.2.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-R">
<span class="sig-name descname"><span class="pre">-R</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-R" title="Link to this definition">¶</a></dt>
<dd><p>Turn on hash randomization. This option only has an effect if the
<span class="target" id="index-13"></span><a class="reference internal" href="#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a> environment variable is set to anything other
than <code class="docutils literal notranslate"><span class="pre">random</span></code>, since hash randomization is enabled by default.</p>
<p>On previous versions of Python, this option turns on hash randomization,
so that the <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__hash__()</span></code></a> values of str and bytes objects
are "salted" with an unpredictable random value. Although they remain
constant within an individual Python process, they are not predictable
between repeated invocations of Python.</p>
<p>Hash randomization is intended to provide protection against a
denial-of-service caused by carefully chosen inputs that exploit the worst
case performance of a dict construction, <em>O</em>(<em>n</em><sup>2</sup>) complexity. See
<a class="reference external" href="https://ocert.org/advisories/ocert-2011-003.html">https://ocert.org/advisories/ocert-2011-003.html</a> for details.</p>
<p><span class="target" id="index-14"></span><a class="reference internal" href="#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a> allows you to set a fixed value for the hash
seed secret.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.2.3.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>The option is no longer ignored.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-s">
<span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-s" title="Link to this definition">¶</a></dt>
<dd><p>Don't add the <a class="reference internal" href="../library/site.html#site.USER_SITE" title="site.USER_SITE"><code class="xref py py-data docutils literal notranslate"><span class="pre">user</span> <span class="pre">site-packages</span> <span class="pre">directory</span></code></a> to
<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
<p>See also <span class="target" id="index-15"></span><a class="reference internal" href="#envvar-PYTHONNOUSERSITE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNOUSERSITE</span></code></a>.</p>
<div class="admonition seealso">
<p class="admonition-title">همچنین ملاحظه نمائید</p>
<p><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0370/"><strong>PEP 370</strong></a> -- Per user site-packages directory</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-S">
<span class="sig-name descname"><span class="pre">-S</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-S" title="Link to this definition">¶</a></dt>
<dd><p>Disable the import of the module <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> and the site-dependent
manipulations of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> that it entails. Also disable these
manipulations if <code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code> is explicitly imported later (call
<a class="reference internal" href="../library/site.html#site.main" title="site.main"><code class="xref py py-func docutils literal notranslate"><span class="pre">site.main()</span></code></a> if you want them to be triggered).</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-u">
<span class="sig-name descname"><span class="pre">-u</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-u" title="Link to this definition">¶</a></dt>
<dd><p>Force the stdout and stderr streams to be unbuffered. This option has no
effect on the stdin stream.</p>
<p>See also <span class="target" id="index-17"></span><a class="reference internal" href="#envvar-PYTHONUNBUFFERED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUNBUFFERED</span></code></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>The text layer of the stdout and stderr streams now is unbuffered.</p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-v">
<span class="sig-name descname"><span class="pre">-v</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-v" title="Link to this definition">¶</a></dt>
<dd><p>Print a message each time a module is initialized, showing the place
(filename or built-in module) from which it is loaded. When given twice
(<code class="xref std std-option docutils literal notranslate"><span class="pre">-vv</span></code>), print a message for each file that is checked for when
searching for a module. Also provides information on module cleanup at exit.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.10: </span>The <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module reports the site-specific paths
and <code class="file docutils literal notranslate"><span class="pre">.pth</span></code> files being processed.</p>
</div>
<p>See also <span class="target" id="index-18"></span><a class="reference internal" href="#envvar-PYTHONVERBOSE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONVERBOSE</span></code></a>.</p>
</dd></dl>
<dl class="std option" id="using-on-warnings">
<dt class="sig sig-object std" id="cmdoption-W">
<span class="sig-name descname"><span class="pre">-W</span></span><span class="sig-prename descclassname"> <span class="pre">arg</span></span><a class="headerlink" href="#cmdoption-W" title="Link to this definition">¶</a></dt>
<dd><p>Warning control. Python's warning machinery by default prints warning
messages to <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a>.</p>
<p>The simplest settings apply a particular action unconditionally to all
warnings emitted by a process (even those that are otherwise ignored by
default):</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>-Wdefault<span class="w"> </span><span class="c1"># Warn once per call location</span>
-Werror<span class="w"> </span><span class="c1"># Convert to exceptions</span>
-Walways<span class="w"> </span><span class="c1"># Warn every time</span>
-Wall<span class="w"> </span><span class="c1"># Same as -Walways</span>
-Wmodule<span class="w"> </span><span class="c1"># Warn once per calling module</span>
-Wonce<span class="w"> </span><span class="c1"># Warn once per Python process</span>
-Wignore<span class="w"> </span><span class="c1"># Never warn</span>
</pre></div>
</div>
<p>The action names can be abbreviated as desired and the interpreter will
resolve them to the appropriate action name. For example, <code class="docutils literal notranslate"><span class="pre">-Wi</span></code> is the
same as <code class="docutils literal notranslate"><span class="pre">-Wignore</span></code>.</p>
<p>The full form of argument is:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>action:message:category:module:lineno
</pre></div>
</div>
<p>Empty fields match all values; trailing empty fields may be omitted. For
example <code class="docutils literal notranslate"><span class="pre">-W</span> <span class="pre">ignore::DeprecationWarning</span></code> ignores all DeprecationWarning
warnings.</p>
<p>The <em>action</em> field is as explained above but only applies to warnings that
match the remaining fields.</p>
<p>The <em>message</em> field must match the whole warning message; this match is
case-insensitive.</p>
<p>The <em>category</em> field matches the warning category
(ex: <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code>). This must be a class name; the match test
whether the actual warning category of the message is a subclass of the
specified warning category.</p>
<p>The <em>module</em> field matches the (fully qualified) module name; this match is
case-sensitive.</p>
<p>The <em>lineno</em> field matches the line number, where zero matches all line
numbers and is thus equivalent to an omitted line number.</p>
<p>Multiple <a class="reference internal" href="#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> options can be given; when a warning matches more than
one option, the action for the last matching option is performed. Invalid
<code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code> options are ignored (though, a warning message is printed about
invalid options when the first warning is issued).</p>
<p>Warnings can also be controlled using the <span class="target" id="index-19"></span><a class="reference internal" href="#envvar-PYTHONWARNINGS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONWARNINGS</span></code></a>
environment variable and from within a Python program using the
<a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module. For example, the <a class="reference internal" href="../library/warnings.html#warnings.filterwarnings" title="warnings.filterwarnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.filterwarnings()</span></code></a>
function can be used to use a regular expression on the warning message.</p>
<p>See <a class="reference internal" href="../library/warnings.html#warning-filter"><span class="std std-ref">The Warnings Filter</span></a> and <a class="reference internal" href="../library/warnings.html#describing-warning-filters"><span class="std std-ref">Describing Warning Filters</span></a> for more
details.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-x">
<span class="sig-name descname"><span class="pre">-x</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-x" title="Link to this definition">¶</a></dt>
<dd><p>Skip the first line of the source, allowing use of non-Unix forms of
<code class="docutils literal notranslate"><span class="pre">#!cmd</span></code>. This is intended for a DOS specific hack only.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-X">
<span class="sig-name descname"><span class="pre">-X</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-X" title="Link to this definition">¶</a></dt>
<dd><p>Reserved for various implementation-specific options. CPython currently
defines the following possible values:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">faulthandler</span></code> to enable <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a>.
See also <span class="target" id="index-20"></span><a class="reference internal" href="#envvar-PYTHONFAULTHANDLER"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONFAULTHANDLER</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.3.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showrefcount</span></code> to output the total reference count and number of used
memory blocks when the program finishes or after each statement in the
interactive interpreter. This only works on <a class="reference internal" href="configure.html#debug-build"><span class="std std-ref">debug builds</span></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">tracemalloc</span></code> to start tracing Python memory allocations using the
<a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module. By default, only the most recent frame is
stored in a traceback of a trace. Use <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">tracemalloc=NFRAME</span></code> to start
tracing with a traceback limit of <em>NFRAME</em> frames.
See <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.start" title="tracemalloc.start"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracemalloc.start()</span></code></a> and <span class="target" id="index-21"></span><a class="reference internal" href="#envvar-PYTHONTRACEMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONTRACEMALLOC</span></code></a>
for more information.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">int_max_str_digits</span></code> configures the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion
length limitation</span></a>. See also
<span class="target" id="index-22"></span><a class="reference internal" href="#envvar-PYTHONINTMAXSTRDIGITS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONINTMAXSTRDIGITS</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">importtime</span></code> to show how long each import takes. It shows module
name, cumulative time (including nested imports) and self time (excluding
nested imports). Note that its output may be broken in multi-threaded
application. Typical usage is <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-X</span> <span class="pre">importtime</span> <span class="pre">-c</span> <span class="pre">'import</span> <span class="pre">asyncio'</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">importtime=2</span></code> enables additional output that indicates when an
imported module has already been loaded. In such cases, the string
<code class="docutils literal notranslate"><span class="pre">cached</span></code> will be printed in both time columns.</p>
<p>See also <span class="target" id="index-23"></span><a class="reference internal" href="#envvar-PYTHONPROFILEIMPORTTIME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPROFILEIMPORTTIME</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.7.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>Added <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">importtime=2</span></code> to also trace imports of loaded modules,
and reserved values other than <code class="docutils literal notranslate"><span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">2</span></code> for future use.</p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">dev</span></code>: enable <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a>, introducing
additional runtime checks that are too expensive to be enabled by
default. See also <span class="target" id="index-24"></span><a class="reference internal" href="#envvar-PYTHONDEVMODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDEVMODE</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.7.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8</span></code> enables the <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.
<code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8=0</span></code> explicitly disables <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>
(even when it would otherwise activate automatically).
See also <span class="target" id="index-25"></span><a class="reference internal" href="#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.7.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">pycache_prefix=PATH</span></code> enables writing <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files to a parallel
tree rooted at the given directory instead of to the code tree. See also
<span class="target" id="index-26"></span><a class="reference internal" href="#envvar-PYTHONPYCACHEPREFIX"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPYCACHEPREFIX</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.8.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">warn_default_encoding</span></code> issues a <a class="reference internal" href="../library/exceptions.html#EncodingWarning" title="EncodingWarning"><code class="xref py py-class docutils literal notranslate"><span class="pre">EncodingWarning</span></code></a> when the
locale-specific default encoding is used for opening files.
See also <span class="target" id="index-27"></span><a class="reference internal" href="#envvar-PYTHONWARNDEFAULTENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONWARNDEFAULTENCODING</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.10.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">no_debug_ranges</span></code> disables the inclusion of the tables mapping extra
location information (end line, start column offset and end column offset)
to every instruction in code objects. This is useful when smaller code
objects and pyc files are desired as well as suppressing the extra visual
location indicators when the interpreter displays tracebacks. See also
<span class="target" id="index-28"></span><a class="reference internal" href="#envvar-PYTHONNODEBUGRANGES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNODEBUGRANGES</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">frozen_modules</span></code> determines whether or not frozen modules are
ignored by the import machinery. A value of <code class="docutils literal notranslate"><span class="pre">on</span></code> means they get
imported and <code class="docutils literal notranslate"><span class="pre">off</span></code> means they are ignored. The default is <code class="docutils literal notranslate"><span class="pre">on</span></code>
if this is an installed Python (the normal case). If it's under
development (running from the source tree) then the default is <code class="docutils literal notranslate"><span class="pre">off</span></code>.
Note that the <code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib_bootstrap</span></code> and
<code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib_bootstrap_external</span></code> frozen modules are always used, even
if this flag is set to <code class="docutils literal notranslate"><span class="pre">off</span></code>. See also <span class="target" id="index-29"></span><a class="reference internal" href="#envvar-PYTHON_FROZEN_MODULES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_FROZEN_MODULES</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">perf</span></code> enables support for the Linux <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler.
When this option is provided, the <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler will be able to
report Python calls. This option is only available on some platforms and
will do nothing if is not supported on the current system. The default value
is "off". See also <span class="target" id="index-30"></span><a class="reference internal" href="#envvar-PYTHONPERFSUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPERFSUPPORT</span></code></a> and <a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">Python support for the Linux perf profiler</span></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.12.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">perf_jit</span></code> enables support for the Linux <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler with DWARF
support. When this option is provided, the <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler will be able
to report Python calls using DWARF information. This option is only available on
some platforms and will do nothing if is not supported on the current
system. The default value is "off". See also <span class="target" id="index-31"></span><a class="reference internal" href="#envvar-PYTHON_PERF_JIT_SUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_PERF_JIT_SUPPORT</span></code></a>
and <a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">Python support for the Linux perf profiler</span></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">disable_remote_debug</span></code> disables the remote debugging support as described
in <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0768/"><strong>PEP 768</strong></a>. This includes both the functionality to schedule code for
execution in another process and the functionality to receive code for
execution in the current process.</p>
<p>This option is only available on some platforms and will do nothing
if is not supported on the current system. See also
<span class="target" id="index-33"></span><a class="reference internal" href="#envvar-PYTHON_DISABLE_REMOTE_DEBUG"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_DISABLE_REMOTE_DEBUG</span></code></a> and <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0768/"><strong>PEP 768</strong></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">cpu_count=</span><em><span class="pre">n</span></em></code> overrides <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a>,
<a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.process_cpu_count()</span></code></a>, and <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.cpu_count" title="multiprocessing.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.cpu_count()</span></code></a>.
<em>n</em> must be greater than or equal to 1.
This option may be useful for users who need to limit CPU resources of a
container system. See also <span class="target" id="index-35"></span><a class="reference internal" href="#envvar-PYTHON_CPU_COUNT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_CPU_COUNT</span></code></a>.
If <em>n</em> is <code class="docutils literal notranslate"><span class="pre">default</span></code>, nothing is overridden.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">presite=</span><em><span class="pre">package.module</span></em></code> specifies a module that should be
imported before the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module is executed and before the
<a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module exists. Therefore, the imported module isn't
<code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code>. This can be used to execute code early during Python
initialization. Python needs to be <a class="reference internal" href="configure.html#debug-build"><span class="std std-ref">built in debug mode</span></a>
for this option to exist. See also <span class="target" id="index-36"></span><a class="reference internal" href="#envvar-PYTHON_PRESITE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_PRESITE</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">gil=</span><em><span class="pre">0,1</span></em></code> forces the GIL to be disabled or enabled,
respectively. Setting to <code class="docutils literal notranslate"><span class="pre">0</span></code> is only available in builds configured with
<a class="reference internal" href="configure.html#cmdoption-disable-gil"><code class="xref std std-option docutils literal notranslate"><span class="pre">--disable-gil</span></code></a>. See also <span class="target" id="index-37"></span><a class="reference internal" href="#envvar-PYTHON_GIL"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_GIL</span></code></a> and
<a class="reference internal" href="../whatsnew/3.13.html#whatsnew313-free-threaded-cpython"><span class="std std-ref">Free-threaded CPython</span></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">thread_inherit_context=</span><em><span class="pre">0,1</span></em></code> causes <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">Thread</span></code></a>
to, by default, use a copy of context of the caller of
<code class="docutils literal notranslate"><span class="pre">Thread.start()</span></code> when starting. Otherwise, threads will start
with an empty context. If unset, the value of this option defaults
to <code class="docutils literal notranslate"><span class="pre">1</span></code> on free-threaded builds and to <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise. See also
<span class="target" id="index-38"></span><a class="reference internal" href="#envvar-PYTHON_THREAD_INHERIT_CONTEXT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_THREAD_INHERIT_CONTEXT</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">context_aware_warnings=</span><em><span class="pre">0,1</span></em></code> causes the
<a class="reference internal" href="../library/warnings.html#warnings.catch_warnings" title="warnings.catch_warnings"><code class="xref py py-class docutils literal notranslate"><span class="pre">warnings.catch_warnings</span></code></a> context manager to use a
<a class="reference internal" href="../library/contextvars.html#contextvars.ContextVar" title="contextvars.ContextVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContextVar</span></code></a> to store warnings filter state. If
unset, the value of this option defaults to <code class="docutils literal notranslate"><span class="pre">1</span></code> on free-threaded builds
and to <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise. See also <span class="target" id="index-39"></span><a class="reference internal" href="#envvar-PYTHON_CONTEXT_AWARE_WARNINGS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_CONTEXT_AWARE_WARNINGS</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</li>
<li><p><code class="samp docutils literal notranslate"><span class="pre">-X</span> <span class="pre">tlbc=</span><em><span class="pre">0,1</span></em></code> enables (1, the default) or disables (0) thread-local
bytecode in builds configured with <a class="reference internal" href="configure.html#cmdoption-disable-gil"><code class="xref std std-option docutils literal notranslate"><span class="pre">--disable-gil</span></code></a>. When disabled,
this also disables the specializing interpreter. See also
<span class="target" id="index-40"></span><a class="reference internal" href="#envvar-PYTHON_TLBC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_TLBC</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</li>
</ul>
<p>It also allows passing arbitrary values and retrieving them through the
<a class="reference internal" href="../library/sys.html#sys._xoptions" title="sys._xoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys._xoptions</span></code></a> dictionary.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.2.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.9: </span>Removed the <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showalloccount</span></code> option.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.10: </span>Removed the <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">oldparser</span></code> option.</p>
</div>
</dd></dl>
<div class="versionremoved">
<p><span class="versionmodified removed">Removed in version 3.14: </span><code class="xref std std-option docutils literal notranslate"><span class="pre">-J</span></code> is no longer reserved for use by <a class="reference external" href="https://www.jython.org/">Jython</a>,
and now has no special meaning.</p>
</div>
</section>
<section id="controlling-color">
<span id="using-on-controlling-color"></span><h3><span class="section-number">1.1.4. </span>Controlling color<a class="headerlink" href="#controlling-color" title="Link to this heading">¶</a></h3>
<p>The Python interpreter is configured by default to use colors to highlight
output in certain situations such as when displaying tracebacks. This
behavior can be controlled by setting different environment variables.</p>
<p>Setting the environment variable <code class="docutils literal notranslate"><span class="pre">TERM</span></code> to <code class="docutils literal notranslate"><span class="pre">dumb</span></code> will disable color.</p>
<p>If the <a class="reference external" href="https://force-color.org/"><code class="docutils literal notranslate"><span class="pre">FORCE_COLOR</span></code></a> environment variable is set, then color will be
enabled regardless of the value of TERM. This is useful on CI systems which
aren’t terminals but can still display ANSI escape sequences.</p>
<p>If the <a class="reference external" href="https://no-color.org/"><code class="docutils literal notranslate"><span class="pre">NO_COLOR</span></code></a> environment variable is set, Python will disable all color
in the output. This takes precedence over <code class="docutils literal notranslate"><span class="pre">FORCE_COLOR</span></code>.</p>
<p>All these environment variables are used also by other tools to control color
output. To control the color output only in the Python interpreter, the
<span class="target" id="index-41"></span><a class="reference internal" href="#envvar-PYTHON_COLORS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_COLORS</span></code></a> environment variable can be used. This variable takes
precedence over <code class="docutils literal notranslate"><span class="pre">NO_COLOR</span></code>, which in turn takes precedence over
<code class="docutils literal notranslate"><span class="pre">FORCE_COLOR</span></code>.</p>
</section>
</section>
<section id="environment-variables">
<span id="using-on-envvars"></span><h2><span class="section-number">1.2. </span>Environment variables<a class="headerlink" href="#environment-variables" title="Link to this heading">¶</a></h2>
<p>These environment variables influence Python's behavior, they are processed
before the command-line switches other than -E or -I. It is customary that
command-line switches override environmental variables where there is a
conflict.</p>
<dl class="std envvar">
<dt class="sig sig-object std" id="envvar-PYTHONHOME">
<span class="sig-name descname"><span class="pre">PYTHONHOME</span></span><a class="headerlink" href="#envvar-PYTHONHOME" title="Link to this definition">¶</a></dt>
<dd><p>Change the location of the standard Python libraries. By default, the
libraries are searched in <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">version</span></em></code> and
<code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">version</span></em></code>, where <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em></code> and
<code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em></code> are installation-dependent directories, both defaulting
to <code class="file docutils literal notranslate"><span class="pre">/usr/local</span></code>.</p>
<p>When <span class="target" id="index-42"></span><a class="reference internal" href="#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> is set to a single directory, its value replaces
both <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em></code> and <code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em></code>. To specify different values
for these, set <span class="target" id="index-43"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code> to <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em><span class="pre">:</span><em><span class="pre">exec_prefix</span></em></code>.</p>
</dd></dl>
<dl class="std envvar">
<dt class="sig sig-object std" id="envvar-PYTHONPATH">
<span class="sig-name descname"><span class="pre">PYTHONPATH</span></span><a class="headerlink" href="#envvar-PYTHONPATH" title="Link to this definition">¶</a></dt>
<dd><p>Augment the default search path for module files. The format is the same as
the shell's <span class="target" id="index-44"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>: one or more directory pathnames separated by
<a class="reference internal" href="../library/os.html#os.pathsep" title="os.pathsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.pathsep</span></code></a> (e.g. colons on Unix or semicolons on Windows).
Non-existent directories are silently ignored.</p>
<p>In addition to normal directories, individual <span class="target" id="index-45"></span><a class="reference internal" href="#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> entries
may refer to zipfiles containing pure Python modules (in either source or
compiled form). Extension modules cannot be imported from zipfiles.</p>
<p>The default search path is installation dependent, but generally begins with
<code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">version</span></em></code> (see <span class="target" id="index-46"></span><a class="reference internal" href="#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> above). It
is <em>always</em> appended to <span class="target" id="index-47"></span><a class="reference internal" href="#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a>.</p>
<p>An additional directory will be inserted in the search path in front of
<span class="target" id="index-48"></span><a class="reference internal" href="#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> as described above under
<a class="reference internal" href="#using-on-interface-options"><span class="std std-ref">Interface options</span></a>. The search path can be manipulated from
within a Python program as the variable <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
</dd></dl>
<dl class="std envvar">
<dt class="sig sig-object std" id="envvar-PYTHONSAFEPATH">
<span class="sig-name descname"><span class="pre">PYTHONSAFEPATH</span></span><a class="headerlink" href="#envvar-PYTHONSAFEPATH" title="Link to this definition">¶</a></dt>
<dd><p>If this is set to a non-empty string, don't prepend a potentially unsafe
path to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>: see the <a class="reference internal" href="#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> option for details.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std envvar">
<dt class="sig sig-object std" id="envvar-PYTHONPLATLIBDIR">
<span class="sig-name descname"><span class="pre">PYTHONPLATLIBDIR</span></span><a class="headerlink" href="#envvar-PYTHONPLATLIBDIR" title="Link to this definition">¶</a></dt>
<dd><p>If this is set to a non-empty string, it overrides the <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a>
value.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.9.</span></p>
</div>
</dd></dl>
<dl class="std envvar">
<dt class="sig sig-object std" id="envvar-PYTHONSTARTUP">
<span class="sig-name descname"><span class="pre">PYTHONSTARTUP</span></span><a class="headerlink" href="#envvar-PYTHONSTARTUP" title="Link to this definition">¶</a></dt>