SyntaxError when runing "python examples/train.py singleagent_ring" - python

When I run python examples/train.py singleagent_ring
I find the following error:
file "examples/train.py", line 201
**config
^
SyntaxError: invalid syntax
Please any help?

Yeah, I feel like if you added the code you were working on as well as well as the line of code where the error was found that would make this question easier to understand. Additionally, have you attempted to debug this issue on your own? If so, what did you try? Informing us of these things would make it much easier to get the full picture of the issue you've encountered.
Aside from that, a SyntaxError is usually associated with something being mistyped in the syntax of your code so you may want to look it over for any spelling errors, missing indents, and/or missing/extra characters in your code. That's the most I or anyone else here can really tell you without any more context.

Related

#local_config_python issue in RBE

I've been having this error while setting up remote exec with python.
The #local_config_python platform rule says it doesn't find the Python-ast.h file. Please, has anyone encountered a problem like that. Here's out it looks. I apologize for my lack of clarity, I don't really understand the problem.

Python SyntaxError: invalid syntax when implementing bbcodepy

I got bbcodepy and I'm allowed to modify it, but I can't import it in my main.py. I keep getting a SyntaxError and I don't really know what's wrong with the code because I didn't write it. I just want to tinker around a little bit and see if I can get it to fill my needs.
Here's an image pointing me in the direction of the syntax error. But I noticed the same code is written on the same line and I don't get the SyntaxError for that. Here's the code:
_URL_RE = re.compile(ur'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?#\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)''')
The problem appears to be "[^\s&()]" but only the second one, not the first one. If you look closely in the code you'll see that the same thing appears twice, but I only get the SyntaxError on the second appearance. Someone enlighten me, please. I've been trying to find a decent BBCode parser for Python for a couple of days now and I believe this is the one I can modify to my needs. I can't seem to get bbcode to work as I want it to, so I'm trying this out.
Well, Python version 3.4 and above does not support a 'UR' prefix.
You need to execute your code with Python 2.7, or change to line into:
_URL_RE = re.compile(r'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?#\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)''')
See also: python version 3.4 does not support a 'ur' prefix
Note: consider avoiding triple-quoted string because if you insert a newline, it can change the meaning of the regex (unless it is compiled in VERBOSE mode).

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.

Keep simpleserver active even on syntax errors

Is there a way to configure the simple-server that Flask uses to not exit on every single syntax error?
app = Flask(__name__)
app.run(host='0.0.0.0', debug=True, use_debugger=True, passthrough_errors=False);
Currently I'm using this setup for the simple-server.
Setting passthrough_errors to False means most of the errors actually keeps the process alive so that I can use the interactive debugger, syntax errors still exits the program though. I've tried different configuration values but I have not found anything that works. Thanks!
I just posted a Flask-Failsafe extension to solve this exact issue.
I hit this all the time and ran across your post earlier looking for a solution. After a bit of experimenting I hacked up a decorator you can use to wrap your initialization code so that if it fails the reloader will keep working. Check it out and let me know what you think.
According to Python documentation there are two types or errors:
Syntax Errors
Exceptions
Syntax errors are produced during parse time (at that moment your code doesn't actually executes, so you have no possibility to catch errors, since parse time is not a runtime, when your code actually executes).
The only way you can catch syntax errors is when they happen inside a piece of code given as an argument to exec function (executes string of python code):
>>> try:
... exec('x===6')
... except SyntaxError:
... print('Hello!')
...
Hello!
But you must remember to use exec() only when you really know what you do. It's not recommended to use exec() at all especially when it depends on user input.

Where to find python-interpreter error codes?

I have a python application that communicates with a PHP application.
Right now, I have defined error codes on both sides so they match (i.e. we can detect the python-side failures in PHP and react accordingly).
My problem comes from python being an interpreted language, here is why :
If the code has a syntax problem, then the interpreter will return error codes.
But these interpreter error codes will be indistinguishable from the application errors.
I am not in charge of the python code, but I was asked to be able to detect eventual python interpreter failures so I can notify the end user using PHP.
Because of that, I need to find a list of the interpreter return codes when malfunctionning.
I failed to find this information on both google, python doc, and man page.
Does anybody have/know where to find this information ?
(also, if you have any other ideas on how to get around this problem, I'd be happy to hear them)
Thanks in advance !
The best solution would be setting an exception hook that always exits with a certain code.
import sys
def excepthook(type, value, traceback):
sys.exit(X) # X is your exit code
sys.excepthook = excepthook
Syntax errors should be irrelevant - why would you ever put a script that contains syntax errors in production?
But anyway, Python always exits with a non-zero code (apparently always 1) in case of an uncaught exception and 0 if everything went fine.
I believe this might be what you need. It will map the error codes to their respective string messages.
http://docs.python.org/library/errno.html
Specifically:
http://docs.python.org/library/os.html#os.strerror

Categories

Resources