{"id":1156,"date":"2022-08-30T05:16:38","date_gmt":"2023-09-16T17:34:56","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/working-with-files-in-python-reading-and-writing-data-using-python\/"},"modified":"2024-03-14T15:22:34","modified_gmt":"2024-03-14T15:22:34","slug":"reading-and-writing-data-using-python","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/","title":{"rendered":"Reading and Writing data using Python"},"content":{"rendered":"<p>In this tutorial, we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other functionalities. So, without wasting any time, let us begin.<\/p>\n<h2>Python file manipulation<\/h2>\n<p>In the tutorial before, we utilized the console for input. However, in this lesson, we will obtain input from a file. Consequently, we will be able to read and write data to files. To accomplish this, we must adhere to a set of instructions. These instructions include:<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>1. Begin by accessing a file<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>Receive input from the file \/ Produce output to the file<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>Conclude by closing the file<\/ol>\n<p>We will also cover important actions like file copying and file deletion during our learning process.<\/p>\n<h2>What is the necessity for file operations in Python?<\/h2>\n<p>To effectively handle extensive datasets in machine learning tasks, it is essential to manipulate files. Given that Python is a widely utilized language in the field of data science, it is crucial to possess proficiency in the various file operations provided by Python.<\/p>\n<p>Therefore, we will now delve into various Python file operations.<\/p>\n<h3>Use the <a href=\"https:\/\/www.w3schools.com\/python\/ref_func_open.asp\">open()<\/a> function in Python to access and read a file.<\/h3>\n<p>To begin utilizing files in Python, it is essential to master the skill of file opening. The open() method enables file opening.<\/p>\n<p>In Python, the open() function has two parameters to pass. The initial parameter is the full path of the file, including its name, and the second parameter is the mode in which the file is opened.<\/p>\n<p>I have outlined below some of the typical ways of reading files.<\/p>\n<ul class=\"post-ul\">\n<li>\u2018r\u2019 : This mode indicate that file will be open for reading only<\/li>\n<li>\u2018w\u2019 : This mode indicate that file will be open for writing only. If file containing containing that name does not exists, it will create a new one<\/li>\n<li>\u2018a\u2019 : This mode indicate that the output of that program will be append to the previous output of that file<\/li>\n<li>\u2018r+\u2019 : This mode indicate that file will be open for both reading and writing<\/li>\n<\/ul>\n<p>Moreover, in the Windows OS, you may add &#8216;b&#8217; to access the file in binary format. This distinction is necessary as Windows distinguishes between binary text files and standard text files.<\/p>\n<p>Imagine that we have a text file named &#8216;file.txt&#8217; in the exact folder where our code is located. Our intention is to access and open that particular file.<\/p>\n<p>The function open(filename, mode) returns a file object which allows you to perform additional operations.<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655cfa37c40ba52feef2d122\/16-0.png\" alt=\"python open file, python file\" \/><\/div>\n<pre class=\"post-pre\"><code><span class=\"token comment\">#directory:   \/home\/imtiaz\/code.py<\/span>\r\ntext_file <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'file.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'r'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token comment\">#Another method using full location<\/span>\r\ntext_file2 <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/home\/imtiaz\/file.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'r'<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'First Method'<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>text_file<span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'Second Method'<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>text_file2<span class=\"token punctuation\">)<\/span>\r\n\r\n<\/code><\/pre>\n<p>The result of the code will be.<\/p>\n<pre class=\"post-pre\"><code>================== RESTART: \/home\/imtiaz\/code.py ==================\r\nFirst Method\r\n\r\nSecond Method\r\n\r\n&gt;&gt;&gt;\r\n<\/code><\/pre>\n<h3>2. In Python, you can both read from and write to files.<\/h3>\n<p>Python provides different functions for reading and writing files, and each function performs distinct actions. It is crucial to consider the file operation mode. If you want to read a file, you must open it in either read or write mode. On the other hand, when writing to a file in Python, it is necessary for the file to be open in write mode.<\/p>\n<p>Below are several Python functions that enable file reading and writing:<\/p>\n<ul class=\"post-ul\">\n<li>read() : This function reads the entire file and returns a string<\/li>\n<li>readline() : This function reads lines from that file and returns as a string. It fetch the line n, if it is been called nth time.<\/li>\n<li>readlines() : This function returns a list where each element is single line of that file.<\/li>\n<li>readlines() : This function returns a list where each element is single line of that file.<\/li>\n<li>write() : This function writes a fixed sequence of characters to a file.<\/li>\n<li>writelines() : This function writes a list of string.<\/li>\n<li>append() : This function append string to the file instead of overwriting the file.<\/li>\n<\/ul>\n<p>For instance, we can consider a file called &#8220;abc.txt&#8221; and utilize a for loop to read each line of the file.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\">#open the file<\/span>\r\ntext_file <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'r'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token comment\">#get the list of line<\/span>\r\nline_list <span class=\"token operator\">=<\/span> text_file<span class=\"token punctuation\">.<\/span>readlines<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n\r\n<span class=\"token comment\">#for each line from the list, print the line<\/span>\r\n<span class=\"token keyword\">for<\/span> line <span class=\"token keyword\">in<\/span> line_list<span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>line<span class=\"token punctuation\">)<\/span>\r\n\r\ntext_file<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#don't forget to close the file<\/span>\r\n<\/code><\/pre>\n<p>What is produced:<\/p>\n<p>Now that we have learned how to read a file in Python, let us proceed and execute a write operation utilizing the writelines() function.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\">#open the file<\/span>\r\ntext_file <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/file.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'w'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token comment\">#initialize an empty list<\/span>\r\nword_list<span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span>\r\n\r\n<span class=\"token comment\">#iterate 4 times<\/span>\r\n<span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"Please enter data: \"<\/span><span class=\"token punctuation\">)<\/span>\r\n    line <span class=\"token operator\">=<\/span> <span class=\"token builtin\">input<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#take input<\/span>\r\n    word_list<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>line<span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#append to the list<\/span>\r\n\r\n\r\ntext_file<span class=\"token punctuation\">.<\/span>writelines<span class=\"token punctuation\">(<\/span>word_list<span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#write 4 words to the file<\/span>\r\n\r\ntext_file<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#don\u2019t forget to close the file<\/span>\r\n<\/code><\/pre>\n<p>One possible paraphrase of &#8220;Output&#8221; could be &#8220;Result.&#8221;<\/p>\n<h3>3. Use the shutil() method in Python to replicate files.<\/h3>\n<p>The shutil module in Python enables us to copy files. It provides us with the ability to perform copy and move actions on various files. To illustrate, let&#8217;s proceed with an example.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token keyword\">import<\/span> shutil\r\n\r\nshutil<span class=\"token punctuation\">.<\/span>copy2<span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc.txt'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'\/Users\/scdev\/abc_copy2.txt'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token comment\">#another way to copy file<\/span>\r\n\r\nshutil<span class=\"token punctuation\">.<\/span>copyfile<span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc.txt'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">'\/Users\/scdev\/abc_copyfile.txt'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"File Copy Done\"<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<\/code><\/pre>\n<h3>4. You can use the shutil.os.remove() method in Python to eliminate files.<\/h3>\n<p>The remove() method from Python\u2019s shutil module provides the capability to delete files from the file system. Now, we will explore how we can carry out a deletion task in Python.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token keyword\">import<\/span> shutil\r\n<span class=\"token keyword\">import<\/span> os\r\n\r\n<span class=\"token comment\">#two ways to delete file<\/span>\r\nshutil<span class=\"token punctuation\">.<\/span>os<span class=\"token punctuation\">.<\/span>remove<span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc_copy2.txt'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\nos<span class=\"token punctuation\">.<\/span>remove<span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc_copy2.txt'<\/span><span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<h3>5. Use the close() method in Python to end an open file.<\/h3>\n<p>In Python, it is crucial to close a file after making modifications. By doing so, you retain the changes, remove the file from memory, and prevent any further reading or writing within the program.<\/p>\n<p>To end an open file in Python, utilize the syntax:<\/p>\n<pre class=\"post-pre\"><code>fileobject.close()\r\n<\/code><\/pre>\n<p>To build upon our prior instances of file reading, here is one way to conclude the file:<\/p>\n<pre class=\"post-pre\"><code>text_file <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/abc.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'r'<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token comment\"># some file operations here<\/span>\r\n\r\ntext_file<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Moreover, if you utilize the with block, there is no need for manual file closure. Once the with block is executed, the files will be automatically closed and unable to be accessed for reading or writing.<\/p>\n<h3>The Python program encounters a FileNotFoundError.<\/h3>\n<p>Receiving the FileNotFoundError is a usual occurrence when dealing with files in Python. However, you can easily prevent this by ensuring you provide complete file paths while creating the file object.<\/p>\n<pre class=\"post-pre\"><code>  File <span class=\"token string\">\"\/Users\/scdev\/Desktop\/string1.py\"<\/span><span class=\"token punctuation\">,<\/span> line <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">in<\/span> <span class=\"token operator\">&lt;<\/span>module<span class=\"token operator\">&gt;<\/span>\r\n    text_file <span class=\"token operator\">=<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/Users\/scdev\/Desktop\/abc.txt'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'r'<\/span><span class=\"token punctuation\">)<\/span>\r\nFileNotFoundError<span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span>Errno <span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> No such <span class=\"token builtin\">file<\/span> <span class=\"token keyword\">or<\/span> directory<span class=\"token punctuation\">:<\/span> <span class=\"token string\">'\/Users\/scdev\/Desktop\/abc.txt'<\/span>\r\n\r\n<\/code><\/pre>\n<p>To resolve the FileNotFoundError, all you have to do is ensure that the path specified in the file open method is accurate.<\/p>\n<h2>In conclusion<\/h2>\n<p>Here are the available file operations in Python. Python offers numerous other ways to work with files, such as reading CSV data and more. This article explains how you can utilize the Pandas module to read CSV datasets in Python.<\/p>\n<p>I hope you had a good time reading the article! Enjoy your learning journey \ud83d\ude42<\/p>\n<p>One possible paraphrase could be:<\/p>\n<p>&#8211; You can find more information about reading and writing files in Python at this link: https:\/\/docs.python.org\/3\/tutorial\/inputoutput.html#reading-and-writing-files.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>More Tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/how-can-properties-files-be-read-in-python\/\" target=\"_blank\" rel=\"noopener\">How can properties files be read in Python?<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-enable-a-port-on-a-linux-operating-system\/\" target=\"_blank\" rel=\"noopener\">How to enable a port on a Linux operating system.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/frequently-asked-questions-about-writing-for-donations\/\" target=\"_blank\" rel=\"noopener\">Frequently Asked Questions about Writing for Donations<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/set-in-python\/\" target=\"_blank\" rel=\"noopener\">Set in Python<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/how-can-i-utilize-photorec-to-retrieve-erased-files\/\" target=\"_blank\" rel=\"noopener\">How can I utilize PhotoRec to retrieve erased files?<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other functionalities. So, without wasting any time, let us begin. Python file manipulation In the tutorial before, we utilized the console for input. However, in this lesson, we will obtain input [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1156","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reading and Writing data using Python - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reading and Writing data using Python\" \/>\n<meta property=\"og:description\" content=\"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-16T17:34:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-14T15:22:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655cfa37c40ba52feef2d122\/16-0.png\" \/>\n<meta name=\"author\" content=\"Isabella Edwards\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isabella Edwards\" \/>\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:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\"},\"author\":{\"name\":\"Isabella Edwards\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\"},\"headline\":\"Reading and Writing data using Python\",\"datePublished\":\"2023-09-16T17:34:56+00:00\",\"dateModified\":\"2024-03-14T15:22:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\"},\"wordCount\":1082,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\",\"name\":\"Reading and Writing data using Python - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-09-16T17:34:56+00:00\",\"dateModified\":\"2024-03-14T15:22:34+00:00\",\"description\":\"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reading and Writing data using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\",\"name\":\"Isabella Edwards\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"caption\":\"Isabella Edwards\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Reading and Writing data using Python - Blog - Silicon Cloud","description":"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other","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:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/","og_locale":"en_US","og_type":"article","og_title":"Reading and Writing data using Python","og_description":"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other","og_url":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-09-16T17:34:56+00:00","article_modified_time":"2024-03-14T15:22:34+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/655cfa37c40ba52feef2d122\/16-0.png"}],"author":"Isabella Edwards","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Isabella Edwards","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/"},"author":{"name":"Isabella Edwards","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd"},"headline":"Reading and Writing data using Python","datePublished":"2023-09-16T17:34:56+00:00","dateModified":"2024-03-14T15:22:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/"},"wordCount":1082,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/","url":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/","name":"Reading and Writing data using Python - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-09-16T17:34:56+00:00","dateModified":"2024-03-14T15:22:34+00:00","description":"we will focus on various file operations within Python. We will cover reading, writing, and deleting files using Python, along with other","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/reading-and-writing-data-using-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Reading and Writing data using Python"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd","name":"Isabella Edwards","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","caption":"Isabella Edwards"},"url":"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=1156"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1156\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=1156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=1156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=1156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}