Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
string Namespace Reference

Functions

def lower
 
def upper
 
def swapcase
 
def strip
 
def lstrip
 
def rstrip
 
def split
 
def join
 
def index
 
def rindex
 
def count
 
def find
 
def rfind
 
def atof
 
def atoi
 
def atol
 
def ljust
 
def rjust
 
def center
 
def zfill
 
def expandtabs
 
def translate
 
def capitalize
 
def capwords
 
def maketrans
 
def replace
 

Variables

string whitespace = ' \t\n\r\v\f'
 
string lowercase = 'abcdefghijklmnopqrstuvwxyz'
 
string uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
 letters = lowercase+uppercase
 
 ascii_lowercase = lowercase
 
 ascii_uppercase = uppercase
 
 ascii_letters = ascii_lowercase+ascii_uppercase
 
string digits = '0123456789'
 
string hexdigits = digits+'abcdef'
 
string octdigits = '01234567'
 
string punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
 
 printable = digits+letters+punctuation+whitespace
 
string _idmap = ''
 
 index_error = ValueError
 
 atoi_error = ValueError
 
 atof_error = ValueError
 
 atol_error = ValueError
 
 splitfields = split
 
 joinfields = join
 
 _float = float
 
 _int = int
 
 _long = long
 
tuple _StringType = type('')
 
 _idmapL = None
 

Detailed Description

A collection of string operations (most are no longer used in Python 1.6).

Warning: most of the code you see here isn't normally used nowadays.  With
Python 1.6, many of these functions are implemented as methods on the
standard string object. They used to be implemented by a built-in module
called strop, but strop is now obsolete itself.

Public module variables:

whitespace -- a string containing all characters considered whitespace
lowercase -- a string containing all characters considered lowercase letters
uppercase -- a string containing all characters considered uppercase letters
letters -- a string containing all characters considered letters
digits -- a string containing all characters considered decimal digits
hexdigits -- a string containing all characters considered hexadecimal digits
octdigits -- a string containing all characters considered octal digits
punctuation -- a string containing all characters considered punctuation
printable -- a string containing all characters considered printable

Function Documentation

def string.atof (   s)
atof(s) -> float

Return the floating point number represented by the string s.

Definition at line 196 of file string.py.

References _float.

197 def atof(s):
198  """atof(s) -> float
199 
200  Return the floating point number represented by the string s.
201 
202  """
203  return _float(s)
204 
205 
# Convert string to integer
def string.atoi (   s,
  base = 10 
)
atoi(s [,base]) -> int

Return the integer represented by the string s in the given
base, which defaults to 10.  The string s must consist of one
or more digits, possibly preceded by a sign.  If base is 0, it
is chosen from the leading characters of s, 0 for octal, 0x or
0X for hexadecimal.  If base is 16, a preceding 0x or 0X is
accepted.

Definition at line 206 of file string.py.

References _int.

207 def atoi(s , base=10):
208  """atoi(s [,base]) -> int
209 
210  Return the integer represented by the string s in the given
211  base, which defaults to 10. The string s must consist of one
212  or more digits, possibly preceded by a sign. If base is 0, it
213  is chosen from the leading characters of s, 0 for octal, 0x or
214  0X for hexadecimal. If base is 16, a preceding 0x or 0X is
215  accepted.
216 
217  """
218  return _int(s, base)
219 
220 
# Convert string to long integer
def string.atol (   s,
  base = 10 
)
atol(s [,base]) -> long

Return the long integer represented by the string s in the
given base, which defaults to 10.  The string s must consist
of one or more digits, possibly preceded by a sign.  If base
is 0, it is chosen from the leading characters of s, 0 for
octal, 0x or 0X for hexadecimal.  If base is 16, a preceding
0x or 0X is accepted.  A trailing L or l is not accepted,
unless base is 0.

Definition at line 221 of file string.py.

References _long.

222 def atol(s, base=10):
223  """atol(s [,base]) -> long
224 
225  Return the long integer represented by the string s in the
226  given base, which defaults to 10. The string s must consist
227  of one or more digits, possibly preceded by a sign. If base
228  is 0, it is chosen from the leading characters of s, 0 for
229  octal, 0x or 0X for hexadecimal. If base is 16, a preceding
230  0x or 0X is accepted. A trailing L or l is not accepted,
231  unless base is 0.
232 
233  """
234  return _long(s, base)
235 
236 
# Left-justify a string
def string.capitalize (   s)
capitalize(s) -> string

Return a copy of the string s with only its first character
capitalized.

Definition at line 320 of file string.py.

321 def capitalize(s):
322  """capitalize(s) -> string
323 
324  Return a copy of the string s with only its first character
325  capitalized.
326 
327  """
328  return s.capitalize()
329 
330 # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
# See also regsub.capwords().
def string.capwords (   s,
  sep = None 
)
capwords(s, [sep]) -> string

