Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have too many lines of code and I want to reduce the line count.

For example, I have a notebook with 2000 lines of code, and i want to hide some of it so there are less than, say, 200 lines. Can I put some of the code in somewhere else and then use it in my main code?

share|improve this question
You can insert a few section headers (using the Format/Style menu). If you double click on the cell bracket belonging to a header any code between that header and the next one will be hidden. – Sjoerd C. de Vries Apr 30 at 17:54

closed as too localized by m_goldberg, István Zachar, Silvia, Yves Klett, Sjoerd C. de Vries Apr 30 at 17:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

One way is to put some of the code in a separate file, and then execute the code in the file using <<. This is the function Get which "reads in a file, evaluating each expression in it and returning the last one."

share|improve this answer
thank you.but i can't try it correctly.for example i made a file "test1" and put code 2+3 then saved it in D:\ now i make new file and write' Get["test1", Path -> {D:\}] '.and then press shift+enter but it doesn't work.could you help me more please – david Apr 30 at 9:23
@david, try a=2+3 and then evaluate a in the notebook. – ruebenko Apr 30 at 9:46
could you write full code for me please? i am confused... – david Apr 30 at 9:56
David's point is that if you put 2+3 in the test file and it executes it, you have no way of accessing the results of the calculation. If you set a=2+3 then when you check after the Get, the value of a will be set. – bill s Apr 30 at 9:57
i know.i edited it but when i try this i still have some errors .i have problem with Get[] i think i wrong path – david Apr 30 at 10:01
show 3 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.