Programming Python
2 System Programming
- System scripting overview
- Intruducing sys Module
- Introducing os Module
System Scripting Overview
- dir, dir(sys), dir(os), dir(os.path)
- import, import sys, import os
- sys.__doc__, print(sys.__doc__)
- help(sys)
- >>> line = 'aaa\nbbb\nccc\n'
>>> line.split('\n')
['aaa', 'bbb', 'ccc', '']
>>> line.splitlines()
['aaa', 'bbb', 'ccc']
- String Method Basics
- mystr.find('XXX'), >>> mystr.find('SPAM') # return first offset
3
- mystr.replace('AA', 'XXX'), >>> mystr.replace('aa', 'SPAM') # global replacement
'xxSPAMxxSPAM'
- 'XXX' in mystr, >>> 'SPAM' in mystr # substring search/test
True
0 件のコメント:
コメントを投稿