Download User Guide: Map Translator Control

Transcript
Python Scripts
Using Python
Here are a few commonly used functions.
String Manipulations
•
Create a new variable name1 by concatenating name2 and name3 with a comma space in between.
name1 = name2 + ', ' + name3;
•
Create string variable name1 from numeric variable name2.
name1 = str(name2);
•
Pad the string variable name1 to 11 characters by adding leading zeros. The indent is important in
Python because it indicates the lines within the loop.
while len(name1) < 11:
name1 = '0' + name1;
•
Create a string variable name1 by converting the string variable name2 to upper case. You must use
the import string statement earlier in the Python script to import the string library. String functions
include:
import string
name1 = string.upper(name2);
•
Change the first letter of the first word to upper case and all other letters to lower case.
string.capitalize(name1);
•
Pad the front and back of name1 with spaces to make it the length specified in width.
string.center(name1,width);
•
Convert all letters in name1 to lower case.
string.lower(name1);
•
Remove leading spaces from name1.
string.lstrip(name1);
•
Remove trailing spaces from name1.
string.rstrip(name1);
•
removes leading and trailing spaces from name1.
70