303 lines
14 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
LettError Type and Typography: RoboThon 2006, The Small Scripting Conference
</title>
<link href="../default.css" type="text/css" rel="stylesheet" />
</head><body>
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
<script type="text/javascript">
_uacct = "UA-2044310-2";
urchinTracker();
</script>
<div id="modellogo">
<img src="../img/drawmodel_header.jpg" width="595" height="112" />
</div>
<div class="leftcontent">
<h1 class="crb-seealso">
RoboFab
</h1>
<p class="menu">
<a href="../index.html">
Home
</a>
<br />
<a href="../download/index.html">
Download v1.1.1
</a>
<br />
<a href="../intro.html">
Intro
</a>
<br />
<a href="../install.html">
Install Notes
</a>
<br />
<a href="../history.html">
History
</a>
<br />
<a href="../executive.html">
Summary
</a>
</p>
<p class="menu">
<a href="../howto/index.html">
How to's
</a>
<br />
<a href="index.html">
Step by step
</a>
<br />
<a href="../tools/dialogs.html">
Fab Dialogs
</a>
<br />
<a href="../objects/index.html">
Object reference
</a>
<br />
<a href="../objects/model.html">
Object map
</a>
<br />
<a href="../tools/index.html">
Tools
</a>
<br />
<a href="../ufo/index.html">
UFO Overview
</a>
<br />
<a href="../ufo/specification.html">
UFO Spec
</a>
<br />
<a href="../limitations.html">
Fab Limitations
</a>
<a href="../links/index.html">
Links
</a>
<br />
<a href="../credits.html">
Credits
</a>
</p>
<h1 class="crb-seealso">
Support RoboFab
</h1>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
<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QQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDYwNTA1MDk0MDI3WjAjBgkqhkiG9w0BCQQxFgQUuGyd1NYqa4RVlKQ48vrRVsRjTXYwDQYJKoZIhvcNAQEBBQAEgYC6ZiJbUzbugBCir8QnRYRas0tJrdMXcUXQnO3HlO5Zj7+F9cGT2NI73VgB5Vhpu+OaMjBcmc8f0LSP6/ns48YZiIki3+nilxKt/sEq3R0B9XeoB21nHxLmlWkFGMGKxPexWEkjJq0v3UNhS6mYDAIdLkrLE6RHRYAVvKET8hkzDw==-----END PKCS7-----
">
</form>
<h2 class="crb-seealso">
Up
</h2>
<p class="menu">
<p class="bonbon_uplink"><a href="index.html">Back to Step by step</a></p>
</p>
<h2 class="crb-seealso">
See also
</h2>
<p class="menu">
<a href="../howto/scripting.html">Scripting</a><br /><a href="dialogkit.html">Dialog Kit</a><br /><a href="editors.html">Editors</a><br /><a href="examples/index.html">RoboThon 2006</a><br /><a href="index.html">Step by step</a><br /><a href="robofab_session4.html">NoneLab</a><br /><a href="robofab_session6.html">Production</a><br />
</p>
</div>
<div class="footer">
<a href="../feedback.html">
Feedback
</a>
<br />
<a href="../map.html">
Sitemap
</a>
<br />
Please also refer to the
<a href="../download/license.html">
Legal
</a>
<br />
Copyright 2003-2006 RoboFab
<br />
version 1.1.1
</div>
<div class="google">
<h2>RoboFab Mailinglist</h2>
<p>
Join the RoboFab users community at Google groups.
</p>
<img src="http://groups.google.com/groups/img/3nb/groups_bar.gif" alt="Google Groups" height="26" width="132" />
<p>
<form action="http://groups.google.com/group/robofab/boxsubscribe">
Email: <input type="text" name="../email" />
<input type="submit" name="../sub" value="Subscribe" />
</form>
</p>
<p>
<a href="http://groups.google.com/group/robofab">Visit this group</a>
</p>
<h2>RoboFab Sponsors</h2>
<script type="text/javascript">
google_ad_client = "pub-3703953449723704";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<div class="content">
<h1>
Python Basics
</h1>
<p>
In these and following examples we'll be using a couple of programming things which are simple enough that, should you not be familiar with them, you might be able to figure out from the contect. While the experienced programmers will tap their feet impatiently for this to finish, and the newbies are struggling to pick their dicts from their strings: a very short overview of the stuff you're missing.
<ul>
<li>
<strong>Conditional statements</strong>: if some condition is met: execute a seperate block of your script.
<div class="pythonsource"><pre><span class="py_res">if</span> <span class="py_num">1</span>+<span class="py_num">1</span> == <span class="py_num">2</span>:<br>&nbsp; &nbsp; <span class="py_res">print</span> <span class="py_str">"still true"</span><br><span class="py_res">else</span>:<br>&nbsp; &nbsp; <span class="py_res">print</span> <span class="py_str">"oops"</span></pre></div>
<div class="pythonoutput"><pre><span class="py_key">still</span> <span class="py_key">true</span></pre></div>
</li>
<li>
<strong>Compound statements</strong>: for each item in this list: execute a seperate block of your script.
<div class="pythonsource"><pre><span class="py_res">for</span> <span class="py_key">item</span> <span class="py_res">in</span> [<span class="py_num">1</span>, <span class="py_num">2</span>, <span class="py_num">3</span>, <span class="py_str">"a"</span>]:<br>&nbsp; &nbsp; <span class="py_res">print</span> <span class="py_key">item</span></pre></div>
<div class="pythonoutput"><pre><span class="py_num">1</span><br><span class="py_num">2</span><br><span class="py_num">3</span><br><span class="py_str">"a"</span></pre></div>
</li>
<li><strong>Assignment</strong>: this is basically setting something to a new value, or attaching a name to something.
<div class="pythonsource"><pre><span class="py_key">a</span> = <span class="py_num">10</span><br><span class="py_res">print</span> <span class="py_key">a</span></pre></div>
<div class="pythonoutput"><pre><span class="py_num">10</span></pre></div>
</li>
</ul>
The information that you want to work with in programming comes in different forms and colors: text, numbers, sequences of things. Python offers a nice range of tupperware boxes to stick them in. More things to keep track of, but: useful and these will be your friends.
<ul>
<li><strong>strings</strong>: text, letters, words, are called strings and they live between quotes. In order to allow quotes in strings you have several quote alternatives:
<div class="pythonsource"><pre># examples of strings<br><span class="py_key">a</span> = <span class="py_str">"a string"</span><br><span class="py_key">b</span> = <span class="py_str">'a string too'</span><br><span class="py_key">c</span> = <span class="py_str">'a "string" too'</span><br><span class="py_key">d</span> = <span class="py_str">"""a triple quoted string - but still just a string."""</span><br><span class="py_key">e</span> = <span class="py_str">'''a triple quoted string - but still just a string.'''</span></pre></div>
</li>
<li><strong>numbers</strong>: whole numbers, decimal numbers. You don't need to do anything special to make them, just write them.
<div class="pythonsource"><pre># examples of numbers<br><span class="py_key">a</span> = <span class="py_num">1900</span><br><span class="py_key">b</span> = -<span class="py_num">239345</span><br><span class="py_key">c</span> = <span class="py_num">1.349683</span><br><span class="py_key">d</span> = <span class="py_num">0</span></pre></div>
</li>
<li><strong>lists</strong>: sequences can be written between brackets. You've seen one earlier. Lists are powerful things to keep stuff in order. Some objects can behave like lists. List objects have useful methods to manipulate them.
<div class="pythonsource"><pre># examples of lists<br><span class="py_key">aList</span> = [<span class="py_num">4</span>, <span class="py_str">"a"</span>, <span class="py_num">2</span>, <span class="py_num">1</span>] <br><span class="py_key">aListInAList</span> = [ [<span class="py_num">1</span>, <span class="py_num">2</span>], [<span class="py_num">3</span>, <span class="py_num">4</span>] ]<br><span class="py_res">print</span> <span class="py_key">len</span>(<span class="py_key">aList</span>)<br><span class="py_key">sort</span>(<span class="py_key">aList</span>)<br><span class="py_res">print</span> <span class="py_key">aList</span></pre></div>
<div class="pythonoutput"><pre><span class="py_num">4</span><br>[<span class="py_num">1</span>, <span class="py_num">2</span>, <span class="py_num">4</span>, <span class="py_str">'a'</span>]</pre></div>
</li>
<li><strong>dictionaries</strong>: these are similar to lists, but rather than just store a sequence, a dictionary stores a <strong>key: value</strong> pair. In order to get the value, you need to provide the key. Dictionaries are written between {braces}. Some objects can behave like dictionaries. Dictionary objects have useful methods to manipulate them. While lists have their sequencential order, dictionaries don't, something to remember when you're iterating.
<div class="pythonsource"><pre># examples of dicts<br><span class="py_key">aDict</span> = {<span class="py_str">"key"</span>: <span class="py_str">"value"</span>, <span class="py_num">100</span>: <span class="py_num">200</span>}<br><span class="py_res">print</span> <span class="py_key">aDict</span>.<span class="py_key">keys</span>()<br><span class="py_res">print</span> <span class="py_key">aDict</span>.<span class="py_key">values</span>()<br><span class="py_res">print</span> <span class="py_key">aDict</span>.<span class="py_key">items</span>()<br><span class="py_res">print</span> <span class="py_key">len</span>(<span class="py_key">aDict</span>)</pre></div>
<div class="pythonoutput"><pre>[<span class="py_num">100</span>, <span class="py_str">'key'</span>]<br>[<span class="py_num">200</span>, <span class="py_str">'value'</span>]<br>[(<span class="py_num">100</span>, <span class="py_num">200</span>), (<span class="py_str">'key'</span>, <span class="py_str">'value'</span>)]<br><span class="py_num">2</span></pre></div>
</li>
<li><strong>tuples</strong> - sequences between parentheses, rather than square brackets. Tuples are very much like lists, except that you can't really change them. For instance a tuple can't sort like a list can.
</li>
</ul>
<div class="pythonsource"><pre># examples of tuples<br><span class="py_key">aTuple</span> = (<span class="py_num">1</span>, <span class="py_num">2</span>, <span class="py_num">3</span>)<br><span class="py_key">aTuple</span> = (<span class="py_str">"a"</span>, <span class="py_str">"b"</span>, <span class="py_str">"c"</span>)</pre></div>
</p>
<p>
And that's really all we're going to say about this. Figure out the rest yourself.
</p>
</div>
</body></html>