Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2"""Solution to chapter 5, exercise 22: passwd_to_csv""" 

3 

4 

5import csv 

6 

7 

8def passwd_to_csv(passwd_filename, csv_filename): 

9 with open(passwd_filename) as passwd, open(csv_filename, 'w') as output: 

10 r = csv.reader(passwd, delimiter=':') 

11 w = csv.writer(output, delimiter='\t') 

12 for record in r: 

13 if len(record) > 1: 

14 w.writerow((record[0], record[2]))