[{"data":1,"prerenderedAt":1492},["ShallowReactive",2],{"doc-\u002Fstandard-library\u002Fpython-sys-module-overview":3},{"id":4,"title":5,"body":6,"description":1485,"extension":1486,"meta":1487,"navigation":88,"path":1488,"seo":1489,"stem":1490,"__hash__":1491},"content\u002Fstandard-library\u002Fpython-sys-module-overview.md","Python sys Module Overview",{"type":7,"value":8,"toc":1465},"minimark",[9,13,22,28,50,56,61,146,152,156,161,164,181,184,195,199,205,236,249,253,259,308,312,321,387,390,447,450,454,459,476,479,635,638,656,659,723,732,736,741,859,862,879,882,922,927,931,936,939,984,989,992,1008,1016,1030,1034,1039,1063,1066,1165,1176,1180,1185,1219,1222,1307,1310,1380,1384,1389,1392,1396,1402,1406,1409,1413,1416,1420,1423,1427,1461],[10,11,5],"h1",{"id":12},"python-sys-module-overview",[14,15,16,17,21],"p",{},"The ",[18,19,20],"code",{},"sys"," module is a built-in Python standard library module. It gives you access to information about the Python interpreter and some parts of the program runtime.",[14,23,24,25,27],{},"Beginners often use ",[18,26,20],{}," for:",[29,30,31,35,41,44,47],"ul",{},[32,33,34],"li",{},"reading command-line arguments",[32,36,37,38],{},"stopping a program with ",[18,39,40],{},"sys.exit()",[32,42,43],{},"checking the Python version",[32,45,46],{},"checking the platform",[32,48,49],{},"understanding where Python looks for modules",[14,51,52,53,55],{},"This page is an overview of the most useful parts of ",[18,54,20],{},". It is not a full reference for every attribute in the module.",[57,58,60],"h2",{"id":59},"quick-example","Quick example",[62,63,68],"pre",{"className":64,"code":65,"language":66,"meta":67,"style":67},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import sys\n\nprint(sys.version)\nprint(sys.platform)\nprint(sys.argv)\n","python","",[18,69,70,83,90,114,130],{"__ignoreMap":67},[71,72,75,79],"span",{"class":73,"line":74},"line",1,[71,76,78],{"class":77},"sVHd0","import",[71,80,82],{"class":81},"su5hD"," sys\n",[71,84,86],{"class":73,"line":85},2,[71,87,89],{"emptyLinePlaceholder":88},true,"\n",[71,91,93,97,101,104,107,111],{"class":73,"line":92},3,[71,94,96],{"class":95},"sptTA","print",[71,98,100],{"class":99},"sP7_E","(",[71,102,20],{"class":103},"slqww",[71,105,106],{"class":99},".",[71,108,110],{"class":109},"skxfh","version",[71,112,113],{"class":99},")\n",[71,115,117,119,121,123,125,128],{"class":73,"line":116},4,[71,118,96],{"class":95},[71,120,100],{"class":99},[71,122,20],{"class":103},[71,124,106],{"class":99},[71,126,127],{"class":109},"platform",[71,129,113],{"class":99},[71,131,133,135,137,139,141,144],{"class":73,"line":132},5,[71,134,96],{"class":95},[71,136,100],{"class":99},[71,138,20],{"class":103},[71,140,106],{"class":99},[71,142,143],{"class":109},"argv",[71,145,113],{"class":99},[14,147,148,149,151],{},"Use this short example to see basic information from the ",[18,150,20],{}," module and inspect command-line arguments.",[57,153,155],{"id":154},"what-the-sys-module-is","What the sys module is",[14,157,158,160],{},[18,159,20],{}," is part of Python's standard library, so you do not need to install it.",[14,162,163],{},"It gives access to:",[29,165,166,169,172,175,178],{},[32,167,168],{},"Python interpreter settings",[32,170,171],{},"runtime information",[32,173,174],{},"command-line arguments",[32,176,177],{},"program exit behavior",[32,179,180],{},"module search paths",[14,182,183],{},"You must import it before using it:",[62,185,187],{"className":64,"code":186,"language":66,"meta":67,"style":67},"import sys\n",[18,188,189],{"__ignoreMap":67},[71,190,191,193],{"class":73,"line":74},[71,192,78],{"class":77},[71,194,82],{"class":81},[57,196,198],{"id":197},"when-to-use-sys","When to use sys",[14,200,201,202,204],{},"Use ",[18,203,20],{}," when you need one of these common tasks:",[29,206,207,213,218,224,230],{},[32,208,201,209,212],{},[18,210,211],{},"sys.argv"," to read command-line arguments.",[32,214,201,215,217],{},[18,216,40],{}," to stop a program intentionally.",[32,219,201,220,223],{},[18,221,222],{},"sys.version"," to check the Python version.",[32,225,201,226,229],{},[18,227,228],{},"sys.path"," to see where Python looks for modules.",[32,231,201,232,235],{},[18,233,234],{},"sys.platform"," to detect the operating system in simple scripts.",[14,237,238,239,244,245,106],{},"If you only need one specific part, it can help to read a focused page such as ",[240,241,243],"a",{"href":242},"\u002Fstandard-library\u002Fsys.argv-explained","sys.argv explained"," or ",[240,246,248],{"href":247},"\u002Fstandard-library\u002Fsys.exit-function-explained","sys.exit() explained",[57,250,252],{"id":251},"commonly-used-parts-of-sys","Commonly used parts of sys",[14,254,255,256,258],{},"Here are the ",[18,257,20],{}," features beginners use most often:",[29,260,261,269,276,283,301],{},[32,262,263,265,268],{},[18,264,211],{},[266,267],"br",{},"\nA list of command-line arguments.",[32,270,271,273,275],{},[18,272,40],{},[266,274],{},"\nStops the program and can return an exit code.",[32,277,278,280,282],{},[18,279,222],{},[266,281],{},"\nA full string showing the Python version.",[32,284,285,287,289,290,293,294,297,298,106],{},[18,286,234],{},[266,288],{},"\nA short platform name such as ",[18,291,292],{},"win32",", ",[18,295,296],{},"linux",", or ",[18,299,300],{},"darwin",[32,302,303,305,307],{},[18,304,228],{},[266,306],{},"\nA list of folders Python searches when importing modules.",[57,309,311],{"id":310},"example-checking-python-version-and-platform","Example: checking Python version and platform",[14,313,314,315,317,318,320],{},"You can use ",[18,316,222],{}," and ",[18,319,234],{}," to quickly inspect your Python environment.",[62,322,324],{"className":64,"code":323,"language":66,"meta":67,"style":67},"import sys\n\nprint(\"Python version:\", sys.version)\nprint(\"Platform:\", sys.platform)\n",[18,325,326,332,336,364],{"__ignoreMap":67},[71,327,328,330],{"class":73,"line":74},[71,329,78],{"class":77},[71,331,82],{"class":81},[71,333,334],{"class":73,"line":85},[71,335,89],{"emptyLinePlaceholder":88},[71,337,338,340,342,346,350,352,355,358,360,362],{"class":73,"line":92},[71,339,96],{"class":95},[71,341,100],{"class":99},[71,343,345],{"class":344},"sjJ54","\"",[71,347,349],{"class":348},"s_sjI","Python version:",[71,351,345],{"class":344},[71,353,354],{"class":99},",",[71,356,357],{"class":103}," sys",[71,359,106],{"class":99},[71,361,110],{"class":109},[71,363,113],{"class":99},[71,365,366,368,370,372,375,377,379,381,383,385],{"class":73,"line":116},[71,367,96],{"class":95},[71,369,100],{"class":99},[71,371,345],{"class":344},[71,373,374],{"class":348},"Platform:",[71,376,345],{"class":344},[71,378,354],{"class":99},[71,380,357],{"class":103},[71,382,106],{"class":99},[71,384,127],{"class":109},[71,386,113],{"class":99},[14,388,389],{},"Example output:",[62,391,393],{"className":64,"code":392,"language":66,"meta":67,"style":67},"Python version: 3.12.2 (main, Feb  6 2024, ...)\nPlatform: win32\n",[18,394,395,437],{"__ignoreMap":67},[71,396,397,400,403,407,409,412,415,418,420,423,426,429,431,435],{"class":73,"line":74},[71,398,399],{"class":81},"Python version",[71,401,402],{"class":99},":",[71,404,406],{"class":405},"srdBf"," 3.12",[71,408,106],{"class":99},[71,410,411],{"class":109},"2",[71,413,414],{"class":99}," (",[71,416,417],{"class":81},"main",[71,419,354],{"class":99},[71,421,422],{"class":81}," Feb  ",[71,424,425],{"class":405},"6",[71,427,428],{"class":405}," 2024",[71,430,354],{"class":99},[71,432,434],{"class":433},"s_hVV"," ...",[71,436,113],{"class":99},[71,438,439,442,444],{"class":73,"line":85},[71,440,441],{"class":81},"Platform",[71,443,402],{"class":99},[71,445,446],{"class":81}," win32\n",[14,448,449],{},"This is useful when code behaves differently on different systems, or when you need to confirm which Python version is running.",[57,451,453],{"id":452},"example-reading-command-line-arguments","Example: reading command-line arguments",[14,455,456,458],{},[18,457,211],{}," is a list.",[29,460,461,467,470],{},[32,462,463,466],{},[18,464,465],{},"sys.argv[0]"," is usually the script name.",[32,468,469],{},"Values after the script name are extra arguments.",[32,471,472,473,475],{},"All values in ",[18,474,211],{}," are strings.",[14,477,478],{},"Example script:",[62,480,482],{"className":64,"code":481,"language":66,"meta":67,"style":67},"import sys\n\nprint(\"Full argv list:\", sys.argv)\nprint(\"Script name:\", sys.argv[0])\n\nif len(sys.argv) > 1:\n    print(\"First extra argument:\", sys.argv[1])\nelse:\n    print(\"No extra argument was provided.\")\n",[18,483,484,490,494,517,547,551,581,611,619],{"__ignoreMap":67},[71,485,486,488],{"class":73,"line":74},[71,487,78],{"class":77},[71,489,82],{"class":81},[71,491,492],{"class":73,"line":85},[71,493,89],{"emptyLinePlaceholder":88},[71,495,496,498,500,502,505,507,509,511,513,515],{"class":73,"line":92},[71,497,96],{"class":95},[71,499,100],{"class":99},[71,501,345],{"class":344},[71,503,504],{"class":348},"Full argv list:",[71,506,345],{"class":344},[71,508,354],{"class":99},[71,510,357],{"class":103},[71,512,106],{"class":99},[71,514,143],{"class":109},[71,516,113],{"class":99},[71,518,519,521,523,525,528,530,532,534,536,538,541,544],{"class":73,"line":116},[71,520,96],{"class":95},[71,522,100],{"class":99},[71,524,345],{"class":344},[71,526,527],{"class":348},"Script name:",[71,529,345],{"class":344},[71,531,354],{"class":99},[71,533,357],{"class":103},[71,535,106],{"class":99},[71,537,143],{"class":109},[71,539,540],{"class":99},"[",[71,542,543],{"class":405},"0",[71,545,546],{"class":99},"])\n",[71,548,549],{"class":73,"line":132},[71,550,89],{"emptyLinePlaceholder":88},[71,552,554,557,560,562,564,566,568,571,575,578],{"class":73,"line":553},6,[71,555,556],{"class":77},"if",[71,558,559],{"class":95}," len",[71,561,100],{"class":99},[71,563,20],{"class":103},[71,565,106],{"class":99},[71,567,143],{"class":109},[71,569,570],{"class":99},")",[71,572,574],{"class":573},"smGrS"," >",[71,576,577],{"class":405}," 1",[71,579,580],{"class":99},":\n",[71,582,584,587,589,591,594,596,598,600,602,604,606,609],{"class":73,"line":583},7,[71,585,586],{"class":95},"    print",[71,588,100],{"class":99},[71,590,345],{"class":344},[71,592,593],{"class":348},"First extra argument:",[71,595,345],{"class":344},[71,597,354],{"class":99},[71,599,357],{"class":103},[71,601,106],{"class":99},[71,603,143],{"class":109},[71,605,540],{"class":99},[71,607,608],{"class":405},"1",[71,610,546],{"class":99},[71,612,614,617],{"class":73,"line":613},8,[71,615,616],{"class":77},"else",[71,618,580],{"class":99},[71,620,622,624,626,628,631,633],{"class":73,"line":621},9,[71,623,586],{"class":95},[71,625,100],{"class":99},[71,627,345],{"class":344},[71,629,630],{"class":348},"No extra argument was provided.",[71,632,345],{"class":344},[71,634,113],{"class":99},[14,636,637],{},"If you run:",[62,639,643],{"className":640,"code":641,"language":642,"meta":67,"style":67},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python your_script.py hello\n","bash",[18,644,645],{"__ignoreMap":67},[71,646,647,650,653],{"class":73,"line":74},[71,648,66],{"class":649},"sbgvK",[71,651,652],{"class":348}," your_script.py",[71,654,655],{"class":348}," hello\n",[14,657,658],{},"You will usually get output like:",[62,660,662],{"className":64,"code":661,"language":66,"meta":67,"style":67},"Full argv list: ['your_script.py', 'hello']\nScript name: your_script.py\nFirst extra argument: hello\n",[18,663,664,699,714],{"__ignoreMap":67},[71,665,666,669,673,675,678,681,684,686,688,691,694,696],{"class":73,"line":74},[71,667,668],{"class":81},"Full argv ",[71,670,672],{"class":671},"sZMiF","list",[71,674,402],{"class":99},[71,676,677],{"class":99}," [",[71,679,680],{"class":344},"'",[71,682,683],{"class":348},"your_script.py",[71,685,680],{"class":344},[71,687,354],{"class":99},[71,689,690],{"class":344}," '",[71,692,693],{"class":348},"hello",[71,695,680],{"class":344},[71,697,698],{"class":99},"]\n",[71,700,701,704,706,709,711],{"class":73,"line":85},[71,702,703],{"class":81},"Script name",[71,705,402],{"class":99},[71,707,708],{"class":81}," your_script",[71,710,106],{"class":99},[71,712,713],{"class":109},"py\n",[71,715,716,719,721],{"class":73,"line":92},[71,717,718],{"class":81},"First extra argument",[71,720,402],{"class":99},[71,722,655],{"class":81},[14,724,725,726,244,728,106],{},"If you need more detail, see ",[240,727,243],{"href":242},[240,729,731],{"href":730},"\u002Fhow-to\u002Fhow-to-use-command-line-arguments-in-python","how to use command-line arguments in Python",[57,733,735],{"id":734},"example-exiting-a-program","Example: exiting a program",[14,737,201,738,740],{},[18,739,40],{}," when you want to stop a script early.",[62,742,744],{"className":64,"code":743,"language":66,"meta":67,"style":67},"import sys\n\nname = input(\"Enter your name: \").strip()\n\nif name == \"\":\n    print(\"Name is required.\")\n    sys.exit(1)\n\nprint(\"Hello,\", name)\n",[18,745,746,752,756,785,789,804,819,835,839],{"__ignoreMap":67},[71,747,748,750],{"class":73,"line":74},[71,749,78],{"class":77},[71,751,82],{"class":81},[71,753,754],{"class":73,"line":85},[71,755,89],{"emptyLinePlaceholder":88},[71,757,758,761,764,767,769,771,774,776,779,782],{"class":73,"line":92},[71,759,760],{"class":81},"name ",[71,762,763],{"class":573},"=",[71,765,766],{"class":95}," input",[71,768,100],{"class":99},[71,770,345],{"class":344},[71,772,773],{"class":348},"Enter your name: ",[71,775,345],{"class":344},[71,777,778],{"class":99},").",[71,780,781],{"class":103},"strip",[71,783,784],{"class":99},"()\n",[71,786,787],{"class":73,"line":116},[71,788,89],{"emptyLinePlaceholder":88},[71,790,791,793,796,799,802],{"class":73,"line":132},[71,792,556],{"class":77},[71,794,795],{"class":81}," name ",[71,797,798],{"class":573},"==",[71,800,801],{"class":344}," \"\"",[71,803,580],{"class":99},[71,805,806,808,810,812,815,817],{"class":73,"line":553},[71,807,586],{"class":95},[71,809,100],{"class":99},[71,811,345],{"class":344},[71,813,814],{"class":348},"Name is required.",[71,816,345],{"class":344},[71,818,113],{"class":99},[71,820,821,824,826,829,831,833],{"class":73,"line":583},[71,822,823],{"class":81},"    sys",[71,825,106],{"class":99},[71,827,828],{"class":103},"exit",[71,830,100],{"class":99},[71,832,608],{"class":405},[71,834,113],{"class":99},[71,836,837],{"class":73,"line":613},[71,838,89],{"emptyLinePlaceholder":88},[71,840,841,843,845,847,850,852,854,857],{"class":73,"line":621},[71,842,96],{"class":95},[71,844,100],{"class":99},[71,846,345],{"class":344},[71,848,849],{"class":348},"Hello,",[71,851,345],{"class":344},[71,853,354],{"class":99},[71,855,856],{"class":103}," name",[71,858,113],{"class":99},[14,860,861],{},"How this works:",[29,863,864,867,873],{},[32,865,866],{},"If the user enters nothing, the script prints a message and stops.",[32,868,869,872],{},[18,870,871],{},"sys.exit(1)"," usually means the program ended with an error.",[32,874,875,878],{},[18,876,877],{},"sys.exit(0)"," usually means success.",[14,880,881],{},"You can also exit without a code:",[62,883,885],{"className":64,"code":884,"language":66,"meta":67,"style":67},"import sys\n\nprint(\"Stopping the program now.\")\nsys.exit()\n",[18,886,887,893,897,912],{"__ignoreMap":67},[71,888,889,891],{"class":73,"line":74},[71,890,78],{"class":77},[71,892,82],{"class":81},[71,894,895],{"class":73,"line":85},[71,896,89],{"emptyLinePlaceholder":88},[71,898,899,901,903,905,908,910],{"class":73,"line":92},[71,900,96],{"class":95},[71,902,100],{"class":99},[71,904,345],{"class":344},[71,906,907],{"class":348},"Stopping the program now.",[71,909,345],{"class":344},[71,911,113],{"class":99},[71,913,914,916,918,920],{"class":73,"line":116},[71,915,20],{"class":81},[71,917,106],{"class":99},[71,919,828],{"class":103},[71,921,784],{"class":99},[14,923,924,925,106],{},"For a deeper explanation, see ",[240,926,248],{"href":247},[57,928,930],{"id":929},"understanding-syspath-at-a-beginner-level","Understanding sys.path at a beginner level",[14,932,933,935],{},[18,934,228],{}," is the list of locations Python checks when you import modules.",[14,937,938],{},"Example:",[62,940,942],{"className":64,"code":941,"language":66,"meta":67,"style":67},"import sys\n\nfor path in sys.path:\n    print(path)\n",[18,943,944,950,954,974],{"__ignoreMap":67},[71,945,946,948],{"class":73,"line":74},[71,947,78],{"class":77},[71,949,82],{"class":81},[71,951,952],{"class":73,"line":85},[71,953,89],{"emptyLinePlaceholder":88},[71,955,956,959,962,965,967,969,972],{"class":73,"line":92},[71,957,958],{"class":77},"for",[71,960,961],{"class":81}," path ",[71,963,964],{"class":77},"in",[71,966,357],{"class":81},[71,968,106],{"class":99},[71,970,971],{"class":109},"path",[71,973,580],{"class":99},[71,975,976,978,980,982],{"class":73,"line":116},[71,977,586],{"class":95},[71,979,100],{"class":99},[71,981,971],{"class":103},[71,983,113],{"class":99},[14,985,986,987,106],{},"This helps explain some import problems. If Python cannot find a module, one possible reason is that the module is not in one of the folders listed in ",[18,988,228],{},[14,990,991],{},"For beginners, the main idea is:",[29,993,994,999,1002],{},[32,995,996,998],{},[18,997,228],{}," affects imports",[32,1000,1001],{},"import errors often relate to search paths",[32,1003,1004,1005,1007],{},"you usually should not modify ",[18,1006,228],{}," unless you understand why",[14,1009,1010,1011,1015],{},"If imports are confusing, read ",[240,1012,1014],{"href":1013},"\u002Flearn\u002Fhow-import-works-in-python","how import works in Python",". If you are fixing an error, these pages may help:",[29,1017,1018,1024],{},[32,1019,1020],{},[240,1021,1023],{"href":1022},"\u002Ferrors\u002Fmodulenotfounderror-no-module-named-x-fix","ModuleNotFoundError: No module named X fix",[32,1025,1026],{},[240,1027,1029],{"href":1028},"\u002Ferrors\u002Fimporterror-no-module-named-x-fix","ImportError: No module named X fix",[57,1031,1033],{"id":1032},"beginner-tips","Beginner tips",[14,1035,1036,1037,402],{},"Keep these points in mind when using ",[18,1038,20],{},[29,1040,1041,1048,1053,1056],{},[32,1042,1043,1044,1047],{},"Always write ",[18,1045,1046],{},"import sys"," first.",[32,1049,1050,1052],{},[18,1051,211],{}," values are strings.",[32,1054,1055],{},"Use conversion functions if you need numbers.",[32,1057,1058,1059,1062],{},"For larger command-line programs, ",[18,1060,1061],{},"argparse"," is usually a better choice.",[14,1064,1065],{},"Example of converting an argument to a number:",[62,1067,1069],{"className":64,"code":1068,"language":66,"meta":67,"style":67},"import sys\n\nif len(sys.argv) > 1:\n    number = int(sys.argv[1])\n    print(number * 2)\nelse:\n    print(\"Please provide a number.\")\n",[18,1070,1071,1077,1081,1103,1127,1144,1150],{"__ignoreMap":67},[71,1072,1073,1075],{"class":73,"line":74},[71,1074,78],{"class":77},[71,1076,82],{"class":81},[71,1078,1079],{"class":73,"line":85},[71,1080,89],{"emptyLinePlaceholder":88},[71,1082,1083,1085,1087,1089,1091,1093,1095,1097,1099,1101],{"class":73,"line":92},[71,1084,556],{"class":77},[71,1086,559],{"class":95},[71,1088,100],{"class":99},[71,1090,20],{"class":103},[71,1092,106],{"class":99},[71,1094,143],{"class":109},[71,1096,570],{"class":99},[71,1098,574],{"class":573},[71,1100,577],{"class":405},[71,1102,580],{"class":99},[71,1104,1105,1108,1110,1113,1115,1117,1119,1121,1123,1125],{"class":73,"line":116},[71,1106,1107],{"class":81},"    number ",[71,1109,763],{"class":573},[71,1111,1112],{"class":671}," int",[71,1114,100],{"class":99},[71,1116,20],{"class":103},[71,1118,106],{"class":99},[71,1120,143],{"class":109},[71,1122,540],{"class":99},[71,1124,608],{"class":405},[71,1126,546],{"class":99},[71,1128,1129,1131,1133,1136,1139,1142],{"class":73,"line":132},[71,1130,586],{"class":95},[71,1132,100],{"class":99},[71,1134,1135],{"class":103},"number ",[71,1137,1138],{"class":573},"*",[71,1140,1141],{"class":405}," 2",[71,1143,113],{"class":99},[71,1145,1146,1148],{"class":73,"line":553},[71,1147,616],{"class":77},[71,1149,580],{"class":99},[71,1151,1152,1154,1156,1158,1161,1163],{"class":73,"line":583},[71,1153,586],{"class":95},[71,1155,100],{"class":99},[71,1157,345],{"class":344},[71,1159,1160],{"class":348},"Please provide a number.",[71,1162,345],{"class":344},[71,1164,113],{"class":99},[14,1166,1167,1168,1171,1172,106],{},"Here, ",[18,1169,1170],{},"int()"," converts the string argument into an integer. If you are not familiar with that conversion, see ",[240,1173,1175],{"href":1174},"\u002Freference\u002Fpython-int-function-explained","Python int() explained",[57,1177,1179],{"id":1178},"common-mistakes","Common mistakes",[14,1181,1182,1183,402],{},"These are common beginner mistakes when using ",[18,1184,20],{},[29,1186,1187,1197,1200,1207,1213],{},[32,1188,1189,1190,1192,1193,244,1195],{},"Forgetting to write ",[18,1191,1046],{}," before using ",[18,1194,211],{},[18,1196,40],{},[32,1198,1199],{},"Assuming command-line arguments are numbers instead of strings",[32,1201,1202,1203,1206],{},"Using ",[18,1204,1205],{},"sys.argv[1]"," when no extra argument was provided",[32,1208,1209,1210,1212],{},"Confusing ",[18,1211,228],{}," with the current working directory",[32,1214,1215,1216,1218],{},"Trying to call ",[18,1217,20],{}," as if it were a function",[14,1220,1221],{},"A common safe pattern is to check the length first:",[62,1223,1225],{"className":64,"code":1224,"language":66,"meta":67,"style":67},"import sys\n\nif len(sys.argv) > 1:\n    print(\"Argument:\", sys.argv[1])\nelse:\n    print(\"No argument provided.\")\n",[18,1226,1227,1233,1237,1259,1286,1292],{"__ignoreMap":67},[71,1228,1229,1231],{"class":73,"line":74},[71,1230,78],{"class":77},[71,1232,82],{"class":81},[71,1234,1235],{"class":73,"line":85},[71,1236,89],{"emptyLinePlaceholder":88},[71,1238,1239,1241,1243,1245,1247,1249,1251,1253,1255,1257],{"class":73,"line":92},[71,1240,556],{"class":77},[71,1242,559],{"class":95},[71,1244,100],{"class":99},[71,1246,20],{"class":103},[71,1248,106],{"class":99},[71,1250,143],{"class":109},[71,1252,570],{"class":99},[71,1254,574],{"class":573},[71,1256,577],{"class":405},[71,1258,580],{"class":99},[71,1260,1261,1263,1265,1267,1270,1272,1274,1276,1278,1280,1282,1284],{"class":73,"line":116},[71,1262,586],{"class":95},[71,1264,100],{"class":99},[71,1266,345],{"class":344},[71,1268,1269],{"class":348},"Argument:",[71,1271,345],{"class":344},[71,1273,354],{"class":99},[71,1275,357],{"class":103},[71,1277,106],{"class":99},[71,1279,143],{"class":109},[71,1281,540],{"class":99},[71,1283,608],{"class":405},[71,1285,546],{"class":99},[71,1287,1288,1290],{"class":73,"line":132},[71,1289,616],{"class":77},[71,1291,580],{"class":99},[71,1293,1294,1296,1298,1300,1303,1305],{"class":73,"line":553},[71,1295,586],{"class":95},[71,1297,100],{"class":99},[71,1299,345],{"class":344},[71,1301,1302],{"class":348},"No argument provided.",[71,1304,345],{"class":344},[71,1306,113],{"class":99},[14,1308,1309],{},"Useful commands for testing:",[62,1311,1313],{"className":640,"code":1312,"language":642,"meta":67,"style":67},"python --version\npython your_script.py\npython your_script.py hello\npython -c \"import sys; print(sys.version)\"\npython -c \"import sys; print(sys.argv)\"\npython -c \"import sys; print(sys.path)\"\n",[18,1314,1315,1323,1330,1338,1354,1367],{"__ignoreMap":67},[71,1316,1317,1319],{"class":73,"line":74},[71,1318,66],{"class":649},[71,1320,1322],{"class":1321},"stzsN"," --version\n",[71,1324,1325,1327],{"class":73,"line":85},[71,1326,66],{"class":649},[71,1328,1329],{"class":348}," your_script.py\n",[71,1331,1332,1334,1336],{"class":73,"line":92},[71,1333,66],{"class":649},[71,1335,652],{"class":348},[71,1337,655],{"class":348},[71,1339,1340,1342,1345,1348,1351],{"class":73,"line":116},[71,1341,66],{"class":649},[71,1343,1344],{"class":1321}," -c",[71,1346,1347],{"class":344}," \"",[71,1349,1350],{"class":348},"import sys; print(sys.version)",[71,1352,1353],{"class":344},"\"\n",[71,1355,1356,1358,1360,1362,1365],{"class":73,"line":132},[71,1357,66],{"class":649},[71,1359,1344],{"class":1321},[71,1361,1347],{"class":344},[71,1363,1364],{"class":348},"import sys; print(sys.argv)",[71,1366,1353],{"class":344},[71,1368,1369,1371,1373,1375,1378],{"class":73,"line":553},[71,1370,66],{"class":649},[71,1372,1344],{"class":1321},[71,1374,1347],{"class":344},[71,1376,1377],{"class":348},"import sys; print(sys.path)",[71,1379,1353],{"class":344},[57,1381,1383],{"id":1382},"faq","FAQ",[1385,1386,1388],"h3",{"id":1387},"what-is-the-sys-module-in-python","What is the sys module in Python?",[14,1390,1391],{},"It is a standard library module that gives information about the Python interpreter and access to features like command-line arguments and program exit.",[1385,1393,1395],{"id":1394},"do-i-need-to-install-sys","Do I need to install sys?",[14,1397,1398,1399,1401],{},"No. ",[18,1400,20],{}," is built into Python, so you only need to import it.",[1385,1403,1405],{"id":1404},"what-does-sysargv-do","What does sys.argv do?",[14,1407,1408],{},"It stores command-line arguments in a list. The first item is usually the script name.",[1385,1410,1412],{"id":1411},"what-does-sysexit-do","What does sys.exit() do?",[14,1414,1415],{},"It stops the program. You can also pass an exit code or message.",[1385,1417,1419],{"id":1418},"what-is-syspath-used-for","What is sys.path used for?",[14,1421,1422],{},"It shows the folders Python searches when importing modules.",[57,1424,1426],{"id":1425},"see-also","See also",[29,1428,1429,1433,1437,1443,1448,1453,1457],{},[32,1430,1431],{},[240,1432,243],{"href":242},[32,1434,1435],{},[240,1436,248],{"href":247},[32,1438,1439],{},[240,1440,1442],{"href":1441},"\u002Fstandard-library\u002Fsys.path-explained","sys.path explained",[32,1444,1445],{},[240,1446,1447],{"href":1013},"How import works in Python",[32,1449,1450],{},[240,1451,1452],{"href":730},"How to use command-line arguments in Python",[32,1454,1455],{},[240,1456,1023],{"href":1022},[32,1458,1459],{},[240,1460,1175],{"href":1174},[1462,1463,1464],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":67,"searchDepth":85,"depth":85,"links":1466},[1467,1468,1469,1470,1471,1472,1473,1474,1475,1476,1477,1484],{"id":59,"depth":85,"text":60},{"id":154,"depth":85,"text":155},{"id":197,"depth":85,"text":198},{"id":251,"depth":85,"text":252},{"id":310,"depth":85,"text":311},{"id":452,"depth":85,"text":453},{"id":734,"depth":85,"text":735},{"id":929,"depth":85,"text":930},{"id":1032,"depth":85,"text":1033},{"id":1178,"depth":85,"text":1179},{"id":1382,"depth":85,"text":1383,"children":1478},[1479,1480,1481,1482,1483],{"id":1387,"depth":92,"text":1388},{"id":1394,"depth":92,"text":1395},{"id":1404,"depth":92,"text":1405},{"id":1411,"depth":92,"text":1412},{"id":1418,"depth":92,"text":1419},{"id":1425,"depth":85,"text":1426},"Master python sys module overview in our comprehensive Python beginner guide.","md",{},"\u002Fstandard-library\u002Fpython-sys-module-overview",{"title":5,"description":1485},"standard-library\u002Fpython-sys-module-overview","LkwcllMOEx69Sr6q2Idl2OewRGzyVHjhNVGjzZbNL4o",1777585471138]