[{"data":1,"prerenderedAt":2292},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-open-function-explained":3},{"id":4,"title":5,"body":6,"description":2284,"extension":2285,"meta":2286,"navigation":2287,"path":2288,"seo":2289,"stem":2290,"__hash__":2291},"content\u002Freference\u002Fpython-open-function-explained.md","Python open() Function Explained",{"type":7,"value":8,"toc":2248},"minimark",[9,13,21,27,32,144,154,158,163,166,217,220,303,309,313,316,349,352,371,373,447,450,469,473,476,513,516,585,663,737,743,747,754,757,774,777,779,843,846,872,878,882,885,955,958,977,983,1059,1062,1066,1072,1077,1082,1152,1156,1161,1235,1239,1242,1320,1332,1336,1341,1431,1436,1504,1507,1527,1538,1542,1545,1550,1553,1615,1618,1629,1634,1637,1640,1645,1648,1651,1655,1658,1664,1667,1678,1680,1742,1758,1764,1767,1770,1781,1792,1798,1801,1803,1865,1875,1881,1886,1892,1896,1902,1905,1926,1930,1936,1964,1967,1996,1999,2039,2042,2080,2083,2144,2147,2151,2155,2158,2162,2168,2177,2185,2189,2192,2196,2202,2206,2244],[10,11,5],"h1",{"id":12},"python-open-function-explained",[14,15,16,20],"p",{},[17,18,19],"code",{},"open()"," is the built-in Python function used to open a file so your program can read from it or write to it.",[14,22,23,24,26],{},"This page is a beginner-friendly reference for ",[17,25,19],{},". You will learn what it does, the most common arguments, what it returns, and how to use it safely when working with files.",[28,29,31],"h2",{"id":30},"quick-example","Quick example",[33,34,39],"pre",{"className":35,"code":36,"language":37,"meta":38,"style":38},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","with open(\"example.txt\", \"r\", encoding=\"utf-8\") as file:\n    content = file.read()\n    print(content)\n","python","",[17,40,41,109,130],{"__ignoreMap":38},[42,43,46,50,54,58,62,66,68,71,74,77,79,81,85,89,91,94,96,99,102,106],"span",{"class":44,"line":45},"line",1,[42,47,49],{"class":48},"sVHd0","with",[42,51,53],{"class":52},"sptTA"," open",[42,55,57],{"class":56},"sP7_E","(",[42,59,61],{"class":60},"sjJ54","\"",[42,63,65],{"class":64},"s_sjI","example.txt",[42,67,61],{"class":60},[42,69,70],{"class":56},",",[42,72,73],{"class":60}," \"",[42,75,76],{"class":64},"r",[42,78,61],{"class":60},[42,80,70],{"class":56},[42,82,84],{"class":83},"s99_P"," encoding",[42,86,88],{"class":87},"smGrS","=",[42,90,61],{"class":60},[42,92,93],{"class":64},"utf-8",[42,95,61],{"class":60},[42,97,98],{"class":56},")",[42,100,101],{"class":48}," as",[42,103,105],{"class":104},"sMMDD"," file",[42,107,108],{"class":56},":\n",[42,110,112,116,118,120,123,127],{"class":44,"line":111},2,[42,113,115],{"class":114},"su5hD","    content ",[42,117,88],{"class":87},[42,119,105],{"class":104},[42,121,122],{"class":56},".",[42,124,126],{"class":125},"slqww","read",[42,128,129],{"class":56},"()\n",[42,131,133,136,138,141],{"class":44,"line":132},3,[42,134,135],{"class":52},"    print",[42,137,57],{"class":56},[42,139,140],{"class":125},"content",[42,142,143],{"class":56},")\n",[14,145,146,147,149,150,153],{},"Use ",[17,148,49],{}," so the file closes automatically. ",[17,151,152],{},"\"r\""," means read mode.",[28,155,157],{"id":156},"what-open-does","What open() does",[14,159,160,162],{},[17,161,19],{}," opens a file and gives your program a way to work with it.",[14,164,165],{},"Important points:",[167,168,169,173,181,187],"ul",{},[170,171,172],"li",{},"It opens a file so your code can read from it or write to it",[170,174,175,176,180],{},"It does ",[177,178,179],"strong",{},"not"," read or write anything by itself",[170,182,183,184],{},"It returns a ",[177,185,186],{},"file object",[170,188,189,190],{},"You use methods on that file object, such as:\n",[167,191,192,197,202,207,212],{},[170,193,194],{},[17,195,196],{},"read()",[170,198,199],{},[17,200,201],{},"readline()",[170,203,204],{},[17,205,206],{},"readlines()",[170,208,209],{},[17,210,211],{},"write()",[170,213,214],{},[17,215,216],{},"close()",[14,218,219],{},"Example:",[33,221,223],{"className":35,"code":222,"language":37,"meta":38,"style":38},"file = open(\"example.txt\", \"r\", encoding=\"utf-8\")\ncontent = file.read()\nprint(content)\nfile.close()\n",[17,224,225,265,280,291],{"__ignoreMap":38},[42,226,227,230,233,235,237,239,241,243,245,247,249,251,253,255,257,259,261,263],{"class":44,"line":45},[42,228,229],{"class":104},"file",[42,231,232],{"class":87}," =",[42,234,53],{"class":52},[42,236,57],{"class":56},[42,238,61],{"class":60},[42,240,65],{"class":64},[42,242,61],{"class":60},[42,244,70],{"class":56},[42,246,73],{"class":60},[42,248,76],{"class":64},[42,250,61],{"class":60},[42,252,70],{"class":56},[42,254,84],{"class":83},[42,256,88],{"class":87},[42,258,61],{"class":60},[42,260,93],{"class":64},[42,262,61],{"class":60},[42,264,143],{"class":56},[42,266,267,270,272,274,276,278],{"class":44,"line":111},[42,268,269],{"class":114},"content ",[42,271,88],{"class":87},[42,273,105],{"class":104},[42,275,122],{"class":56},[42,277,126],{"class":125},[42,279,129],{"class":56},[42,281,282,285,287,289],{"class":44,"line":132},[42,283,284],{"class":52},"print",[42,286,57],{"class":56},[42,288,140],{"class":125},[42,290,143],{"class":56},[42,292,294,296,298,301],{"class":44,"line":293},4,[42,295,229],{"class":104},[42,297,122],{"class":56},[42,299,300],{"class":125},"close",[42,302,129],{"class":56},[14,304,305,306,308],{},"This works, but in most cases you should use ",[17,307,49],{}," instead, because it closes the file for you automatically.",[28,310,312],{"id":311},"basic-syntax","Basic syntax",[14,314,315],{},"A common form is:",[33,317,319],{"className":35,"code":318,"language":37,"meta":38,"style":38},"open(file, mode, encoding=\"utf-8\")\n",[17,320,321],{"__ignoreMap":38},[42,322,323,326,328,330,332,335,337,339,341,343,345,347],{"class":44,"line":45},[42,324,325],{"class":52},"open",[42,327,57],{"class":56},[42,329,229],{"class":104},[42,331,70],{"class":56},[42,333,334],{"class":125}," mode",[42,336,70],{"class":56},[42,338,84],{"class":83},[42,340,88],{"class":87},[42,342,61],{"class":60},[42,344,93],{"class":64},[42,346,61],{"class":60},[42,348,143],{"class":56},[14,350,351],{},"Here is what each part means:",[167,353,354,359,365],{},[170,355,356,358],{},[17,357,229],{}," is the file name or file path",[170,360,361,364],{},[17,362,363],{},"mode"," controls how the file is opened",[170,366,367,370],{},[17,368,369],{},"encoding"," matters when you are working with text files",[14,372,219],{},[33,374,376],{"className":35,"code":375,"language":37,"meta":38,"style":38},"with open(\"notes.txt\", \"r\", encoding=\"utf-8\") as file:\n    text = file.read()\n    print(text)\n",[17,377,378,421,436],{"__ignoreMap":38},[42,379,380,382,384,386,388,391,393,395,397,399,401,403,405,407,409,411,413,415,417,419],{"class":44,"line":45},[42,381,49],{"class":48},[42,383,53],{"class":52},[42,385,57],{"class":56},[42,387,61],{"class":60},[42,389,390],{"class":64},"notes.txt",[42,392,61],{"class":60},[42,394,70],{"class":56},[42,396,73],{"class":60},[42,398,76],{"class":64},[42,400,61],{"class":60},[42,402,70],{"class":56},[42,404,84],{"class":83},[42,406,88],{"class":87},[42,408,61],{"class":60},[42,410,93],{"class":64},[42,412,61],{"class":60},[42,414,98],{"class":56},[42,416,101],{"class":48},[42,418,105],{"class":104},[42,420,108],{"class":56},[42,422,423,426,428,430,432,434],{"class":44,"line":111},[42,424,425],{"class":114},"    text ",[42,427,88],{"class":87},[42,429,105],{"class":104},[42,431,122],{"class":56},[42,433,126],{"class":125},[42,435,129],{"class":56},[42,437,438,440,442,445],{"class":44,"line":132},[42,439,135],{"class":52},[42,441,57],{"class":56},[42,443,444],{"class":125},"text",[42,446,143],{"class":56},[14,448,449],{},"In this example:",[167,451,452,458,463],{},[170,453,454,457],{},[17,455,456],{},"\"notes.txt\""," is the file name",[170,459,460,462],{},[17,461,152],{}," means open for reading",[170,464,465,468],{},[17,466,467],{},"encoding=\"utf-8\""," tells Python how to decode the text",[28,470,472],{"id":471},"common-file-modes","Common file modes",[14,474,475],{},"These are the modes beginners use most often:",[167,477,478,483,489,495,501,507],{},[170,479,480,482],{},[17,481,152],{}," = read a text file",[170,484,485,488],{},[17,486,487],{},"\"w\""," = write a text file and replace existing content",[170,490,491,494],{},[17,492,493],{},"\"a\""," = append text to the end of a file",[170,496,497,500],{},[17,498,499],{},"\"x\""," = create a new file and fail if it already exists",[170,502,503,506],{},[17,504,505],{},"\"rb\""," = read a binary file",[170,508,509,512],{},[17,510,511],{},"\"wb\""," = write a binary file",[14,514,515],{},"Examples:",[33,517,519],{"className":35,"code":518,"language":37,"meta":38,"style":38},"# Read a text file\nwith open(\"data.txt\", \"r\", encoding=\"utf-8\") as file:\n    print(file.read())\n",[17,520,521,527,570],{"__ignoreMap":38},[42,522,523],{"class":44,"line":45},[42,524,526],{"class":525},"sutJx","# Read a text file\n",[42,528,529,531,533,535,537,540,542,544,546,548,550,552,554,556,558,560,562,564,566,568],{"class":44,"line":111},[42,530,49],{"class":48},[42,532,53],{"class":52},[42,534,57],{"class":56},[42,536,61],{"class":60},[42,538,539],{"class":64},"data.txt",[42,541,61],{"class":60},[42,543,70],{"class":56},[42,545,73],{"class":60},[42,547,76],{"class":64},[42,549,61],{"class":60},[42,551,70],{"class":56},[42,553,84],{"class":83},[42,555,88],{"class":87},[42,557,61],{"class":60},[42,559,93],{"class":64},[42,561,61],{"class":60},[42,563,98],{"class":56},[42,565,101],{"class":48},[42,567,105],{"class":104},[42,569,108],{"class":56},[42,571,572,574,576,578,580,582],{"class":44,"line":132},[42,573,135],{"class":52},[42,575,57],{"class":56},[42,577,229],{"class":104},[42,579,122],{"class":56},[42,581,126],{"class":125},[42,583,584],{"class":56},"())\n",[33,586,588],{"className":35,"code":587,"language":37,"meta":38,"style":38},"# Write a text file (overwrites old content)\nwith open(\"data.txt\", \"w\", encoding=\"utf-8\") as file:\n    file.write(\"Hello\\n\")\n",[17,589,590,595,638],{"__ignoreMap":38},[42,591,592],{"class":44,"line":45},[42,593,594],{"class":525},"# Write a text file (overwrites old content)\n",[42,596,597,599,601,603,605,607,609,611,613,616,618,620,622,624,626,628,630,632,634,636],{"class":44,"line":111},[42,598,49],{"class":48},[42,600,53],{"class":52},[42,602,57],{"class":56},[42,604,61],{"class":60},[42,606,539],{"class":64},[42,608,61],{"class":60},[42,610,70],{"class":56},[42,612,73],{"class":60},[42,614,615],{"class":64},"w",[42,617,61],{"class":60},[42,619,70],{"class":56},[42,621,84],{"class":83},[42,623,88],{"class":87},[42,625,61],{"class":60},[42,627,93],{"class":64},[42,629,61],{"class":60},[42,631,98],{"class":56},[42,633,101],{"class":48},[42,635,105],{"class":104},[42,637,108],{"class":56},[42,639,640,643,645,648,650,652,655,659,661],{"class":44,"line":132},[42,641,642],{"class":104},"    file",[42,644,122],{"class":56},[42,646,647],{"class":125},"write",[42,649,57],{"class":56},[42,651,61],{"class":60},[42,653,654],{"class":64},"Hello",[42,656,658],{"class":657},"s_hVV","\\n",[42,660,61],{"class":60},[42,662,143],{"class":56},[33,664,666],{"className":35,"code":665,"language":37,"meta":38,"style":38},"# Append to a text file\nwith open(\"data.txt\", \"a\", encoding=\"utf-8\") as file:\n    file.write(\"Another line\\n\")\n",[17,667,668,673,716],{"__ignoreMap":38},[42,669,670],{"class":44,"line":45},[42,671,672],{"class":525},"# Append to a text file\n",[42,674,675,677,679,681,683,685,687,689,691,694,696,698,700,702,704,706,708,710,712,714],{"class":44,"line":111},[42,676,49],{"class":48},[42,678,53],{"class":52},[42,680,57],{"class":56},[42,682,61],{"class":60},[42,684,539],{"class":64},[42,686,61],{"class":60},[42,688,70],{"class":56},[42,690,73],{"class":60},[42,692,693],{"class":64},"a",[42,695,61],{"class":60},[42,697,70],{"class":56},[42,699,84],{"class":83},[42,701,88],{"class":87},[42,703,61],{"class":60},[42,705,93],{"class":64},[42,707,61],{"class":60},[42,709,98],{"class":56},[42,711,101],{"class":48},[42,713,105],{"class":104},[42,715,108],{"class":56},[42,717,718,720,722,724,726,728,731,733,735],{"class":44,"line":132},[42,719,642],{"class":104},[42,721,122],{"class":56},[42,723,647],{"class":125},[42,725,57],{"class":56},[42,727,61],{"class":60},[42,729,730],{"class":64},"Another line",[42,732,658],{"class":657},[42,734,61],{"class":60},[42,736,143],{"class":56},[14,738,739,740,742],{},"Be careful with ",[17,741,487],{}," mode. If the file already exists, its old contents are removed.",[28,744,746],{"id":745},"what-open-returns","What open() returns",[14,748,749,751,752,122],{},[17,750,19],{}," returns a ",[177,753,186],{},[14,755,756],{},"A file object is the thing you actually use to work with the file. It gives you methods like:",[167,758,759,764,769],{},[170,760,761],{},[17,762,763],{},"file.read()",[170,765,766],{},[17,767,768],{},"file.write()",[170,770,771],{},[17,772,773],{},"file.close()",[14,775,776],{},"It also keeps track of the current position in the file.",[14,778,219],{},[33,780,782],{"className":35,"code":781,"language":37,"meta":38,"style":38},"with open(\"example.txt\", \"r\", encoding=\"utf-8\") as file:\n    print(type(file))\n",[17,783,784,826],{"__ignoreMap":38},[42,785,786,788,790,792,794,796,798,800,802,804,806,808,810,812,814,816,818,820,822,824],{"class":44,"line":45},[42,787,49],{"class":48},[42,789,53],{"class":52},[42,791,57],{"class":56},[42,793,61],{"class":60},[42,795,65],{"class":64},[42,797,61],{"class":60},[42,799,70],{"class":56},[42,801,73],{"class":60},[42,803,76],{"class":64},[42,805,61],{"class":60},[42,807,70],{"class":56},[42,809,84],{"class":83},[42,811,88],{"class":87},[42,813,61],{"class":60},[42,815,93],{"class":64},[42,817,61],{"class":60},[42,819,98],{"class":56},[42,821,101],{"class":48},[42,823,105],{"class":104},[42,825,108],{"class":56},[42,827,828,830,832,836,838,840],{"class":44,"line":111},[42,829,135],{"class":52},[42,831,57],{"class":56},[42,833,835],{"class":834},"sZMiF","type",[42,837,57],{"class":56},[42,839,229],{"class":104},[42,841,842],{"class":56},"))\n",[14,844,845],{},"Possible output:",[33,847,849],{"className":35,"code":848,"language":37,"meta":38,"style":38},"\u003Cclass '_io.TextIOWrapper'>\n",[17,850,851],{"__ignoreMap":38},[42,852,853,856,860,863,866,869],{"class":44,"line":45},[42,854,855],{"class":87},"\u003C",[42,857,859],{"class":858},"sbsja","class",[42,861,862],{"class":60}," '",[42,864,865],{"class":64},"_io.TextIOWrapper",[42,867,868],{"class":60},"'",[42,870,871],{"class":87},">\n",[14,873,874,875,877],{},"You do not need to memorize that type name. The important idea is that ",[17,876,19],{}," gives you an object that knows how to interact with the file.",[28,879,881],{"id":880},"why-beginners-should-use-with","Why beginners should use with",[14,883,884],{},"Beginners should usually write file code like this:",[33,886,887],{"className":35,"code":36,"language":37,"meta":38,"style":38},[17,888,889,931,945],{"__ignoreMap":38},[42,890,891,893,895,897,899,901,903,905,907,909,911,913,915,917,919,921,923,925,927,929],{"class":44,"line":45},[42,892,49],{"class":48},[42,894,53],{"class":52},[42,896,57],{"class":56},[42,898,61],{"class":60},[42,900,65],{"class":64},[42,902,61],{"class":60},[42,904,70],{"class":56},[42,906,73],{"class":60},[42,908,76],{"class":64},[42,910,61],{"class":60},[42,912,70],{"class":56},[42,914,84],{"class":83},[42,916,88],{"class":87},[42,918,61],{"class":60},[42,920,93],{"class":64},[42,922,61],{"class":60},[42,924,98],{"class":56},[42,926,101],{"class":48},[42,928,105],{"class":104},[42,930,108],{"class":56},[42,932,933,935,937,939,941,943],{"class":44,"line":111},[42,934,115],{"class":114},[42,936,88],{"class":87},[42,938,105],{"class":104},[42,940,122],{"class":56},[42,942,126],{"class":125},[42,944,129],{"class":56},[42,946,947,949,951,953],{"class":44,"line":132},[42,948,135],{"class":52},[42,950,57],{"class":56},[42,952,140],{"class":125},[42,954,143],{"class":56},[14,956,957],{},"Why this is recommended:",[167,959,960,965,971,974],{},[170,961,962,964],{},[17,963,49],{}," automatically closes the file when the block ends",[170,966,967,968,970],{},"It is safer than calling ",[17,969,216],{}," yourself",[170,972,973],{},"It helps prevent bugs caused by leaving files open",[170,975,976],{},"It is the standard pattern you will see in most Python code",[14,978,979,980,982],{},"Without ",[17,981,49],{},", you must remember to close the file yourself:",[33,984,985],{"className":35,"code":222,"language":37,"meta":38,"style":38},[17,986,987,1025,1039,1049],{"__ignoreMap":38},[42,988,989,991,993,995,997,999,1001,1003,1005,1007,1009,1011,1013,1015,1017,1019,1021,1023],{"class":44,"line":45},[42,990,229],{"class":104},[42,992,232],{"class":87},[42,994,53],{"class":52},[42,996,57],{"class":56},[42,998,61],{"class":60},[42,1000,65],{"class":64},[42,1002,61],{"class":60},[42,1004,70],{"class":56},[42,1006,73],{"class":60},[42,1008,76],{"class":64},[42,1010,61],{"class":60},[42,1012,70],{"class":56},[42,1014,84],{"class":83},[42,1016,88],{"class":87},[42,1018,61],{"class":60},[42,1020,93],{"class":64},[42,1022,61],{"class":60},[42,1024,143],{"class":56},[42,1026,1027,1029,1031,1033,1035,1037],{"class":44,"line":111},[42,1028,269],{"class":114},[42,1030,88],{"class":87},[42,1032,105],{"class":104},[42,1034,122],{"class":56},[42,1036,126],{"class":125},[42,1038,129],{"class":56},[42,1040,1041,1043,1045,1047],{"class":44,"line":132},[42,1042,284],{"class":52},[42,1044,57],{"class":56},[42,1046,140],{"class":125},[42,1048,143],{"class":56},[42,1050,1051,1053,1055,1057],{"class":44,"line":293},[42,1052,229],{"class":104},[42,1054,122],{"class":56},[42,1056,300],{"class":125},[42,1058,129],{"class":56},[14,1060,1061],{},"That version is easier to get wrong.",[28,1063,1065],{"id":1064},"reading-text-with-open","Reading text with open()",[14,1067,1068,1069,1071],{},"Use mode ",[17,1070,152],{}," when you want to read a text file.",[1073,1074,1076],"h3",{"id":1075},"read-the-whole-file","Read the whole file",[14,1078,1079,1081],{},[17,1080,196],{}," returns the full contents as one string.",[33,1083,1084],{"className":35,"code":36,"language":37,"meta":38,"style":38},[17,1085,1086,1128,1142],{"__ignoreMap":38},[42,1087,1088,1090,1092,1094,1096,1098,1100,1102,1104,1106,1108,1110,1112,1114,1116,1118,1120,1122,1124,1126],{"class":44,"line":45},[42,1089,49],{"class":48},[42,1091,53],{"class":52},[42,1093,57],{"class":56},[42,1095,61],{"class":60},[42,1097,65],{"class":64},[42,1099,61],{"class":60},[42,1101,70],{"class":56},[42,1103,73],{"class":60},[42,1105,76],{"class":64},[42,1107,61],{"class":60},[42,1109,70],{"class":56},[42,1111,84],{"class":83},[42,1113,88],{"class":87},[42,1115,61],{"class":60},[42,1117,93],{"class":64},[42,1119,61],{"class":60},[42,1121,98],{"class":56},[42,1123,101],{"class":48},[42,1125,105],{"class":104},[42,1127,108],{"class":56},[42,1129,1130,1132,1134,1136,1138,1140],{"class":44,"line":111},[42,1131,115],{"class":114},[42,1133,88],{"class":87},[42,1135,105],{"class":104},[42,1137,122],{"class":56},[42,1139,126],{"class":125},[42,1141,129],{"class":56},[42,1143,1144,1146,1148,1150],{"class":44,"line":132},[42,1145,135],{"class":52},[42,1147,57],{"class":56},[42,1149,140],{"class":125},[42,1151,143],{"class":56},[1073,1153,1155],{"id":1154},"read-one-line","Read one line",[14,1157,1158,1160],{},[17,1159,201],{}," reads one line at a time.",[33,1162,1164],{"className":35,"code":1163,"language":37,"meta":38,"style":38},"with open(\"example.txt\", \"r\", encoding=\"utf-8\") as file:\n    first_line = file.readline()\n    print(first_line)\n",[17,1165,1166,1208,1224],{"__ignoreMap":38},[42,1167,1168,1170,1172,1174,1176,1178,1180,1182,1184,1186,1188,1190,1192,1194,1196,1198,1200,1202,1204,1206],{"class":44,"line":45},[42,1169,49],{"class":48},[42,1171,53],{"class":52},[42,1173,57],{"class":56},[42,1175,61],{"class":60},[42,1177,65],{"class":64},[42,1179,61],{"class":60},[42,1181,70],{"class":56},[42,1183,73],{"class":60},[42,1185,76],{"class":64},[42,1187,61],{"class":60},[42,1189,70],{"class":56},[42,1191,84],{"class":83},[42,1193,88],{"class":87},[42,1195,61],{"class":60},[42,1197,93],{"class":64},[42,1199,61],{"class":60},[42,1201,98],{"class":56},[42,1203,101],{"class":48},[42,1205,105],{"class":104},[42,1207,108],{"class":56},[42,1209,1210,1213,1215,1217,1219,1222],{"class":44,"line":111},[42,1211,1212],{"class":114},"    first_line ",[42,1214,88],{"class":87},[42,1216,105],{"class":104},[42,1218,122],{"class":56},[42,1220,1221],{"class":125},"readline",[42,1223,129],{"class":56},[42,1225,1226,1228,1230,1233],{"class":44,"line":132},[42,1227,135],{"class":52},[42,1229,57],{"class":56},[42,1231,1232],{"class":125},"first_line",[42,1234,143],{"class":56},[1073,1236,1238],{"id":1237},"loop-over-the-file-line-by-line","Loop over the file line by line",[14,1240,1241],{},"This is often the best choice for larger files.",[33,1243,1245],{"className":35,"code":1244,"language":37,"meta":38,"style":38},"with open(\"example.txt\", \"r\", encoding=\"utf-8\") as file:\n    for line in file:\n        print(line.strip())\n",[17,1246,1247,1289,1304],{"__ignoreMap":38},[42,1248,1249,1251,1253,1255,1257,1259,1261,1263,1265,1267,1269,1271,1273,1275,1277,1279,1281,1283,1285,1287],{"class":44,"line":45},[42,1250,49],{"class":48},[42,1252,53],{"class":52},[42,1254,57],{"class":56},[42,1256,61],{"class":60},[42,1258,65],{"class":64},[42,1260,61],{"class":60},[42,1262,70],{"class":56},[42,1264,73],{"class":60},[42,1266,76],{"class":64},[42,1268,61],{"class":60},[42,1270,70],{"class":56},[42,1272,84],{"class":83},[42,1274,88],{"class":87},[42,1276,61],{"class":60},[42,1278,93],{"class":64},[42,1280,61],{"class":60},[42,1282,98],{"class":56},[42,1284,101],{"class":48},[42,1286,105],{"class":104},[42,1288,108],{"class":56},[42,1290,1291,1294,1297,1300,1302],{"class":44,"line":111},[42,1292,1293],{"class":48},"    for",[42,1295,1296],{"class":114}," line ",[42,1298,1299],{"class":48},"in",[42,1301,105],{"class":104},[42,1303,108],{"class":56},[42,1305,1306,1309,1311,1313,1315,1318],{"class":44,"line":132},[42,1307,1308],{"class":52},"        print",[42,1310,57],{"class":56},[42,1312,44],{"class":125},[42,1314,122],{"class":56},[42,1316,1317],{"class":125},"strip",[42,1319,584],{"class":56},[14,1321,1322,1323,1327,1328,122],{},"If you want a full beginner walkthrough, see ",[693,1324,1326],{"href":1325},"\u002Fhow-to\u002Fhow-to-read-a-file-in-python\u002F","How to Read a File in Python"," or ",[693,1329,1331],{"href":1330},"\u002Fhow-to\u002Fhow-to-read-a-file-line-by-line-in-python\u002F","How to Read a File Line by Line in Python",[28,1333,1335],{"id":1334},"writing-text-with-open","Writing text with open()",[14,1337,146,1338,1340],{},[17,1339,487],{}," to create a file or overwrite an existing file.",[33,1342,1344],{"className":35,"code":1343,"language":37,"meta":38,"style":38},"with open(\"output.txt\", \"w\", encoding=\"utf-8\") as file:\n    file.write(\"First line\\n\")\n    file.write(\"Second line\\n\")\n",[17,1345,1346,1389,1410],{"__ignoreMap":38},[42,1347,1348,1350,1352,1354,1356,1359,1361,1363,1365,1367,1369,1371,1373,1375,1377,1379,1381,1383,1385,1387],{"class":44,"line":45},[42,1349,49],{"class":48},[42,1351,53],{"class":52},[42,1353,57],{"class":56},[42,1355,61],{"class":60},[42,1357,1358],{"class":64},"output.txt",[42,1360,61],{"class":60},[42,1362,70],{"class":56},[42,1364,73],{"class":60},[42,1366,615],{"class":64},[42,1368,61],{"class":60},[42,1370,70],{"class":56},[42,1372,84],{"class":83},[42,1374,88],{"class":87},[42,1376,61],{"class":60},[42,1378,93],{"class":64},[42,1380,61],{"class":60},[42,1382,98],{"class":56},[42,1384,101],{"class":48},[42,1386,105],{"class":104},[42,1388,108],{"class":56},[42,1390,1391,1393,1395,1397,1399,1401,1404,1406,1408],{"class":44,"line":111},[42,1392,642],{"class":104},[42,1394,122],{"class":56},[42,1396,647],{"class":125},[42,1398,57],{"class":56},[42,1400,61],{"class":60},[42,1402,1403],{"class":64},"First line",[42,1405,658],{"class":657},[42,1407,61],{"class":60},[42,1409,143],{"class":56},[42,1411,1412,1414,1416,1418,1420,1422,1425,1427,1429],{"class":44,"line":132},[42,1413,642],{"class":104},[42,1415,122],{"class":56},[42,1417,647],{"class":125},[42,1419,57],{"class":56},[42,1421,61],{"class":60},[42,1423,1424],{"class":64},"Second line",[42,1426,658],{"class":657},[42,1428,61],{"class":60},[42,1430,143],{"class":56},[14,1432,146,1433,1435],{},[17,1434,493],{}," if you want to add content without deleting what is already there.",[33,1437,1439],{"className":35,"code":1438,"language":37,"meta":38,"style":38},"with open(\"output.txt\", \"a\", encoding=\"utf-8\") as file:\n    file.write(\"Third line\\n\")\n",[17,1440,1441,1483],{"__ignoreMap":38},[42,1442,1443,1445,1447,1449,1451,1453,1455,1457,1459,1461,1463,1465,1467,1469,1471,1473,1475,1477,1479,1481],{"class":44,"line":45},[42,1444,49],{"class":48},[42,1446,53],{"class":52},[42,1448,57],{"class":56},[42,1450,61],{"class":60},[42,1452,1358],{"class":64},[42,1454,61],{"class":60},[42,1456,70],{"class":56},[42,1458,73],{"class":60},[42,1460,693],{"class":64},[42,1462,61],{"class":60},[42,1464,70],{"class":56},[42,1466,84],{"class":83},[42,1468,88],{"class":87},[42,1470,61],{"class":60},[42,1472,93],{"class":64},[42,1474,61],{"class":60},[42,1476,98],{"class":56},[42,1478,101],{"class":48},[42,1480,105],{"class":104},[42,1482,108],{"class":56},[42,1484,1485,1487,1489,1491,1493,1495,1498,1500,1502],{"class":44,"line":111},[42,1486,642],{"class":104},[42,1488,122],{"class":56},[42,1490,647],{"class":125},[42,1492,57],{"class":56},[42,1494,61],{"class":60},[42,1496,1497],{"class":64},"Third line",[42,1499,658],{"class":657},[42,1501,61],{"class":60},[42,1503,143],{"class":56},[14,1505,1506],{},"Important detail:",[167,1508,1509,1514,1522],{},[170,1510,1511,1513],{},[17,1512,211],{}," writes a string",[170,1515,1516,1518,1519,1521],{},[17,1517,211],{}," does ",[177,1520,179],{}," add a newline for you",[170,1523,1524,1525,970],{},"If you want a new line, include ",[17,1526,658],{},[14,1528,1529,1530,1327,1534,122],{},"If your goal is a full task rather than a function reference, see ",[693,1531,1533],{"href":1532},"\u002Fhow-to\u002Fhow-to-write-to-a-file-in-python\u002F","How to Write to a File in Python",[693,1535,1537],{"href":1536},"\u002Fhow-to\u002Fhow-to-append-to-a-file-in-python\u002F","How to Append to a File in Python",[28,1539,1541],{"id":1540},"important-arguments-beginners-should-know","Important arguments beginners should know",[14,1543,1544],{},"A few arguments matter more than others when starting out.",[1073,1546,1548],{"id":1547},"encodingutf-8",[17,1549,467],{},[14,1551,1552],{},"For text files, this is a good default.",[33,1554,1556],{"className":35,"code":1555,"language":37,"meta":38,"style":38},"with open(\"message.txt\", \"r\", encoding=\"utf-8\") as file:\n    print(file.read())\n",[17,1557,1558,1601],{"__ignoreMap":38},[42,1559,1560,1562,1564,1566,1568,1571,1573,1575,1577,1579,1581,1583,1585,1587,1589,1591,1593,1595,1597,1599],{"class":44,"line":45},[42,1561,49],{"class":48},[42,1563,53],{"class":52},[42,1565,57],{"class":56},[42,1567,61],{"class":60},[42,1569,1570],{"class":64},"message.txt",[42,1572,61],{"class":60},[42,1574,70],{"class":56},[42,1576,73],{"class":60},[42,1578,76],{"class":64},[42,1580,61],{"class":60},[42,1582,70],{"class":56},[42,1584,84],{"class":83},[42,1586,88],{"class":87},[42,1588,61],{"class":60},[42,1590,93],{"class":64},[42,1592,61],{"class":60},[42,1594,98],{"class":56},[42,1596,101],{"class":48},[42,1598,105],{"class":104},[42,1600,108],{"class":56},[42,1602,1603,1605,1607,1609,1611,1613],{"class":44,"line":111},[42,1604,135],{"class":52},[42,1606,57],{"class":56},[42,1608,229],{"class":104},[42,1610,122],{"class":56},[42,1612,126],{"class":125},[42,1614,584],{"class":56},[14,1616,1617],{},"Why it matters:",[167,1619,1620,1623,1626],{},[170,1621,1622],{},"It helps Python read text correctly",[170,1624,1625],{},"It avoids some text decoding problems",[170,1627,1628],{},"It makes your code more consistent across systems",[1073,1630,1632],{"id":1631},"newline",[17,1633,1631],{},[14,1635,1636],{},"This is mostly useful when writing CSV files or when you need exact control over line endings.",[14,1638,1639],{},"Beginners usually do not need it for normal text files.",[1073,1641,1643],{"id":1642},"buffering",[17,1644,1642],{},[14,1646,1647],{},"This is an advanced argument.",[14,1649,1650],{},"Most beginners can ignore it and use the default.",[28,1652,1654],{"id":1653},"common-errors-when-using-open","Common errors when using open()",[14,1656,1657],{},"Here are some common file-related errors you may see.",[1073,1659,1661],{"id":1660},"filenotfounderror",[17,1662,1663],{},"FileNotFoundError",[14,1665,1666],{},"This happens when:",[167,1668,1669,1672,1675],{},[170,1670,1671],{},"the file does not exist",[170,1673,1674],{},"the path is wrong",[170,1676,1677],{},"your program is running from a different folder than you expect",[14,1679,219],{},[33,1681,1683],{"className":35,"code":1682,"language":37,"meta":38,"style":38},"with open(\"missing.txt\", \"r\", encoding=\"utf-8\") as file:\n    print(file.read())\n",[17,1684,1685,1728],{"__ignoreMap":38},[42,1686,1687,1689,1691,1693,1695,1698,1700,1702,1704,1706,1708,1710,1712,1714,1716,1718,1720,1722,1724,1726],{"class":44,"line":45},[42,1688,49],{"class":48},[42,1690,53],{"class":52},[42,1692,57],{"class":56},[42,1694,61],{"class":60},[42,1696,1697],{"class":64},"missing.txt",[42,1699,61],{"class":60},[42,1701,70],{"class":56},[42,1703,73],{"class":60},[42,1705,76],{"class":64},[42,1707,61],{"class":60},[42,1709,70],{"class":56},[42,1711,84],{"class":83},[42,1713,88],{"class":87},[42,1715,61],{"class":60},[42,1717,93],{"class":64},[42,1719,61],{"class":60},[42,1721,98],{"class":56},[42,1723,101],{"class":48},[42,1725,105],{"class":104},[42,1727,108],{"class":56},[42,1729,1730,1732,1734,1736,1738,1740],{"class":44,"line":111},[42,1731,135],{"class":52},[42,1733,57],{"class":56},[42,1735,229],{"class":104},[42,1737,122],{"class":56},[42,1739,126],{"class":125},[42,1741,584],{"class":56},[14,1743,1744,1745,1753,1754,122],{},"If you are stuck, see ",[693,1746,1748,1749,1752],{"href":1747},"\u002Ferrors\u002Ffilenotfounderror-errno-2-no-such-file-or-directory-fix\u002F","FileNotFoundError: ",[42,1750,1751],{},"Errno 2"," No such file or directory"," and ",[693,1755,1757],{"href":1756},"\u002Flearn\u002Fworking-with-file-paths-in-python\u002F","Working with File Paths in Python",[1073,1759,1761],{"id":1760},"permissionerror",[17,1762,1763],{},"PermissionError",[14,1765,1766],{},"This happens when Python does not have permission to access the file.",[14,1768,1769],{},"Example causes:",[167,1771,1772,1775,1778],{},[170,1773,1774],{},"the file is protected",[170,1776,1777],{},"you are trying to write somewhere you should not",[170,1779,1780],{},"another program is blocking access",[14,1782,1783,1784],{},"Related page: ",[693,1785,1787,1788,1791],{"href":1786},"\u002Ferrors\u002Fpermissionerror-errno-13-permission-denied-fix\u002F","PermissionError: ",[42,1789,1790],{},"Errno 13"," Permission denied",[1073,1793,1795],{"id":1794},"isadirectoryerror",[17,1796,1797],{},"IsADirectoryError",[14,1799,1800],{},"This happens when you pass a folder path instead of a file path.",[14,1802,219],{},[33,1804,1806],{"className":35,"code":1805,"language":37,"meta":38,"style":38},"with open(\"my_folder\", \"r\", encoding=\"utf-8\") as file:\n    print(file.read())\n",[17,1807,1808,1851],{"__ignoreMap":38},[42,1809,1810,1812,1814,1816,1818,1821,1823,1825,1827,1829,1831,1833,1835,1837,1839,1841,1843,1845,1847,1849],{"class":44,"line":45},[42,1811,49],{"class":48},[42,1813,53],{"class":52},[42,1815,57],{"class":56},[42,1817,61],{"class":60},[42,1819,1820],{"class":64},"my_folder",[42,1822,61],{"class":60},[42,1824,70],{"class":56},[42,1826,73],{"class":60},[42,1828,76],{"class":64},[42,1830,61],{"class":60},[42,1832,70],{"class":56},[42,1834,84],{"class":83},[42,1836,88],{"class":87},[42,1838,61],{"class":60},[42,1840,93],{"class":64},[42,1842,61],{"class":60},[42,1844,98],{"class":56},[42,1846,101],{"class":48},[42,1848,105],{"class":104},[42,1850,108],{"class":56},[42,1852,1853,1855,1857,1859,1861,1863],{"class":44,"line":111},[42,1854,135],{"class":52},[42,1856,57],{"class":56},[42,1858,229],{"class":104},[42,1860,122],{"class":56},[42,1862,126],{"class":125},[42,1864,584],{"class":56},[14,1866,1783,1867],{},[693,1868,1870,1871,1874],{"href":1869},"\u002Ferrors\u002Fisadirectoryerror-errno-21-is-a-directory-fix\u002F","IsADirectoryError: ",[42,1872,1873],{},"Errno 21"," Is a directory",[1073,1876,1878],{"id":1877},"unicodedecodeerror",[17,1879,1880],{},"UnicodeDecodeError",[14,1882,1883,1884,122],{},"This can happen when the file's real encoding does not match the encoding you used in ",[17,1885,19],{},[14,1887,1783,1888],{},[693,1889,1891],{"href":1890},"\u002Ferrors\u002Funicodedecodeerror-utf-8-codec-cant-decode-byte-fix\u002F","UnicodeDecodeError: 'utf-8' codec can't decode byte",[28,1893,1895],{"id":1894},"when-to-use-other-pages","When to use other pages",[14,1897,1898,1899,1901],{},"This page is a reference for the ",[17,1900,19],{}," function.",[14,1903,1904],{},"Use other pages when you need something more specific:",[167,1906,1907,1910,1913,1919],{},[170,1908,1909],{},"Use a how-to page for a full task, such as reading a file line by line",[170,1911,1912],{},"Use an error page when you already have a specific exception to fix",[170,1914,1915,1916,1918],{},"Use a path page when the real problem is the file location, not ",[17,1917,19],{}," itself",[170,1920,1921,1922],{},"For a broader introduction, see ",[693,1923,1925],{"href":1924},"\u002Flearn\u002Fpython-file-handling-basics-read-and-write\u002F","Python File Handling Basics: Read and Write",[28,1927,1929],{"id":1928},"common-mistakes","Common mistakes",[14,1931,1932,1933,1935],{},"These are some of the most common beginner mistakes with ",[17,1934,19],{},":",[167,1937,1938,1944,1950,1955,1958,1961],{},[170,1939,1940,1941,1943],{},"Using ",[17,1942,152],{}," mode on a file that does not exist",[170,1945,1946,1947,1949],{},"Forgetting to use ",[17,1948,369],{}," for text files",[170,1951,1940,1952,1954],{},[17,1953,487],{}," and accidentally deleting old content",[170,1956,1957],{},"Trying to read from a file opened in write mode",[170,1959,1960],{},"Passing a folder path instead of a file path",[170,1962,1963],{},"Using a relative path from the wrong working directory",[14,1965,1966],{},"If you are not sure what Python is trying to open, these quick checks can help:",[33,1968,1970],{"className":35,"code":1969,"language":37,"meta":38,"style":38},"import os\nprint(os.getcwd())\n",[17,1971,1972,1980],{"__ignoreMap":38},[42,1973,1974,1977],{"class":44,"line":45},[42,1975,1976],{"class":48},"import",[42,1978,1979],{"class":114}," os\n",[42,1981,1982,1984,1986,1989,1991,1994],{"class":44,"line":111},[42,1983,284],{"class":52},[42,1985,57],{"class":56},[42,1987,1988],{"class":125},"os",[42,1990,122],{"class":56},[42,1992,1993],{"class":125},"getcwd",[42,1995,584],{"class":56},[14,1997,1998],{},"This shows the current working directory.",[33,2000,2002],{"className":35,"code":2001,"language":37,"meta":38,"style":38},"import os\nprint(os.path.exists(\"example.txt\"))\n",[17,2003,2004,2010],{"__ignoreMap":38},[42,2005,2006,2008],{"class":44,"line":45},[42,2007,1976],{"class":48},[42,2009,1979],{"class":114},[42,2011,2012,2014,2016,2018,2020,2024,2026,2029,2031,2033,2035,2037],{"class":44,"line":111},[42,2013,284],{"class":52},[42,2015,57],{"class":56},[42,2017,1988],{"class":125},[42,2019,122],{"class":56},[42,2021,2023],{"class":2022},"skxfh","path",[42,2025,122],{"class":56},[42,2027,2028],{"class":125},"exists",[42,2030,57],{"class":56},[42,2032,61],{"class":60},[42,2034,65],{"class":64},[42,2036,61],{"class":60},[42,2038,842],{"class":56},[14,2040,2041],{},"This checks whether the path exists.",[33,2043,2045],{"className":35,"code":2044,"language":37,"meta":38,"style":38},"import os\nprint(os.path.isfile(\"example.txt\"))\n",[17,2046,2047,2053],{"__ignoreMap":38},[42,2048,2049,2051],{"class":44,"line":45},[42,2050,1976],{"class":48},[42,2052,1979],{"class":114},[42,2054,2055,2057,2059,2061,2063,2065,2067,2070,2072,2074,2076,2078],{"class":44,"line":111},[42,2056,284],{"class":52},[42,2058,57],{"class":56},[42,2060,1988],{"class":125},[42,2062,122],{"class":56},[42,2064,2023],{"class":2022},[42,2066,122],{"class":56},[42,2068,2069],{"class":125},"isfile",[42,2071,57],{"class":56},[42,2073,61],{"class":60},[42,2075,65],{"class":64},[42,2077,61],{"class":60},[42,2079,842],{"class":56},[14,2081,2082],{},"This checks whether the path is a file.",[33,2084,2086],{"className":35,"code":2085,"language":37,"meta":38,"style":38},"with open(\"example.txt\", \"r\", encoding=\"utf-8\") as file:\n    print(file.read())\n",[17,2087,2088,2130],{"__ignoreMap":38},[42,2089,2090,2092,2094,2096,2098,2100,2102,2104,2106,2108,2110,2112,2114,2116,2118,2120,2122,2124,2126,2128],{"class":44,"line":45},[42,2091,49],{"class":48},[42,2093,53],{"class":52},[42,2095,57],{"class":56},[42,2097,61],{"class":60},[42,2099,65],{"class":64},[42,2101,61],{"class":60},[42,2103,70],{"class":56},[42,2105,73],{"class":60},[42,2107,76],{"class":64},[42,2109,61],{"class":60},[42,2111,70],{"class":56},[42,2113,84],{"class":83},[42,2115,88],{"class":87},[42,2117,61],{"class":60},[42,2119,93],{"class":64},[42,2121,61],{"class":60},[42,2123,98],{"class":56},[42,2125,101],{"class":48},[42,2127,105],{"class":104},[42,2129,108],{"class":56},[42,2131,2132,2134,2136,2138,2140,2142],{"class":44,"line":111},[42,2133,135],{"class":52},[42,2135,57],{"class":56},[42,2137,229],{"class":104},[42,2139,122],{"class":56},[42,2141,126],{"class":125},[42,2143,584],{"class":56},[14,2145,2146],{},"This is a simple test to confirm the file can be opened and read.",[28,2148,2150],{"id":2149},"faq","FAQ",[1073,2152,2154],{"id":2153},"what-does-open-return-in-python","What does open() return in Python?",[14,2156,2157],{},"It returns a file object. You use that object to read, write, or close the file.",[1073,2159,2161],{"id":2160},"what-is-the-safest-way-to-use-open","What is the safest way to use open()?",[14,2163,2164,2165,2167],{},"Use it inside a ",[17,2166,49],{}," block so the file closes automatically.",[1073,2169,2171,2172,1753,2174,2176],{"id":2170},"what-is-the-difference-between-w-and-a-mode","What is the difference between ",[17,2173,487],{},[17,2175,493],{}," mode?",[14,2178,2179,2181,2182,2184],{},[17,2180,487],{}," overwrites the file. ",[17,2183,493],{}," adds new content to the end.",[1073,2186,2188],{"id":2187},"why-do-i-get-filenotfounderror-with-open","Why do I get FileNotFoundError with open()?",[14,2190,2191],{},"Usually the file path is wrong, the file does not exist, or your program is running from a different folder than you expect.",[1073,2193,2195],{"id":2194},"should-i-always-set-encoding-when-opening-a-text-file","Should I always set encoding when opening a text file?",[14,2197,2198,2199,2201],{},"It is a good habit. ",[17,2200,467],{}," is a safe default for many text files.",[28,2203,2205],{"id":2204},"see-also","See also",[167,2207,2208,2212,2216,2220,2224,2228,2232,2238],{},[170,2209,2210],{},[693,2211,1326],{"href":1325},[170,2213,2214],{},[693,2215,1533],{"href":1532},[170,2217,2218],{},[693,2219,1537],{"href":1536},[170,2221,2222],{},[693,2223,1331],{"href":1330},[170,2225,2226],{},[693,2227,1925],{"href":1924},[170,2229,2230],{},[693,2231,1757],{"href":1756},[170,2233,2234],{},[693,2235,1748,2236,1752],{"href":1747},[42,2237,1751],{},[170,2239,2240],{},[693,2241,1787,2242,1791],{"href":1786},[42,2243,1790],{},[2245,2246,2247],"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 .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 .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 .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sMMDD, html code.shiki .sMMDD{--shiki-light:#90A4AE;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--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 .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 .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}",{"title":38,"searchDepth":111,"depth":111,"links":2249},[2250,2251,2252,2253,2254,2255,2256,2261,2262,2267,2273,2274,2275,2283],{"id":30,"depth":111,"text":31},{"id":156,"depth":111,"text":157},{"id":311,"depth":111,"text":312},{"id":471,"depth":111,"text":472},{"id":745,"depth":111,"text":746},{"id":880,"depth":111,"text":881},{"id":1064,"depth":111,"text":1065,"children":2257},[2258,2259,2260],{"id":1075,"depth":132,"text":1076},{"id":1154,"depth":132,"text":1155},{"id":1237,"depth":132,"text":1238},{"id":1334,"depth":111,"text":1335},{"id":1540,"depth":111,"text":1541,"children":2263},[2264,2265,2266],{"id":1547,"depth":132,"text":467},{"id":1631,"depth":132,"text":1631},{"id":1642,"depth":132,"text":1642},{"id":1653,"depth":111,"text":1654,"children":2268},[2269,2270,2271,2272],{"id":1660,"depth":132,"text":1663},{"id":1760,"depth":132,"text":1763},{"id":1794,"depth":132,"text":1797},{"id":1877,"depth":132,"text":1880},{"id":1894,"depth":111,"text":1895},{"id":1928,"depth":111,"text":1929},{"id":2149,"depth":111,"text":2150,"children":2276},[2277,2278,2279,2281,2282],{"id":2153,"depth":132,"text":2154},{"id":2160,"depth":132,"text":2161},{"id":2170,"depth":132,"text":2280},"What is the difference between \"w\" and \"a\" mode?",{"id":2187,"depth":132,"text":2188},{"id":2194,"depth":132,"text":2195},{"id":2204,"depth":111,"text":2205},"Master python open function explained in our comprehensive Python beginner guide.","md",{},true,"\u002Freference\u002Fpython-open-function-explained",{"title":5,"description":2284},"reference\u002Fpython-open-function-explained","2NUk1nPkzgPoyQ-eW0tXGQJ5BkMh9G3DaGNf-J4gI50",1777585497596]