##// END OF EJS Templates
Fix docstrings in utils.text
Thomas Kluyver -
Show More
@@ -225,6 +225,7 b' class SList(list):'
225 225 """ sort by specified fields (see fields())
226 226
227 227 Example::
228
228 229 a.sort(1, nums = True)
229 230
230 231 Sorts a by second field, in numerical order (so that 21 > 3)
@@ -310,6 +311,7 b' def list_strings(arg):'
310 311 as input.
311 312
312 313 :Examples:
314 ::
313 315
314 316 In [7]: list_strings('A single string')
315 317 Out[7]: ['A single string']
@@ -329,6 +331,7 b" def marquee(txt='',width=78,mark='*'):"
329 331 """Return the input string centered in a 'marquee'.
330 332
331 333 :Examples:
334 ::
332 335
333 336 In [16]: marquee('A test',40)
334 337 Out[16]: '**************** A test ****************'
@@ -499,13 +502,14 b' class EvalFormatter(Formatter):'
499 502
500 503 Examples
501 504 --------
502
503 In [1]: f = EvalFormatter()
504 In [2]: f.format('{n//4}', n=8)
505 Out [2]: '2'
506
507 In [3]: f.format("{greeting[slice(2,4)]}", greeting="Hello")
508 Out [3]: 'll'
505 ::
506
507 In [1]: f = EvalFormatter()
508 In [2]: f.format('{n//4}', n=8)
509 Out[2]: '2'
510
511 In [3]: f.format("{greeting[slice(2,4)]}", greeting="Hello")
512 Out[3]: 'll'
509 513 """
510 514 def get_field(self, name, args, kwargs):
511 515 v = eval(name, kwargs)
@@ -524,16 +528,17 b' class FullEvalFormatter(Formatter):'
524 528
525 529 Examples
526 530 --------
527
528 In [1]: f = FullEvalFormatter()
529 In [2]: f.format('{n//4}', n=8)
530 Out[2]: u'2'
531
532 In [3]: f.format('{list(range(5))[2:4]}')
533 Out[3]: u'[2, 3]'
531 ::
532
533 In [1]: f = FullEvalFormatter()
534 In [2]: f.format('{n//4}', n=8)
535 Out[2]: u'2'
536
537 In [3]: f.format('{list(range(5))[2:4]}')
538 Out[3]: u'[2, 3]'
534 539
535 In [4]: f.format('{3*2}')
536 Out[4]: u'6'
540 In [4]: f.format('{3*2}')
541 Out[4]: u'6'
537 542 """
538 543 # copied from Formatter._vformat with minor changes to allow eval
539 544 # and replace the format_spec code with slicing
@@ -578,15 +583,17 b' class DollarFormatter(FullEvalFormatter):'
578 583
579 584 Examples
580 585 --------
581 In [1]: f = DollarFormatter()
582 In [2]: f.format('{n//4}', n=8)
583 Out[2]: u'2'
584
585 In [3]: f.format('23 * 76 is $result', result=23*76)
586 Out[3]: u'23 * 76 is 1748'
587
588 In [4]: f.format('$a or {b}', a=1, b=2)
589 Out[4]: u'1 or 2'
586 ::
587
588 In [1]: f = DollarFormatter()
589 In [2]: f.format('{n//4}', n=8)
590 Out[2]: u'2'
591
592 In [3]: f.format('23 * 76 is $result', result=23*76)
593 Out[3]: u'23 * 76 is 1748'
594
595 In [4]: f.format('$a or {b}', a=1, b=2)
596 Out[4]: u'1 or 2'
590 597 """
591 598 _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)")
592 599 def parse(self, fmt_string):
@@ -649,7 +656,7 b' def compute_item_matrix(items, empty=None, *args, **kwargs) :'
649 656 Parameters
650 657 ----------
651 658
652 items :
659 items
653 660 list of strings to columize
654 661 empty : (default None)
655 662 default value to fill list if needed
@@ -661,39 +668,41 b' def compute_item_matrix(items, empty=None, *args, **kwargs) :'
661 668 Returns
662 669 -------
663 670
664 Returns a tuple of (strings_matrix, dict_info)
665
666 strings_matrix :
671 strings_matrix
667 672
668 673 nested list of string, the outer most list contains as many list as
669 674 rows, the innermost lists have each as many element as colums. If the
670 675 total number of elements in `items` does not equal the product of
671 676 rows*columns, the last element of some lists are filled with `None`.
672 677
673 dict_info :
678 dict_info
674 679 some info to make columnize easier:
675 680
676 columns_numbers : number of columns
677 rows_numbers : number of rows
678 columns_width : list of with of each columns
679 optimal_separator_width : best separator width between columns
681 columns_numbers
682 number of columns
683 rows_numbers
684 number of rows
685 columns_width
686 list of with of each columns
687 optimal_separator_width
688 best separator width between columns
680 689
681 690 Examples
682 691 --------
683
684 In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
685 ...: compute_item_matrix(l,displaywidth=12)
686 Out[1]:
687 ([['aaa', 'f', 'k'],
688 ['b', 'g', 'l'],
689 ['cc', 'h', None],
690 ['d', 'i', None],
691 ['eeeee', 'j', None]],
692 {'columns_numbers': 3,
693 'columns_width': [5, 1, 1],
694 'optimal_separator_width': 2,
695 'rows_numbers': 5})
696
692 ::
693
694 In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
695 ...: compute_item_matrix(l,displaywidth=12)
696 Out[1]:
697 ([['aaa', 'f', 'k'],
698 ['b', 'g', 'l'],
699 ['cc', 'h', None],
700 ['d', 'i', None],
701 ['eeeee', 'j', None]],
702 {'columns_numbers': 3,
703 'columns_width': [5, 1, 1],
704 'optimal_separator_width': 2,
705 'rows_numbers': 5})
697 706 """
698 707 info = _find_optimal(list(map(len, items)), *args, **kwargs)
699 708 nrow, ncol = info['rows_numbers'], info['columns_numbers']
General Comments 0
You need to be logged in to leave comments. Login now