>>> from bicicletes import selecciona >>> s = 'Resident ; EIXAMPLE ; 18 ; 14/3 ; Electrica\nTurista ; GRACIA ; 42 ; 5/7 ; Mecànica\nResident ; SANTS-MONTJUIC ; 25 ; 21/9 ; Mecànica\nResident ; GRACIA ; 12 ; 1/1 ; Electrica\nTurista ; EIXAMPLE ; 31 ; 17/8 ; Electrica\nResident ; CIUTAT VELLA ; 9 ; 4/3 ; Mecànica\nTurista ; SANTS-MONTJUIC ; 36 ; 2/11 ; Electrica\nResident ; EIXAMPLE ; 20 ; 30/12 ; Mecànica\nResident ; GRACIA ; 15 ; 7/7 ; Electrica\n' >>> with open('trajectes1.txt', 'w') as f: ... n = f.write(s) >>> selecciona('trajectes1.txt', 'sortida1.txt', 3, 7, 'Resident') >>> with open('sortida1.txt', 'r') as f: ... resultat1 = f.read() >>> resultat1 == 'EIXAMPLE,Electrica,mig\nCIUTAT VELLA,Mecànica,curt\nGRACIA,Electrica,mig\n' True >>> s2 = 'Resident ; EIXAMPLE ; 14 ; 1/3 ; Electrica\nTurista ; GRACIA ; 15 ; 5/7 ; Mecànica\nResident ; SANTS-MONTJUIC ; 30 ; 21/9 ; Mecànica\nResident ; GRACIA ; 31 ; 1/1 ; Electrica\nTurista ; EIXAMPLE ; 18 ; 17/8 ; Electrica\nResident ; CIUTAT VELLA ; 9 ; 4/3 ; Mecànica\nResident ; SARRIA ; 15 ; 15/7 ; Electrica\nResident ; LES CORTS ; 30 ; 30/6 ; Mecànica\nResident ; NOU BARRIS ; 31 ; 2/5 ; Electrica\nTurista ; HORTA ; 45 ; 10/6 ; Electrica\nResident ; SANT ANDREU ; 12 ; 7/4 ; Mecànica\nResident ; GRACIA ; 45 ; 11/12 ; Electrica\nAbonat ; EIXAMPLE ; 16 ; 2/7 ; Mecànica\nAbonat ; SANTS ; 8 ; 28/3 ; Electrica\n' >>> with open('trajectes2.txt','w') as f: ... n = f.write(s2) >>> selecciona('trajectes2.txt', 'sortida2_1.txt', 3, 7, 'Resident') >>> with open('sortida2_1.txt','r') as f: ... resultat2_1 = f.read() >>> resultat2_1 == 'EIXAMPLE,Electrica,curt\nCIUTAT VELLA,Mecànica,curt\nSARRIA,Electrica,mig\nLES CORTS,Mecànica,mig\nNOU BARRIS,Electrica,llarg\nSANT ANDREU,Mecànica,curt\n' True >>> selecciona('trajectes2.txt', 'sortida2_2.txt', 6, 8, 'Turista') >>> with open('sortida2_2.txt','r') as f: ... resultat2_2 = f.read() >>> resultat2_2 =='GRACIA,Mecànica,mig\nEIXAMPLE,Electrica,mig\nHORTA,Electrica,llarg\n' True