Python - very ambiguous error message - python

I'm working on a large scale software system written in Python right now, which includes multiple modules. I was wondering what I should do about this, if anyone could make any sense of this error message that I keep receiving:
File "<string>", line 1, in <module>
NameError: name 'CerealObject' is not defined
The thing that makes it very cryptic is that it seems to not provide an actual file name or a specific module. From a beginner's standpoint this makes it seem impossible to debug.

File "<string>" in an exception stack trace typically means that you're using either exec or eval somewhere. They execute code from a string, hence the lack of an actual file name.
You'll need to look at the following line(s) of your stack trace to determine the source of the problem.

Related

shelve module even not creating shelf

I am new to stackoverflow and experimenting with Python, currently just trying tutorial examples. Experienced a wonderful learning curve but got completely stuck with the following (working under windows 10):
import shelve
s = shelve.open("test")
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\dbm\dumb.py", line 82, in _create
f = _io.open(self._datfile, 'r', encoding="Latin-1")
FileNotFoundError: [Errno 2] No such file or directory: 'test.dat'
It would be great to get some help to resolve this.
During handling of the above exception, another exception occurred:
In Python 3, by default, shelve.open tries to open an existing shelf for reading. You have to pass an explicit flag to create a new shelf if if doesn't already exist.
s = shelve.open("test", "c")
This is in contrast to Python 2, where the default flag was "c" instead of "r".
How to read an error message
In general, error messages will do their best to tell you what's wrong. In the case of python, you'll typically start at the bottom; here
No such file or directory: 'test.dat'
tells you exactly why the error's being thrown: test.dat doesn't exist.
Next you would read upward through the stack trace until we got to something that we either understood or had written recently, and we'd try to make sense of the error message from there.
How to troubleshoot an error
Is the stated problem intelligible?
Yes, we asked the software to do something with a (.dat?) file called "test", so we at least know what the hell the error message is talking about.
Do we agree with the underlying premise of the error?
Specifically, does it make sense that it should matter if test.dat exists or not? Chepner covers this.
Do we agree with the specific problem as stated?
For example, it wouldn't be weird at all to get such an error message when there was in fact such a file. Then we would have a more specific question: "Why can't the software find the file?" That's progress.
(Usually the answer would be either "Because it's looking in the wrong place" or "Because it doesn't have permission to access that file".)
Read the documentation for the tools and functions in question.
How can we validate either our own understanding of the situation, or the situation described in the error message?
Depending on the context this may involve some trial and error of re-writing our code to
print out (log) its state during execution
do something similar but different from what it was doing, which we're more certain should work.
do something similar but different from what it was doing, which we're more certain should not work.
Ask for help.
Seems shelve sometimes uses the dumbdbm to serialize.
Use dbm to use dbm instead:
import dbm
with dbm.open($filename, 'n') as db:
# read/write

Find The Value of An Argument Without Executing The File

I need to scan a python file and figure out the value of an argument to a function. Take for example a file containing following code.
# start of file
path = "/a/b/c"
def main():
run(full_path=path, os="linux")
# end of file
I need to know what is the value of argument "full_path" without executing or importing this file.
I think any library which is used in developing IDEs can do it. Please help in case you have solved similar problems.
To give a little bit of background to the problem, I am running a server application hence cannot afford to execute any arbitrary python file and also I may not have all the related dependent packages in my environment in order to execute.

Configure Django's test debugging to print shorter paths.

