Package osh :: Package command :: Module expand
[frames] | no frames]

Module expand

source code

expand [POSITION]

Receives a stream of sequences as input. If POSITION is omitted, then each item of the sequence is generated as a separate 1-tuple in the output stream.

Example: If the input contains these sequences:

   ('a', 'b')
   ('c', 'd')

then expand generates this output:

   ('a',)
   ('b',)
   ('c',)
   ('d',)

If POSITION is specified, then each input sequence is used to generate zero or more output sequences. In each output sequence, the item at the selected position is replaced by one component of the selected object.

The types that can be expanded are list, tuple, generator, and osh.file.File. Expansion of a osh.file.File yields each line of the named file.

Example: If the input contains these sequences:

   ('a', [1, 2, 3], 'x')
   ('b', [4, 5], 'y')
   ('c', [], 'z')

then expand 1 generates this output:

   ('a', 1, 'x')
   ('a', 2, 'x')
   ('a', 3, 'x')
   ('b', 4, 'y')
   ('b', 5, 'y')

Note that an empty nested sequence results in no output, (as for ('c', [], 'z').)

Functions
 
expand(position=None)
Flattens an input sequence by generating output sequences in which an interior element is expanded.
source code
Function Details

expand(position=None)

source code 

Flattens an input sequence by generating output sequences in which an interior element is expanded. If position is omitted, then each element of the input sequence is generated as a separate 1-tuples. If position is specified, then the item at the given position is expanded. If the element being expanded is a string, then the string is interpreted as a filename, and the expansion yields each line of the file in turn.