Friday, January 9, 2015

Python programming Day 07

Python 3

#!/usr/bin/python3


1. Define classes

class Dog:
    def bark(self):
        print('Gau Gau Gau!')

    def swim(self):
        print('Swims like a dog.')

def main():
    nauvang = Dog()
    nauvang.bark()
    nauvang.swim()

if __name__ == "__main__": main()


2. Define and use a function
2.1
def main():
    testfunc()

def testfunc():
    print('This is a test function')

if __name__ == "__main__": main()

2.2
def main():
    print("This is the functions.py file.")
    for i in range(25):
        print(i, end = ' ')

if __name__ == "__main__": main()

3. Work with regular expressions

import re

def main():
    fh = open('toys.txt')
    for line in fh:
        if re.search('(Leg|g)o', line):
            print(line, end='')

if __name__ == "__main__": main()

4. Work with files

def main():
    f = open('readme.txt')
    for line in f:
        print(line, end = '')

if __name__ == "__main__": main()


Mounting USB drives in Windows Subsystem for Linux

Windows Subsystem for Linux can use (mount): SD card USB drives CD drives (CDFS) Network drives UNC paths Local storage / drives Drives form...