diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2011-05-11 17:58:31 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2011-05-11 17:58:31 -0400 |
| commit | a2b62669b7fef42e835da0010c63ef1cb9ef0f92 (patch) | |
| tree | 909e2665fc6f9cca42d3808f56b62f39a59bd44b /docs | |
| parent | 7ae7d3ff46f323d0d85678cb3415865357ed0e25 (diff) | |
| download | tablib-a2b62669b7fef42e835da0010c63ef1cb9ef0f92.tar.gz | |
seperator => separator
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/tutorial.rst | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 4349952..07939c2 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -30,11 +30,11 @@ A :class:`Dataset <tablib.Dataset>` is nothing more than what its name implies†Creating your own instance of the :class:`tablib.Dataset` object is simple. :: data = tablib.Dataset() - + You can now start filling this :class:`Dataset <tablib.Dataset>` object with data. .. admonition:: Example Context - + From here on out, if you see ``data``, assume that it's a fresh :class:`Dataset <tablib.Dataset>` object. @@ -52,7 +52,7 @@ Let's say you want to collect a simple list of names. :: for name in names: # split name appropriately fname, lname = name.split() - + # add names to Dataset data.append([fname, lname]) @@ -76,19 +76,19 @@ Now our data looks a little different. :: >>> data.dict [{'Last Name': 'Reitz', 'First Name': 'Kenneth'}, {'Last Name': 'Monke', 'First Name': 'Bessie'}] - + -------------- -Adding Columns +Adding Columns -------------- Now that we have a basic :class:`Dataset` in place, let's add a column of **ages** to it. :: data.append(col=[22, 20], header='Age') - + Let's view the data now. :: >>> data.dict @@ -106,8 +106,8 @@ Tablib's killer feature is the ability to export your :class:`Dataset` objects i **Comma-Separated Values** :: >>> data.csv - Last Name,First Name,Age - Reitz,Kenneth,22 + Last Name,First Name,Age + Reitz,Kenneth,22 Monke,Bessie,20 **JavaScript Object Notation** :: @@ -121,7 +121,7 @@ Tablib's killer feature is the ability to export your :class:`Dataset` objects i >>> data.yaml - {Age: 22, First Name: Kenneth, Last Name: Reitz} - {Age: 20, First Name: Bessie, Last Name: Monke} - + **Microsoft Excel** :: @@ -190,11 +190,11 @@ Thanks to Josh Ourisman, Tablib now supports adding dynamic columns. A dynamic c Let's add a dynamic column to our :class:`Dataset` object. In this example, we have a function that generates a random grade for our students. :: import random - + def random_grade(row): """Returns a random integer for entry.""" return (random.randint(60,100)/100.0) - + data.append(col=[random_grade], header='Grade') Let's have a look at our data. :: @@ -209,7 +209,7 @@ Let's remove that column. :: >>> del data['Grade'] -When you add a dynamic column, the first argument that is passed in to the given callable is the current data row. You can use this to perform calculations against your data row. +When you add a dynamic column, the first argument that is passed in to the given callable is the current data row. You can use this to perform calculations against your data row. For example, we can use the data available in the row to guess the gender of a student. :: @@ -217,9 +217,9 @@ For example, we can use the data available in the row to guess the gender of a s """Calculates gender of given student data row.""" m_names = ('Kenneth', 'Mike', 'Yuri') f_names = ('Bessie', 'Samantha', 'Heather') - + name = row[0] - + if name in m_names: return 'Male' elif name in f_names: @@ -243,8 +243,8 @@ Filtering Datasets with Tags .. versionadded:: 0.9.0 -When constructing a :class:`Dataset` object, you can add tags to rows by specifying the ``tags`` parameter. -This allows you to filter your :class:`Dataset` later. This can be useful so separate rows of data based on +When constructing a :class:`Dataset` object, you can add tags to rows by specifying the ``tags`` parameter. +This allows you to filter your :class:`Dataset` later. This can be useful so separate rows of data based on arbitrary criteria (*e.g.* origin) that you don't want to include in your :class:`Dataset`. Let's tag some students. :: @@ -266,10 +266,10 @@ It's that simple. The original :class:`Dataset` is untouched. Excel Workbook With Multiple Sheets ------------------------------------- +------------------------------------ When dealing with a large number of :class:`Datasets <Dataset>` in spreadsheet format, it's quite common to group multiple spreadsheets into a single Excel file, known as a Workbook. Tablib makes it extremely easy to build workbooks with the handy, :class:`Databook` class. - + Let's say we have 3 different :class:`Datasets <Dataset>`. All we have to do is add then to a :class:`Databook` object... :: @@ -287,15 +287,15 @@ The resulting **students.xls** file will contain a separate spreadsheet for each Make sure to open the output file in binary mode. -.. _seperators: +.. _separators: ---------- -Seperators +Separators ---------- .. versionadded:: 0.8.2 -When, it's often useful to create a blank row containing information on the upcoming data. So, +When, it's often useful to create a blank row containing information on the upcoming data. So, @@ -305,24 +305,24 @@ When, it's often useful to create a blank row containing information on the upco ('11/24/09', 'Math 101 Mid-term Exam', 56.), ('05/24/10', 'Math 101 Final Exam', 62.) ] - + suzie_tests = [ ('11/24/09', 'Math 101 Mid-term Exam', 56.), ('05/24/10', 'Math 101 Final Exam', 62.) ] - + # Create new dataset tests = tablib.Dataset() tests.headers = ['Date', 'Test Name', 'Grade'] # Daniel's Tests - tests.append_seperator('Daniel\'s Scores') + tests.append_separator('Daniel\'s Scores') for test_row in daniel_tests: tests.append(test_row) # Susie's Tests - tests.append_seperator('Susie\'s Scores') + tests.append_separator('Susie\'s Scores') for test_row in suzie_tests: tests.append(test_row) @@ -331,7 +331,7 @@ When, it's often useful to create a blank row containing information on the upco with open('grades.xls', 'wb') as f: f.write(tests.xls) -The resulting **tests.xls** will have the following layout: +The resulting **tests.xls** will have the following layout: Daniel's Scores: @@ -347,7 +347,7 @@ The resulting **tests.xls** will have the following layout: .. admonition:: Format Support At this time, only :class:`Excel <Dataset.xls>` output supports separators. - + ---- Now, go check out the :ref:`API Documentation <api>` or begin :ref:`Tablib Development <development>`. |
