تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1534 أدوات العرض

Hola, intento trasladar el valor de un dominio que escribo en texto para usarlo en el campo de busqueda de la funcion search, pero cuando aplico la transformación no obtengo resultado alguno:

b=[]

a="[1,2,3]"

exec('b='+a)


Debería dar b=[1,2,3]

y da b=[]


como puedo solucionarlo? hay algún metodo de odoo que permita hacer esto?


Inglish:

Hi, im trying to become in code a string, but when i use the "exec()" function (native of python) doesnt work in odoo:

b=[]

a="[1,2,3]"

exec('b='+a)


should be : b=[1,2,3]

and give: b=[]


how can i fixe it? or exist another function of odoo?

الصورة الرمزية
إهمال
الكاتب

yes! that works perfectly by what i need for, thaks!

أفضل إجابة

Hi,

In Odoo you can use the literal_eval() for this,

Try like this,

​import ast 

​a = "[1,2,3]" 

​b = ast.literal_eval(a) 

​print(b)

OUTPUT: [1, 2, 3]

Thanks



الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 15
5741
2
ديسمبر 24
5499
1
ديسمبر 23
1492
2
يونيو 20
5905
2
يونيو 18
5839