-
Notifications
You must be signed in to change notification settings - Fork 2
/
cdbs_paddescrip.py
45 lines (32 loc) · 984 Bytes
/
cdbs_paddescrip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Pad DESCRIP in CDBS reference files.
Examples
--------
>>> from cdbs_paddescrip import pad_dscrp
>>> pad_dscrp('BLAH')
'BLAH---------------------------------------------------------------'
"""
__author__ = 'Pey Lian Lim'
__organization__ = 'Space Telescope Science Institute'
def pad_dscrp(in_str, out_len=67, pad_char='-'):
"""Pad DESCRIP with dashes until required length is met.
Parameters
----------
in_str : string
String to pad.
out_len : int, optional
The required length. CDBS default is 67 char.
pad_char : char, optional
Char to pad with. CDBS default is '-'.
Returns
-------
out_str : string
Padded string.
"""
sz_str = len(in_str)
if sz_str > out_len: # truncate
out_str = in_str[:out_len]
elif sz_str < out_len: # pad
out_str = in_str + pad_char * (out_len - sz_str)
else: # no change
out_str = in_str
return out_str