Python Guide V1.2.11

Readline texteachlinesaveline flinkcloseclosefile file

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: o string, and manipulate them • • • • • • • • • • • str(x) default string representation of x "banana".index('an')! !1!#!first!location "banana".index('an',!2)! !3!#!location!after!2 "%".join(['a',!'b',!'c'])! !'a%b%c' "abcb".replace('b',"xx")! !'axxcxx' "a6bc6d6".split()! !['a',!'bc',!'d'] "a6bc6d6".split('b')! !['a6',!'c6d'] "66ab6c6".strip() 'ab!c' "'ab'c'".strip("'") "ab'c" "2006Hike!".upper()! !'2006HIKE!' "2006HIKE!".lower()! !'2006hike!' Page"2"/"2! ! ! File reading from file in current directory • from!os!import!chdir!#!change!folder!function! from!sys!import!path!#!current!path! chdir(path[0])!#!change!folder!to!.! flink!=!open(filename,!"rU")!#!open! text!=!""!!!!!!!!#!initialize!input! for!each!in!flink!:!!!!#!read!line! !!!!text!+=!eachline!!!#!save!line! flink.close()!!!!!!!!!!#!close!file! File reading from url • import6urllib6 url6=6"http:...
View Full Document

This document was uploaded on 02/14/2014 for the course COMP 1012 at Manitoba.

Ask a homework question - tutors are online