Category: Uncategorized

48. Using pickle

If you use lists to store the data from your program, there is a neat function called pickle() that can be used to save the entire list rather than using loops The example below saves a list to a file and then reloads it The data is not stored as text though, so you can’t […]

47. Writing a list into a file

A really important thing you will need to be able to do is read and write text files with variable numbers of lines Because we don’t know how many lines there will be, we tend to read text files into a list, make any changes, and then write the whole list back over the file […]

44. Reading Delimited Files

Sometimes, you need to read in files from other programs containing information such as student records or address details. We use files known as comma separated values files They are simply text files with a different extension (.csv) Each line will have multiple items on it, each usually separated by a comma. It might look […]

43. Writing Multiple Lines

When writing to files, you can either overwrite the information in the file (w), or add to it as you go along (a). This is set as shown below. Choose one or the other, not both There is a function called writeline() that you might assume is the opposite of readline(). Using this is slightly […]