tutorial addition
Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
attached patch puts "expressions" higher on the tutorial-python page, while leaving the stuff about glob and sufreplace intact. it explains backticks, and mentions how to get environment variables, which is promised somewhere else in the tutorial but wasn't made good. -- pub 1024D/FEA2A3FE 2002-06-18 Adriaan de Groot <[email protected]> If the door is ajar, can we fill it with door-jamb?
docs.diff
(text/x-diff, 2.2 KB)
Index: tutor-python.sgml
===================================================================
RCS file: /cvsroot/a-a-p/Exec/doc/tutor-python.sgml,v
retrieving revision 1.17
diff -u -3 -p -r1.17 tutor-python.sgml
--- tutor-python.sgml 11 Sep 2003 18:06:49 -0000 1.17
+++ tutor-python.sgml 13 Oct 2003 22:14:44 -0000
@@ -15,6 +15,40 @@ will only use a few Python items. But w
anything with it.
</para>
+<bridgehead>Expressions</bridgehead>
+
+<para>
+(Almost) anywhere you have a value, such as a text string, you
+can use a Python expression instead. For instance, you could use a
+Python expression to retrieve the value of an environment variable
+for use in a recipe, or use an expression to compute some
+strange value.
+</para>
+
+<para>
+Expressions are written between backticks (` `)
+and must be valid Python expressions.
+Some examples:
+</para>
+
+<programlisting>
+1 myhome=`os.environ.get("HOME")`
+2 label=`"L"+str(17*22)`
+</programlisting>
+
+<para>
+The first example line shows how to retrieve an environment variable
+by using Python's built-in <literal>os.environ</literal> module.
+The second shows how you can use Python to compute something
+within an &Aap; recipe. It doesn't do anything useful, but it
+uses Python to compute the value <literal>L374</literal>,
+and then &Aap; assigns that value to the variable <literal>label</literal>.
+</para>
+
+<note>
+Using environment variables is probably not portable.
+</note>
+
<bridgehead>Conditionals</bridgehead>
<para>
@@ -24,13 +58,13 @@ Here is an example how you can handle th
</para>
<programlisting>
- @if OSTYPE == "posix":
- INCLUDE += -I/usr/local/include
- @else:
- INCLUDE += -Ic:/vc/include
-
- all:
- :print INCLUDE is "$INCLUDE"
+1 @if OSTYPE == "posix":
+2 INCLUDE += -I/usr/local/include
+3 @else:
+4 INCLUDE += -Ic:/vc/include
+5
+6 all:
+7 :print INCLUDE is "$INCLUDE"
</programlisting>
<para>
@@ -179,7 +213,7 @@ same as the recipe assignment, but what
</para>
-<bridgehead>Expressions</bridgehead>
+<bridgehead>Expressions for Files</bridgehead>
<para>
In many places a Python expression can be used. For example, the