Show More
@@ -0,0 +1,74 b'' | |||
|
1 | from IPython.demo import Demo,IPythonDemo,LineDemo,IPythonLineDemo,ClearDemo,ClearIPDemo | |
|
2 | import tempfile, os, StringIO, shutil | |
|
3 | ||
|
4 | """This is meant to be run from the IPython prompt: | |
|
5 | run demo-exercizer.py | |
|
6 | -- it will created demo objects of the example that is | |
|
7 | embedded in demo.py in a number of ways and allow you | |
|
8 | to see how they work, just follow the printed directions.""" | |
|
9 | ||
|
10 | example1 = """ | |
|
11 | '''A simple interactive demo to illustrate the use of IPython's Demo class.''' | |
|
12 | ||
|
13 | print 'Hello, welcome to an interactive IPython demo.' | |
|
14 | ||
|
15 | # The mark below defines a block boundary, which is a point where IPython will | |
|
16 | # stop execution and return to the interactive prompt. The dashes are actually | |
|
17 | # optional and used only as a visual aid to clearly separate blocks while | |
|
18 | # editing the demo code. | |
|
19 | # <demo> stop | |
|
20 | ||
|
21 | x = 1 | |
|
22 | y = 2 | |
|
23 | ||
|
24 | # <demo> stop | |
|
25 | ||
|
26 | # the mark below makes this block as silent | |
|
27 | # <demo> silent | |
|
28 | ||
|
29 | print 'This is a silent block, which gets executed but not printed.' | |
|
30 | ||
|
31 | # <demo> stop | |
|
32 | # <demo> auto | |
|
33 | print 'This is an automatic block.' | |
|
34 | print 'It is executed without asking for confirmation, but printed.' | |
|
35 | z = x+y | |
|
36 | ||
|
37 | print 'z=',x | |
|
38 | ||
|
39 | # <demo> stop | |
|
40 | # This is just another normal block. | |
|
41 | print 'z is now:', z | |
|
42 | ||
|
43 | print 'bye!' | |
|
44 | """ | |
|
45 | fp = tempfile.mkdtemp(prefix = 'DemoTmp') | |
|
46 | fd, filename = tempfile.mkstemp(prefix = 'demoExample1File', suffix = '.py', dir = fp) | |
|
47 | f = os.fdopen(fd, 'wt') | |
|
48 | ||
|
49 | f.write(example1) | |
|
50 | f.close() | |
|
51 | ||
|
52 | my_d = Demo(filename) | |
|
53 | my_cd = ClearDemo(filename) | |
|
54 | ||
|
55 | fobj = StringIO.StringIO(example1) | |
|
56 | str_d = Demo(fobj, title='via stringio') | |
|
57 | #~ def tmpcleanup(): | |
|
58 | #~ global my_d, my_cd, fp | |
|
59 | #~ del my_d | |
|
60 | #~ del my_cd | |
|
61 | #~ shutil.rmtree(fp, False) | |
|
62 | ||
|
63 | print ''' | |
|
64 | The example that is embeded in demo.py file has been used to create | |
|
65 | the following 3 demos, and should now be available to use: | |
|
66 | my_d() -- created from a file | |
|
67 | my_cd() -- created from a file, a ClearDemo | |
|
68 | str_d() -- same as above, but created via a stringi\o object | |
|
69 | Call by typing their name, (with parentheses), at the | |
|
70 | ipython prompt, interact with the block, then call again | |
|
71 | to run the next block. | |
|
72 | ''' | |
|
73 | # call tmpcleanup to delete the temporary files created. -not implemented | |
|
74 |
General Comments 0
You need to be logged in to leave comments.
Login now