Split the argument into words using split, capitalize each
word using capitalize, and join the capitalized words using
join. Note that this replaces runs of whitespace characters by
a single space.

Definition at line 331 of file string.py.

References join().

332 def capwords(s, sep=None):
333  """capwords(s, [sep]) -> string
334 
335  Split the argument into words using split, capitalize each
336  word using capitalize, and join the capitalized words using
337  join. Note that this replaces runs of whitespace characters by
338  a single space.
339 
340  """
341  return join(map(capitalize, s.split(sep)), sep or ' ')
342 
# Construct a translation string
def string.center (   s,
  width 
)
center(s, width) -> string

Return a center version of s, in a field of the specified
width. padded with spaces as needed.  The string is never
truncated.

Definition at line 259 of file string.py.

260 def center(s, width):
261  """center(s, width) -> string
262 
263  Return a center version of s, in a field of the specified
264  width. padded with spaces as needed. The string is never
265  truncated.
266 
267  """
268  return s.center(width)
269 
270 # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
271 # Decadent feature: the argument may be a string or a number
# (Use of this is deprecated; it should be a string as with ljust c.s.)
def string.count (   s,
  args 
)
count(s, sub[, start[,end]]) -> int

Return the number of occurrences of substring sub in string
s[start:end].  Optional arguments start and end are
interpreted as in slice notation.

Definition at line 153 of file string.py.

154 def count(s, *args):
155  """count(s, sub[, start[,end]]) -> int
156 
157  Return the number of occurrences of substring sub in string
158  s[start:end]. Optional arguments start and end are
159  interpreted as in slice notation.
160 
161  """
162  return s.count(*args)
163 
# Find substring, return -1 if not found
def string.expandtabs (   s,
  tabsize = 8 
)
expandtabs(s [,tabsize]) -> string

Return a copy of the string s with all tab characters replaced
by the appropriate number of spaces, depending on the current
column, and the tabsize (default 8).

Definition at line 290 of file string.py.

291 def expandtabs(s, tabsize=8):
292  """expandtabs(s [,tabsize]) -> string
293 
294  Return a copy of the string s with all tab characters replaced
295  by the appropriate number of spaces, depending on the current
296  column, and the tabsize (default 8).
297 
298  """
299  return s.expandtabs(tabsize)
300 
# Character translation through look-up table.
def string.find (   s,
  args 
)
find(s, sub [,start [,end]]) -> in

Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

Definition at line 164 of file string.py.

165 def find(s, *args):
166  """find(s, sub [,start [,end]]) -> in
167 
168  Return the lowest index in s where substring sub is found,
169  such that sub is contained within s[start,end]. Optional
170  arguments start and end are interpreted as in slice notation.
171 
172  Return -1 on failure.
173 
174  """
175  return s.find(*args)
176 
# Find last substring, return -1 if not found
def string.index (   s,
  args 
)
index(s, sub [,start [,end]]) -> int

Like find but raises ValueError when the substring is not found.

Definition at line 135 of file string.py.

136 def index(s, *args):
137  """index(s, sub [,start [,end]]) -> int
138 
139  Like find but raises ValueError when the substring is not found.
140 
141  """
142  return s.index(*args)
143 
# Find last substring, raise exception if not found
def string.join (   words,
  sep = ' ' 
)
join(list [,sep]) -> string

Return a string composed of the words in list, with
intervening occurrences of sep.  The default separator is a
single space.

(joinfields and join are synonymous)

Definition at line 121 of file string.py.

122 def join(words, sep = ' '):
123  """join(list [,sep]) -> string
124 
125  Return a string composed of the words in list, with
126  intervening occurrences of sep. The default separator is a
127  single space.
128 
129  (joinfields and join are synonymous)
130 
131  """
return sep.join(words)
def string.ljust (   s,
  width 
)
ljust(s, width) -> string

Return a left-justified version of s, in a field of the
specified width, padded with spaces as needed.  The string is
never truncated.

Definition at line 237 of file string.py.

238 def ljust(s, width):
239  """ljust(s, width) -> string
240 
241  Return a left-justified version of s, in a field of the
242  specified width, padded with spaces as needed. The string is
243  never truncated.
244 
245  """
246  return s.ljust(width)
247 
# Right-justify a string
def string.lower (   s)
lower(s) -> string

Return a copy of the string s converted to lowercase.

Definition at line 48 of file string.py.

48 
49 def lower(s):
50  """lower(s) -> string
51 
52  Return a copy of the string s converted to lowercase.
53 
54  """
55  return s.lower()
56 
# Convert lower case letters to UPPER CASE
def string.lstrip (   s)
lstrip(s) -> string

