We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDB.at("test").create({"a": 0}, force_overwrite=True) with DDB.at("test", key="a").session() as (session, a): a = 1 session.write() print(DDB.at("test").read())
prints 0, but it would be more intuitive if it was 1. The reason is that primitives like int are passed by value, not by ref.
The current way to solve this is:
DDB.at("test").create({"a": 0}, force_overwrite=True) with DDB.at("test_pd").session() as (session, d): d["a"] = 1 session.write() print(DDB.at("test").read())
But this is not as efficient, since, the whole test file has to be loaded instead of only the key.
Another solution would be to pass the variable into the session.write()
DDB.at("test").create({"a": 0}, force_overwrite=True) with DDB.at("test", key="a").session() as (session, a): a = 1 session.write(a) print(DDB.at("test").read())
A possible solution without changing the syntax is using the current frame with inspect:
import inspect class ObtainVarInWith: def __enter__(self): f = inspect.currentframe().f_back self.x = 2 self.oldvars = dict(f.f_locals) # Take copy of locals dict. return self.x def __exit__(self, type, value, tb): f = inspect.currentframe().f_back for name, val in f.f_locals.items(): if name not in self.oldvars: print("New variable:", name, val) elif val is not self.oldvars[name]: print("Changed variable", name, val) with ObtainVarInWith() as x: print("in with block", x) x = 2 print("after assign with block", x)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
prints 0, but it would be more intuitive if it was 1. The reason is that primitives like int are passed by value, not by ref.
The current way to solve this is:
But this is not as efficient, since, the whole test file has to be loaded instead of only the key.
Another solution would be to pass the variable into the session.write()
A possible solution without changing the syntax is using the current frame with inspect:
The text was updated successfully, but these errors were encountered: