Abdullah Md
Abdullah Md

Reputation: 151

how to print only english string?

I have excel file that contain arabic & english string.

ex:

{"ar": "ابراج التيسير", "en": "abrag altisyr"}

I want to print only english string.

ex:

abrag altisyr

I use this code:

for i in range(sheet.nrows):
    hotel_column = (sheet.cell_value(i, 0))
    re = hotel_column.replace('{"ar": "', '')
    res1 = res.replace('", "en": "', ' ')
    res2 = res1.replace('"}', '')

but i get :

ابراج التيسير abrag altisyr

Any kind of help please?

Upvotes: 1

Views: 78

Answers (1)

bereal
bereal

Reputation: 34282

This value is in JSON format. Use json.loads() and you'll get the dict with those values:

import json
for i in range(sheet.nrows):
    hotel_column = sheet.cell_value(i, 0)
    data = json.loads(hotel_column)
    print(data['en'])

Upvotes: 4

Related Questions