{ "metadata": { "language": "Julia", "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#8 PLEAC Julia: File Contents" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[PLEAC = Language Examples Alike Cookbook](http://pleac.sourceforge.net/)\n", "PLEAC examples are drawn from the \"Perl Cookbook\" by Tom Christiansen & Nathan Torkington, published by O'Reilly. They provide a nice range of examples oriented toward data munging, the type of work I tend to want to do first when learning a new language.\n", "\n", "\n", "The Julia examples below are principally translations from the [Python version](http://pleac.sourceforge.net/pleac_python/)\n", "\n", "###Caution\n", "I'm learning as I go, so the code below probably doesn't represent best practice. Your suggestions are welcome! \n", "Please file an issue or make a pull request to the [github repo](https://github.com/catawbasam/IJulia_PLEAC/).\n", "\n", "The examples are not complete. Missing items are generally noted in comments. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.0 Introduction" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#make a file\n", "contents=\"\"\"Here are\n", "a few\n", "lines of\n", "text content.\"\"\"\n", "\n", "fo=open(\"julia_file.txt\", \"w\")\n", "write(fo, contents)\n", "close(fo)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt\", \"r\")\n", "for line in readlines(fi)\n", " line = rstrip(line)\n", " size = length(line)\n", " println(size)\n", "end\n", "close(fi)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "8" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "5\n", "8\n", "13\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt\", \"r\")\n", "for line in readlines(fi)\n", " println(length(rstrip(line)))\n", "end\n", "close(fi)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "8\n", "5\n", "8\n", "13\n" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "al=readlines(open(\"julia_file.txt\", \"r\"))" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "4-element Array{Any,1}:\n", " \"Here are\\n\" \n", " \"a few\\n\" \n", " \"lines of\\n\" \n", " \"text content.\"" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "t=readall(open(\"julia_file.txt\", \"r\"))" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 5, "text": [ "\"Here are\\na few\\nlines of\\ntext content.\"" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "t" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 6, "text": [ "\"Here are\\na few\\nlines of\\ntext content.\"" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "w=readdlm(open(\"julia_file.txt\", \"r\"), ' ')[1] #first word" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 7, "text": [ "\"Here\"" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt2\", \"w\")\n", "writedlm(fi, [\"One\",\"Two\",\"Three\"], ' ')\n", "close(fi)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "help(seek)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Loading help data..." ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Base.seek(s, pos)\n", "\n", " Seek a stream to the given position.\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt\", \"r\")\n", "ba=readbytes(fi, 4096)\n", "ba'" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 10, "text": [ "1x37 Array{Uint8,2}:\n", " 0x48 0x65 0x72 0x65 0x20 0x61 \u2026 0x6e 0x74 0x65 0x6e 0x74 0x2e" ] } ], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "seek(fi,12) #seek to byte 12\n", "println(\"I'm $(position(fi)) bytes from the start of the file\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "I'm 12 bytes from the start of the file" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "seekstart(fi) #seek to start\n", "seekend(fi) #seek to end" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 12, "text": [ "IOStream()" ] } ], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "seekend(fi)\n", "skip(fi, -2) #relative seek\n", "position(fi)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 13, "text": [ "35" ] } ], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "position(fi)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 14, "text": [ "35" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "# NOT IMPLEMENTED:\n", "# pos = os.lseek(myfile.fileno(),0,1) #?? what does this do?" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 15 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.1 Reading Lines with Continuation Characters" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#not implemented" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 16 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.2 Counting Lines (or Paragraphs or Records) in a File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "open(\"julia_file.txt\", \"r\") do fi\n", " lines= readlines(fi)\n", "end\n", "length(lines)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "WARNING: " ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "ename": "LoadError", "evalue": "lines not defined\nat In[17]:4", "output_type": "pyerr", "traceback": [ "lines not defined\nat In[17]:4" ] } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [ "t=readall(open(\"julia_file.txt\", \"r\"))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "backtraces on your platform are often misleading or partially incorrect\n" ] }, { "metadata": {}, "output_type": "pyout", "prompt_number": 18, "text": [ "\"Here are\\na few\\nlines of\\ntext content.\"" ] } ], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "para_count = length(split(t, \"in\"))" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 19, "text": [ "2" ] } ], "prompt_number": 19 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.3 Processing Every Word in a File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#simple word count\n", "words=split(t)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 20, "text": [ "8-element Array{String,1}:\n", " \"Here\" \n", " \"are\" \n", " \"a\" \n", " \"few\" \n", " \"lines\" \n", " \"of\" \n", " \"text\" \n", " \"content.\"" ] } ], "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ "word_dict=Dict()\n", "for w in words\n", " word_dict[w] = get(word_dict, w, 0)+1\n", "end\n", "word_dict" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 21, "text": [ "{\"text\"=>1,\"content.\"=>1,\"are\"=>1,\"few\"=>1,\"Here\"=>1,\"lines\"=>1,\"of\"=>1,\"a\"=>1}" ] } ], "prompt_number": 21 }, { "cell_type": "markdown", "metadata": {}, "source": [ "####Cleaner results using TextAnalysis" ] }, { "cell_type": "code", "collapsed": false, "input": [ "using TextAnalysis" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 22 }, { "cell_type": "code", "collapsed": false, "input": [ "tokens(Document(t))" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 23, "text": [ "8-element Array{UTF8String,1}:\n", " \"Here\" \n", " \"are\" \n", " \"a\" \n", " \"few\" \n", " \"lines\" \n", " \"of\" \n", " \"text\" \n", " \"content.\"" ] } ], "prompt_number": 23 }, { "cell_type": "code", "collapsed": false, "input": [ "words=split(remove_punctuation!(Document(t))) #we could remove numbers too." ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 24, "text": [ "8-element Array{String,1}:\n", " \"Here\" \n", " \"are\" \n", " \"a\" \n", " \"few\" \n", " \"lines\" \n", " \"of\" \n", " \"text\" \n", " \"content\"" ] } ], "prompt_number": 24 }, { "cell_type": "code", "collapsed": false, "input": [ "word_dict=Dict()\n", "for w in words\n", " word_dict[w] = get(word_dict, w, 0)+1\n", "end\n", "word_dict" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 25, "text": [ "{\"text\"=>1,\"are\"=>1,\"few\"=>1,\"Here\"=>1,\"lines\"=>1,\"content\"=>1,\"of\"=>1,\"a\"=>1}" ] } ], "prompt_number": 25 }, { "cell_type": "code", "collapsed": false, "input": [ "#line frequency count\n", "lines=readlines(open(\"julia_file.txt\", \"r\"))\n", "line_dict=Dict()\n", "for w in lines\n", " line_dict[w] = get(line_dict, w, 0)+1\n", "end\n", "line_dict" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 26, "text": [ "{\"lines of\\n\"=>1,\"Here are\\n\"=>1,\"a few\\n\"=>1,\"text content.\"=>1}" ] } ], "prompt_number": 26 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.4 Reading a File Backwards by Line or Paragraph" ] }, { "cell_type": "code", "collapsed": false, "input": [ "lines= reverse( readlines(open(\"julia_file.txt\", \"r\")) )" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 27, "text": [ "4-element Array{Any,1}:\n", " \"text content.\"\n", " \"lines of\\n\" \n", " \"a few\\n\" \n", " \"Here are\\n\" " ] } ], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.5 Trailing a Growing File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt\", \"r\")\n", "seekend(fi)\n", "endpos = position(fi)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 28, "text": [ "37" ] } ], "prompt_number": 28 }, { "cell_type": "code", "collapsed": false, "input": [ "i=1\n", "while i<3 #or while true\n", " sleep(1)\n", " seekend(fi)\n", " if position(fi)>endpos\n", " endpos=position(fi)\n", " println(\"time: $i. new size: $endpos\")\n", " end\n", " i=i+1\n", "end" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "close(fi)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 30 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.6 Picking a Random Line from a File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "lines= reverse( readlines(open(\"julia_file.txt\", \"r\")) )\n", "length(lines)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 31, "text": [ "4" ] } ], "prompt_number": 31 }, { "cell_type": "code", "collapsed": false, "input": [ "pick = rand(1:length(lines))\n", "lines[pick]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 32, "text": [ "\"Here are\\n\"" ] } ], "prompt_number": 32 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.7 Randomizing All Lines" ] }, { "cell_type": "code", "collapsed": false, "input": [ "using Distributions" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "shuffle(lines)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 34, "text": [ "4-element Array{Any,1}:\n", " \"a few\\n\" \n", " \"text content.\"\n", " \"Here are\\n\" \n", " \"lines of\\n\" " ] } ], "prompt_number": 34 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.8 Reading a Particular Line in a File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "DESIRED_LINE=3\n", "lines[DESIRED_LINE]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 35, "text": [ "\"a few\\n\"" ] } ], "prompt_number": 35 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.9 Processing Variable-Length Text Fields" ] }, { "cell_type": "code", "collapsed": false, "input": [ "pattern=\" \"\n", "record = lines[1]\n", "split(record)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 36, "text": [ "2-element Array{String,1}:\n", " \"text\" \n", " \"content.\"" ] } ], "prompt_number": 36 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.10 Removing the Last Line of a File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#create test file\n", "#make a file\n", "contents=\"\"\"Here are\n", "a few\n", "lines of\n", "text content.\"\"\"\n", "\n", "fo=open(\"julia_file.txt\", \"w\")\n", "write(fo, contents)\n", "close(fo)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 37 }, { "cell_type": "code", "collapsed": false, "input": [ "fi=open(\"julia_file.txt\", \"r+\")\n", "pos=0\n", "prev_pos=0\n", "for ln in eachline(fi)\n", " prev_pos = pos\n", " pos = position(fi)\n", "end\n", "close(fi)\n", "println(prev_pos)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "Warning: could not import Base.foldl into NumericExtensions\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "24" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "Warning: could not import Base.foldr into NumericExtensions\n" ] } ], "prompt_number": 38 }, { "cell_type": "code", "collapsed": false, "input": [ "cp(\"julia_file.txt\", \"julia_file2.txt\")\n", "open(\"julia_file2.txt\", \"w\") do fi\n", " truncate(fi, prev_pos)\n", "end\n", "\n", "trunc8 = readall(open(\"julia_file.txt\", \"r\"))\n", "open(\"julia_file2.txt\", \"w\") do fo\n", " write(fo, trunc8[1:prev_pos])\n", "end\n", "\n", "result = readall(open(\"julia_file2.txt\", \"r\"))\n", "result" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 39, "text": [ "\"Here are\\na few\\nlines of\\n\"" ] } ], "prompt_number": 39 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.11 Processing Binary Files" ] }, { "cell_type": "code", "collapsed": false, "input": [ "open(\"julia_file.txt\", \"r\") do fi\n", " ba=readbytes(fi)\n", "end\n", "ba'" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 40, "text": [ "1x37 Array{Uint8,2}:\n", " 0x48 0x65 0x72 0x65 0x20 0x61 \u2026 0x6e 0x74 0x65 0x6e 0x74 0x2e" ] } ], "prompt_number": 40 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.12 Using Random-Access I/O" ] }, { "cell_type": "code", "collapsed": false, "input": [ "function readstring(stream, numchars)\n", " bytes=readbytes(stream, numchars)\n", " return join([char(v) for v in bytes])\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 41, "text": [ "readstring (generic function with 1 method)" ] } ], "prompt_number": 41 }, { "cell_type": "code", "collapsed": false, "input": [ "#make a file : 2 fields of 4 chars (+ \\n) = 9 characters per line\n", "contents=\"\"\" a b\n", "blah at\n", "line of\n", "text1234\"\"\"\n", "\n", "open(\"julia_fixed.dat\", \"w\") do fo\n", " write(fo, contents)\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 42, "text": [ "35" ] } ], "prompt_number": 42 }, { "cell_type": "code", "collapsed": false, "input": [ "recsize=8+1 # 8 characters of data + line ending\n", "recno=2\n", "address = recsize * recno \n", "open(\"julia_fixed.dat\", \"r\") do fi\n", " seek(fi,address)\n", " println(readstring(fi, recsize))\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "line of\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] } ], "prompt_number": 43 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.13 Updating a Random-Access File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "open(\"julia_fixed.dat\", \"r+\") do fi\n", " seek(fi,address)\n", " recstr = readstring(fi, recsize)\n", " newrec = uppercase(recstr)\n", " seek(fi,address)\n", " write(fi,newrec)\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 52, "text": [ "9" ] } ], "prompt_number": 52 }, { "cell_type": "code", "collapsed": false, "input": [ "open(\"julia_fixed.dat\", \"r\") do fi\n", " dt=readall(fi)\n", " print(dt)\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " a b\n", "blah at\n", "LINE OF\n", "text1234" ] } ], "prompt_number": 54 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.14 Reading a String from a Binary File" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#NOT IMPLEMENTED" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "\n" ] } ], "prompt_number": 46 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.15 Reading Fixed-Length Records" ] }, { "cell_type": "code", "collapsed": false, "input": [ "Pkg.add(\"IniFile\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "INFO: " ] }, { "output_type": "stream", "stream": "stderr", "text": [ "No packages to install, update or remove.\n", "INFO: REQUIRE updated.\n" ] } ], "prompt_number": 85 }, { "cell_type": "code", "collapsed": false, "input": [ "# define a packable binary record\n", "using StrPack\n", "@struct type TstStr\n", " int1::Int64\n", " float1::Float64\n", "end\n", "RECORDSIZE=sizeof(TstStr)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 71, "text": [ "16" ] } ], "prompt_number": 71 }, { "cell_type": "code", "collapsed": false, "input": [ "#write out sample data\n", "rec=TstStr(4455, 556.32)\n", "open(\"bintest.dat\",\"w\") do fo\n", " pack(fo, rec)\n", " pack(fo, TstStr(3455, 556.32))\n", " pack(fo, TstStr(6453, 656.32)) \n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "WARNING: " ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", "\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "max(x) is deprecated, use maximum(x) instead.\n", " in depwarn at deprecated.jl:29\n", " in string at ascii.jl:35\n", "WARNING: max(x) is deprecated, use maximum(x) instead.\n", " in depwarn at deprecated.jl:29\n", " in string at ascii.jl:35\n", "WARNING: max(x) is deprecated, use maximum(x) instead.\n", " in depwarn at deprecated.jl:29\n", " in string at ascii.jl:35\n" ] }, { "metadata": {}, "output_type": "pyout", "prompt_number": 81, "text": [ "16" ] } ], "prompt_number": 81 }, { "cell_type": "code", "collapsed": false, "input": [ "open(\"bintest.dat\",\"r\") do fi\n", " seek(fi, RECORDSIZE) # \"rewind\" to the beginning of the buffer\n", " s2 = unpack(fi, TstStr)\n", " println(s2)\n", "end" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "WARNING: " ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "TstStr(3455,556.32)\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "max(x) is deprecated, use maximum(x) instead.\n", " in depwarn at deprecated.jl:29\n", " in string at ascii.jl:35\n" ] } ], "prompt_number": 84 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.16 Reading Configuration Files" ] }, { "cell_type": "code", "collapsed": false, "input": [ "using IniFile\n", "ini = Inifile()\n", "read(ini, \"test.ini\")\n", "get(ini, \"section 1\", \"strname1\") #== \"section1name1\"" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 87, "text": [ "\"section1name1\"" ] } ], "prompt_number": 87 }, { "cell_type": "markdown", "metadata": {}, "source": [ "##8.17 Testing a File for Trustworthiness" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Will not implement" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 49 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Programs" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Will not implement" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 50 } ], "metadata": {} } ] }