{"id":21286,"date":"2020-08-17T11:32:13","date_gmt":"2020-08-17T18:32:13","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=21286"},"modified":"2023-12-01T03:57:59","modified_gmt":"2023-12-01T11:57:59","slug":"python-valueerror-io-operation-on-closed-file","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/","title":{"rendered":"Python ValueError: I\/O operation on closed file Solution"},"content":{"rendered":"\n<p>You can only read from and write to a Python file if the file is open. If you try to access or manipulate a file that has been closed, the \u201cValueError : I\/O operation on closed file\u201d appears in your code.<br><\/p>\n\n\n\n<p>In this guide, we talk about what this error means and why it is raised. We walk through two examples of this error so you can learn how to solve it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ValueError : I\/O operation on closed file<\/h2>\n\n\n\n<p>It has become good practice in Python to <a href=\"https:\/\/careerkarma.com\/blog\/python-read-file\/\">close a file as soon as you have finished working with the file<\/a>. This helps you clean up your code in the Python interpreter. Once a file has been closed in a Python program, you can no longer read from or write to that file directly.<br><\/p>\n\n\n\n<p>There are two common scenarios where the \u201cValueError : I\/O operation on closed file\u201d is encountered:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>When you forget to indent your code correctly in a <a href=\"https:\/\/careerkarma.com\/blog\/python-write-to-file\/\">\u201cwith\u201d statement<\/a><\/li><li>When you try to read a file after it has been closed using the <code>close()<\/code> statement<\/li><\/ul>\n\n\n\n<p>Let\u2019s walk through each of these scenarios and discuss them in detail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #1: Improper Indentation<\/h2>\n\n\n\n<p>Let\u2019s write a program that reads a list of student grades from a CSV file. Our CSV file is called students.csv. It currently stores the following data:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Andrew,73,84,92\nLinda,76,77,72\nSamantha,64,63,75<\/pre><\/div>\n\n\n\n<p>To start, we <a href=\"https:\/\/careerkarma.com\/blog\/python-csv-module\/\">import the csv library<\/a> in our code so we can read our CSV file. We then use a <code>with<\/code> statement to open our file:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv\n\nwith open(&quot;students.csv&quot;, &quot;r&quot;) as students:\n\tread_file = csv.reader(students)<\/pre><\/div>\n\n\n\n<p>This code opens the file \u201cstudents.csv\u201d in read (\u201cr\u201d) mode. We assign the contents of the file to the variable \u201cread_file\u201d.<br><\/p>\n\n\n\n<p>Let\u2019s print each student\u2019s record to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for s in read_file:\n\t\t print(&quot;Name: &quot; + s[0])\n\t\t print(&quot;Test 1 Score: &quot; + s[1])\n\t\t print(&quot;Test 2 Score: &quot; + s[2])\n\t\t print(&quot;Unit Assessment Score: &quot; + s[3])<\/pre><\/div>\n\n\n\n<p>We use a <a href=\"https:\/\/careerkarma.com\/blog\/python-for-loop\/\">\u201cfor\u201d loop<\/a> to iterate over every item in the \u201cread_file\u201d variable. This variable stores our CSV file in a list. Next, we use indexing to access each value from each student record. We print each of these values to the console.<br><\/p>\n\n\n\n<p>Run our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;main.py&quot;, line 6, in &lt;module&gt;\n\tfor s in read_file:\nValueError: I\/O operation on closed file.<\/pre><\/div>\n\n\n\n<p>Our code returns an error. This is because we\u2019ve tried to iterate over \u201cread_file\u201d outside of our <code>with<\/code> statement. The \u201cread_file\u201d <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">variable<\/a> can only read inside the <code>with<\/code> statement. After the <code>with<\/code> statement is executed, the file is closed.<br><\/p>\n\n\n\n<p>To solve this problem, we need to indent our for loop so that it is within our <code>with<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import csv\n\nwith open(&quot;students.csv&quot;, &quot;r&quot;) as students:\n\tread_file = csv.reader(students)\n\n\tfor s in range(1, read_file):\n\t\t\t print(&quot;Name: &quot; + s[0])\n\t\t\t print(&quot;Test 1 Score: &quot; + s[1])\n\t\t\t print(&quot;Test 2 Score: &quot; + s[2])\n\t\t\t print(&quot;Unit Assessment Score: &quot; + s[3])<\/pre><\/div>\n\n\n\n<p>Run this revised code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Name: Andrew\nTest 1 Score: 73\nTest 2 Score: 84\nUnit Assessment Score: 92\nName: Linda\nTest 1 Score: 76\nTest 2 Score: 77\nUnit Assessment Score: 72\nName: Samantha\nTest 1 Score: 64\nTest 2 Score: 63\nUnit Assessment Score: 75<\/pre><\/div>\n\n\n\n<p>Our code successfully executes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #2: Accessing a Closed File<\/h2>\n\n\n\n<p>While <code>with<\/code> statements are the most common way of accessing a file, you can use an <code>open()<\/code> statement without a <code>with<\/code> statement to access a file.<br><\/p>\n\n\n\n<p>Read the contents of our \u201cstudents.csv\u201d file:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>students = open(&quot;students.csv&quot;, &quot;r&quot;)\nread_file = csv.reader(students)\nstudents.close()<\/pre><\/div>\n\n\n\n<p>We use the <code>open()<\/code> method to open the \u201cstudents.csv\u201d file in read mode. We then use the <code>csv.reader()<\/code> method to read our CSV file. We then close our file because we have read its contents into a variable.<br><\/p>\n\n\n\n<p>Next, print each record from our file to the console using a for loop:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for s in read_file:\n\t\t print(&quot;Name: &quot; + s[0])\n\t\t print(&quot;Test 1 Score: &quot; + s[1])\n\t\t print(&quot;Test 2 Score: &quot; + s[2])\n\t\t print(&quot;Unit Assessment Score: &quot; + s[3])<\/pre><\/div>\n\n\n\n<p>This for loop is the same as the one from our last example. The loop prints out all the information about each record in our CSV file. Let\u2019s test out our code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;main.py&quot;, line 7, in &lt;module&gt;\n\tfor s in read_file:\nValueError: I\/O operation on closed file.<\/pre><\/div>\n\n\n\n<p>Our code raises an error. This is because we try to iterate over \u201cread_file\u201d after we have closed our file. To solve this error, we should close our file after we have iterated over \u201cread_file\u201d:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>students = open(&quot;students.csv&quot;, &quot;r&quot;)\nread_file = csv.reader(students)\n\nfor s in read_file:\n\t\t print(&quot;Name: &quot; + s[0])\n\t\t print(&quot;Test 1 Score: &quot; + s[1])\n\t\t print(&quot;Test 2 Score: &quot; + s[2])\n\t\t print(&quot;Unit Assessment Score: &quot; + s[3])\n\nstudents.close()<\/pre><\/div>\n\n\n\n<p>Let\u2019s run our code again:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Name: Andrew\nTest 1 Score: 73\nTest 2 Score: 84\nUnit Assessment Score: 92\nName: Linda\nTest 1 Score: 76\nTest 2 Score: 77\nUnit Assessment Score: 72\nName: Samantha\nTest 1 Score: 64\nTest 2 Score: 63\nUnit Assessment Score: 75<\/pre><\/div>\n\n\n\n<p>Our code executes successfully. The values in \u201cread_file\u201d are accessible until we close our file. Because we\u2019ve used our <code>for<\/code> loop before our <code>close()<\/code> statement, our code executes without an error. Once we print each student record to the console, we close our file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The \u201cValueError : I\/O operation on closed file\u201d error is raised when you try to read from or write to a file that has been closed.<br><\/p>\n\n\n\n<p>If you are using a <code>with<\/code> statement, check to make sure that your code is properly indented. If you are not using a <code>with<\/code> statement, make sure that you do not close your file before you read its contents.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to solve this error like a <a href=\"https:\/\/careerkarma.com\/blog\/what-python-is-used-for\/\">Python<\/a> expert!<\/p>\n","protected":false},"excerpt":{"rendered":"You can only read from and write to a Python file if the file is open. If you try to access or manipulate a file that has been closed, the \u201cValueError : I\/O operation on closed file\u201d appears in your code. In this guide, we talk about what this error means and why it is&hellip;","protected":false},"author":240,"featured_media":21060,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-21286","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python ValueError: I\/O operation on closed file Solution | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python ValueError: I\/O operation on closed file Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-17T18:32:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python ValueError: I\/O operation on closed file Solution\",\"datePublished\":\"2020-08-17T18:32:13+00:00\",\"dateModified\":\"2023-12-01T11:57:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\"},\"wordCount\":685,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\",\"name\":\"Python ValueError: I\/O operation on closed file Solution | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg\",\"datePublished\":\"2020-08-17T18:32:13+00:00\",\"dateModified\":\"2023-12-01T11:57:59+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python ValueError: I\/O operation on closed file Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python ValueError: I\/O operation on closed file Solution | Career Karma","description":"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/","og_locale":"en_US","og_type":"article","og_title":"Python ValueError: I\/O operation on closed file Solution","og_description":"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.","og_url":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-17T18:32:13+00:00","article_modified_time":"2023-12-01T11:57:59+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python ValueError: I\/O operation on closed file Solution","datePublished":"2020-08-17T18:32:13+00:00","dateModified":"2023-12-01T11:57:59+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/"},"wordCount":685,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/","url":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/","name":"Python ValueError: I\/O operation on closed file Solution | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg","datePublished":"2020-08-17T18:32:13+00:00","dateModified":"2023-12-01T11:57:59+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn about the Python ValueError: I\/O operation on closed file, how the error works, and how to solve the error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/fabian-irsara-67l-QujB14w-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-valueerror-io-operation-on-closed-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python ValueError: I\/O operation on closed file Solution"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=21286"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21286\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/21060"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=21286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=21286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=21286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}