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