{"id":125470,"date":"2022-06-06T19:17:28","date_gmt":"2022-06-06T19:17:28","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=403242"},"modified":"2022-06-06T19:17:28","modified_gmt":"2022-06-06T19:17:28","slug":"how-to-open-multiple-files-in-python","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/06\/06\/how-to-open-multiple-files-in-python\/","title":{"rendered":"How to Open Multiple Files in Python"},"content":{"rendered":"<div class=\"kk-star-ratings kksr-valign-top kksr-align-left \" data-payload=\"{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;403242&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;count&quot;:&quot;0&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;}\">\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\"> <span class=\"kksr-muted\">Rate this post<\/span> <\/div>\n<\/div>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">In this article, you&#8217;ll learn how to open multiple files in Python.<\/p>\n<h2 class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">Problem Formulation and Solution Overview<\/h2>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio has-global-color-8-background-color has-background\"><em><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4ac.png\" alt=\"\ud83d\udcac\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Question<\/strong>: How would we write Python code to open multiple files?<\/em><\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">We can accomplish this task by one of the following options:<\/p>\n<ul type=\"video\" class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<li><strong>Method 1<\/strong>: Open Multiple Text Files using <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-open-function\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-open-function\/\" target=\"_blank\"><code>open()<\/code><\/a><\/li>\n<li><strong>Method 2<\/strong>:Open Multiple Text Files using <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-open-function\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-open-function\/\" target=\"_blank\"><code>open()<\/code><\/a> and backslash (<code>\\<\/code>)<\/li>\n<li><strong>Method 3<\/strong>: Open Multiple Text Files using Parenthesized Context Managers and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-open-function\/\" target=\"_blank\"><code>open()<\/code><\/a><\/li>\n<li><strong>Method 4<\/strong>: Open Multiple Text Files using the <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/os.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/os.html\" target=\"_blank\">os<\/a> library and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-open-function\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-open-function\/\" target=\"_blank\"><code>open()<\/code><\/a><\/li>\n<\/ul>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">To make it more fun, we have the following running scenario:<\/p>\n<p><em>You have been contacted by the <a rel=\"noreferrer noopener\" href=\"https:\/\/academy.finxter.com\/\" data-type=\"URL\" data-id=\"https:\/\/academy.finxter.com\/\" target=\"_blank\">Finxter Academy<\/a> to write code that opens multiple files and writes the contents from one file to another.<\/em><\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Preparation &amp; Overview<\/h2>\n<p>If your script opens files, it is a good practice to check for errors, such as:<\/p>\n<ul>\n<li><em>No Such File Or Directory<\/em><\/li>\n<li><em>Not Readable<\/em><\/li>\n<li><em>Not Writable<\/em><\/li>\n<\/ul>\n<p> In this regard, all examples in this article will be wrapped in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" target=\"_blank\"><code>try\/except<\/code><\/a> statement to catch these errors.<\/p>\n<p><strong>Contents of <code>orig_file.txt<\/code><\/strong><\/p>\n<p>To follow along with this article, create <code>orig_file.txt<\/code> with the contents below and place it in the current working directory.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>30022425,Oliver,Grandmaster,2476<br \/>30022437,Cindy,Intermediate,1569<br \/>30022450,Leon,Authority,1967<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.<\/p>\n<pre class=\"EnlighterJSRAW wp-embed-aspect-16-9 wp-has-aspect-ratio\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import logging<\/pre>\n<p>This allows us to log any error message that may occur when handling the files.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Method 1: Open Multiple Text Files with open()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method opens multiple text files simultaneously on <strong>one<\/strong> line using the <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-open-function\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-open-function\/\" target=\"_blank\"><code>open()<\/code><\/a> statement separated by the comma (<code>,<\/code>) character. <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">try: with open('orig_file.txt', 'r') as fp1, open('new_file.txt', 'w') as fp2: fp2.write(fp1.read())\nexcept OSError as error: logging.error(\"This Error Occurred: %s\", error)<\/pre>\n<p>This code snippet is wrapped in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" target=\"_blank\"><code>try\/except<\/code><\/a> statement to catch errors. When this runs, it falls inside the <code>try<\/code> statement and executes as follows:<\/p>\n<ul>\n<li>Opens two (2) text files on <strong>one <\/strong>line of code.\n<ul>\n<li>The file for reading, which contains a comma (<code>,<\/code>) character at the end to let Python know there is another file to open: <code>open('orig_file.txt', 'r') as fp1<\/code><\/li>\n<li>The second is for writing: <code>open('new_file.txt', 'w') as fp2<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Then, the entire contents of <code>orig_file.txt<\/code> writes to <code>new_file.txt<\/code>.<\/li>\n<\/ul>\n<p>If an error occurs during the above process, the code falls to the <code>except<\/code> statement, which retrieves and outputs the error message to the terminal.<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>&nbsp;<strong>Note<\/strong>: The <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-strip\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-strip\/\" target=\"_blank\"><code>strip()<\/code><\/a> function removes any trailing space characters.<br \/>The newline character (<code>\\n<\/code>) is added to place each iteration on its own line. <\/p>\n<p>If successful, the contents of <code>orig_file.txt<\/code> and <code>new_file.txt<\/code> are identical.<\/p>\n<p><strong>Output of new_file.txt<\/strong><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>30022425,Oliver,Grandmaster,2476<br \/>30022437,Cindy,Intermediate,1569<br \/>30022450,Leon,Authority,1967<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Python open() Function -- An 80\/20 Guide by Example\" width=\"780\" height=\"439\" src=\"https:\/\/www.youtube.com\/embed\/so9MlRnUG1Y?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div>\n<\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Method 2: Open Files Across Multiple Lines with open() and Backslash (\\)<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">Before <a href=\"https:\/\/blog.finxter.com\/how-to-check-your-python-version\/\" data-type=\"post\" data-id=\"1371\" target=\"_blank\" rel=\"noreferrer noopener\">Python version<\/a> <a href=\"https:\/\/blog.finxter.com\/python-version-history\/\" data-type=\"post\" data-id=\"35256\" target=\"_blank\" rel=\"noreferrer noopener\">3.10<\/a>, and in use today, opening multiple files on one line could be awkward. To circumvent this, use the backslash (\\) character as shown below to place the <code>open()<\/code> statements on separate lines.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2-3\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">try: with open('orig_file.txt', 'r') as fp1, \\ open('new_file3.txt', 'w') as fp2: fp2.write(fp1.read())\nexcept OSError as error: logging.error(\"This Error Occurred: %s\", error)<\/pre>\n<p>This code snippet is wrapped in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" target=\"_blank\"><code>try\/except<\/code><\/a> statement to catch errors. When this runs, it falls inside the <code>try<\/code> statement and executes as follows:<\/p>\n<ul>\n<li>Opens the first file using <code>open('orig_file.txt', 'r')<\/code> for reading and contains a backslash (<code>\\<\/code>) character to let Python know there is another file to open.<\/li>\n<li>Opens the second file using <code>open('new_file.txt', 'w')<\/code> for writing.<\/li>\n<li>Then, the entire contents of <code>orig_file.txt<\/code> writes to <code>new_file.txt<\/code>.<\/li>\n<\/ul>\n<p>If an error occurs during the above process, the code falls to the <code>except<\/code> statement, which retrieves and outputs the error message to the terminal.<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>&nbsp;<strong>Note<\/strong>: The <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-strip\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-strip\/\" target=\"_blank\"><code>strip()<\/code><\/a> function removes any trailing space characters.<br \/>The newline character (<code>\\n<\/code>) is added to place each iteration on its own line. <\/p>\n<p>If successful, the contents of <code>orig_file.txt<\/code> and <code>new_file.txt<\/code> are identical.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Method 3: Open Multiple Text Files using Parenthesized Context Managers and open()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">In Python version 3.10, Parenthesized Context Managers were added. This fixes a bug found in version 3.9, which did not support the use of parentheses across multiple lines of code. How Pythonic!<\/p>\n<p>Here&#8217;s how they look in a short example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2-5\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">try: with ( open('orig_file.txt', 'r') as fp1, open('new_file.txt', 'w') as fp2 ): fp2.write(fp1.read())\nexcept OSError as error: logging.error(\"This Error Occurred: %s\", error)\n<\/pre>\n<p>This code snippet is wrapped in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" target=\"_blank\"><code>try\/except<\/code><\/a> statement to catch errors. When this runs, it falls inside the <code>try<\/code> statement and executes as follows:<\/p>\n<ul>\n<li>Declare the opening of <code>with<\/code> and the opening bracket (<code>with (<\/code>)).\n<ul>\n<li>Opens <code>orig_file.txt<\/code> (<code>open('orig_file.txt', 'r') as fp1,<\/code>) for reading with a comma (,) to let Python know to expect another file.<\/li>\n<li>Open <code>new_file.txt<\/code> (<code>open('new_file.txt', 'w') as fp2<\/code>) for writing.<\/li>\n<\/ul>\n<\/li>\n<li>Closes the <code>with<\/code> statement by using <code>):<\/code>.<\/li>\n<li>Then, the entire contents of <code>orig_file.txt<\/code> writes to <code>new_file.txt<\/code>.<\/li>\n<\/ul>\n<p>If an error occurs during the above process, the code falls to the <code>except<\/code> statement, which retrieves and outputs the error message to the terminal.<\/p>\n<p>If successful, the contents of <code>orig_file.txt<\/code> and <code>new_file.txt<\/code> are identical.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Method 4: Open Multiple Text Files using the os library and open()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method calls in the <code><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/os.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/os.html\" target=\"_blank\">os<\/a><\/code> library (<code>import os<\/code>) which provides functionality to work with the Operating System. Specifically, for this example, file and folder manipulation. <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"8\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import os os.chdir('files')\nfilelist = os.listdir(os.getcwd()) for i in filelist: try: with open(i, 'r') as f: for line in f.readlines(): print(line) except OSError as error: print('error %s', error) <\/pre>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/>&nbsp;<strong>Note<\/strong>: In this example, two (2) files are read in and <strong>output<\/strong> to the terminal.<\/p>\n<p>This code snippet imports the <code><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/os.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/os.html\" target=\"_blank\">os<\/a><\/code> library to access the required functions.<\/p>\n<p>For this example, we have two (2) text files located in our <code>files<\/code> directory:<br \/><code>file1.txt<\/code> and <code>file2.txt.<\/code> To access and work with these files, we call <code>os.chdir('files')<\/code> to change to this folder (directory).<\/p>\n<p>Next, we retrieve a list of all files residing in the current working directory <br \/>(<code>os.listdir(os.getcwd()<\/code>) and save the results to <code>filelist<\/code>.<\/p>\n<p>IF we output the contents of <code>filelist<\/code> to the terminal, we would have the following: a list of all files in the current working directory in a <a href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a> format.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>['file1.txt', 'file2.txt']<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>This code snippet is wrapped in a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-try-except-an-illustrated-guide\/\" target=\"_blank\"><code>try\/except<\/code><\/a> statement to catch errors. When this runs, it falls inside the <code>try<\/code> statement and executes as follows:<\/p>\n<ul>\n<li>Instantiates a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-loops\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-loops\/\" target=\"_blank\"><code>for<\/code><\/a> loop to traverse through each file in the <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a> and does the following:\n<ul>\n<li>Opens the current file for reading.<\/li>\n<li>Reads in this file one line at a time and output to the terminal.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>If an error occurs during the above process, the code falls to the <code>except<\/code> statement, which retrieves and outputs the error message to the terminal.<\/p>\n<p><strong>Output<\/strong><\/p>\n<p>The contents of the two (2) files are:<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>Contents of File1.<br \/>Contents of File2.<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Summary<\/h2>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">These four (4) methods of how to multiple files should give you enough information to select the best one for your coding requirements.<\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">Good Luck &amp; Happy Coding!<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<h2>Programmer Humor<\/h2>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2753.png\" alt=\"\u2753\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <code><strong>Question:<\/strong> How did the programmer <strong><em>die<\/em><\/strong> in the shower? &#x2620;<\/p>\n<p>&#x2757; <strong>Answer<\/strong>: They read the shampoo bottle instructions: <br \/><em><strong>Lather. Rinse. Repeat.<\/strong><\/em><\/code><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rate this post In this article, you&#8217;ll learn how to open multiple files in Python. Problem Formulation and Solution Overview Question: How would we write Python code to open multiple files? We can accomplish this task by one of the following options: Method 1: Open Multiple Text Files using open() Method 2:Open Multiple Text Files [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-125470","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/125470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=125470"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/125470\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=125470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=125470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=125470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}