You can also use the global keyword to export the variables inside a function into the global namespace.<br><br>For example if you define:<br><br>def f(x):<br> global a<br> a=5<br> return x+a<br><br>you can check the value of a outside of f.<br>
<br>Hope this helps,<br>Carlos<br><br><div class="gmail_quote">2010/3/18 Scott Sinclair <span dir="ltr"><<a href="http://scott.sinclair.za">scott.sinclair.za</a>@<a href="http://gmail.com">gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">>On 18 March 2010 22:18, lixo1 <<a href="mailto:lixo1@hotmail.fr">lixo1@hotmail.fr</a>> wrote:<br>
> Yes if you uses %run it loads a function but I really would like to get<br>
> something like matlab, for example in Matlab I create a function like this:<br>
><br>
> function [result,dataA,dataB] = Toff(x);<br>
> stuff<br>
> resuts = 65;<br>
> ...<br>
><br>
> It means that when I call this function the variables result, dataA, dataB<br>
> are created and stocked in the workspace. If I well understand in ipython<br>
> (python) it's like C, you return 1 singular value from a function.<br>
<br>
</div>Python does return a single object, but you can pack your variables<br>
into a tuple object and return that.<br>
<br>
Something like this:<br>
<br>
# example.py<br>
import numpy as np<br>
<br>
def foo():<br>
a = np.ones(3)<br>
b = 3*a<br>
c = a+b<br>
<br>
return a, b, c<br>
<br>
A, B, C = foo()<br>
<br>
IPython session:<br>
<br>
[~] |1>dir()<br>
<1><br>
['In',<br>
'LA',<br>
'Out',<br>
'_',<br>
'__',<br>
'__IP',<br>
'___',<br>
'__builtins__',<br>
'__name__',<br>
'__package__',<br>
'_dh',<br>
'_i',<br>
'_i1',<br>
'_ih',<br>
'_ii',<br>
'_iii',<br>
'_ip',<br>
'_oh',<br>
'_prompt_title',<br>
'_sh',<br>
'help',<br>
'os',<br>
'path',<br>
'up']<br>
[~] |2>%run example.py<br>
[~] |3>dir()<br>
<3><br>
['A',<br>
'B',<br>
'C',<br>
'In',<br>
'LA',<br>
'Out',<br>
'_',<br>
'_1',<br>
'__',<br>
'__IP',<br>
'___',<br>
'__builtins__',<br>
'__file__',<br>
'__name__',<br>
'__nonzero__',<br>
'__package__',<br>
'_dh',<br>
'_i',<br>
'_i1',<br>
'_i2',<br>
'_i3',<br>
'_ih',<br>
'_ii',<br>
'_iii',<br>
'_ip',<br>
'_oh',<br>
'_prompt_title',<br>
'_sh',<br>
'foo',<br>
'help',<br>
'np',<br>
'os',<br>
'path',<br>
'up']<br>
[~] |4>A<br>
<4> array([ 1., 1., 1.])<br>
[~] |5>B<br>
<5> array([ 3., 3., 3.])<br>
[~] |6>C<br>
<6> array([ 4., 4., 4.])<br>
<br>
Cheers,<br>
<font color="#888888">Scott<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
IPython-user mailing list<br>
<a href="mailto:IPython-user@scipy.org">IPython-user@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-user" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-user</a><br>
</div></div></blockquote></div><br>