Python Forum
[solved] subdictionaries path as variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] subdictionaries path as variable
#1
Hi

I'm using different levels of subdictionnaries in order to sort types of data (In the same idea of directories and sub-directories) ; it works fine. To update or add new ones, I need to provide explicitly the structure such as:
MyDict[subdict][subsubdict].update(Newdict)
In the previous example, everything is variable (subdict, subsubdict and so on); I'm wondering if ther's a way to remplace what I'm calling here a "path" by a variable, i.e. "[subdict][subsubdict]" by a kind of "path = [subdict][subsubdict]"?

Of course I can use the next code, but it's better to avoid it, isn't it?
path = '[subdict][subsubdict]'
exec("MyDict%s.update(Newdict)" % path )
Thanks for any suggestion.

Paul
Reply


Messages In This Thread
[solved] subdictionaries path as variable - by paul18fr - May-16-2021, 08:55 PM
RE: subdictionaries path as variable - by bowlofred - May-16-2021, 11:13 PM
RE: subdictionaries path as variable - by perfringo - May-17-2021, 08:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  working directory if using windows path-variable chitarup 2 732 Nov-28-2023, 11:36 PM
Last Post: chitarup
  SOLVED variable as tuple name krayon70 7 1,812 Apr-09-2022, 03:30 PM
Last Post: krayon70
  Get latest version off website and save it as variable [SOLVED] AlphaInc 5 1,963 Nov-14-2021, 09:00 PM
Last Post: DeaD_EyE
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,208 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  [solved] Variable number of dictionnaries as argument in def() paul18fr 11 6,132 Apr-20-2021, 11:15 AM
Last Post: paul18fr
  How to include Variable in File Path penahuse 3 7,297 Jan-05-2020, 03:08 AM
Last Post: ichabod801
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,751 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020