IDLE , Python. , (Integrated Development Environment, IDE). , Python Python , .
IDE, Python, , Python 3. PyDev, Eclipse [1], Python. Eclipse, PyDev .
Komodo IDE ActiveState. , , .
Python , GNU Emacs [2], Python . Python . , , , .
1. , . w:en:PATH (variable). . .
2. . Python 3.1. . .
3. Papaya whip (.) . . .
Python
, . ? ! ! : ! |
- . . , Python. , . , . , .
[humansize.py]
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
''' .
:
size --
a_kilobyte_is_1024_bytes -- True ( ), 1024
False, 1000
: (string)
'''
if size < 0:
raise ValueError(' ')
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
for suffix in SUFFIXES[multiple]:
size /= multiple
if size < multiple:
return '{0:.1f} {1}'.format(size, suffix)
raise ValueError(' ')
if __name__ == '__main__':
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))
|
|
. Windows :
c:\home\diveintopython3\examples> c:\python31\python.exe humansize.py
1.0 TB
931.3 GiB
Mac OS X Linux, :
you@localhost:~/diveintopython3/examples$ python3 humansize.py
1.0 TB
931.3 GiB
? Python. Python , . approximate_size(), ( ) . (, Windows, Mac OS X Finder, Nautilus, Dolphin Thunar Linux. , , , , , . . 1093- TODO, TODO 1093 ; - TODO 1 . approximate_size().)
, print(approximate_size()). . approximate_size(), , print(). print() , . Ÿ , . ( , , . , .)
, , ? . approximate_size().
Python , , , C++, interface/implementation, . , , , :
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
, .
def, , . , .
, , . Python ; , . ( , Python ; return, , None .)
( ) function, ( ) sub. Python . ( None), def. |
approximate_size() : size kilobyte_is_1024_bytes, . Python . Python .
|
|
Java . Python , -, . Python . |