0

I'm trying to get all Schemas with "master" keyword in it. I got it, but my output looks like tuple parts and I would like only to get strings.

I did this:

def get_all_schemas():
    tmp_arr = []
    for name in db.engine.execute("""select schema_name from information_schema.schemata
                                    where schema_name like 'master%%' order by 1"""):
        tmp_arr.append({"name": name})
        print(tmp_arr)
    return tmp_arr

My output looks like:

[{'name': (u'master',)}, {'name': (u'master_old',)}, {'name': (u'master_old1',)}]

and I would like:

[{'name': 'master'}, {'name': 'master_old'}, {'name': 'master_old1'}]

Thanks

1 Answer 1

1

Modification:

tmp_arr.append({"name": str(name[0])})

Sample:

a=(u'master',)    
str(a[0])
'master'

The output of your query is tuple with Unicode string so you can get first element using [0] and can convert it into acsii strings using str() for more on converting string see this SO question and this also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.