I'm not sure how to approach this, whether it's a Django, Python, or even Terminal solution that I can tweak.
The thing is I'm learning Django following a book (reference here, really like it), and whenever I run the tests, I get really long output in the terminal for debugging matters. Obviously there's many traceback functions that get called after another, but what started bugging me is that the file paths are very long and they all have the same project folder... which is long by itself, and then it adds all the virtualenv stuff like this:
Traceback (most recent call last):
File "home/user/code/projects/type_of_projects_like_hobby/my_project_application/this_django_version/virtualenv/lib/python3.6/site-packages/django/db/models/base.py", line 808, in save
force_update=force_update, update_fields=update_fields)
Since the paths take two or more lines, I can't focus on what functions I should be looking at clearly.
I have looked at the verbosity option when calling manage.py test but it doesn't help with the paths. If anyone has an idea on how to ~fix~ go about this issue, it'd be cool.
Thanks guys.
There's really not a way to change the behavior (this is how Python displays tracebacks). But you can pipe the output into something that will reformat it. For example, here's a tool you can pipe traceback output into that will do various types of formatting.

Syntax error: bad input '' in codeskulptor

Sometimes when I load a particular codeskulptor program that gives me the
error: Syntax error: bad token '' on a line of code, what is wrong?
Note: This is a different question, I know I asked a similar question before but this is a different issue.
I generally consider this as a bug in codeskulptor. When this happens, you probably copied that line of code, You could just delete and rewrite the exact same line of code. If it works then you're set, if it doesn't then there is a bug in your code but most likely won't be on that very line.

Maxscript registeroleinterface appears to not be working

First off, thanks to whoever reads through this and provides me some help/feedback as I have been struggling with this for a couple of days. I am new to stackoverflow and have tried to be as detailed as possible in the question.
I am trying to set up an OLE server on 3ds Max. I have followed the instructions described [here] (http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-AE4CAED2-1EF9-40EF-9761-83F535FE953A.htm,topicNumber=d30e714562) including editing the registry and exposing the function.
However, when I try to call the function from another program (I tried with MATLAB and a python script) I get an error which leads me to suspect that registerOLEInterface is not registering the function. In python, I used a very similar script to the first one [here] (http://tech-artists.org/forum/showthread.php?2723-Python-to-MaxScript-to-Python) and get an error like this:
`Traceback (most recent call last):
File "start.py", line 8, in <module>
maxCOM ._FlagAsMethod("maxCommand")
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 437, in _FlagAsMethod
details = build.MapEntry(self.__AttrToID__(name), (name,))
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 442, in __AttrToID__
return self._oleobj_.GetIDsOfNames(0,attr) pywintypes.com_error: (-2147352570, 'Unknown name.', None, None)`
In MATLAB, h = actxserver('Max.Application.15') works fine, but when I try to access the function using h.maxCommand, I get this error:
`No appropriate method, property, or field maxCommand for class COM.Max_Application_15.`
I would appreciate any help as to what I might be doing wrong. I am using Max 2013 and have tried with 32 and 64-bit versions.
Thanks,
Please note that I don't have access to 3DS Max, and my answer is based on my experience connecting to other OLE and COM Servers from MATLAB (such as Microsoft Office, and OPC servers).
I would be fairly sure that if h = actxserver('Max.Application.15') is working fine and doesn't give you an error message, then you have successfully set up and connected to an OLE server.
The problem is more likely to be that you are using an incorrect syntax for whatever the maxCommand does in 3DS Max. Perhaps, for example, it requires an input argument. Note that the MATLAB error message is a bit elliptical - it says that there is no appropriate method, property or field, not that there is no method, property, or field. I've found that a common reason for getting this message is that I am calling a method that does exist, but not calling it in the right way.
To find out what syntax maxCommand is expecting, try typing methodsview(h). This will give you a list of all the methods of h, along with their expected input types, and may give you a hint about how maxCommand expects to be called.
Hope that helps - I'm afraid there's not much more I can do without access to a copy of 3DS Max.
EDIT
Having taken a quick look at the 3DS Max documentation link you provided, it looks like there's a simple function maxVersion that doesn't require any input arguments, and just returns you the version number of 3DS Max. Try running h.maxVersion as a simple test, to see whether you have successfully connected to a server while avoiding any potential confusions about input arguments to maxCommand.

Categories

Resources