Changeset 2385 in lmdz_wrf for trunk/tools
- Timestamp:
- Mar 8, 2019, 4:41:18 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2380 r2385 158 158 # Nstr: Function to transform a number to string, but making sure it preserves 159 159 # characteristics of the number 160 # Ntchar: Function to repeat a number of times a given tring160 # Ntchar: Function to repeat a number of times a given string 161 161 # num_chainSnum: Function to pass a value to a `ChainStrNum' number 162 162 # num_ordinal: Function to provide the ordinal of a given number, language, format and gender … … 178 178 # intervals for a sub-set of the dimensions in order to avoid memory problems 179 179 # rectangular_spiral: Function to provide a rectangular spiral (along x,y-axis values) of values 180 # remove_extraspaces: Function to remove from a string any chain of more or equal than 2 spaces 180 181 # remove_monotones: Function to remove the monotones (len(dim) = 1) from an array 181 182 # replace_list: Function to replace a value in a given list … … 15383 15384 # for j in range(4): 15384 15385 # print ' ' , '(', inds[i,j,0], ',', inds[i,j,1], ')' 15386 15387 def remove_extraspaces(string, maxNspaces=30): 15388 """ Function to remove from a string any chain of more or equal than 2 spaces 15389 string: string to modify 15390 maxNspaces: maximum number of consecutive spaces to look for (30 default value) 15391 >>> remove_extraspaces(' 87047 01011991 6 19.0 6 70 7 27 2 17.9 874.9 1471.0 1 2 4 5 1 0 ') 15392 87047 01011991 6 19.0 6 70 7 27 2 17.9 874.9 1471.0 1 2 4 5 1 0 15393 """ 15394 fname = 'remove_extraspaces' 15395 15396 newstring = string + '' 15397 for i in range(maxNspaces,1,-1): 15398 spaces = Ntchar(' ',i) 15399 newstring = newstring.replace(spaces, ' ') 15400 15401 return newstring 15402 15385 15403 #quit() 15386 15404
Note: See TracChangeset
for help on using the changeset viewer.