Last active
June 28, 2016 09:46
-
-
Save lkluft/dd336947e3841e63f8efa6607c244f33 to your computer and use it in GitHub Desktop.
Use cases for the string class' format function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2016-05-25T09:18:11.222571", | |
"start_time": "2016-05-25T09:18:11.219015" | |
} | |
}, | |
"cell_type": "markdown", | |
"source": "# String format" | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"ExecuteTime": { | |
"end_time": "2016-05-25T09:52:54.441558", | |
"start_time": "2016-05-25T09:52:54.433629" | |
}, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "import os\n\nfilename = '{curdir}/{Y:04d}{m:02d}{d:02d}_{H:02d}{M:02d}{S:02d}.txt'.format\n\ndate = {'curdir': os.getcwd(),\n 'Y': 2015,\n 'm': 5,\n 'd': 6,\n 'H': 7,\n 'M': 8,\n 'S': 9,\n }\n\nfor year in range(2000, 2017):\n date['Y'] = year\n print(filename(**date))", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"text": "/home/zmaw/u300509/Documents/Python/20000506_070809.txt\n/home/zmaw/u300509/Documents/Python/20010506_070809.txt\n/home/zmaw/u300509/Documents/Python/20020506_070809.txt\n/home/zmaw/u300509/Documents/Python/20030506_070809.txt\n/home/zmaw/u300509/Documents/Python/20040506_070809.txt\n/home/zmaw/u300509/Documents/Python/20050506_070809.txt\n/home/zmaw/u300509/Documents/Python/20060506_070809.txt\n/home/zmaw/u300509/Documents/Python/20070506_070809.txt\n/home/zmaw/u300509/Documents/Python/20080506_070809.txt\n/home/zmaw/u300509/Documents/Python/20090506_070809.txt\n/home/zmaw/u300509/Documents/Python/20100506_070809.txt\n/home/zmaw/u300509/Documents/Python/20110506_070809.txt\n/home/zmaw/u300509/Documents/Python/20120506_070809.txt\n/home/zmaw/u300509/Documents/Python/20130506_070809.txt\n/home/zmaw/u300509/Documents/Python/20140506_070809.txt\n/home/zmaw/u300509/Documents/Python/20150506_070809.txt\n/home/zmaw/u300509/Documents/Python/20160506_070809.txt\n", | |
"name": "stdout", | |
"output_type": "stream" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"language_info": { | |
"pygments_lexer": "ipython3", | |
"codemirror_mode": { | |
"version": 3, | |
"name": "ipython" | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"version": "3.5.1", | |
"name": "python", | |
"nbconvert_exporter": "python" | |
}, | |
"toc": { | |
"toc_threshold": 6, | |
"toc_number_sections": true, | |
"toc_cell": false, | |
"toc_window_display": false | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"gist": { | |
"id": "dd336947e3841e63f8efa6607c244f33", | |
"data": { | |
"description": "Use cases for the string class' format function.", | |
"public": true | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/dd336947e3841e63f8efa6607c244f33" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment