Monday, 15 August 2011

python - Try, Except:Pass on multiple lines -


I am writing a script for a program called Abaqus, which plots XY data on a chart .... and change line styles at my scripts if they are based on a specific names ....

so I have a bunch of different curve names and if the chart in the specific Name, I want to execute the code to change the style ... for example ...

  session.curves [PathNameNew + '_ S201-16']. SymbolStyle.setValues ​​(show = true) session.curves [PathNameNew + '_S201- 16']. SymbolStyle.setValues ​​(Marker = FILLED_DIAMOND) session.curves [PathNameNew + '_ S201-16']. SymbolStyle.setValues ​​(size = 2) session.curves [PathNameNew + '_ S201-16']. SymbolStyle.setValues ​​(color = '# 009afb') session.curves [PathNameNew + '_ S247-16']. SymbolStyle.setValues ​​(show = true) session.curves [PathNameNew + '_ S247-16']. SymbolStyle.setValues ​​(Marker = FILLED_DIAMOND) session.curves [PathNameNew + '_S247-16']. Icons Style Set Value (size = 2) session. Cover [Pathnem eNew + '_ S247-16'] SymbolStyle.setValues ​​(color = '# 009afb') session.curves [PathNameNew + '_ release']. SymbolStyle.setValues ​​(show = true) session.curves [pathNameNew + '_ release']. SymbolStyle.setValues ​​(Marker = FILLED_DIAMOND) session.curves [PathNameNew + '_ release']. SymbolStyle.setValues ​​(size = 2) session.curves [PathNameNew + '_ release']. SymbolStyle.setValues ​​(color = '# 009afb') session.curves [PathNameNew + '_S205-18']. Line Style Kset value (thickness = 1)  

which I have called about 50 different curve that will have to do with different styles and use all curves every time, so Apart from trying to try: Pass method to get this method ... though it would mean that I have to do this for every curve name ...

Is there a better way ?

You can always make a stop function to it:

 < code> def my_big_function (): ... Do def try: set_symbolstyle_value (key, ** kwargs): session.curves [PathNameNew + Key] .symbolStyle.setValues ​​(** kwargs) except MyException: do_something () set_symbolstyle_value ( '_ S201-16', show = true) set_symbolstyle_value ( '_ S201-16', marker = FILLED_DIAMOND) ...  

work cheaper do not be afraid to use them.


No comments:

Post a Comment