cancel
Showing results for 
Search instead for 
Did you mean: 

[Python] Call another script

Valued Contributor
Valued Contributor

Hello,

In my app I am trying to call another python script by clicking on a button.

The "click and call" works, but if I call a script which displays a curve with matplotlib, it doesn't work (the script works fine if I call it outside from AMESim)

 

data='my_data.txt'
plt.plotfile(data, delimiter=' ', cols=(0, 1),
             names=('col1', 'col2'), marker='o')
plt.show()

 

I get the error:

[Python] IndexError: list index out of range

 

Any Idea?

Thank you for any tip

Maxime

2 REPLIES

Re: [Python] Call another script

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

Hi mAx,

 

The error seems to be comming from Matplotlib (fom TkInter actually); it's trying to use sys.argv[0] to get the name of the currently executing script. At the moment, Amesim apps don't populate sys.arv[0], so matplotlib fails with an error because the list is empty.

 

As a work-around, you can add an empty string to sys.argv to stop the error. Try adding the following code immediatly before the plotfile call and import sys if needed:

 

if not sys.argv:
    sys.argv.append('')

 

Your code would become:

 

import sys

...

if not sys.argv:
sys.argv.append('')

data=r"my_data.txt"
plt.plotfile(data, delimiter=' ', cols=(0, 1),
names=('col1', 'col2'), marker='o')
plt.show()

 

Kind regards,

Florin

Re: [Python] Call another script

Valued Contributor
Valued Contributor

Hi @FlorinDinu,

Thanks for your reply.

I used also a workaround by plotting the curve within anorther software (gnuplot)

I will keep your suggestion, and try it

Thanks again

Maxime