Ignore:
Timestamp:
10/18/19 00:13:27 (5 years ago)
Author:
jdquinn
Message:

BUG: Extra spaces (committing progress, but grep and manual fix is taking too long; will talk tomorrow to Basile about reverting and modifying his syntax parsing script)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/qmu/helpers.py

    r24213 r24254  
    2424Example uses:
    2525
    26 x = Lstruct(1, 2, 3, 4) - > [1, 2, 3, 4]
     26x = Lstruct(1, 2, 3, 4) -> [1, 2, 3, 4]
    2727    x.a = 'hello'
    28     len(x) - > 4
     28    len(x) -> 4
    2929    x.append(5)
    30     len(x) - > 5
    31     x[2] - > 3
    32     x.a - > 'hello'
    33     print x - > [1, 2, 3, 4, 5]
    34     x.__dict__ - > {'a': 'hello'}
     30    len(x) -> 5
     31    x[2] -> 3
     32    x.a -> 'hello'
     33    print x -> [1, 2, 3, 4, 5]
     34    x.__dict__ -> {'a':'hello'}
    3535    x.b = [6, 7, 8, 9]
    36     x.b[-1] - > 9
    37     len(x.b) - > 4
     36    x.b[-1] -> 9
     37    len(x.b) -> 4
    3838
    3939Other valid constructors:
    40           x = Lstruct(1, 2, 3, a = 'hello') - > x.a - > 'hello', x - > [1, 2, 3]
     40          x = Lstruct(1, 2, 3, a = 'hello') -> x.a -> 'hello', x -> [1, 2, 3]
    4141          x = Lstruct(1, 2, 3)(a = 'hello')
    4242          x = Lstruct([1, 2, 3], x = 'hello')
    4343          x = Lstruct((1, 2, 3), a = 'hello')
    4444
    45 Credit: https: / / github.com / Vectorized / Python - Attribute-List
     45Credit: https://github.com/Vectorized/Python-Attribute-List
    4646'''
    4747
     
    6363class OrderedStruct(object):
    6464    '''
    65 A form of dictionary - like structure that maintains the
     65A form of dictionary-like structure that maintains the
    6666    ordering in which its fields / attributes and their
    6767    corresponding values were added.
     
    7070    can be used as an "ordered struct / class" giving
    7171    it much more flexibility in practice. It is
    72     also easier to work with fixed valued keys in - code.
     72    also easier to work with fixed valued keys in-code.
    7373
    7474Eg:
     
    7979    x.y = 5
    8080    OR
    81     x['y'] = 5  # supports OrderedDict - style usage
    82 
    83 Supports: len(x), str(x), for - loop iteration.
     81    x['y'] = 5  # supports OrderedDict-style usage
     82
     83Supports: len(x), str(x), for-loop iteration.
    8484Has methods: x.keys(), x.values(), x.items(), x.iterkeys()
    8585
     
    9494    #    in the same order as the inputs
    9595
    96     x.keys() - > ['y', 'z']
    97     x.values() - > [5, 6]
    98     x.items() - > [('y', 6), ('z', 6)]
    99     x.__dict__ - > [('y', 6), ('z', 6)]
    100     vars(x) - > [('y', 6), ('z', 6)]
    101 
    102     x.y - > 5
    103     x['y'] - > 5
    104     x.z - > 6
    105     x['z'] - > 6
     96    x.keys() -> ['y', 'z']
     97    x.values() -> [5, 6]
     98    x.items() -> [('y', 6), ('z', 6)]
     99    x.__dict__ -> [('y', 6), ('z', 6)]
     100    vars(x) -> [('y', 6), ('z', 6)]
     101
     102    x.y -> 5
     103    x['y'] -> 5
     104    x.z -> 6
     105    x['z'] -> 6
    106106
    107107    for i in x:  # same as x.items()
    108108        print i
    109      - >
     109     ->
    110110    ('x', 5)
    111111    ('y', 6)
     
    197197        # same thing but call deepcopy recursively
    198198        # technically not how it should be done,
    199         # (see https: / / docs.python.org / 2 / library / copy.html  #copy.deepcopy )
     199        # (see https://docs.python.org/2/library/copy.html  #copy.deepcopy )
    200200        # but will generally work in this case
    201201        newInstance = type(self)()
     
    227227def isempty(x):
    228228    '''
    229     returns true if object is +  - infinity, NaN, None, '', has length 0, or is an
    230     array / matrix composed only of such components (includes mixtures of "empty" types)'''
     229    returns true if object is +  -infinity, NaN, None, '', has length 0, or is an
     230    array/matrix composed only of such components (includes mixtures of "empty" types)'''
    231231
    232232    if type(x) in [list, np.ndarray, tuple]:
     
    247247    if x is None:
    248248        return True
    249     if type(x) == str and x.lower() in ['', 'nan', 'none', 'inf', 'infinity', ' - inf', ' - infinity']:
     249    if type(x) == str and x.lower() in ['', 'nan', 'none', 'inf', 'infinity', '-inf', '-infinity']:
    250250        return True
    251251
     
    280280def fileparts(x):
    281281    '''
    282     given:   "path / path / ... / file_name.ext"
     282    given:   "path/path/.../file_name.ext"
    283283    returns: [path, file_name, ext] (list of strings)'''
    284284    try:
     
    300300
    301301    fullfile(path, path, ... , file_name + ext)
    302     returns: "path / path / ... / file_name.ext"
    303 
    304     with all arguments as strings with no " / "s
     302    returns: "path/path/.../file_name.ext"
     303
     304    with all arguments as strings with no "/"s
    305305
    306306    regarding extensions and the '.':
     
    331331def empty_nd_list(shape, filler=0., as_numpy_ndarray=False):
    332332    '''
    333 returns a python list of the size / shape given (shape must be int or tuple)
     333returns a python list of the size/shape given (shape must be int or tuple)
    334334    the list will be filled with the optional second argument
    335335
     
    338338    as_numpy_ndarray will return the result as a numpy.ndarray and is False by default
    339339
    340     Note: the filler must be either None / np.nan / float('NaN'), float / double, or int
    341         other numpy and float values such as + / - np.inf will also work
     340    Note: the filler must be either None/np.nan/float('NaN'), float/double, or int
     341        other numpy and float values such as +/- np.inf will also work
    342342
    343343use:
Note: See TracChangeset for help on using the changeset viewer.