Return a copy of the string s with leading whitespace removed.

Definition at line 86 of file string.py.

86 
87 def lstrip(s):
88  """lstrip(s) -> string
89 
90  Return a copy of the string s with leading whitespace removed.
91 
92  """
93  return s.lstrip()
94 
# Strip trailing tabs and spaces
def string.maketrans (   fromstr,
  tostr 
)
maketrans(frm, to) -> string

Return a translation table (a string of 256 bytes long)
suitable for use in string.translate.  The strings frm and to
must be of the same length.

Definition at line 344 of file string.py.

References join().

345 def maketrans(fromstr, tostr):
346  """maketrans(frm, to) -> string
347 
348  Return a translation table (a string of 256 bytes long)
349  suitable for use in string.translate. The strings frm and to
350  must be of the same length.
351 
352  """
353  if len(fromstr) != len(tostr):
354  raise ValueError, "maketrans arguments must have same length"
355  global _idmapL
356  if not _idmapL:
357  _idmapL = map(None, _idmap)
358  L = _idmapL[:]
359  fromstr = map(ord, fromstr)
360  for i in range(len(fromstr)):
361  L[fromstr[i]] = tostr[i]
362  return join(L, "")
363 
# Substring replacement (global)
def string.replace (   s,
  old,
  new,
  maxsplit = -1 
)
replace (str, old, new[, maxsplit]) -> string

Return a copy of string str with all occurrences of substring
old replaced by new. If the optional argument maxsplit is
given, only the first maxsplit occurrences are replaced.

Definition at line 364 of file string.py.

365 def replace(s, old, new, maxsplit=-1):
366  """replace (str, old, new[, maxsplit]) -> string
367 
368  Return a copy of string str with all occurrences of substring
369  old replaced by new. If the optional argument maxsplit is
370  given, only the first maxsplit occurrences are replaced.
371 
372  """
373  return s.replace(old, new, maxsplit)
374 
375 
376 # Try importing optional built-in module "strop" -- if it exists,
377 # it redefines some string operations that are 100-1000 times faster.
378 # It also defines values for whitespace, lowercase and uppercase
379 # that match <ctype.h>'s definitions.
380 
381 try:
382  from strop import maketrans, lowercase, uppercase, whitespace
letters = lowercase + uppercase
def string.rfind (   s,
  args 
)
rfind(s, sub [,start [,end]]) -> int

Return the highest index in s where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

Definition at line 177 of file string.py.

178 def rfind(s, *args):
179  """rfind(s, sub [,start [,end]]) -> int
180 
181  Return the highest index in s where substring sub is found,
182  such that sub is contained within s[start,end]. Optional
183  arguments start and end are interpreted as in slice notation.
184 
185  Return -1 on failure.
186 
187  """
188  return s.rfind(*args)
189 
# for a bit of speed
def string.rindex (   s,
  args 
)
rindex(s, sub [,start [,end]]) -> int

Like rfind but raises ValueError when the substring is not found.

Definition at line 144 of file string.py.

145 def rindex(s, *args):
146  """rindex(s, sub [,start [,end]]) -> int
147 
148  Like rfind but raises ValueError when the substring is not found.
149 
150  """
151  return s.rindex(*args)
152 
# Count non-overlapping occurrences of substring
def string.rjust (   s,
  width 
)
rjust(s, width) -> string

Return a right-justified version of s, in a field of the
specified width, padded with spaces as needed.  The string is
never truncated.

Definition at line 248 of file string.py.

249 def rjust(s, width):
250  """rjust(s, width) -> string
251 
252  Return a right-justified version of s, in a field of the
253  specified width, padded with spaces as needed. The string is
254  never truncated.
255 
256  """
257  return s.rjust(width)
258 
# Center a string
def string.rstrip (   s)
rstrip(s) -> string

Return a copy of the string s with trailing whitespace
removed.

Definition at line 95 of file string.py.

95 
96 def rstrip(s):
97  """rstrip(s) -> string
98 
99  Return a copy of the string s with trailing whitespace
100  removed.
101 
102  """
103  return s.rstrip()
104 
105 
# Split a string into a list of space/tab-separated words
def string.split (   s,
  sep = None,
  maxsplit = -1 
)
split(s [,sep [,maxsplit]]) -> list of strings

Return a list of the words in the string s, using sep as the
delimiter string.  If maxsplit is given, splits at no more than
maxsplit places (resulting in at most maxsplit+1 words).  If sep
is not specified, any whitespace string is a separator.

(split and splitfields are synonymous)

Definition at line 106 of file string.py.

