0

I'm connecting access db and fetching values. In one of the column values are stored like

abc|def|ghi|xyz. 

Need to replace | with space and store in array.

I'm trying below code but each character is stored in array like "a b c ..."

for row in cursor.fetchall():
   names = row[1]
   names = names .replace("|", ",")

namesarray = []
namesarray = names

for fullname in (namesarray):
 --do something --
5
  • please print the output of row[1] Commented Jul 21, 2018 at 17:04
  • 1
    Maybe you want names=names.split("|") instead of replacing with comma? Commented Jul 21, 2018 at 17:04
  • Try print("abc|def|ghi|xyz".split('|')) Commented Jul 21, 2018 at 17:05
  • output of row[1] = abc|def|ghi|xyz Commented Jul 21, 2018 at 17:09
  • Thanks pault and Sagar. Split works. Commented Jul 21, 2018 at 17:11

1 Answer 1

1

Try:

for row in cursor.fetchall(): names = row[1] names_arr = names.split('|') print (names_arr)

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.