Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/kenbauer/public_kenscourses/tc101winter2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php:152) in /home/kenbauer/public_kenscourses/tc101winter2015/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":13463,"date":"2015-05-04T17:14:32","date_gmt":"2015-05-04T22:14:32","guid":{"rendered":"https:\/\/jorgepadilla95.withknown.com\/2015\/reading-and-writing-of-files-in-python"},"modified":"2015-05-04T17:14:32","modified_gmt":"2015-05-04T22:14:32","slug":"reading-and-writing-of-files-in-python-2","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2015\/2015\/reading-and-writing-of-files-in-python-2\/","title":{"rendered":"Reading and writing of files in Python"},"content":{"rendered":"
\n

For reading and writing of files in python, the first thing you need to do is to get a file object, using the “open” function.<\/p>\n

The open function has two parameter, the first one is the name of the file that we are creating and the other parameter is going to check if you are going to read(r) or write(w) the file. Now to write inside the file you need to write the name of the object we just created followed by a dot with the word “write” adn you open parenthesis where you are going to write the text.It is important to point out that the end line is given by “\/n”. To save it we just have to close our object.<\/p>\n

this is the syntax:\u00a0file =\u00a0open(“newfile.txt”, “w”)<\/strong><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0file.write(“hello worldn”)<\/strong><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0file.write(“this is another linen”)<\/strong><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0file.close()<\/strong>\u00a0<\/p>\n

the object name is file and the text file is example.<\/p>\n

Now we know how to use write(), I can explain read().<\/p>\n

read() is used for reading the text file. The syntax is very simple like with the write() method, just where we wrote “w” now we have to write “r”.<\/p>\n

this is the syntax of this:<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 file = open(‘newfile.txt’, ‘r’)<\/strong><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span>print file.read()<\/strong><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>\u00a0<\/span>file.close()<\/strong><\/p>\n

In this example it shows us the two parameters, the first one tells us what the text file is going to open and the second parameter tells us what is going to do. In this case “r” means that is going to read. Print means that when you are in the terminal, it will print the text that is in the file. In this case it will print:<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>\u00a0<\/span>hello world\u00a0<\/strong>
\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 this is<\/span>\u00a0another line<\/strong><\/p>\n

We can also specify how many characters the string should return, by using
file.read(n), where “n” determines the number of characters.<\/p>\n

This reads the first 5 characters of data and returns it as a string.<\/p>\n

In this case, it will print : hello<\/p>\n

I learned all this stuff on this web page, you may want to check it out:\u00a0\u00a0<\/span>http:\/<\/wbr>\/<\/wbr>www.pythonforbeginners.com\/<\/wbr>files\/<\/wbr>reading-and-writing-files-in-python<\/a><\/p>\n

#Mastery<\/a>30<\/p>\n

#TC<\/a>1014<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

\n

For reading and writing of files in python, the first thing you need to do is to get a file object, using the “open” function.<\/p>\n

The open function has two parameter, the first one is the name of the file that we are creating and the other parameter is going to check if you are going to read(r) or write(w) the file. Now to write inside the file you need to write the name of the object we just created followed by a dot with the word “write” adn you open parenthesis where you are going to write the text.It is important to point out that the end line is given by “\/n”. To save it we just have to close our object.<\/p>\n

this is the syntax: file = open(“newfile.txt”, “w”)<\/strong><\/p>\n

                                           file.write(“hello worldn”)<\/strong><\/p>\n

                                           file.write(“this is another linen”)<\/strong><\/p>\n

                                           file.close()<\/strong> <\/p>\n

the object name is file and the text file is example.<\/p>\n

Now we know how to use write(), I can explain read().<\/p>\n

read() is used for reading the text file. The syntax is very simple like with the write() method, just where we wrote “w” now we have to write “r”.<\/p>\n

this is the syntax of this:<\/p>\n

                                              file = open(‘newfile.txt’, ‘r’)<\/strong><\/p>\n

                                              <\/span>print file.read()<\/strong><\/p>\n

                                             <\/span> <\/span>file.close()<\/strong><\/p>\n

In this example it shows us the two parameters, the first one tells us what the text file is going to open and the second parameter tells us what is going to do. In this case “r” means that is going to read. Print means that when you are in the terminal, it will print the text that is in the file. In this case it will print:<\/p>\n

                                             <\/span> <\/span>hello world <\/strong>
                                              this is<\/span> another line<\/strong><\/p>\n

We can also specify how many characters the string should return, by using
file.read(n), where “n” determines the number of characters.<\/p>\n

This reads the first 5 characters of data and returns it as a string.<\/p>\n

In this case, it will print : hello<\/p>\n

I learned all this stuff on this web page, you may want to check it out:  <\/span>http:\/\/www.pythonforbeginners.com\/files\/reading-and-writing-files-in-python<\/a><\/p>\n

#Mastery<\/a>30<\/p>\n

#TC<\/a>1014<\/p>\n<\/div>\n

Continue reading →<\/span><\/a><\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,25],"tags":[144,181,431,486,45,287],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/13463"}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/comments?post=13463"}],"version-history":[{"count":4,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/13463\/revisions"}],"predecessor-version":[{"id":17471,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/posts\/13463\/revisions\/17471"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/media?parent=13463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/categories?post=13463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2015\/wp-json\/wp\/v2\/tags?post=13463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}