{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Module biogeme.filenames" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examples of use of each function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This webpage is for programmers who need examples of use of the functions of the module. The examples are designed to illustrate the syntax. They do not correspond to any meaningful model. For examples of models, visit [biogeme.epfl.ch](http://biogeme.epfl.ch)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2021-08-04 16:38:43.667581\n" ] } ], "source": [ "import datetime\n", "print(datetime.datetime.now())" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "biogeme 3.2.8 [2021-08-04]\n", "Version entirely written in Python\n", "Home page: http://biogeme.epfl.ch\n", "Submit questions to https://groups.google.com/d/forum/biogeme\n", "Michel Bierlaire, Transport and Mobility Laboratory, Ecole Polytechnique Fédérale de Lausanne (EPFL)\n", "\n" ] } ], "source": [ "import biogeme.version as ver\n", "print(ver.getText())" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import biogeme.filenames as fl" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The role of this function is to obtain the name of a file that does not exist." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'test.dat'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "theName = fl.getNewFileName('test', 'dat')\n", "theName" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let's create that file, and call the function again. A suffix with a number is appended to the name of the file, before its extension." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "open(theName, 'a').close()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'test~00.dat'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "theName = fl.getNewFileName('test', 'dat')\n", "theName" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we do it again, the number is incremented. " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "open(theName, 'a').close()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'test~01.dat'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "theName = fl.getNewFileName('test', 'dat')\n", "theName" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.5" } }, "nbformat": 4, "nbformat_minor": 4 }