~azzar1/unity/add-show-desktop-key

1559 by Matt Giuca
docs: Added a new help page, Running and Serving.
1
<div class="helpfile">
2
<p>You can <strong>run</strong> Python code directly from the IVLE File
3
Browser to try it out. You can also <strong>serve</strong> Python web
4
applications and other files publicly.</p>
5
6
<h2>Running</h2>
7
8
<p>In the IVLE Editor, you can create Python scripts (<strong>.py</strong>
9
files), which contain working programs. Often, simple programs work by
10
printing things out (with the <strong>print</strong> statement), and reading
11
input from the user (with the <strong>raw_input</strong> function).</p>
12
13
<p>You can run these programs by selecting the <strong>.py</strong> file in
14
the File Browser, and clicking <strong>run</strong>. This will open up the
15
Python console and display the output of the program, just as if you had typed
16
the program into the console yourself.</p>
17
18
<p>For example, the following simple Python program prints a message:</p>
19
20
<pre>print "Hello, world!"</pre>
21
22
<h2>Serving</h2>
23
24
<p>IVLE also allows you to create web pages or web applications to show to
25
your friends. In the IVLE Editor, you can create HTML web pages
26
(<strong>.html</strong> files). For example, the following page contains a
27
message:</p>
28
29
<pre>&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello, world!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>
30
31
<p>You can ask IVLE to serve such a file as a web page by selecting the
32
<strong>.html</strong> file in the File Browser, and clicking
33
<strong>serve</strong>. This will open a new tab with the web page.</p>
34
35
<p>You can also run a Python file as a web application in the same way. In
36
IVLE, we use CGI to write web applications in Python, which are a little
37
different from a normal Python script. If you serve the above script, you will
38
see a warning, explaining that you didn't use CGI properly. An example of a
39
simple CGI script follows:</p>
40
41
<pre>print "Content-Type: text/html"
42
print
43
print "&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello, world!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"</pre>
44
45
<h2>Publishing</h2>
46
47
<p>If you wish to show your web pages and applications to the world, first,
48
select nothing and choose <strong>publish</strong> from the "More actions"
49
menu. This will <em>publish</em> the directory and all files in it to the
50
web.</p>
51
52
<p>Then, select the file, and choose <strong>share this file</strong> from the
53
"More actions" menu. This will open the file in a new tab, just like
54
<strong>serve</strong>, except the address bar will show a "public" URL. If
55
you give this URL to someone else (e.g., as a link in an email), they will be
56
able to view your content.</p>
57
58
<h2>Summary</h2>
59
<ul>
60
<li><strong>Run</strong> runs Python programs as command-line applications.</li>
61
<li><strong>Serve</strong> runs Python programs as CGI applications, showing their web output.</li>
62
<li><strong>Publish</strong> lets other people view your web pages and CGI applications as if they were <strong>served</strong>.</li>
63
</ul>
64
</div>