0

The code below will not execute because the fstring error. Is from a reserved word in dotmap ?

from dotmap import DotMap

oWithFrom = {"from":"from Data", "to":"to Data"}

dmWithFrom = DotMap(oWithFrom)

print(f"to:{dmWithFrom.to}")

print(f"from:{dmWithFrom['from']}")

# This does not get past pylint
# invalid syntax (<fstring>, line 1)
print(f"from:{dmWithFrom.from}")
  • "from" is a reserved word in Python. You can't have a variable or object member named "from". Same with the other reserved words, like `if`, `else`, etc. – Tim Roberts Apr 09 '21 at 18:24

1 Answers1

0

Ok .. rookie move. from is a keyword so it is getting parsed differently even as a dotmap variable.

  • Right. DotMap is a facade. It doesn't actually store those names as class members. They're stored as a dict, so it's only when you try to refer to it as `x.from` that you trigger Python's anger. – Tim Roberts Apr 09 '21 at 18:25