Thursday, November 29, 2018

Pickling and unpickling

Pickling  In order to store complex information such as list and dictionary Python's pickle module is used as text files are limited to storing a series of characters. Once written as a text file, it is a simple text file, meaning next time you read it in you will have parse the text and process it back to your original data structure.  What you want, then, is a way to save your Python...
Share:

Wednesday, November 28, 2018

The os.path module

The os.path module contains many helpful functions related to filenames and file paths. Since os.path is a module inside the os module, you can import it by simply running import os. Lets us look at some some methods in the os.path module. 1. os.path.join() If we pass it the string values of individual file and folder names in our path, os.path.join() will return a string with a file path using...
Share:

Tuesday, November 27, 2018

More on File Handling in Python

Opening and Reading Text Files by Buffer Size The read() function in Python allows us to specify the buffer size we want so that our program does not use too much memory resources. The read() takes a parameter which specifies the data to be fetched from a file in bytes. Lets see this through a program: sourcefile = open('cities.txt','r')targetfile = open('mycities.txt','w')mytext = sourcefile.read(10)while...
Share:

Monday, November 26, 2018

File Handling in Python

We usually use variables to store data while our program is running, but if we need our data to persist even after the program has finished, we need to save it to a file. Se we can think of a file’s contents as a single string value, potentially gigabytes in size. Thus an incredible amount of data...
Share:

Wednesday, November 21, 2018

Private variable and method in Python

Python doesn't have real private variables and methods. Thus there is an adopted convention of having two underlines at the beginning make a variable and a method private. The following example explains this behavior: class Amount():         __value = 50    ...
Share: