[{"data":1,"prerenderedAt":998},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fsyntaxerror-unexpected-eof-while-parsing-fix":3},{"id":4,"title":5,"body":6,"description":991,"extension":992,"meta":993,"navigation":542,"path":994,"seo":995,"stem":996,"__hash__":997},"content\u002Ferrors\u002Fsyntaxerror-unexpected-eof-while-parsing-fix.md","SyntaxError: unexpected EOF while parsing (Fix)",{"type":7,"value":8,"toc":959},"minimark",[9,13,21,24,43,46,51,54,111,114,117,141,145,148,154,165,176,179,192,196,199,216,220,223,242,248,253,272,276,288,292,295,299,328,331,358,361,364,371,375,378,381,422,427,430,494,498,501,601,604,607,610,614,617,661,664,682,688,691,721,725,728,754,757,772,775,793,797,800,826,833,837,840,880,884,888,894,898,901,905,908,912,925,929,955],[10,11,5],"h1",{"id":12},"syntaxerror-unexpected-eof-while-parsing-fix",[14,15,16,20],"p",{},[17,18,19],"code",{},"SyntaxError: unexpected EOF while parsing"," means Python reached the end of your file before the code was complete.",[14,22,23],{},"This usually happens when something is missing, such as:",[25,26,27,31,34,37,40],"ul",{},[28,29,30],"li",{},"a closing quote",[28,32,33],{},"a closing parenthesis",[28,35,36],{},"a closing bracket",[28,38,39],{},"a closing brace",[28,41,42],{},"the rest of an unfinished statement",[14,44,45],{},"This page will help you find the missing part, fix the syntax, and understand why Python shows this error.",[47,48,50],"h2",{"id":49},"quick-fix","Quick fix",[14,52,53],{},"A complete statement looks like this:",[55,56,61],"pre",{"className":57,"code":58,"language":59,"meta":60,"style":60},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","name = input(\"Enter your name: \")\nprint(name)\n","python","",[17,62,63,97],{"__ignoreMap":60},[64,65,68,72,76,80,84,88,92,94],"span",{"class":66,"line":67},"line",1,[64,69,71],{"class":70},"su5hD","name ",[64,73,75],{"class":74},"smGrS","=",[64,77,79],{"class":78},"sptTA"," input",[64,81,83],{"class":82},"sP7_E","(",[64,85,87],{"class":86},"sjJ54","\"",[64,89,91],{"class":90},"s_sjI","Enter your name: ",[64,93,87],{"class":86},[64,95,96],{"class":82},")\n",[64,98,100,103,105,109],{"class":66,"line":99},2,[64,101,102],{"class":78},"print",[64,104,83],{"class":82},[64,106,108],{"class":107},"slqww","name",[64,110,96],{"class":82},[14,112,113],{},"This error usually means Python expected something more before the file ended.",[14,115,116],{},"Check for:",[25,118,119,122,128,133,138],{},[28,120,121],{},"a missing closing quote",[28,123,124,125],{},"a missing ",[17,126,127],{},")",[28,129,124,130],{},[17,131,132],{},"]",[28,134,124,135],{},[17,136,137],{},"}",[28,139,140],{},"an unfinished function call or expression",[47,142,144],{"id":143},"what-this-error-means","What this error means",[14,146,147],{},"Python reads your code from top to bottom.",[14,149,150,151,153],{},"When you get ",[17,152,19],{},", Python is saying:",[25,155,156,159,162],{},[28,157,158],{},"it got to the end of the file",[28,160,161],{},"it was still expecting more code",[28,163,164],{},"something earlier was left incomplete",[14,166,167,170,171,175],{},[17,168,169],{},"EOF"," means ",[172,173,174],"strong",{},"end of file",".",[14,177,178],{},"In many cases, the line shown in the error is not the real problem. The mistake is often on the same line or a line above it.",[14,180,181,182,187,188,175],{},"If you want a broader overview of how syntax problems work, see ",[183,184,186],"a",{"href":185},"\u002Flearn\u002Fpython-syntax-basics-explained\u002F","Python syntax basics explained"," and ",[183,189,191],{"href":190},"\u002Flearn\u002Fpython-errors-and-exceptions-explained\u002F","Python errors and exceptions explained",[47,193,195],{"id":194},"why-this-happens","Why this happens",[14,197,198],{},"This error is commonly caused by one of these problems:",[25,200,201,204,207,210,213],{},[28,202,203],{},"A parenthesis was opened but not closed.",[28,205,206],{},"A string started with a quote but never ended.",[28,208,209],{},"A list, tuple, dictionary, or set was not closed.",[28,211,212],{},"A function call or expression was left unfinished.",[28,214,215],{},"A multi-line statement was started but not completed.",[47,217,219],{"id":218},"example-missing-closing-parenthesis","Example: missing closing parenthesis",[14,221,222],{},"Here is a common example:",[55,224,226],{"className":57,"code":225,"language":59,"meta":60,"style":60},"print(\"Hello\"\n",[17,227,228],{"__ignoreMap":60},[64,229,230,232,234,236,239],{"class":66,"line":67},[64,231,102],{"class":78},[64,233,83],{"class":82},[64,235,87],{"class":86},[64,237,238],{"class":90},"Hello",[64,240,241],{"class":86},"\"\n",[14,243,244,245,247],{},"Python expects a closing ",[17,246,127],{}," but reaches the end of the file first.",[249,250,252],"h3",{"id":251},"fix","Fix",[55,254,256],{"className":57,"code":255,"language":59,"meta":60,"style":60},"print(\"Hello\")\n",[17,257,258],{"__ignoreMap":60},[64,259,260,262,264,266,268,270],{"class":66,"line":67},[64,261,102],{"class":78},[64,263,83],{"class":82},[64,265,87],{"class":86},[64,267,238],{"class":90},[64,269,87],{"class":86},[64,271,96],{"class":82},[249,273,275],{"id":274},"why-this-works","Why this works",[14,277,278,279,282,283,285,286,175],{},"The ",[17,280,281],{},"print()"," function call starts with ",[17,284,83],{}," and must end with ",[17,287,127],{},[47,289,291],{"id":290},"example-missing-quote","Example: missing quote",[14,293,294],{},"If a string starts but never ends, Python keeps reading until the file ends.",[249,296,298],{"id":297},"bad-code","Bad code",[55,300,302],{"className":57,"code":301,"language":59,"meta":60,"style":60},"message = \"Hello\nprint(message)\n",[17,303,304,317],{"__ignoreMap":60},[64,305,306,309,311,314],{"class":66,"line":67},[64,307,308],{"class":70},"message ",[64,310,75],{"class":74},[64,312,313],{"class":86}," \"",[64,315,316],{"class":90},"Hello\n",[64,318,319,321,323,326],{"class":66,"line":99},[64,320,102],{"class":78},[64,322,83],{"class":82},[64,324,325],{"class":107},"message",[64,327,96],{"class":82},[249,329,252],{"id":330},"fix-1",[55,332,334],{"className":57,"code":333,"language":59,"meta":60,"style":60},"message = \"Hello\"\nprint(message)\n",[17,335,336,348],{"__ignoreMap":60},[64,337,338,340,342,344,346],{"class":66,"line":67},[64,339,308],{"class":70},[64,341,75],{"class":74},[64,343,313],{"class":86},[64,345,238],{"class":90},[64,347,241],{"class":86},[64,349,350,352,354,356],{"class":66,"line":99},[64,351,102],{"class":78},[64,353,83],{"class":82},[64,355,325],{"class":107},[64,357,96],{"class":82},[249,359,275],{"id":360},"why-this-works-1",[14,362,363],{},"Strings must have both an opening and a closing quote.",[14,365,366,367,175],{},"If your problem is specifically caused by an unclosed string, see ",[183,368,370],{"href":369},"\u002Ferrors\u002Fsyntaxerror-eol-while-scanning-string-literal-fix\u002F","SyntaxError: EOL while scanning string literal",[47,372,374],{"id":373},"example-unfinished-list-or-dictionary","Example: unfinished list or dictionary",[14,376,377],{},"This can also happen with collections.",[249,379,298],{"id":380},"bad-code-1",[55,382,384],{"className":57,"code":383,"language":59,"meta":60,"style":60},"numbers = [1, 2, 3\nprint(numbers)\n",[17,385,386,411],{"__ignoreMap":60},[64,387,388,391,393,396,400,403,406,408],{"class":66,"line":67},[64,389,390],{"class":70},"numbers ",[64,392,75],{"class":74},[64,394,395],{"class":82}," [",[64,397,399],{"class":398},"srdBf","1",[64,401,402],{"class":82},",",[64,404,405],{"class":398}," 2",[64,407,402],{"class":82},[64,409,410],{"class":398}," 3\n",[64,412,413,415,417,420],{"class":66,"line":99},[64,414,102],{"class":78},[64,416,83],{"class":82},[64,418,419],{"class":107},"numbers",[64,421,96],{"class":82},[14,423,424,425,175],{},"Python expects the closing ",[17,426,132],{},[14,428,429],{},"Another example:",[55,431,433],{"className":57,"code":432,"language":59,"meta":60,"style":60},"person = {\n    \"name\": \"Ana\",\n    \"age\": 25\nprint(person)\n",[17,434,435,445,467,482],{"__ignoreMap":60},[64,436,437,440,442],{"class":66,"line":67},[64,438,439],{"class":70},"person ",[64,441,75],{"class":74},[64,443,444],{"class":82}," {\n",[64,446,447,450,452,454,457,459,462,464],{"class":66,"line":99},[64,448,449],{"class":86},"    \"",[64,451,108],{"class":90},[64,453,87],{"class":86},[64,455,456],{"class":82},":",[64,458,313],{"class":86},[64,460,461],{"class":90},"Ana",[64,463,87],{"class":86},[64,465,466],{"class":82},",\n",[64,468,470,472,475,477,479],{"class":66,"line":469},3,[64,471,449],{"class":86},[64,473,474],{"class":90},"age",[64,476,87],{"class":86},[64,478,456],{"class":82},[64,480,481],{"class":398}," 25\n",[64,483,485,487,489,492],{"class":66,"line":484},4,[64,486,102],{"class":78},[64,488,83],{"class":82},[64,490,491],{"class":107},"person",[64,493,96],{"class":82},[14,495,424,496,175],{},[17,497,137],{},[249,499,252],{"id":500},"fix-2",[55,502,504],{"className":57,"code":503,"language":59,"meta":60,"style":60},"numbers = [1, 2, 3]\nprint(numbers)\n\nperson = {\n    \"name\": \"Ana\",\n    \"age\": 25\n}\nprint(person)\n",[17,505,506,528,538,544,552,571,584,590],{"__ignoreMap":60},[64,507,508,510,512,514,516,518,520,522,525],{"class":66,"line":67},[64,509,390],{"class":70},[64,511,75],{"class":74},[64,513,395],{"class":82},[64,515,399],{"class":398},[64,517,402],{"class":82},[64,519,405],{"class":398},[64,521,402],{"class":82},[64,523,524],{"class":398}," 3",[64,526,527],{"class":82},"]\n",[64,529,530,532,534,536],{"class":66,"line":99},[64,531,102],{"class":78},[64,533,83],{"class":82},[64,535,419],{"class":107},[64,537,96],{"class":82},[64,539,540],{"class":66,"line":469},[64,541,543],{"emptyLinePlaceholder":542},true,"\n",[64,545,546,548,550],{"class":66,"line":484},[64,547,439],{"class":70},[64,549,75],{"class":74},[64,551,444],{"class":82},[64,553,555,557,559,561,563,565,567,569],{"class":66,"line":554},5,[64,556,449],{"class":86},[64,558,108],{"class":90},[64,560,87],{"class":86},[64,562,456],{"class":82},[64,564,313],{"class":86},[64,566,461],{"class":90},[64,568,87],{"class":86},[64,570,466],{"class":82},[64,572,574,576,578,580,582],{"class":66,"line":573},6,[64,575,449],{"class":86},[64,577,474],{"class":90},[64,579,87],{"class":86},[64,581,456],{"class":82},[64,583,481],{"class":398},[64,585,587],{"class":66,"line":586},7,[64,588,589],{"class":82},"}\n",[64,591,593,595,597,599],{"class":66,"line":592},8,[64,594,102],{"class":78},[64,596,83],{"class":82},[64,598,491],{"class":107},[64,600,96],{"class":82},[249,602,275],{"id":603},"why-this-works-2",[14,605,606],{},"Lists, dictionaries, tuples, and sets must be fully closed before Python can continue.",[14,608,609],{},"Check collection literals carefully, especially when they span multiple lines.",[47,611,613],{"id":612},"how-to-fix-it-step-by-step","How to fix it step by step",[14,615,616],{},"Use this process when you see the error:",[618,619,620,623,626,652,655,658],"ol",{},[28,621,622],{},"Read the line shown in the error message.",[28,624,625],{},"Check the line above it too.",[28,627,628,629],{},"Match every opening symbol with a closing symbol:\n",[25,630,631,638,645],{},[28,632,633,635,636],{},[17,634,83],{}," with ",[17,637,127],{},[28,639,640,635,643],{},[17,641,642],{},"[",[17,644,132],{},[28,646,647,635,650],{},[17,648,649],{},"{",[17,651,137],{},[28,653,654],{},"Check that all strings have both opening and closing quotes.",[28,656,657],{},"Look for unfinished function calls or expressions.",[28,659,660],{},"If needed, delete the broken line and type it again carefully.",[14,662,663],{},"For example, this unfinished expression causes the same problem:",[55,665,667],{"className":57,"code":666,"language":59,"meta":60,"style":60},"total = 10 +\n",[17,668,669],{"__ignoreMap":60},[64,670,671,674,676,679],{"class":66,"line":67},[64,672,673],{"class":70},"total ",[64,675,75],{"class":74},[64,677,678],{"class":398}," 10",[64,680,681],{"class":74}," +\n",[14,683,684,685,175],{},"Python expects something after the ",[17,686,687],{},"+",[249,689,252],{"id":690},"fix-3",[55,692,694],{"className":57,"code":693,"language":59,"meta":60,"style":60},"total = 10 + 5\nprint(total)\n",[17,695,696,710],{"__ignoreMap":60},[64,697,698,700,702,704,707],{"class":66,"line":67},[64,699,673],{"class":70},[64,701,75],{"class":74},[64,703,678],{"class":398},[64,705,706],{"class":74}," +",[64,708,709],{"class":398}," 5\n",[64,711,712,714,716,719],{"class":66,"line":99},[64,713,102],{"class":78},[64,715,83],{"class":82},[64,717,718],{"class":107},"total",[64,720,96],{"class":82},[47,722,724],{"id":723},"fast-debugging-checklist","Fast debugging checklist",[14,726,727],{},"When you need to fix the error quickly, check these first:",[25,729,730,742,745,748,751],{},[28,731,732,733,735,736,738,739,741],{},"Count ",[17,734,83],{},", ",[17,737,642],{},", and ",[17,740,649],{}," characters and make sure they are closed.",[28,743,744],{},"Check for single or double quotes that were not closed.",[28,746,747],{},"Look for a comma or operator at the end of a line with no next value.",[28,749,750],{},"Check code copied from the web for missing last characters.",[28,752,753],{},"Use an editor that highlights matching brackets.",[14,755,756],{},"You can also run your file from the command line:",[55,758,762],{"className":759,"code":760,"language":761,"meta":60,"style":60},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python your_script.py\n","bash",[17,763,764],{"__ignoreMap":60},[64,765,766,769],{"class":66,"line":67},[64,767,59],{"class":768},"sbgvK",[64,770,771],{"class":90}," your_script.py\n",[14,773,774],{},"Or check the file for syntax problems with:",[55,776,778],{"className":759,"code":777,"language":761,"meta":60,"style":60},"python -m py_compile your_script.py\n",[17,779,780],{"__ignoreMap":60},[64,781,782,784,788,791],{"class":66,"line":67},[64,783,59],{"class":768},[64,785,787],{"class":786},"stzsN"," -m",[64,789,790],{"class":90}," py_compile",[64,792,771],{"class":90},[47,794,796],{"id":795},"common-causes","Common causes",[14,798,799],{},"These are the most common reasons for this error:",[25,801,802,807,812,817,820,823],{},[28,803,804,805],{},"Missing closing parenthesis ",[17,806,127],{},[28,808,809,810],{},"Missing closing bracket ",[17,811,132],{},[28,813,814,815],{},"Missing closing brace ",[17,816,137],{},[28,818,819],{},"Unclosed string quote",[28,821,822],{},"Unfinished function call",[28,824,825],{},"Incomplete expression at the end of the file",[14,827,828,829,175],{},"A more general syntax page may also help if the message is less clear: ",[183,830,832],{"href":831},"\u002Ferrors\u002Fsyntaxerror-invalid-syntax-fix\u002F","SyntaxError: invalid syntax",[47,834,836],{"id":835},"related-errors-to-compare","Related errors to compare",[14,838,839],{},"Some syntax errors look similar but mean different things:",[25,841,842,847,873],{},[28,843,844,846],{},[183,845,370],{"href":369}," is more specific for unclosed strings.",[28,848,849,853,854,856,857,735,860,735,863,735,866,869,870,175],{},[183,850,852],{"href":851},"\u002Ferrors\u002Fsyntaxerror-missing-colon-fix\u002F","SyntaxError: missing colon"," happens when Python expects ",[17,855,456],{}," after ",[17,858,859],{},"if",[17,861,862],{},"for",[17,864,865],{},"while",[17,867,868],{},"def",", or ",[17,871,872],{},"class",[28,874,875,879],{},[183,876,878],{"href":877},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block"," happens when the syntax is otherwise valid, but the block indentation is wrong.",[47,881,883],{"id":882},"faq","FAQ",[249,885,887],{"id":886},"what-does-eof-mean-in-python","What does EOF mean in Python?",[14,889,890,891,893],{},"EOF means ",[172,892,174],{},". Python got to the end of your code while still expecting more syntax.",[249,895,897],{"id":896},"is-the-error-always-on-the-last-line","Is the error always on the last line?",[14,899,900],{},"No. The real problem is often earlier, such as an unclosed quote or bracket on a previous line.",[249,902,904],{"id":903},"can-this-happen-with-copy-pasted-code","Can this happen with copy-pasted code?",[14,906,907],{},"Yes. Code can be missing a closing character or may have been cut off when copied.",[249,909,911],{"id":910},"how-do-i-find-the-missing-symbol-quickly","How do I find the missing symbol quickly?",[14,913,914,915,735,918,735,921,924],{},"Check matching pairs: ",[17,916,917],{},"()",[17,919,920],{},"[]",[17,922,923],{},"{}",", and quotes. Most editors also highlight matching brackets.",[47,926,928],{"id":927},"see-also","See also",[25,930,931,935,939,943,947,951],{},[28,932,933],{},[183,934,832],{"href":831},[28,936,937],{},[183,938,370],{"href":369},[28,940,941],{},[183,942,852],{"href":851},[28,944,945],{},[183,946,878],{"href":877},[28,948,949],{},[183,950,191],{"href":190},[28,952,953],{},[183,954,186],{"href":185},[956,957,958],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}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 .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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":60,"searchDepth":99,"depth":99,"links":960},[961,962,963,964,968,973,978,981,982,983,984,990],{"id":49,"depth":99,"text":50},{"id":143,"depth":99,"text":144},{"id":194,"depth":99,"text":195},{"id":218,"depth":99,"text":219,"children":965},[966,967],{"id":251,"depth":469,"text":252},{"id":274,"depth":469,"text":275},{"id":290,"depth":99,"text":291,"children":969},[970,971,972],{"id":297,"depth":469,"text":298},{"id":330,"depth":469,"text":252},{"id":360,"depth":469,"text":275},{"id":373,"depth":99,"text":374,"children":974},[975,976,977],{"id":380,"depth":469,"text":298},{"id":500,"depth":469,"text":252},{"id":603,"depth":469,"text":275},{"id":612,"depth":99,"text":613,"children":979},[980],{"id":690,"depth":469,"text":252},{"id":723,"depth":99,"text":724},{"id":795,"depth":99,"text":796},{"id":835,"depth":99,"text":836},{"id":882,"depth":99,"text":883,"children":985},[986,987,988,989],{"id":886,"depth":469,"text":887},{"id":896,"depth":469,"text":897},{"id":903,"depth":469,"text":904},{"id":910,"depth":469,"text":911},{"id":927,"depth":99,"text":928},"Master syntaxerror unexpected eof while parsing fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fsyntaxerror-unexpected-eof-while-parsing-fix",{"title":5,"description":991},"errors\u002Fsyntaxerror-unexpected-eof-while-parsing-fix","leI94pTqZ7aMQm3-O4mw0OZrzn_mnI9eCgoInKasNWw",1777585480947]