Using Get function to return a specific expression

I am trying to use Getto import data saved as a .nb document. The problem is Getevaluates all expressions but only returns the last one.
How can I return other expressions from the document?

e.g.

A={1,2,3,4,5};
B=A^2;
C=Mean[B];
Save[“test”,{A,B,C}];

Get[“test”]

The output is 11, but I also want B to be listed in the output.

I am not able to rearrange the .nb document as it would require rerunning the code (takes several days), or manually changing the data (very tedious with~5GB worth of data).
Are there any alternative functions I might be able to use?

=================

2

 

What are you trying to accomplish? The values of b, etc. will be set, so they’re available for use. Frankly, this seems like a bit of a bizarre way to do something. In addition, don’t use uppercase initials for your symbols – it can clash with built-ins (I’m surprised you don’t report an error with C – that’s protected…)
– ciao
Aug 5 ’15 at 4:48

  

 

Related: (60734)
– Mr.Wizard♦
Aug 5 ’15 at 5:21

  

 

With the uppercase initials I was just trying to create a simple example of the problem I have. I understand the values of b are available, however my actual data is importing several documents that use the same expression names. If I import using Get only the data (ie. b) from the last document is available.
– James Reeve
Aug 6 ’15 at 0:02

  

 

I came up with this and it seems to work; Table[Get[“test”<>ToSting[i]<>“.nb”]; B, {i,1,rep}]. Where rep is the number of replicate runs.
– James Reeve
Aug 7 ’15 at 0:15

=================

1 Answer
1

=================

Possibly you want the Import format “HeldExpressions”:

Import[“test”, “HeldExpressions”]

{HoldComplete[A = {1, 2, 3, 4, 5}],
HoldComplete[B = {1, 4, 9, 16, 25}],
HoldComplete[Attributes[C] = {NHoldAll, Protected}]}

The last expression may not be as you expect until you remember that C is a reserved System Symbol.

Sorry, I overlooked the fact that you said you had a .nb file as your first example is a different format. Instead of Import please look at NotebookImport and try a command like:

NotebookImport[NotebookOpen @ “file.nb”]

It has a number of configuration options; please try a few of them. If you have trouble getting what you want let me know.

  

 

Import seems to be the way to go, I just don’t know which format to use to return the data in a way it can be expressed. The Import can only use the formats {Data, Lines, Plaintext, String, Words} with a .nb document.
– James Reeve
Aug 6 ’15 at 0:46

  

 

@JamesReeve updated.
– Mr.Wizard♦
Aug 6 ’15 at 2:45

  

 

Thanks that should work, I just can’t use the NotebookImport function on my version of Mathematica, even though I am using Mathematica 10 for Mac OS.
– James Reeve
Aug 7 ’15 at 0:08

  

 

@JamesReeve Perhaps it was only introduced in 10.1? I’ll try to think of another solution.
– Mr.Wizard♦
Aug 7 ’15 at 1:21