Skip to content

Commit 2c4993d

Browse files
committed
Add a comment about PYTHONPATH to the reference manual.
1 parent 26cc507 commit 2c4993d

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

examples/ref_import.cnb

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
2+
"cell_id" : 8781633447072324819,
23
"cells" :
34
[
45
{
6+
"cell_id" : 18335642165121633802,
57
"cell_origin" : "client",
68
"cell_type" : "latex",
79
"cells" :
810
[
911
{
12+
"cell_id" : 18438625418858246260,
1013
"cell_origin" : "client",
1114
"cell_type" : "latex_view",
1215
"source" : "\\section*{Using multiple files and notebooks}\n\nAt some point, you will encounter computations which are best separated out into their\nown notebook. Or you will do a computation which takes a long time, and you want to write\nan intermediate result into a file so that you can read it back later easily. There are \ntwo options for this in Cadabra: importing notebooks into other notebooks, or writing \nindividual expressions to a file and reading them back."
@@ -16,11 +19,13 @@
1619
"source" : "\\section*{Using multiple files and notebooks}\n\nAt some point, you will encounter computations which are best separated out into their\nown notebook. Or you will do a computation which takes a long time, and you want to write\nan intermediate result into a file so that you can read it back later easily. There are \ntwo options for this in Cadabra: importing notebooks into other notebooks, or writing \nindividual expressions to a file and reading them back."
1720
},
1821
{
22+
"cell_id" : 8213440041221983394,
1923
"cell_origin" : "client",
2024
"cell_type" : "latex",
2125
"cells" :
2226
[
2327
{
28+
"cell_id" : 7789347635294861682,
2429
"cell_origin" : "client",
2530
"cell_type" : "latex_view",
2631
"source" : "\\subsection*{Importing a notebook into another one}\n\nThe simplest way to separate functionality is to simply write a separate notebook with the\nproperties and expressions which you want to re-use elsewhere. In this way, writing a \n`package' for Cadabra is nothing else but writing a separate notebook. You can import any \nnotebook into another one by using the standard Python import logic."
@@ -30,11 +35,13 @@
3035
"source" : "\\subsection*{Importing a notebook into another one}\n\nThe simplest way to separate functionality is to simply write a separate notebook with the\nproperties and expressions which you want to re-use elsewhere. In this way, writing a \n`package' for Cadabra is nothing else but writing a separate notebook. You can import any \nnotebook into another one by using the standard Python import logic."
3136
},
3237
{
38+
"cell_id" : 1942692638989080526,
3339
"cell_origin" : "client",
3440
"cell_type" : "latex",
3541
"cells" :
3642
[
3743
{
44+
"cell_id" : 11079700572726959640,
3845
"cell_origin" : "client",
3946
"cell_type" : "latex_view",
4047
"source" : "\\subsubsection*{Example}\n\nLet us say we have a notebook \\verb|library.cnb|, which contains a single cell with the following \ncontent:\n\\begin{verbatim}\n {m,n,p,q,r}::Indices;\n ex:=A_{q r} A_{q r};\n\\end{verbatim}\nYou can now import this into another notebook by simply using"
@@ -44,35 +51,41 @@
4451
"source" : "\\subsubsection*{Example}\n\nLet us say we have a notebook \\verb|library.cnb|, which contains a single cell with the following \ncontent:\n\\begin{verbatim}\n {m,n,p,q,r}::Indices;\n ex:=A_{q r} A_{q r};\n\\end{verbatim}\nYou can now import this into another notebook by simply using"
4552
},
4653
{
54+
"cell_id" : 3561489114726530089,
4755
"cell_origin" : "client",
4856
"cell_type" : "input",
4957
"source" : "from library import *"
5058
},
5159
{
60+
"cell_id" : 1316256212347283961,
5261
"cell_origin" : "client",
5362
"cell_type" : "latex",
5463
"cells" :
5564
[
5665
{
66+
"cell_id" : 11518391810218108451,
5767
"cell_origin" : "client",
5868
"cell_type" : "latex_view",
59-
"source" : "You can see that this worked by e.g. the following:"
69+
"source" : "Cadabra looks for the \\verb|library.cnb| notebook in your \\verb|PYTHONPATH| (just as in ordinary Python programs),\n as well as in the current directory. You can see that this worked by e.g. the following:"
6070
}
6171
],
6272
"hidden" : true,
63-
"source" : "You can see that this worked by e.g. the following:"
73+
"source" : "Cadabra looks for the \\verb|library.cnb| notebook in your \\verb|PYTHONPATH| (just as in ordinary Python programs),\n as well as in the current directory. You can see that this worked by e.g. the following:"
6474
},
6575
{
76+
"cell_id" : 37268896913279161,
6677
"cell_origin" : "client",
6778
"cell_type" : "input",
6879
"cells" :
6980
[
7081
{
82+
"cell_id" : 16774845059730372451,
7183
"cell_origin" : "server",
7284
"cell_type" : "latex_view",
7385
"cells" :
7486
[
7587
{
88+
"cell_id" : 15291342196228748438,
7689
"cell_origin" : "server",
7790
"cell_type" : "input_form",
7891
"source" : "A_{q r} A_{q r}"
@@ -81,11 +94,13 @@
8194
"source" : "\\begin{dmath*}{}A_{q r} A_{q r}\\end{dmath*}"
8295
},
8396
{
97+
"cell_id" : 10215936131369656133,
8498
"cell_origin" : "server",
8599
"cell_type" : "latex_view",
86100
"cells" :
87101
[
88102
{
103+
"cell_id" : 2008929433626558299,
89104
"cell_origin" : "server",
90105
"cell_type" : "input_form",
91106
"source" : "A_{m n} A_{m n}"
@@ -97,11 +112,13 @@
97112
"source" : "ex;\nrename_dummies(ex);"
98113
},
99114
{
115+
"cell_id" : 8355013287855316724,
100116
"cell_origin" : "client",
101117
"cell_type" : "latex",
102118
"cells" :
103119
[
104120
{
121+
"cell_id" : 5820656270542915781,
105122
"cell_origin" : "client",
106123
"cell_type" : "latex_view",
107124
"source" : "Note that the import has thus not only imported the \\verb|ex| expression, but also the property \ninformation about the index set, which enabled the \\verb|rename_dummies| to work."
@@ -111,11 +128,13 @@
111128
"source" : "Note that the import has thus not only imported the \\verb|ex| expression, but also the property \ninformation about the index set, which enabled the \\verb|rename_dummies| to work."
112129
},
113130
{
131+
"cell_id" : 14481788688662175832,
114132
"cell_origin" : "client",
115133
"cell_type" : "latex",
116134
"cells" :
117135
[
118136
{
137+
"cell_id" : 3233447126429706603,
119138
"cell_origin" : "client",
120139
"cell_type" : "latex_view",
121140
"source" : "Behind the scenes, what happens is that the import statement looks for a file \\verb|library.cnb|. If it\nfinds this, it will first convert that file to a proper Python file (remember the \\verb|library.cnb| file is a \nCadabra notebook, not a Python file). It then uses the standard Python logic to do the import."
@@ -125,11 +144,13 @@
125144
"source" : "Behind the scenes, what happens is that the import statement looks for a file \\verb|library.cnb|. If it\nfinds this, it will first convert that file to a proper Python file (remember the \\verb|library.cnb| file is a \nCadabra notebook, not a Python file). It then uses the standard Python logic to do the import."
126145
},
127146
{
147+
"cell_id" : 13398410042259813666,
128148
"cell_origin" : "client",
129149
"cell_type" : "latex",
130150
"cells" :
131151
[
132152
{
153+
"cell_id" : 15901214011191945668,
133154
"cell_origin" : "client",
134155
"cell_type" : "latex_view",
135156
"source" : "\\subsection*{Writing expressions to a file and reading them back}\n\nA somewhat more difficult way to re-use expressions is to write them to a file\nusing standard Python methods, and then read them back elsewhere. This method is best\nused for long computations of which you want to write an intermediate result out to \ndisk, to be read in later (instead of doing a re-computation). Be aware that if you \nwrite an expression to disk, you do not write the property information of any of the\nsymbols in that expression to disk. "
@@ -139,11 +160,13 @@
139160
"source" : "\\subsection*{Writing expressions to a file and reading them back}\n\nA somewhat more difficult way to re-use expressions is to write them to a file\nusing standard Python methods, and then read them back elsewhere. This method is best\nused for long computations of which you want to write an intermediate result out to \ndisk, to be read in later (instead of doing a re-computation). Be aware that if you \nwrite an expression to disk, you do not write the property information of any of the\nsymbols in that expression to disk. "
140161
},
141162
{
163+
"cell_id" : 11444201106378708990,
142164
"cell_origin" : "client",
143165
"cell_type" : "latex",
144166
"cells" :
145167
[
146168
{
169+
"cell_id" : 12988076038731780414,
147170
"cell_origin" : "client",
148171
"cell_type" : "latex_view",
149172
"source" : "\\subsubsection*{Example}\n\nThe following example declares two expressions and writes them to disk. It then reads the\nexpressions back in again and assigns them to different Python names."
@@ -153,16 +176,19 @@
153176
"source" : "\\subsubsection*{Example}\n\nThe following example declares two expressions and writes them to disk. It then reads the\nexpressions back in again and assigns them to different Python names."
154177
},
155178
{
179+
"cell_id" : 11792617782253406692,
156180
"cell_origin" : "client",
157181
"cell_type" : "input",
158182
"cells" :
159183
[
160184
{
185+
"cell_id" : 74831037821067521,
161186
"cell_origin" : "server",
162187
"cell_type" : "latex_view",
163188
"cells" :
164189
[
165190
{
191+
"cell_id" : 15970060422258541493,
166192
"cell_origin" : "server",
167193
"cell_type" : "input_form",
168194
"source" : "A_{m n} \\sin(x)"
@@ -171,11 +197,13 @@
171197
"source" : "\\begin{dmath*}{}A_{m n} \\sin{x}\\end{dmath*}"
172198
},
173199
{
200+
"cell_id" : 6535555148371619996,
174201
"cell_origin" : "server",
175202
"cell_type" : "latex_view",
176203
"cells" :
177204
[
178205
{
206+
"cell_id" : 8248852654806885795,
179207
"cell_origin" : "server",
180208
"cell_type" : "input_form",
181209
"source" : "B_{m n}"
@@ -187,21 +215,25 @@
187215
"source" : "ex1:= A_{m n} \\sin{x};\nex2:= B_{m n};\nwith open(\"output.cdb\", \"w\") as file:\n file.write( ex1.input_form()+\"\\n\" )\n file.write( ex2.input_form()+\"\\n\" )"
188216
},
189217
{
218+
"cell_id" : 12958713239442749254,
190219
"cell_origin" : "client",
191220
"cell_type" : "input",
192221
"source" : "with open(\"output.cdb\", \"r\") as file:\n ex3=Ex( file.readline() )\n ex4=Ex( file.readline() )"
193222
},
194223
{
224+
"cell_id" : 2842740079552019795,
195225
"cell_origin" : "client",
196226
"cell_type" : "input",
197227
"cells" :
198228
[
199229
{
230+
"cell_id" : 3025403952431302262,
200231
"cell_origin" : "server",
201232
"cell_type" : "latex_view",
202233
"cells" :
203234
[
204235
{
236+
"cell_id" : 1436721049922411551,
205237
"cell_origin" : "server",
206238
"cell_type" : "input_form",
207239
"source" : "A_{m n} \\sin(x)"
@@ -210,11 +242,13 @@
210242
"source" : "\\begin{dmath*}{}A_{m n} \\sin{x}\\end{dmath*}"
211243
},
212244
{
245+
"cell_id" : 11419665305986047774,
213246
"cell_origin" : "server",
214247
"cell_type" : "latex_view",
215248
"cells" :
216249
[
217250
{
251+
"cell_id" : 5706079747164185254,
218252
"cell_origin" : "server",
219253
"cell_type" : "input_form",
220254
"source" : "B_{m n}"
@@ -226,11 +260,13 @@
226260
"source" : "ex3;\nex4;"
227261
},
228262
{
263+
"cell_id" : 4528355418093952061,
229264
"cell_origin" : "client",
230265
"cell_type" : "latex",
231266
"cells" :
232267
[
233268
{
269+
"cell_id" : 2572353665904379176,
234270
"cell_origin" : "client",
235271
"cell_type" : "latex_view",
236272
"source" : "Note that when written in this way, the file \\verb|output.cdb| only contains the expressions, not their names \n(\\verb|ex1| and \\verb|ex2| in the example above)."
@@ -240,6 +276,7 @@
240276
"source" : "Note that when written in this way, the file \\verb|output.cdb| only contains the expressions, not their names \n(\\verb|ex1| and \\verb|ex2| in the example above)."
241277
},
242278
{
279+
"cell_id" : 18362525774477466829,
243280
"cell_origin" : "client",
244281
"cell_type" : "input",
245282
"source" : ""

0 commit comments

Comments
 (0)