Oversimplifying slightly, your code:
with x as 1:
y = 1
… translates to something like this:
try:
1 = x.__enter__()
y = 1
finally:
1.__exit__()
Writing 1 = x.__enter__() is obviously going to raise a SyntaxError: can't assign to literal, because it doesn't mean anything to assign a new value to the literal constant 1.
Doing the same thing in a with statement raises the same exception. (In old versions of Python (I think just 2.5?), the error message wasn't quite as useful, and it just said SyntaxError: invalid syntax, but the problem is the same.)
Depending on what was in x, getting past the SyntaxError may well just raise a new exception, AttributeError: __enter__. Only context managers can be used in a with statement. Roughly, these are things that know how to clean up after themselves, and where it's important to get them to clean up at the end of some block of code no matter what. Files are the prototypical example: they call self.close() when you exit the block, which makes sure you don't get OS errors from having hundreds of open files lying around, or fail to flush the last write, or other such problems.
For more information on with, see PEP 343, the proposal that originally added with to Python 2.5, or Understanding Python's "with" statement (from effbot).
So, the question here is: what were you trying to do? If you just want to assign the value 1 to the name x, you already know how to do that, because you did it with y in the very next line: just x = 1. If you were trying to do something different… well, there probably is a way to do it, but with may well be nowhere near the right answer.
ashas to be an assignment target, and you can't assign to constants like1.with x as 1:would do it, we could probably explain the right way to do it.SyntaxError: can't assign to literal, and I think that's been true since around 2.6 and 3.2.