107 def split(s, sep=None, maxsplit=-1):
108  """split(s [,sep [,maxsplit]]) -> list of strings
109 
110  Return a list of the words in the string s, using sep as the
111  delimiter string. If maxsplit is given, splits at no more than
112  maxsplit places (resulting in at most maxsplit+1 words). If sep
113  is not specified, any whitespace string is a separator.
114 
115  (split and splitfields are synonymous)
116 
117  """
return s.split(sep, maxsplit)
def string.strip (   s)
strip(s) -> string

Return a copy of the string s with leading and trailing
whitespace removed.

Definition at line 76 of file string.py.

76 
77 def strip(s):
78  """strip(s) -> string
79 
80  Return a copy of the string s with leading and trailing
81  whitespace removed.
82 
83  """
84  return s.strip()
85 
# Strip leading tabs and spaces
def string.swapcase (   s)
swapcase(s) -> string

Return a copy of the string s with upper case characters
converted to lowercase and vice versa.

Definition at line 66 of file string.py.

66 
67 def swapcase(s):
68  """swapcase(s) -> string
69 
70  Return a copy of the string s with upper case characters
71  converted to lowercase and vice versa.
72 
73  """
74  return s.swapcase()
75 
# Strip leading and trailing tabs and spaces
def string.translate (   s,
  table,
  deletions = "" 
)
translate(s,table [,deletions]) -> string

Return a copy of the string s, where all characters occurring
in the optional argument deletions are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256.  The
deletions argument is not allowed for Unicode strings.

Definition at line 301 of file string.py.

302 def translate(s, table, deletions=""):
303  """translate(s,table [,deletions]) -> string
304 
305  Return a copy of the string s, where all characters occurring
306  in the optional argument deletions are removed, and the
307  remaining characters have been mapped through the given
308  translation table, which must be a string of length 256. The
309  deletions argument is not allowed for Unicode strings.
310 
311  """
312  if deletions:
313  return s.translate(table, deletions)
314  else:
315  # Add s[:0] so that if s is Unicode and table is an 8-bit string,
316  # table is converted to Unicode. This means that table *cannot*
317  # be a dictionary -- for that feature, use u.translate() directly.
318  return s.translate(table + s[:0])
319 
# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
def string.upper (   s)
upper(s) -> string

Return a copy of the string s converted to uppercase.

Definition at line 57 of file string.py.

57 
58 def upper(s):
59  """upper(s) -> string
60 
61  Return a copy of the string s converted to uppercase.
62 
63  """
64  return s.upper()
65 
# Swap lower case letters and UPPER CASE
def string.zfill (   x,
  width 
)
zfill(x, width) -> string

Pad a numeric string x with zeros on the left, to fill a field
of the specified width.  The string x is never truncated.

Definition at line 272 of file string.py.

273 def zfill(x, width):
274  """zfill(x, width) -> string
275 
276  Pad a numeric string x with zeros on the left, to fill a field
277  of the specified width. The string x is never truncated.
278 
279  """
280  if type(x) == type(''): s = x
281  else: s = `x`
282  n = len(s)
283  if n >= width: return s
284  sign = ''
285  if s[0] in ('-', '+'):
286  sign, s = s[0], s[1:]
287  return sign + '0'*(width-n) + s
288 
289 # Expand tabs in a string.
# Doesn't take non-printing chars into account, but does understand \n.

Variable Documentation

_float = float

Definition at line 190 of file string.py.

string _idmap = ''

Definition at line 37 of file string.py.

_idmapL = None

Definition at line 343 of file string.py.

_int = int

Definition at line 191 of file string.py.

_long = long

Definition at line 192 of file string.py.

tuple _StringType = type('')

Definition at line 193 of file string.py.

ascii_letters = ascii_lowercase+ascii_uppercase

Definition at line 29 of file string.py.

ascii_lowercase = lowercase

Definition at line 27 of file string.py.

ascii_uppercase = uppercase

Definition at line 28 of file string.py.

atof_error = ValueError

Definition at line 44 of file string.py.

atoi_error = ValueError

Definition at line 43 of file string.py.

atol_error = ValueError

Definition at line 45 of file string.py.

string digits = '0123456789'

Definition at line 30 of file string.py.

string hexdigits = digits+'abcdef'

Definition at line 31 of file string.py.

index_error = ValueError

Definition at line 42 of file string.py.

joinfields = join

Definition at line 132 of file string.py.

letters = lowercase+uppercase

Definition at line 26 of file string.py.

string lowercase = 'abcdefghijklmnopqrstuvwxyz'

Definition at line 24 of file string.py.

string octdigits = '01234567'

Definition at line 32 of file string.py.

printable = digits+letters+punctuation+whitespace

Definition at line 34 of file string.py.

string punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""

Definition at line 33 of file string.py.

splitfields = split

Definition at line 118 of file string.py.

string uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

Definition at line 25 of file string.py.

string whitespace = ' \t\n\r\v\f'

Definition at line 23 of file string.py.