Python Forum
IPython console vs Spyder script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: IPython console vs Spyder script (/thread-26389.html)



IPython console vs Spyder script - losc - Apr-30-2020

Hello, I wrote a code to control a device (I have created a device class and defined attributes to execute different operation with the device). At some point (for unknown reason) I got an error, and I can not handle it via my Spyder script. I have added a try, exception block to reset the device in case of error, but I always receive an error saying that the device does not have those attributes. For example, let's say I declare the instance MyDevice of the device class, by writing MyDevice = device(). Among different commands, I have defined a reset command. In my exception block I write MyDevice.reset(), but this give me the error: "MyDevice does not have the attribute reset. When I then run the same command (MyDevide.reset()) on the IPython console, this is executed correctly. Any idea about what could be the difference between running those command in the script or via console? I am interested even in a general sense, as maybe this could help me to find out what is the cause of the error. Thanks a lot for your help!


RE: IPython console vs Spyder script - deanhystad - Apr-30-2020

Hard to say without seeing the code. My guess is MyDevice in your exception handler is not the same kind of thing as MyDevide in your IPython console. Easy enough to test. What do you get for type(MyDevice) or MyDevice.__dict__. Are they the same in both cases (IPython console Spyder script)


RE: IPython console vs Spyder script - losc - Apr-30-2020

Ok, I will try your suggestion.

Sorry for not sharing the code. It is very long and there are a lot of things going on, so here I am just trying to narrow down the issue. Actually, one thing I have just realised is that in my exception block I was still using an attribute of MyDevice. But what I could do is to generate a new instance of the device class with the same name, and then run a reset commands. Maybe like this it could work. Of course this is not understanding the issue, but I am just trying to find a way to avoid stopping the measurement while running over night.

Also, I am now trying to run the script via command prompt instead of Spyder. Not sure if this will make any difference.


RE: IPython console vs Spyder script - deanhystad - Apr-30-2020

That sounds like a bad idea. I would put a raise ExceptionType(msg) line in the code to force the exception and add a bunch of print statements to the exception code. You should be able to figure it out in a few minutes.