Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="prev" href="module-cmd.html" /> | |
13 | <link rel="parent" href="misc.html" /> | |
14 | <link rel="next" href="shlex-objects.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>5.21 shlex -- Simple lexical analysis</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="5.20.1 Cmd Objects" | |
24 | href="Cmd-objects.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
27 | href="misc.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="5.21.1 shlex Objects" | |
30 | href="shlex-objects.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Python Library Reference</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
37 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
38 | <td class='online-navigation'><a rel="index" title="Index" | |
39 | href="genindex.html"><img src='../icons/index.png' | |
40 | border='0' height='32' alt='Index' width='32' /></A></td> | |
41 | </tr></table> | |
42 | <div class='online-navigation'> | |
43 | <b class="navlabel">Previous:</b> | |
44 | <a class="sectref" rel="prev" href="Cmd-objects.html">5.20.1 Cmd Objects</A> | |
45 | <b class="navlabel">Up:</b> | |
46 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
47 | <b class="navlabel">Next:</b> | |
48 | <a class="sectref" rel="next" href="shlex-objects.html">5.21.1 shlex Objects</A> | |
49 | </div> | |
50 | <hr /></div> | |
51 | </DIV> | |
52 | <!--End of Navigation Panel--> | |
53 | ||
54 | <H1><A NAME="SECTION0072100000000000000000"> | |
55 | 5.21 <tt class="module">shlex</tt> -- | |
56 | Simple lexical analysis</A> | |
57 | </H1> | |
58 | ||
59 | <P> | |
60 | <A NAME="module-shlex"></A> | |
61 | ||
62 | <P> | |
63 | ||
64 | <span class="versionnote">New in version 1.5.2.</span> | |
65 | ||
66 | <P> | |
67 | The <tt class="class">shlex</tt> class makes it easy to write lexical analyzers for | |
68 | simple syntaxes resembling that of the <span class="Unix">Unix</span> shell. This will often | |
69 | be useful for writing minilanguages, (for example, in run control | |
70 | files for Python applications) or for parsing quoted strings. | |
71 | ||
72 | <P> | |
73 | The <tt class="module">shlex</tt> module defines the following functions: | |
74 | ||
75 | <P> | |
76 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
77 | <td><nobr><b><tt id='l2h-1480' xml:id='l2h-1480' class="function">split</tt></b>(</nobr></td> | |
78 | <td><var>s</var><big>[</big><var>, comments</var><big>]</big><var></var>)</td></tr></table></dt> | |
79 | <dd> | |
80 | Split the string <var>s</var> using shell-like syntax. If <var>comments</var> is | |
81 | <tt class="constant">False</tt> (the default), the parsing of comments in the given | |
82 | string will be disabled (setting the <tt class="member">commenters</tt> member of the | |
83 | <tt class="class">shlex</tt> instance to the empty string). This function operates | |
84 | in POSIX mode. | |
85 | ||
86 | <span class="versionnote">New in version 2.3.</span> | |
87 | ||
88 | </dl> | |
89 | ||
90 | <P> | |
91 | The <tt class="module">shlex</tt> module defines the following class: | |
92 | ||
93 | <P> | |
94 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
95 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-1481' xml:id='l2h-1481' class="class">shlex</tt></b>(</nobr></td> | |
96 | <td><var></var><big>[</big><var>instream</var><big>[</big><var>, | |
97 | infile</var><big>[</big><var>, posix</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
98 | <dd> | |
99 | A <tt class="class">shlex</tt> instance or subclass instance is a lexical analyzer | |
100 | object. The initialization argument, if present, specifies where to | |
101 | read characters from. It must be a file-/stream-like object with | |
102 | <tt class="method">read()</tt> and <tt class="method">readline()</tt> methods, or a string (strings | |
103 | are accepted since Python 2.3). If no argument is given, input will be | |
104 | taken from <code>sys.stdin</code>. The second optional argument is a filename | |
105 | string, which sets the initial value of the <tt class="member">infile</tt> member. If | |
106 | the <var>instream</var> argument is omitted or equal to <code>sys.stdin</code>, | |
107 | this second argument defaults to ``stdin''. The <var>posix</var> argument | |
108 | was introduced in Python 2.3, and defines the operational mode. When | |
109 | <var>posix</var> is not true (default), the <tt class="class">shlex</tt> instance will | |
110 | operate in compatibility mode. When operating in POSIX mode, | |
111 | <tt class="class">shlex</tt> will try to be as close as possible to the POSIX shell | |
112 | parsing rules. See section <A href="shlex-objects.html#shlex-objects">5.21.1</A>. | |
113 | </dl> | |
114 | ||
115 | <P> | |
116 | <div class="seealso"> | |
117 | <p class="heading">See Also:</p> | |
118 | ||
119 | <dl compact="compact" class="seemodule"> | |
120 | <dt>Module <b><tt class="module"><a href="module-ConfigParser.html">ConfigParser</a></tt>:</b> | |
121 | <dd>Parser for configuration files similar to the | |
122 | Windows <span class="file">.ini</span> files. | |
123 | </dl> | |
124 | </div> | |
125 | ||
126 | <P> | |
127 | ||
128 | <p><br /></p><hr class='online-navigation' /> | |
129 | <div class='online-navigation'> | |
130 | <!--Table of Child-Links--> | |
131 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
132 | ||
133 | <UL CLASS="ChildLinks"> | |
134 | <LI><A href="shlex-objects.html">5.21.1 shlex Objects</a> | |
135 | <LI><A href="shlex-parsing-rules.html">5.21.2 Parsing Rules</a> | |
136 | </ul> | |
137 | <!--End of Table of Child-Links--> | |
138 | </div> | |
139 | ||
140 | <DIV CLASS="navigation"> | |
141 | <div class='online-navigation'> | |
142 | <p></p><hr /> | |
143 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
144 | <tr> | |
145 | <td class='online-navigation'><a rel="prev" title="5.20.1 Cmd Objects" | |
146 | href="Cmd-objects.html"><img src='../icons/previous.png' | |
147 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
148 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" | |
149 | href="misc.html"><img src='../icons/up.png' | |
150 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
151 | <td class='online-navigation'><a rel="next" title="5.21.1 shlex Objects" | |
152 | href="shlex-objects.html"><img src='../icons/next.png' | |
153 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
154 | <td align="center" width="100%">Python Library Reference</td> | |
155 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
156 | href="contents.html"><img src='../icons/contents.png' | |
157 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
158 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
159 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
160 | <td class='online-navigation'><a rel="index" title="Index" | |
161 | href="genindex.html"><img src='../icons/index.png' | |
162 | border='0' height='32' alt='Index' width='32' /></A></td> | |
163 | </tr></table> | |
164 | <div class='online-navigation'> | |
165 | <b class="navlabel">Previous:</b> | |
166 | <a class="sectref" rel="prev" href="Cmd-objects.html">5.20.1 Cmd Objects</A> | |
167 | <b class="navlabel">Up:</b> | |
168 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> | |
169 | <b class="navlabel">Next:</b> | |
170 | <a class="sectref" rel="next" href="shlex-objects.html">5.21.1 shlex Objects</A> | |
171 | </div> | |
172 | </div> | |
173 | <hr /> | |
174 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
175 | </DIV> | |
176 | <!--End of Navigation Panel--> | |
177 | <ADDRESS> | |
178 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
179 | </ADDRESS> | |
180 | </BODY> | |
181 | </HTML> |