[v7] How to print dictionary with frappe.msgprint?

Hi,

I’m working on v7. I am trying to use frappe.msgprint from my custom python code.

However, I am faced with this error on my console:

This only occurs when I am printing a variable with an assigned value.

If I were to do a simple frappe.msgprint(“hello”), there are no issues.

Thank you for any help.

1 Like

What are you trying to print?

I’m trying to print a variable, with a calculated value of type float/int. Thank you.

@rmehta Even I have faced this issue, when we try to print a LIST in frappe.msgprint then the list earlier used to show as python list but now it is rendered as separate elements and show in the next line so

frappe.msgprint(["foo", "bar"]) would earlier show as below:

[“foo”, “bar”]

But now it shows as:

foo
bar

Also this error mentioned by @fachristy would come when we try to msgprint a dict variable.

Any update as to how can we debug the lists and dicts in v7 since the frappe.msgprint now does not support dicts to be printed.

frappe.msgprint(str(dict)) ?

1 Like

I like to use json dump.

import json

frappe.msgprint(json.dumps(list))
frappe.msgprint(json.dumps(dict))
1 Like

Hello;
@rmehta

using str, it is giving error but we can use String without error. Anyway, it did not work to display the dictionary content as needed.

@BhupeshGupta

In javascript, if we typed import json, it is giving error once we load the page (even if I typed import json;).

Anyway, I was only able to display the content of the dictionary using alert(JSON.stringify(dict)); and I was not able to achieve this using msgprint or frappe.msgprint.

Regards
Bilal

@bghayad

on server side you can use

frappe.msgprint("<pre>{}</pre>".format(frappe.as_json(my_dict)))
2 Likes

Thank you @max_morais_dmm
And on javascript side?

Regards
Bilal

frappe.msgprint('<pre>' + JSON.stringify(my_dict, null, 2) + '</pre>');
4 Likes