Skip to content

Commit 3c0208c

Browse files
committed
[doc/tutorial] Add new '__repr__' style changes
1 parent f6422bd commit 3c0208c

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

doc/tutorial.rst

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,18 @@ The Document
237237
If you loaded the example odML file, let's have a first look at the Document::
238238

239239
>>> print odmlEX
240-
<Doc 42 by D. N. Adams (2 sections)>
240+
Document 42 {author = D. N. Adams, 2 sections}
241241

242242
As you can see, the printout gives you a short summary of the Document of the
243243
loaded example odML file.
244244

245245
The print out gives you already the follwing information about the odML file:
246246

247-
- ``<...>`` indicates that you are looking at an object
248-
- ``Doc`` tells you that you are looking at an odML Document
247+
- ``Document`` tells you that you are looking at an odML Document
249248
- ``42`` is the user defined version of this odML file
250-
- ``by D. N. Adams`` states the author of the odML file
251-
- ``(2 sections)`` tells you that this odML Document has 2 Section directly
249+
- ``{...}`` provides ``author`` and number of attached sections
250+
- ``author`` states the author of the odML file, "D. N. Adams" in the example case
251+
- ``2 sections`` tells you that this odML Document has 2 Section directly
252252
appended
253253

254254
Note that the Document printout tells you nothing about the depth of the
@@ -289,7 +289,7 @@ Let's check out all attributes with the following commands::
289289
>>> print(odmlEX.date)
290290
1979-10-12
291291
>>> print(odmlEX.document)
292-
<Doc 42 by D. N. Adams (2 sections)>
292+
Document 42 {author = D. N. Adams, 2 sections}
293293
>>> print(odmlEX.parent)
294294
None
295295
>>> print(odmlEX.repository)
@@ -307,7 +307,8 @@ Sections were attached to the Document of our example odML file using the
307307
following command::
308308

309309
>>> print(odmlEX.sections)
310-
[Section[4/2] {name = TheCrew, type = crew, id = ...}, Section[1/7] {name = TheStarship, type = starship, id = ...}]
310+
[Section[4|2] {name = TheCrew, type = crew, id = ...},
311+
Section[1|7] {name = TheStarship, type = starship, id = ...}]
311312

312313
As expected from the Document printout our example contains two Sections. The
313314
printout and attributes of a Section are explained in the next chapter.
@@ -324,13 +325,13 @@ look at the first Section in the sections list attached to the Document in our
324325
example odML file::
325326

326327
>>> print(odmlEX.sections['TheCrew'])
327-
Section[4/2] {name = TheCrew, type = crew, id = ...}
328+
Section[4|2] {name = TheCrew, type = crew, id = ...}
328329
>>> print(odmlEX.sections[0])
329-
Section[4/2] {name = TheCrew, type = crew, id = ...}
330+
Section[4|2] {name = TheCrew, type = crew, id = ...}
330331
>>> print(odmlEX['TheCrew'])
331-
Section[4/2] {name = TheCrew, type = crew, id = ...}
332+
Section[4|2] {name = TheCrew, type = crew, id = ...}
332333
>>> print(odmlEX[0])
333-
Section[4/2] {name = TheCrew, type = crew, id = ...}
334+
Section[4|2] {name = TheCrew, type = crew, id = ...}
334335

335336
In the following we will call Sections explicitly by their name using the
336337
short cut notation.
@@ -339,7 +340,7 @@ The printout of a Section is similar to the Document printout and gives you
339340
already the following information:
340341

341342
- ``Section`` tells you that you are looking at an odML Section
342-
- ``[4/2]`` states that this Section has four Sections and two Properties directly attached to it
343+
- ``[4|2]`` states that this Section has four Sections and two Properties directly attached to it
343344
- ``{...}`` provides ``name``, ``type`` and ``id`` of the Section
344345
- ``name`` is the name of this Section, 'TheCrew' in the example case
345346
- ``type`` provides the type of the Section, 'crew' in the example case
@@ -394,9 +395,9 @@ Let's have a look at the attributes for the Section 'TheCrew'::
394395
>>> print(odmlEX['TheCrew'].definition)
395396
Information on the crew
396397
>>> print(odmlEX['TheCrew'].document)
397-
<Doc 42 by D. N. Adams (2 sections)>
398+
Document 42 {author = D. N. Adams, 2 sections}
398399
>>> print(odmlEX['TheCrew'].parent)
399-
<Doc 42 by D. N. Adams (2 sections)>
400+
Document 42 {author = D. N. Adams, 2 sections}
400401
>>> print(odmlEX['TheCrew'].type)
401402
crew
402403
>>> print(odmlEX['TheCrew'].reference)
@@ -414,27 +415,28 @@ To see which Sections are directly attached to the Section 'TheCrew' again use
414415
the following command::
415416

416417
>>> print(odmlEX['TheCrew'].sections)
417-
[Section[0/5] {name = Arthur Philip Dent, type = crew/person, id = ...},
418-
Section[0/5] {name = Zaphod Beeblebrox, type = crew/person, id = ...},
419-
Section[0/5] {name = Tricia Marie McMillan, type = crew/person, id = ...},
420-
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}]
418+
[Section[0|5] {name = Arthur Philip Dent, type = crew/person, id = ...},
419+
Section[0|5] {name = Zaphod Beeblebrox, type = crew/person, id = ...},
420+
Section[0|5] {name = Tricia Marie McMillan, type = crew/person, id = ...},
421+
Section[0|5] {name = Ford Prefect, type = crew/person, id = ...}]
421422

