* Added slice_str for easy printout of a slice object in python typical slice

syntax (e.g. 0:10: or 0:10:3 or :10:3, etc).
master
wirawan 15 years ago
parent 733c518735
commit ed52cd4af0
  1. 10
      text_tools.py

@ -1,4 +1,4 @@
# $Id: text_tools.py,v 1.2 2010-01-22 18:50:09 wirawan Exp $ # $Id: text_tools.py,v 1.3 2010-02-24 14:28:13 wirawan Exp $
# #
# wpylib.text_tools # wpylib.text_tools
# Created: 20091204 # Created: 20091204
@ -8,6 +8,7 @@
# #
import numpy import numpy
from wpylib.sugar import ifelse
def make_matrix(Str, debug=None): def make_matrix(Str, debug=None):
"""Simple tool to convert a string like """Simple tool to convert a string like
@ -103,4 +104,11 @@ def str_expand(template, params, maxiter=100):
return str1 return str1
def slice_str(s):
return "%s:%s:%s" % (
ifelse(s.start == None, "", str(s.start)),
ifelse(s.stop == None, "", str(s.stop)),
ifelse(s.step == None, "", str(s.step)),
)

Loading…
Cancel
Save