Re: [spyder] How to run my script file....

3,884 views
Skip to first unread message

David Nicholls

unread,
May 3, 2013, 10:26:55 AM5/3/13
to spyd...@googlegroups.com
Hi,

This is a generic Python question, not really a Spyder one, so it would be better to post it on http://stackoverflow.com That's a very useful forum and usually helpful.

DN

On 03/05/2013, at 8:25 PM, Jeonghoon Choi <4my...@gmail.com> wrote:

> Hi, I have something to ask. I think it's very easy question.
>
> This is related to Spyder. Actually I am used to using matlab, so I am using spyder because it provides very similar environment to matlab.
>
> I made a scipt, 'abc.py' in which function abs(A,B,C) is defined.
>
> This function returns matrices K and S.
>
> I am now running this program by following steps.
>
> 1. type on the console as
> >>> runfile(r'abc.py')
>
> => Then I can declare the function abc(A,B,C)
>
> 2. Now, I retype (I already have the input matrices A, B and C)
> >>> (K,S) = abc(A,B,C)
>
> => Then I can get the resulting matrices, K and S.
>
> I think there would be one way to run this program by one step.
>
> If in matlab, after I made a function file, I just type >> (K,S) = abc(A,B,C).
>
> Please help.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "spyder" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
> To post to this group, send email to spyd...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spyderlib?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Jed Ludlow

unread,
May 3, 2013, 10:43:44 AM5/3/13
to spyderlib
On Fri, May 3, 2013 at 4:25 AM, Jeonghoon Choi <4my...@gmail.com> wrote:
Hi, I have something to ask. I think it's very easy question.

This  is related to Spyder. Actually I am used to using matlab, so I am using spyder because it provides very similar environment to matlab.

I made a scipt, 'abc.py' in which function abs(A,B,C) is defined.

This function returns matrices K and S.

I am now running this program by following steps.

1. type on the console as 
>>> runfile(r'abc.py')

=> Then I can declare the function abc(A,B,C)

2. Now, I retype (I already have the input matrices A, B and C)
>>> (K,S) = abc(A,B,C)

=> Then I can get the resulting matrices, K and S.

I think there would be one way to run this program by one step.

If in matlab, after I made a function file, I just type >> (K,S) = abc(A,B,C).

Please help.

Thanks.

Hello.

In MATLAB you are generally required to place functions in their own file and make the filename match the function name. Then you write a separate script that calls your function. In Python, you can just place it all in the same file and name the file whatever you'd like. In your case, call the file test_abc.py. File contents would look like:

def abc(A,B,C):
    (add the function details here)
    return (K, S)

A = some matrix
B = some matrix
C = some matrix

K, S = abc(A,B,C)
print K, S

If you open this file in Spyder, you can execute it by hitting F5. You can run it interactively like MATLAB by first hitting F6, select "Execute in current Python or IPython interpreter", and then hit Run. Subsequent F5 hits will remember your selected preference here and will keep executing the file in the same interrupter.

As a more general overview of Pyhton, consider the tutorial here: http://docs.python.org/2/tutorial/index.html. It's well worth your time. There are also several good Python sites for MATLAB users. Here's one for example: http://mathesaurus.sourceforge.net/matlab-numpy.html.

Hope this helps.
Reply all
Reply to author
Forward
0 new messages