Files Reading Writing Open Close DIRECTORY
<p>Feb 19, 2013 10:07 PM   to get current working directory...
 
>>>  import os    # these functions are in the os module, which you need to open
>>>  os.getcwd()   
'C:\Python27'    #  that's the dir you're connected to...
 
 
 
Jan 24, 2013 05:09 PM  FILES:  Reading Writing Open and Close Files
 
open takes a windows path as an argument  eg
>>> bob=open('C:\Python27\LICENSE.txt')    ...# note the path is a string;
 
>>> bob.close()  # that will close the file object bob   that's bob dot close.
bob = open('LICENSE.txt')   # it <b>defaults to 'C:\Python27\' </b>  ....
 
>>> bob
<open file 'LICENSE.txt', mode 'r' at 0x0000000002C79300>   # that is a file object (a pointer to a file).
license = bob.readlines()   # license is the entire text of the license, read as strings delim. by CRLFs
each line ends in '\n'   a CRLF
>>> license[:3]     # a list containing the first 3 entries
['A. HISTORY OF THE SOFTWARE\n', '==\n', '\n']
>>> license[3]   # the 4th entry
'Python was created in the early 1990s by Guido van Rossum at Stichting\n'
 
>>> aliceobject = open('alice','w')   # creates a brand new file called alice in Python27 direc
 
>>> aliceobject.write('hello world')
>>> aliceobject.close()   # only AFTER closing the file, can you open it on Python27 with Notepad
            #to see the hello world.
 
 also note... once a file exists, then you can read or write it with mode 'r+'  nstead of 'w')
 
>>> 'klfjdlfd ieutoiweut 394853'.split(' ') =>  [strg1 ,strg 2 ,  strg3]  # this SPLITs the string
 
        # using space as the break char... ie delimited by whatever is btwn the quotes,
        #  so,  '$'  wll break at the $ .
 
>>> sample = "sljflksd$sljdlfsj$wioreu"
 
>>> sample
'sljflksd$sljdlfsj$wioreu'
 
>>> samplewords = sample.split('$')
 
>>> samplewords
['sljflksd', 'sljdlfsj', 'wioreu']
 
 
 
 
 </p>