422423
Or, for accessing these sub-Sections::
423424

424425
>>> print(odmlEX['TheCrew'].sections['Ford Prefect'])
425-
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
426+
Section[0|5] {name = Ford Prefect, type = crew/person, id = ...}
426427
>>> print(odmlEX['TheCrew'].sections[3])
427-
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
428+
Section[0|5] {name = Ford Prefect, type = crew/person, id = ...}
428429
>>> print(odmlEX['TheCrew']['Ford Prefect'])
429-
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
430+
Section[0|5] {name = Ford Prefect, type = crew/person, id = ...}
430431
>>> print(odmlEX['TheCrew'][3])
431-
Section[0/5] {name = Ford Prefect, type = crew/person, id = ...}
432+
Section[0|5] {name = Ford Prefect, type = crew/person, id = ...}
432433

433434
As you learned, besides sub-Sections, a Section can also have Properties
434435
attached. Let's see which Properties are attached to the Section 'TheCrew'::
435436

436437
>>> print(odmlEX['TheCrew'].properties)
437-
[Property: {name = NameCrewMembers}, Property: {name = NoCrewMembers}]
438+
[Property: {name = NameCrewMembers},
439+
Property: {name = NoCrewMembers}]
438440

439441
The printout and attributes of a Property are explained in the next chapter.
440442

@@ -518,7 +520,7 @@ Let's check which attributes were defined for the Property 'NoCrewMembers'::
518520
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].definition)
519521
Number of crew members
520522
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].document)
521-
<Doc 42 by D. N. Adams (2 sections)>
523+
Document 42 {author = D. N. Adams, 2 sections}
522524
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].values)
523525
[4]
524526
>>> print(odmlEX['TheCrew'].properties['NoCrewMembers'].dtype)
@@ -586,7 +588,7 @@ You can check if your new Document contains actually what you created by using
586588
some of the commands you learned before::
587589

588590
>>> MYodML
589-
>>> <Doc None by None (0 sections)>
591+
>>> Document None {author = None, 0 sections}
590592

591593
As you can see, we created an "empty" Document where the version and the author
592594
attributes are not defined and no section is yet attached. You will learn how to create
@@ -623,7 +625,7 @@ Check if your new Document contains actually all attributes now::
623625
>>> print(MYodML.date)
624626
1979-10-12
625627
>>> print(MYodML.document)
626-
<Doc 42 by D. N. Adams (0 sections)>
628+
Document 42 {author = D. N. Adams, 0 sections}
627629
>>> print(MYodML.parent)
628630
None
629631
>>> print(MYodML.repository)
@@ -663,14 +665,14 @@ updated::
663665
>>> MYodML.append(sec1)
664666

665667
>>> print(MYodML)
666-
<Doc 42 by Douglas Adams (1 sections)>
668+
Document 42 {author = D. N. Adams, 1 sections}
667669
>>> print(MYodML.sections)
668-
[Section[0/0] {name = TheCrew, type = crew, id = ...}]
670+
[Section[0|0] {name = TheCrew, type = crew, id = ...}]
669671

670672
>>> print(sec1.document)
671-
<Doc 42 by D. N. Adams (1 sections)>
673+
Document 42 {author = D. N. Adams, 1 sections}
672674
>>> print(sec1.parent)
673-
<Doc 42 by D. N. Adams (1 sections)>
675+
Document 42 {author = D. N. Adams, 1 sections}
674676

675677
It is also possible to connect a Section directly to a parent object.
676678
Let's try this with the next Section we create::
@@ -681,12 +683,12 @@ Let's try this with the next Section we create::
681683
parent=sec1)
682684

683685
>>> print(sec2)
684-
Section[0/0] {name = Arthur Philip Dent, type = crew/person, id = ...}
686+
Section[0|0] {name = Arthur Philip Dent, type = crew/person, id = ...}
685687

686688
>>> print(sec2.document)
687-
<Doc 42 by D. N. Adams (1 sections)>
689+
Document 42 {author = D. N. Adams, 1 sections}
688690
>>> print(sec2.parent)
689-
[Section[1/0] {name = TheCrew, type = crew, id = ...}
691+
[Section[1|0] {name = TheCrew, type = crew, id = ...}
690692

691693
Note that all of our created Sections do not contain any Properties yet. Let's
692694
see if we can change this...
@@ -751,9 +753,9 @@ automatically update its parent attribute::
751753
>>> MYodML['TheCrew']['Arthur Philip Dent'].append(prop1)
752754

753755
>>> print(prop1.document)
754-
<Doc 42 by D. N. Adams (1 sections)>
756+
Document 42 {author = D. N. Adams, 1 sections}
755757
>>> print(prop1.parent)
756-
Section[0/1] {name = Arthur Philip Dent, type = crew/person, id = ...}
758+
Section[0|1] {name = Arthur Philip Dent, type = crew/person, id = ...}
757759

758760
Next, let us create a Property with multiple metadata entries::
759761

0 commit comments

Comments
 (0)