Python Forum
IPython console vs Spyder script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IPython console vs Spyder script
#1
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!
Reply
#2
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)
Reply
#3
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.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine console script + GUI (tkinter) dejot 2 361 Feb-27-2024, 04:38 PM
Last Post: deanhystad
  Spyder console zoom in not working? Dionysis 2 396 Feb-06-2024, 03:31 PM
Last Post: paul18fr
  IPython errors for numpy array min/max methods muelaner 1 509 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Can a program execute code in iPython shell and get result? deanhystad 3 1,664 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,189 May-05-2022, 12:32 PM
Last Post: H84Gabor
  Encountering `importlib_metadata.PackageNotFoundError` trying to run console script gretchenfrage 0 5,546 Jul-08-2021, 09:26 PM
Last Post: gretchenfrage
  Spyder Quirk? global variable does not increment when function called in console rrace001 1 2,163 Sep-18-2020, 02:50 PM
Last Post: deanhystad
  Problem running script within console koepjo 3 9,807 Mar-26-2020, 07:11 AM
Last Post: koepjo
  How can I create a multiline input in ipython? DataMower 3 4,309 Oct-28-2019, 08:50 PM
Last Post: DataMower
  ipython autocomplete broke indentation! Exsul 6 4,467 Aug-20-2019, 01:29 AM
Last Post: Exsul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020