{"id":1034,"date":"2023-03-21T20:53:00","date_gmt":"2023-03-21T15:23:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=1034"},"modified":"2023-08-15T13:46:35","modified_gmt":"2023-08-15T08:16:35","slug":"handling-files-in-python","status":"publish","type":"post","link":"https:\/\/geekpython.in\/handling-files-in-python","title":{"rendered":"File IO In Python &#8211; Opening, Reading &#038; Writing"},"content":{"rendered":"\n<p>Files are used to store information, and when we need to access the information, we open the file and read or modify it. We can use the GUI to perform these operations in our systems.<\/p>\n\n\n\n<p>Many programming languages include methods and functions for managing, reading, and even modifying file data. Python is one of the programming languages that can handle files.<\/p>\n\n\n\n<p>In this article, we&#8217;ll look at how to handle files, which includes the methods and operations for reading and writing files, as well as other methods for working with files in Python. We&#8217;ll also make a project to adopt a pet and save the entry in the file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-primary-operation-opening-a-file\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-primary-operation-opening-a-file\"><\/a>Primary operation &#8211; Opening a file<\/h2>\n\n\n\n<p>We must first open a file before we can read or write to it. Use Python&#8217;s built-in&nbsp;<code>open()<\/code>&nbsp;function to perform this operation on the file.<\/p>\n\n\n\n<p>Here&#8217;s an example of how to use Python&#8217;s&nbsp;<code>open()<\/code>&nbsp;function.<\/p>\n\n\n\n<p><code>file_obj = open('file.txt', mode='r')<\/code><\/p>\n\n\n\n<p>We specified two parameters. The first is the&nbsp;<strong>file name<\/strong>, and the second is the&nbsp;<strong>mode<\/strong>, which determines the mode in which we want to open the file.<\/p>\n\n\n\n<p>There are several modes to open files, and the most commonly used ones are listed below.<\/p>\n\n\n\n<p><code>r<\/code>&nbsp;&#8211;&nbsp;<strong>Read<\/strong>. The file opens in read mode. Shows an error if the file doesn&#8217;t exist.<\/p>\n\n\n\n<p><code>w<\/code>&nbsp;&#8211;&nbsp;<strong>Write<\/strong>. The file opens in write mode. Creates a file if the file doesn&#8217;t exist.<\/p>\n\n\n\n<p><code>a<\/code>&nbsp;&#8211;&nbsp;<strong>Append<\/strong>. The file opens in append mode. Writes data into an existing file.<\/p>\n\n\n\n<p><code>x<\/code>&nbsp;&#8211;&nbsp;<strong>Create<\/strong>. Creates a file. If the specified file exists, returns an error.<\/p>\n\n\n\n<p><strong>To specify in which mode a file should be handled, we can use<\/strong><\/p>\n\n\n\n<p><code>t<\/code>&nbsp;&#8211;&nbsp;<strong>Text<\/strong>. The file opens in text mode which means the file will store text data. It is a default mode.<\/p>\n\n\n\n<p><code>b<\/code>&nbsp;&#8211;&nbsp;<strong>Binary<\/strong>. The file opens in the binary mode which means the file will store binary data.<\/p>\n\n\n\n<p>Hence, the primary task is to open a file on which you must operate and specify the mode specific to the work you wish to perform on the file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-reading-a-file\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-reading-a-file\"><\/a>Reading a file<\/h2>\n\n\n\n<p>We can open the file reading mode after specifying the file name to the&nbsp;<code>open()<\/code>&nbsp;function. This is the default value; if the mode parameter is not specified, the file will open in the default&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>text<\/strong>&nbsp;mode.<\/p>\n\n\n\n<p>To perform this operation, we have a file called&nbsp;<code>text_file.txt<\/code>&nbsp;which has some content inside it.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using open() function\nfile = open('text_file.txt', 'r')\n# Printing the content inside the file\nfor content in file:\n    print(content)\n\n----------\nHey, there Geeks. Welcome to GeekPython.<\/pre><\/div>\n\n\n\n<p>We successfully read the content inside the file by iterating them using the Python&nbsp;<code>for<\/code>&nbsp;loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-using-read\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-using-read\"><\/a>Using read()<\/h3>\n\n\n\n<p>We can use&nbsp;<code>file.read()<\/code>&nbsp;to read the characters from the file. Here&#8217;s a code that will read the content from the file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using open() function\nfile = open('text_file.txt', 'r')\n# Reading file using read()\nprint(file.read())\n\n----------\nHey, there Geeks. Welcome to GeekPython.<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-closing-the-file\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-closing-the-file\"><\/a>Closing the file<\/h3>\n\n\n\n<p>When we&#8217;re done working with files, we need to close them so that the resources associated with them can be released. After working with a file, it is best practice to close it.<\/p>\n\n\n\n<p>We can use&nbsp;<code>file.close()<\/code>&nbsp;to close the current working file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using open() function\nfile = open('text_file.txt', 'r')\n# Reading file using read()\nprint(file.read())\n\n# Closing the file\nfile.close()\n# Checking if the file is closed or not\nprint(file.closed)\n\n----------\nHey, there Geeks. Welcome to GeekPython.\nTrue<\/pre><\/div>\n\n\n\n<p>The code returned&nbsp;<strong>True<\/strong>&nbsp;which means the file was closed successfully.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-using-with-keyword\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-using-with-keyword\"><\/a>Using with keyword<\/h3>\n\n\n\n<p>Python&#8217;s&nbsp;<code>open()<\/code>&nbsp;is a context manager, so we can use&nbsp;<code>with<\/code>&nbsp;keyword with it to open and read the file&#8217;s content.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Using with keyword\nwith open('text_file.txt', 'r') as file:\n    # Printing the content\n    print(file.read())<\/pre><\/div>\n\n\n\n<p>Here,&nbsp;<code>open()<\/code>&nbsp;will open the file and returns the file object and then the&nbsp;<code>as<\/code>&nbsp;keyword will bind the returned value to the&nbsp;<code>file<\/code>. We can now use&nbsp;<code>file<\/code>&nbsp;to print the content. Then the file will be automatically closed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-writing-into-file\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-writing-into-file\"><\/a>Writing into file<\/h2>\n\n\n\n<p>As we saw in the upper section, if we want to write data into the file then we need to use the&nbsp;<code>'w'<\/code>&nbsp;mode. But before writing data into the file, remember that<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the specified file does not exist, a new one will be created.<\/li>\n\n\n\n<li>If the specified file already exists, the data within it will be replaced with new data.<\/li>\n<\/ul>\n\n\n\n<p>In the following code, we&#8217;ll create a new file and then write some content inside it.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Creating and writing in a file\nwith open('test.txt', 'w') as file:\n    # Writing data inside the file\n    file.write('You guys are awesome, Thanks for reading.')\n    print('Data written successfully.')\n\n    # Closing the file\n    file.close()\n\n----------\nData written successfully.<\/pre><\/div>\n\n\n\n<p>The file name&nbsp;<code>test.txt<\/code>&nbsp;will be created and the content will be written inside it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"957\" height=\"109\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-9.png\" alt=\"File create and data was written\" class=\"wp-image-1036\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-9.png 957w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-9-300x34.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-9-768x87.png 768w\" sizes=\"auto, (max-width: 957px) 100vw, 957px\" \/><\/figure>\n\n\n\n<p>What do you think will happen if we try to add more content inside the&nbsp;<code>test.txt<\/code>&nbsp;file and run the above code?<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Writing in a file\nwith open('test.txt', 'w') as file:\n    # Writing data inside the file\n    file.write('If you love this, Bookmark it and share this.')\n    print('Data written successfully.')\n\n    # Closing the file\n    file.close()\n\n----------\nData written successfully.<\/pre><\/div>\n\n\n\n<p>The previous content will be erased and the new content will be written.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"947\" height=\"150\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-10.png\" alt=\"Content replaced\" class=\"wp-image-1037\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-10.png 947w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-10-300x48.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-10-768x122.png 768w\" sizes=\"auto, (max-width: 947px) 100vw, 947px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-appending-data-to-the-file\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-appending-data-to-the-file\"><\/a>Appending data to the file<\/h3>\n\n\n\n<p>We can append data to files by opening them in&nbsp;<code>'a'<\/code>&nbsp;mode. This will not overwrite our existing content but rather add new data to the file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Adding new data to the file\nwith open('test.txt', 'a') as file:\n    # Writing new data\n    file.write('\\nPlease check other articles on GeekPython.')\n    print('Data written successfully.')\n\n    # Closing the file\n    file.close()\n\n----------\nData written successfully.<\/pre><\/div>\n\n\n\n<p>The&nbsp;<code>test.txt<\/code>&nbsp;file will be opened in append mode, and the content will be appended to it without overwriting any existing data.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"218\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-7.png\" alt=\"Data appended to the file\" class=\"wp-image-1038\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-7.png 970w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-7-300x67.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-7-768x173.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-using-readlines\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-using-readlines\"><\/a>Using readlines()<\/h3>\n\n\n\n<p>Now that we have some content stored in two different lines in our file, it&#8217;s a good time to demonstrate the&nbsp;<code>readlines()<\/code>&nbsp;function.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">with open('test.txt', 'r') as file:\n    # Reading first line\n    print(file.readline())\n    # Reading second line\n    print(file.readline())\n\n# Closing the file\nfile.close()\n\n----------\nIf you love this, Bookmark it and share this.\n\nPlease check other articles on GeekPython.<\/pre><\/div>\n\n\n\n<p>The&nbsp;<code>readlines()<\/code>&nbsp;function allows us to read the content of the file line by line. Our&nbsp;<code>test.txt<\/code>&nbsp;file contains two lines so we used the&nbsp;<code>readlines()<\/code>&nbsp;function twice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-reading-amp-writing-binary-data\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-reading-amp-writing-binary-data\"><\/a>Reading &amp; writing binary data<\/h2>\n\n\n\n<p>Binary(<code>'b'<\/code>) mode is available for reading and writing binary data. We must specify&nbsp;<code>'rb'<\/code>&nbsp;to read the binary content from the file, and similarly,&nbsp;<code>'wb'<\/code>&nbsp;to write binary data into the file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Opening an image file in read binary mode\nwith open('writing.png', 'rb') as f:\n    # Reading the bytes of the image\n    print(f.read())\n    f.close()<\/pre><\/div>\n\n\n\n<p>We&#8217;ll get data as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"474\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-7.png\" alt=\"Bytes of the image\" class=\"wp-image-1039\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-7.png 825w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-7-300x172.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-7-768x441.png 768w\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" \/><\/figure>\n\n\n\n<p>The following code will show how we can write binary data into the file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Opening image in write binary mode\nwith open('writing.png', 'wb') as binary_file:\n    # Overriding the bytes of the image\n    binary_file.write(b'Hello there')\n\n    # Closing the file\n    binary_file.close()<\/pre><\/div>\n\n\n\n<p>We overrode the image file&#8217;s previous content and added new content. Now, if we read the image&#8217;s bytes, we&#8217;ll get the output shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"243\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-6.png\" alt=\"Image bytes overrode\" class=\"wp-image-1040\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-6.png 663w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-6-300x110.png 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/figure>\n\n\n\n<p>The image file is now corrupted and we won&#8217;t be able to open this image.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-exception-handling-try-finally\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-exception-handling-try-finally\"><\/a>Exception handling &#8211; try&#8230; finally<\/h2>\n\n\n\n<p>When we encounter errors or exceptions while performing a specific operation on a file, the program exits without closing the file. As a result, we must take precautions to address this issue.<\/p>\n\n\n\n<p>We can use a&nbsp;<code>try-finally<\/code>&nbsp;block to handle the exception. The following code shows how to use it.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">try:\n    file = open('test.txt', 'w')\n    # Writing content\n    write_data = file.write(\"Hey, how it's going.\")\n    # Trying to read the content\n    read_data = file.read()\n    print(read_data)\nfinally:\n    # Closing the file\n    file.close()\n    # Printing if file is closed\n    print(file.closed)<\/pre><\/div>\n\n\n\n<p>The above code will return an error stating that the read operation is not supported, but instead of terminating immediately, the program will run the block of code written within the&nbsp;<code>finally<\/code>&nbsp;block, resulting in the file being closed.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Traceback (most recent call last):\n  ....\n    read_data = file.read()\nio.UnsupportedOperation: not readable\nTrue<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-bonus-pet-adoption-project\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-bonus-pet-adoption-project\"><\/a>Bonus &#8211; Pet Adoption project<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" title=\"pet_adoption.py\">'''\nA Python program to adopt a pet and appending the details in a file.\nThe entry can also be viewed by reading the file\n'''\n\nimport datetime\n\n\n# Defining main function\ndef get_pet(pet):\n    # If user input 1 then this condition executes\n    if pet == 1:\n        adopt = int(input(\"Press 1 for Pet Dog 2 for Pet Cat: \\n\"))\n\n        if adopt == 1:\n            with open(\"Pet-Dog.txt\", \"a\") as f:\n                f.write(str(datetime.datetime.now()) + \": \" + f\"{name_inp} just adopted a Dog. \\n\")\n            print(\"Successfully Entered.\")\n\n        elif adopt == 2:\n            with open(\"Pet-Cat.txt\", \"a\") as f:\n                f.write(str(datetime.datetime.now()) + \": \" + f\"{name_inp} just adopted a Cat. \\n\")\n            print(\"Successfully Entered.\")\n\n        else:\n            print(\"We have only CATS and DOGS.\")\n\n    # If usr input 2 then this condition executes\n    elif pet == 2:\n        info = int(input(\"Enter 1 for Pet Dog Details 2 for Pet Cat Details: \\n\"))\n        if info == 1:\n            with open(\"Pet-Dog.txt\") as f:\n                for content in f:\n                    print(content, end='')\n\n        elif info == 2:\n            with open(\"Pet-Cat.txt\") as f:\n                for content in f:\n                    print(content, end='')\n\n        else:\n            print(\"Enter Valid Option!!\")\n\n    else:\n        print(\"Choose 1 for adoption and 2 for Information...\")\n\n\nif __name__ == '__main__':\n    print(\"------------ Welcome to Pet Adoption Center -----------\")\n\n    # Username Input\n    name_inp = input(\"Enter your name: \\n\")\n\n    # Taking Input from users\n    user_input = int(input(\"Press 1 for Adoption 2 for Information: \\n\"))\n\n    # Conditions according to user input\n    if user_input == 1:\n        get_pet(user_input)\n    else:\n        get_pet(user_input)<\/pre><\/div>\n\n\n\n<p>Here&#8217;s a simple Python program that prompts the user to select which operations they want to perform after they enter their name. When a user performs an adoption operation, the name is saved in the file along with the current timestamp. The user can view the information stored in the file by performing the information operation.<\/p>\n\n\n\n<p>Go ahead and run it in your code editor and also try to make a better version of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-conclusion\"><a href=\"https:\/\/geekpython.in\/handling-files-in-python#heading-conclusion\"><\/a>Conclusion<\/h2>\n\n\n\n<p>With code examples, we learned the fundamental operations of creating, reading, writing, and closing files in this article. To perform these operations, the file must first be opened, and then the mode specific to the operation we want to perform on the file must be specified.<\/p>\n\n\n\n<p>If no mode is specified,&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>text<\/strong>&nbsp;mode is used to open a file, and we can also write and read binary data from the file.<\/p>\n\n\n\n<p>We&#8217;ve also written a Python program in which a user can adopt a pet for themselves, and the data is saved in a file.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83c\udfc6<strong>Other articles you might be interested in if you liked this one<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/how-to-open-and-read-multiple-files-using-with-in-python\" rel=\"noreferrer noopener\">How to open and read multiple files simultaneously in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python\" rel=\"noreferrer noopener\">Reading and writing zip files without extracting them in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/shutil-module-in-python\" rel=\"noreferrer noopener\">Perform high-level file operations on the file using the shutil module in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/multiple-inputs-in-python\" rel=\"noreferrer noopener\">Take multiple inputs from the user in a single line in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/python-enumerate-function-with-example-beginners-guide\" rel=\"noreferrer noopener\">enumerate() function in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/asyncio-how-to-use-asyncawait-in-python\" rel=\"noreferrer noopener\">How to use async-await in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code\" rel=\"noreferrer noopener\">Perform a parallel iteration over multiple iterables using zip() function in Python<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Files are used to store information, and when we need to access the information, we open the file and read or modify it. We can use the GUI to perform these operations in our systems. Many programming languages include methods and functions for managing, reading, and even modifying file data. Python is one of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1041,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2],"tags":[59,12,31],"class_list":["post-1034","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-file-io","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=1034"}],"version-history":[{"count":3,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1034\/revisions"}],"predecessor-version":[{"id":1305,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1034\/revisions\/1305"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/1041"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=1034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=1034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=1034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}