APIs & Integrations

Cadriel
Member

Dict variables and updating them

Hi there,

I'm still relatively new to hubspot and am working my way through implementing an existing site onto the platform.

I need to create a relatively complex dictionary of data, that'll be updated further into the page template. So, i'm working through some simple examples to make sure I know hubl can do what I need.

{% set dict_var = {'name': 'Item Name', 'price': '$20', 'size':'XL'} %}
{% set dict_var['location'] = 'fancy location' %}

The above is one example of what I'd like to do. I.e., create a dict - and then update it on the next line. However - this simply won't work. If I print this variable on to the page (further down) it only shows the data without the location key.

I've tried various other ways of attempting to adjust the dict to no avail. Help?

0 Upvotes
8 Replies 8
SabaTechatom
Member

Dict variables and updating them

Hi @Cadriel ,normally for every solution we check out on youtube ,however I like the articles related with it ,as i can have the codes clearly mentioned in the posts and find out what went wrong and my internet data will be saved 

recently i came across this python dictionary methods where they have shown us different methods .you can refer this for the solution.

Along with It,i read one more  article named most asked  pattern programs in C and loved it, they made everything so simple.

0 Upvotes
dasagriva
Member

Dict variables and updating them

One can use a couple of ways to create, update, and append elements to a dictionary. This tutorial (http://www.techbeamers.com/python-tutorial-step-by-step/) explains them all with examples.

0 Upvotes
Not applicable

Dict variables and updating them

The simple answer is

def setVar(self, var):
    for key, value in var.iteritems():
        setattr(self, key, value)

Or you can refer this
For learning python: Visit

Johnny21
Member

Dict variables and updating them

Great resource! I personally prefer this for learning python

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Dict variables and updating them

Hi @cadriel, it doesn't look like this method is documented on our end, but since HubL is based loosely off of jinja2 which is a subset of python (more info on dicts in python here: https://www.digitalocean.com/community/tutorials/understanding-dictionaries-in-python-3), you can use the update method on the dictionary. The way I updated this dictionary is via the following code:

{% set dict_var = {'name': 'Item Name', 'price': '$20', 'size':'XL'} %}
{% set test = dict_var.update({'7': 'seven'}) %}
{% set test = dict_var.update({'8': 'eight'}) %}
    
{{ dict_var }}

Printing dict_var on that last line above ends up including both the 7 and 8 properties, and the whole dictionary is printed out. Here's an example --> http://blog.playtimepottery.net/macros

theversetech
Member

Dict variables and updating them


Robotic- An entity that mimics humans.

Process- A sequence of steps that achieve a task.

Automation- Process of making tasks happen without human intervention. The reality is "Robot" in RPA is not a physical entity. It is a virtual system that helps in the automation of manual tiring tasks. RPA or Robotic Process Automation is a technology that allows engineers to accomplish tasks that once required human guidance.

The principal objective of the Robotics Process Automation process to supplant dreary and exhausting administrative errands performed by people, with a virtual workforce.

Hey mate! SR is at your service. You seem to be doing good so far. Let's now learn categories of RPA technology.

RPA technologies can be divided into three categories.



  1. Probiotics
  2. Knowbots
  3. Chatbots
  4. Probiotics



These are the bots that follow simple, repeatable rules to process data.

 

 

https://www.theversetech.com/ 

 

 

0 Upvotes
Cadriel
Member

Dict variables and updating them

You're a legend. Thanks @Connor_Barley.

Are there other generic docs around I could refer to in cases like this? I did refer to some python docs before creating this post but it didn't mention the update method. Perhaps the Jinja docs? Any specific versions?

0 Upvotes
cbarley
HubSpot Alumni
HubSpot Alumni

Dict variables and updating them

Hey @cadriel, I usually take a look at these docs: http://jinja.pocoo.org/docs/2.10/ and I really like these ones on Python: https://www.programiz.com/python-programming/methods/dictionary/update

0 Upvotes