{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AsciiDataTable Example\n",
    "The AsciiDataTable class is meant to deal with data in the form of a table with a header and footer. It has the ability to change formating, load a file, and do simple manipulations.\n",
    "\n",
    "Some key elements of the AsciiDataTable class:\n",
    "1. It can be created by opening a file with the right options. To preserve the options of a given file use the save_schema method and the read_schema function. \n",
    "2. It can save, or print.\n",
    "3. It has a large amount of formatting flexability\n",
    "\n",
    "To make a new data table:\n",
    "```python\n",
    "new_table=AsciiDataTable()\n",
    "#or\n",
    "new_table=AsciiDataTable(header=[\"My Header\",\"Line2\" ],column_names=[\"a\",\"b\",\"c\"],data=[[1,2,3]])\n",
    "```\n",
    "To open an existing table:\n",
    "```python\n",
    "#in default format (csv with no #)\n",
    "existing_table=AsciiDataTable(\"My_Table.txt\")\n",
    "# for an existing format with a saved schema\n",
    "schema=read_schema(\"My_Schema\")\n",
    "existing_table=AsciiDataTable(\"My_Table.txt\",**schema)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Importing pyMez, this should take roughly 30 seconds\n",
      "Importing Code.DataHandlers.GeneralModels\n",
      "It took 0.521029 s to import Code.DataHandlers.GeneralModels\n",
      "Importing Code.DataHandlers.HTMLModels\n",
      "It took 0.099006 s to import Code.DataHandlers.HTMLModels\n",
      "Importing Code.DataHandlers.NISTModels\n",
      "The module smithplot was not found,please put it on the python path\n",
      "It took 0.723041 s to import Code.DataHandlers.NISTModels\n",
      "Importing Code.DataHandlers.TouchstoneModels\n",
      "It took 0.0 s to import Code.DataHandlers.TouchstoneModels\n",
      "Importing Code.DataHandlers.XMLModels\n",
      "It took 0.128008 s to import Code.DataHandlers.XMLModels\n",
      "Importing Code.DataHandlers.ZipModels\n",
      "It took 0.014 s to import Code.DataHandlers.ZipModels\n",
      "Importing Code.InstrumentControl.Experiments\n",
      "It took 3.360193 s to import Code.InstrumentControl.Experiments\n",
      "Importing Code.InstrumentControl.Instruments\n",
      "It took 0.001 s to import Code.InstrumentControl.Instruments\n",
      "Importing Code.Utils.Names\n",
      "It took 0.0 s to import Code.Utils.Names\n",
      "It took 4.846277 s to import all of the active modules\n"
     ]
    }
   ],
   "source": [
    "# As an example\n",
    "import pyMez.Code.DataHandlers.GeneralModels as GeneralModels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Lets make a table and put it into the AsciiDataTable \n",
    "new_table=GeneralModels.AsciiDataTable()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0, 1, 2], [3, 4, 5], [6, 7, 8]]\n"
     ]
    }
   ],
   "source": [
    "# The data is a list of lists with the first dimension # of rows and the second dimension # of columns\n",
    "table_data=[[i+j*3 for i in range(3)]for j in range(3)]\n",
    "print(table_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#input the data directly\n",
    "new_table.data=table_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# assign the column names\n",
    "new_table.column_names=['x1','x2','x3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x1,x2,x3\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n"
     ]
    }
   ],
   "source": [
    "# when a string related command is called it uses build string to output the string print(new_table) also works\n",
    "print(new_table.build_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# the attribute options stores the schema for the data\n",
    "new_table.options['column_names_begin_token']='#'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#x1,x2,x3\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n"
     ]
    }
   ],
   "source": [
    "print(new_table.build_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# changing a formating option doesn't change the data\n",
    "new_table.options['column_names_begin_token']='['\n",
    "new_table.options['column_names_end_token']=']'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n"
     ]
    }
   ],
   "source": [
    "print(new_table.build_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# There is the ability to control the output format in many ways\n",
    "new_table.options['data_begin_token']='*'*80+'\\n'\n",
    "new_table.options['data_end_token']=\"\\n\"+'*'*80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[x1,x2,x3]\n",
      "********************************************************************************\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "********************************************************************************\n"
     ]
    }
   ],
   "source": [
    "print(new_table.build_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# the header is where we would store metadata\n",
    "new_table.header=['My First Header Line','My Second Header Line']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My First Header Line\n",
      "My Second Header Line\n",
      "[x1,x2,x3]\n",
      "********************************************************************************\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "********************************************************************************\n"
     ]
    }
   ],
   "source": [
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_table.options['comment_begin']='#'\n",
    "new_table.options['comment_end']='\\n'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "********************************************************************************\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "********************************************************************************\n"
     ]
    }
   ],
   "source": [
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data_delimiter = ,\n",
      "column_names_delimiter = ,\n",
      "specific_descriptor = Data\n",
      "general_descriptor = Table\n",
      "directory = None\n",
      "extension = txt\n",
      "comment_begin = #\n",
      "comment_end = \n",
      "\n",
      "inline_comment_begin = None\n",
      "inline_comment_end = None\n",
      "block_comment_begin = None\n",
      "block_comment_end = None\n",
      "footer_begin_line = None\n",
      "footer_end_line = None\n",
      "header_begin_line = 0\n",
      "header_end_line = 2\n",
      "column_names_begin_line = 3\n",
      "column_names_end_line = 4\n",
      "data_begin_line = 4\n",
      "data_end_line = None\n",
      "footer_begin_token = None\n",
      "footer_end_token = None\n",
      "header_begin_token = None\n",
      "header_end_token = None\n",
      "column_names_begin_token = [\n",
      "column_names_end_token = ]\n",
      "data_begin_token = ********************************************************************************\n",
      "\n",
      "data_end_token = \n",
      "********************************************************************************\n",
      "metadata_delimiter = None\n",
      "metadata_key_value_delimiter = None\n",
      "header_line_types = None\n",
      "column_types = None\n",
      "column_descriptions = None\n",
      "column_units = None\n",
      "footer_line_types = None\n",
      "header = None\n",
      "column_names = None\n",
      "data = None\n",
      "footer = None\n",
      "inline_comments = None\n",
      "row_begin_token = None\n",
      "row_end_token = None\n",
      "row_formatter_string = None\n",
      "empty_value = None\n",
      "escape_character = None\n",
      "data_table_element_separator = \n",
      "\n",
      "treat_header_as_comment = None\n",
      "treat_footer_as_comment = None\n",
      "metadata = None\n",
      "data_list_dictionary = None\n",
      "save_schema = True\n",
      "open_with_schema = True\n",
      "use_alternative_parser = True\n",
      "validate = False\n"
     ]
    }
   ],
   "source": [
    "# get_options returns all options printed in a nice form \n",
    "new_table.get_options()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Data_Table_20181113_001.txt'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# when we created the file it autonamed itself. This is the place the file will save to using new_table.save()\n",
    "new_table.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Each formatting option can be turned off\n",
    "new_table.options['data_begin_token']=None\n",
    "new_table.options['data_end_token']=None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n"
     ]
    }
   ],
   "source": [
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We can build the table this way or using \n",
    "# AsciiDataTable(header=new_table.header,column_names=new_table.column_names)\n",
    "new_table2=GeneralModels.AsciiDataTable()\n",
    "new_table2.header=new_table.header\n",
    "new_table2.column_names=new_table.column_names\n",
    "new_table2.options=new_table.options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n"
     ]
    }
   ],
   "source": [
    "print(new_table2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_table2.data=[[2*(i+j*3) for i in range(3)]for j in range(3)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "print(new_table2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pyMez.Code.DataHandlers.GeneralModels.AsciiDataTable at 0x9149080>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Adding the tables, if column names are the same\n",
    "new_table+new_table2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n",
      "\n",
      " --End of Table 1 -- --End of Table 1 -- --End of Table 1 -- --End of Table 1 -- --End of Table 1 --\n",
      "\n",
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "print(new_table)\n",
    "print(\"\\n\"+\" --End of Table 1 --\"*5+\"\\n\")\n",
    "print(new_table2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "print(new_table2.build_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(new_table2).count(\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_string=str(new_table2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'#My First Header Line\\n#My Second Header Line\\n\\n[x1,x2,x3]\\n0,2,4\\n6,8,10\\n12,14,16'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_list=test_string.split('\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['#My First Header Line',\n",
       " '#My Second Header Line',\n",
       " '',\n",
       " '[x1,x2,x3]',\n",
       " '0,2,4',\n",
       " '6,8,10',\n",
       " '12,14,16']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#My(*Hello, This  is an inline comment*) First Header Line\n",
      "#My Second Header Line\n",
      "\n",
      "[x1,x2,x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n"
     ]
    }
   ],
   "source": [
    "new_table.options['inline_comment_begin']='(*'\n",
    "new_table.options['inline_comment_end']='*)'\n",
    "new_table.inline_comments=[[\"Hello, This  is an inline comment\",0,3]]\n",
    "print(new_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6, 7, 2, 8, 6, 2, 0, 2, 4, 4, 7, 9, 8, 8, 1, 3, 9, 4, 3, 1]\n"
     ]
    }
   ],
   "source": [
    "data_delimiters=[\",\",\".\",\":\",\";\",\"-\",\" \",\"\\t\",\"::\",\"~\",\" | \"]\n",
    "begin_end_pairs=[[\"<\",\">\"],[\"(*\",\"*)\"],[\"[\",\"]\"],[\"/*\",\"*/\"],[\"(\",\")\"],[\"<\",\"/>\"],[\"#\",\"\"]]\n",
    "random_int=random.randint(0,len(data_delimiters)-1)\n",
    "random_list=[random.randint(0,len(data_delimiters)-1) for i in range(20)]\n",
    "print(random_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "random_delimiter_list_1=[data_delimiters[random.randint(0,len(data_delimiters)-1)] for i in range(20)]\n",
    "random_delimiter_list_2=[data_delimiters[random.randint(0,len(data_delimiters)-1)] for i in range(20)]\n",
    "random_pairs_1=[begin_end_pairs[random.randint(0,6)] for i in range(20)]\n",
    "random_pairs_2=[begin_end_pairs[random.randint(0,6)] for i in range(20)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['<', '>'], ['(*', '*)'], ['[', ']'], ['/*', '*/'], ['(', ')'], ['<', '/>'], ['#', '']]\n"
     ]
    }
   ],
   "source": [
    "print(begin_end_pairs)\n",
    "new_table.inline_comments=[[\"Hello, This  is an inline comment\",0,-1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "(*My First Header Line*)(*Hello, This  is an inline comment*)\n",
      "(*My Second Header Line*)\n",
      "\n",
      "(x1,x2,x3)\n",
      "0 1 2\n",
      "3 4 5\n",
      "6 7 8\n",
      "0 2 4\n",
      "6 8 10\n",
      "12 14 16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "#x1 | x2 | x3\n",
      "0~1~2\n",
      "3~4~5\n",
      "6~7~8\n",
      "0~2~4\n",
      "6~8~10\n",
      "12~14~16\n",
      "\n",
      "\n",
      "(*My First Header Line*)(*Hello, This  is an inline comment*)\n",
      "(*My Second Header Line*)\n",
      "\n",
      "#x1;x2;x3\n",
      "0 1 2\n",
      "3 4 5\n",
      "6 7 8\n",
      "0 2 4\n",
      "6 8 10\n",
      "12 14 16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "<x1-x2-x3>\n",
      "0 | 1 | 2\n",
      "3 | 4 | 5\n",
      "6 | 7 | 8\n",
      "0 | 2 | 4\n",
      "6 | 8 | 10\n",
      "12 | 14 | 16\n",
      "\n",
      "\n",
      "[My First Header Line](*Hello, This  is an inline comment*)\n",
      "[My Second Header Line]\n",
      "\n",
      "[x1\tx2\tx3]\n",
      "0.1.2\n",
      "3.4.5\n",
      "6.7.8\n",
      "0.2.4\n",
      "6.8.10\n",
      "12.14.16\n",
      "\n",
      "\n",
      "[My First Header Line](*Hello, This  is an inline comment*)\n",
      "[My Second Header Line]\n",
      "\n",
      "/*x1~x2~x3*/\n",
      "0:1:2\n",
      "3:4:5\n",
      "6:7:8\n",
      "0:2:4\n",
      "6:8:10\n",
      "12:14:16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "(*x1:x2:x3*)\n",
      "0:1:2\n",
      "3:4:5\n",
      "6:7:8\n",
      "0:2:4\n",
      "6:8:10\n",
      "12:14:16\n",
      "\n",
      "\n",
      "/*My First Header Line*/(*Hello, This  is an inline comment*)\n",
      "/*My Second Header Line*/\n",
      "\n",
      "(*x1\tx2\tx3*)\n",
      "0::1::2\n",
      "3::4::5\n",
      "6::7::8\n",
      "0::2::4\n",
      "6::8::10\n",
      "12::14::16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "(*x1;x2;x3*)\n",
      "0 | 1 | 2\n",
      "3 | 4 | 5\n",
      "6 | 7 | 8\n",
      "0 | 2 | 4\n",
      "6 | 8 | 10\n",
      "12 | 14 | 16\n",
      "\n",
      "\n",
      "#My First Header Line(*Hello, This  is an inline comment*)\n",
      "#My Second Header Line\n",
      "\n",
      "#x1-x2-x3\n",
      "0:1:2\n",
      "3:4:5\n",
      "6:7:8\n",
      "0:2:4\n",
      "6:8:10\n",
      "12:14:16\n",
      "\n",
      "\n",
      "(My First Header Line)(*Hello, This  is an inline comment*)\n",
      "(My Second Header Line)\n",
      "\n",
      "[x1::x2::x3]\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n",
      "\n",
      "\n",
      "(*My First Header Line*)(*Hello, This  is an inline comment*)\n",
      "(*My Second Header Line*)\n",
      "\n",
      "<x1~x2~x3/>\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n",
      "\n",
      "\n",
      "(*My First Header Line*)(*Hello, This  is an inline comment*)\n",
      "(*My Second Header Line*)\n",
      "\n",
      "(*x1~x2~x3*)\n",
      "0,1,2\n",
      "3,4,5\n",
      "6,7,8\n",
      "0,2,4\n",
      "6,8,10\n",
      "12,14,16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "(x1::x2::x3)\n",
      "0 1 2\n",
      "3 4 5\n",
      "6 7 8\n",
      "0 2 4\n",
      "6 8 10\n",
      "12 14 16\n",
      "\n",
      "\n",
      "[My First Header Line](*Hello, This  is an inline comment*)\n",
      "[My Second Header Line]\n",
      "\n",
      "(x1-x2-x3)\n",
      "0 | 1 | 2\n",
      "3 | 4 | 5\n",
      "6 | 7 | 8\n",
      "0 | 2 | 4\n",
      "6 | 8 | 10\n",
      "12 | 14 | 16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "[x1::x2::x3]\n",
      "0 1 2\n",
      "3 4 5\n",
      "6 7 8\n",
      "0 2 4\n",
      "6 8 10\n",
      "12 14 16\n",
      "\n",
      "\n",
      "(My First Header Line)(*Hello, This  is an inline comment*)\n",
      "(My Second Header Line)\n",
      "\n",
      "<x1,x2,x3>\n",
      "0 | 1 | 2\n",
      "3 | 4 | 5\n",
      "6 | 7 | 8\n",
      "0 | 2 | 4\n",
      "6 | 8 | 10\n",
      "12 | 14 | 16\n",
      "\n",
      "\n",
      "<My First Header Line/>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line/>\n",
      "\n",
      "[x1;x2;x3]\n",
      "0 1 2\n",
      "3 4 5\n",
      "6 7 8\n",
      "0 2 4\n",
      "6 8 10\n",
      "12 14 16\n",
      "\n",
      "\n",
      "[My First Header Line](*Hello, This  is an inline comment*)\n",
      "[My Second Header Line]\n",
      "\n",
      "(x1;x2;x3)\n",
      "0\t1\t2\n",
      "3\t4\t5\n",
      "6\t7\t8\n",
      "0\t2\t4\n",
      "6\t8\t10\n",
      "12\t14\t16\n",
      "\n",
      "\n",
      "<My First Header Line>(*Hello, This  is an inline comment*)\n",
      "<My Second Header Line>\n",
      "\n",
      "(*x1;x2;x3*)\n",
      "0 | 1 | 2\n",
      "3 | 4 | 5\n",
      "6 | 7 | 8\n",
      "0 | 2 | 4\n",
      "6 | 8 | 10\n",
      "12 | 14 | 16\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# An example of all the formats randomized\n",
    "for index in range(len(random_delimiter_list_1)):\n",
    "    new_table.options[\"data_delimiter\"]=random_delimiter_list_1[index]\n",
    "    new_table.options[\"column_names_delimiter\"]=random_delimiter_list_2[index]\n",
    "    new_table.options[\"comment_begin\"]=random_pairs_1[index][0]\n",
    "    new_table.options[\"comment_end\"]=random_pairs_1[index][1]+\"\\n\"\n",
    "    new_table.options[\"column_names_begin_token\"]=random_pairs_2[index][0]\n",
    "    new_table.options[\"column_names_end_token\"]=random_pairs_2[index][1]    \n",
    "    print( \"\\n{0}\\n\".format(new_table))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Printing the string representation of the table\n",
      "--------------------------------------------------------------------------------\n",
      "{header_begin_token}\n",
      "self.header[0]\n",
      "self.header[1]{inline_comment_begin}inline_comments[0][0]{inline_comment_end}\n",
      "{comment_begin}self.header[2]{comment_end}\n",
      "\n",
      "{block_comment_begin}\n",
      "self.header[3]\n",
      "self.header{4]\n",
      "{block_comment_end}\n",
      "{header_end_token}\n",
      "{data_table_element_separator}\n",
      "{column_names_begin_token}column_names[0]{column_names_delimiter}column_names[1]{column_names_delimiter}column_names[2]{column_names_end_token}\n",
      "{data_table_element_separator}\n",
      "{data_begin_token}\n",
      "{row_begin_token}data[0][0]{data_delimiter}data[1][0]{data_delimiter}data[2][0]{row_end_token}\n",
      "{row_begin_token}data[0][1]{data_delimiter}data[1][1]{data_delimiter}data[2][1]{row_end_token}\n",
      "{data_end_token}\n",
      "{data_table_element_separator}\n",
      "{footer_begin_token}\n",
      "{block_comment_begin}\n",
      "self.footer[0]\n",
      "self.footer[1]\n",
      "{block_comment_end}\n",
      "{footer_end_token}\n",
      "Printing the lines representation of the table with line numbers\n",
      "--------------------------------------------------------------------------------\n",
      "0 {header_begin_token}\n",
      "1 self.header[0]\n",
      "2 self.header[1]{inline_comment_begin}inline_comments[0][0]{inline_comment_end}\n",
      "3 {comment_begin}self.header[2]{comment_end}\n",
      "4 \n",
      "5 {block_comment_begin}\n",
      "6 self.header[3]\n",
      "7 self.header{4]\n",
      "8 {block_comment_end}\n",
      "9 {header_end_token}\n",
      "10 {data_table_element_separator}\n",
      "11 {column_names_begin_token}column_names[0]{column_names_delimiter}column_names[1]{column_names_delimiter}column_names[2]{column_names_end_token}\n",
      "12 {data_table_element_separator}\n",
      "13 {data_begin_token}\n",
      "14 {row_begin_token}data[0][0]{data_delimiter}data[1][0]{data_delimiter}data[2][0]{row_end_token}\n",
      "15 {row_begin_token}data[0][1]{data_delimiter}data[1][1]{data_delimiter}data[2][1]{row_end_token}\n",
      "16 {data_end_token}\n",
      "17 {data_table_element_separator}\n",
      "18 {footer_begin_token}\n",
      "19 {block_comment_begin}\n",
      "20 self.footer[0]\n",
      "21 self.footer[1]\n",
      "22 {block_comment_end}\n",
      "23 {footer_end_token}\n",
      "--------------------------------------------------------------------------------\n",
      "The result of self.lines[0:10] is :\n",
      "{header_begin_token}\n",
      "self.header[0]\n",
      "self.header[1]{inline_comment_begin}inline_comments[0][0]{inline_comment_end}\n",
      "{comment_begin}self.header[2]{comment_end}\n",
      "\n",
      "{block_comment_begin}\n",
      "self.header[3]\n",
      "self.header{4]\n",
      "{block_comment_end}\n",
      "{header_end_token}\n",
      "--------------------------------------------------------------------------------\n",
      "--------------------------------------------------------------------------------\n",
      "The result of self.lines[11:12] is :\n",
      "{column_names_begin_token}column_names[0]{column_names_delimiter}column_names[1]{column_names_delimiter}column_names[2]{column_names_end_token}\n",
      "--------------------------------------------------------------------------------\n",
      "--------------------------------------------------------------------------------\n",
      "The result of self.lines[13:17] is :\n",
      "{data_begin_token}\n",
      "{row_begin_token}data[0][0]{data_delimiter}data[1][0]{data_delimiter}data[2][0]{row_end_token}\n",
      "{row_begin_token}data[0][1]{data_delimiter}data[1][1]{data_delimiter}data[2][1]{row_end_token}\n",
      "{data_end_token}\n",
      "--------------------------------------------------------------------------------\n",
      "--------------------------------------------------------------------------------\n",
      "The result of self.lines[18:None] is :\n",
      "{footer_begin_token}\n",
      "{block_comment_begin}\n",
      "self.footer[0]\n",
      "self.footer[1]\n",
      "{block_comment_end}\n",
      "{footer_end_token}\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "GeneralModels.show_structure_script()"
   ]
  },
  {
   "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.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
