"Python"의 두 판 사이의 차이
ph
56번째 줄: | 56번째 줄: | ||
==File existence== | ==File existence== | ||
− | |||
os.path.exists(file_path) | os.path.exists(file_path) | ||
[http://stackoverflow.com/a/82846/766330] [https://docs.python.org/2/library/os.path.html#os.path.exists] | [http://stackoverflow.com/a/82846/766330] [https://docs.python.org/2/library/os.path.html#os.path.exists] |
2017년 4월 10일 (월) 12:07 판
목차
Time
>>> import time >>> time.time() 1491792653.410371 >>> import datetime >>> datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') '2017-04-10 11:51:17' >>> datetime.datetime.utcnow() datetime.datetime(2017, 4, 10, 2, 51, 34, 356682) >>> datetime.datetime.now() datetime.datetime(2017, 4, 10, 11, 51, 36, 572681) >>> datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p") 'Monday, 10. April 2017 11:51AM'
is and ==
is is identity testing, == is equality testing. what happens in your code would be emulated in the interpreter like this:
>>> a = 'pub' >>> b = ''.join(['p', 'u', 'b']) >>> a == b True >>> a is b False
Access index in for loop
for idx, val in enumerate(ints): print(idx, val)
Max integer
sys.maxint
Argument parsing
use argparse
range by step
>>> step = .1 >>> N = 10 # number of data points >>> [ x / pow(step, -1) for x in range(0, N + 1) ] [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
File existence
os.path.exists(file_path)
==