Exporting arabic words to csv in Python 3
up vote
0
down vote
favorite
I'm trying to export some arabic in a csv file after getting it from the translater. I Always run into a problem when trying to write it in the CSV. The problem is this one :
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-7: character maps to <undefined>
My code goes as follow (a bit of it, trying to be concise here) :
from bs4 import BeautifulSoup
import requests
import csv
from yandex_translate import YandexTranslate
csv_file = open("syno.csv", "w", newline = '')
csv_writer = csv.writer(csv_file)
#making the request to the translater and so on, not written here, tell me if you need it but I don't think so.
traduction =(translate.translate('bonjour', 'fr-ar'))
csv_writer.writerow([traduction["text"]])
csv_file.close()
When I build it in SublimeText with a print instead of the csvwriter, I get the result without problem.
It's only when I want to write in the csv that I get the issue. Any ideas on how to fix this?
I've seen Something about encoding or decoding it in UTF-8, but I don't know where to add this possibility
Thanks!
python csv arabic writer
add a comment |
up vote
0
down vote
favorite
I'm trying to export some arabic in a csv file after getting it from the translater. I Always run into a problem when trying to write it in the CSV. The problem is this one :
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-7: character maps to <undefined>
My code goes as follow (a bit of it, trying to be concise here) :
from bs4 import BeautifulSoup
import requests
import csv
from yandex_translate import YandexTranslate
csv_file = open("syno.csv", "w", newline = '')
csv_writer = csv.writer(csv_file)
#making the request to the translater and so on, not written here, tell me if you need it but I don't think so.
traduction =(translate.translate('bonjour', 'fr-ar'))
csv_writer.writerow([traduction["text"]])
csv_file.close()
When I build it in SublimeText with a print instead of the csvwriter, I get the result without problem.
It's only when I want to write in the csv that I get the issue. Any ideas on how to fix this?
I've seen Something about encoding or decoding it in UTF-8, but I don't know where to add this possibility
Thanks!
python csv arabic writer
Write file encoding goes in theopen
statement for that file: docs.python.org/3/howto/…
– usr2564301
Nov 13 at 12:20
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to export some arabic in a csv file after getting it from the translater. I Always run into a problem when trying to write it in the CSV. The problem is this one :
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-7: character maps to <undefined>
My code goes as follow (a bit of it, trying to be concise here) :
from bs4 import BeautifulSoup
import requests
import csv
from yandex_translate import YandexTranslate
csv_file = open("syno.csv", "w", newline = '')
csv_writer = csv.writer(csv_file)
#making the request to the translater and so on, not written here, tell me if you need it but I don't think so.
traduction =(translate.translate('bonjour', 'fr-ar'))
csv_writer.writerow([traduction["text"]])
csv_file.close()
When I build it in SublimeText with a print instead of the csvwriter, I get the result without problem.
It's only when I want to write in the csv that I get the issue. Any ideas on how to fix this?
I've seen Something about encoding or decoding it in UTF-8, but I don't know where to add this possibility
Thanks!
python csv arabic writer
I'm trying to export some arabic in a csv file after getting it from the translater. I Always run into a problem when trying to write it in the CSV. The problem is this one :
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-7: character maps to <undefined>
My code goes as follow (a bit of it, trying to be concise here) :
from bs4 import BeautifulSoup
import requests
import csv
from yandex_translate import YandexTranslate
csv_file = open("syno.csv", "w", newline = '')
csv_writer = csv.writer(csv_file)
#making the request to the translater and so on, not written here, tell me if you need it but I don't think so.
traduction =(translate.translate('bonjour', 'fr-ar'))
csv_writer.writerow([traduction["text"]])
csv_file.close()
When I build it in SublimeText with a print instead of the csvwriter, I get the result without problem.
It's only when I want to write in the csv that I get the issue. Any ideas on how to fix this?
I've seen Something about encoding or decoding it in UTF-8, but I don't know where to add this possibility
Thanks!
python csv arabic writer
python csv arabic writer
asked Nov 13 at 11:46
BeatJuice
223
223
Write file encoding goes in theopen
statement for that file: docs.python.org/3/howto/…
– usr2564301
Nov 13 at 12:20
add a comment |
Write file encoding goes in theopen
statement for that file: docs.python.org/3/howto/…
– usr2564301
Nov 13 at 12:20
Write file encoding goes in the
open
statement for that file: docs.python.org/3/howto/…– usr2564301
Nov 13 at 12:20
Write file encoding goes in the
open
statement for that file: docs.python.org/3/howto/…– usr2564301
Nov 13 at 12:20
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
you can use UTF-8 by declaring it at the top of your code :
# -*- coding: <encoding name> -*-
then you can use utf-8 encoding/decoding.
UPDATE: Based on these answers you should change the other environments Unicode like your console.
[answer-1][1]
[answer-2][2]
try opening your file with UTF-8 encoding :
csv_file = open("syno.csv", "w", encoding='utf-8', newline = '')
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
you can use UTF-8 by declaring it at the top of your code :
# -*- coding: <encoding name> -*-
then you can use utf-8 encoding/decoding.
UPDATE: Based on these answers you should change the other environments Unicode like your console.
[answer-1][1]
[answer-2][2]
try opening your file with UTF-8 encoding :
csv_file = open("syno.csv", "w", encoding='utf-8', newline = '')
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
add a comment |
up vote
1
down vote
accepted
you can use UTF-8 by declaring it at the top of your code :
# -*- coding: <encoding name> -*-
then you can use utf-8 encoding/decoding.
UPDATE: Based on these answers you should change the other environments Unicode like your console.
[answer-1][1]
[answer-2][2]
try opening your file with UTF-8 encoding :
csv_file = open("syno.csv", "w", encoding='utf-8', newline = '')
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
you can use UTF-8 by declaring it at the top of your code :
# -*- coding: <encoding name> -*-
then you can use utf-8 encoding/decoding.
UPDATE: Based on these answers you should change the other environments Unicode like your console.
[answer-1][1]
[answer-2][2]
try opening your file with UTF-8 encoding :
csv_file = open("syno.csv", "w", encoding='utf-8', newline = '')
you can use UTF-8 by declaring it at the top of your code :
# -*- coding: <encoding name> -*-
then you can use utf-8 encoding/decoding.
UPDATE: Based on these answers you should change the other environments Unicode like your console.
[answer-1][1]
[answer-2][2]
try opening your file with UTF-8 encoding :
csv_file = open("syno.csv", "w", encoding='utf-8', newline = '')
edited Nov 13 at 12:33
answered Nov 13 at 12:05
Ali Kargar
1444
1444
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
add a comment |
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
1
1
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
I think the problem is not in Python, since it's working fine when I build it without writing in the csv.
– BeatJuice
Nov 13 at 12:12
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
It's working, i was setting encoding("utf-8") instead of the = sign. Thank you!
– BeatJuice
Nov 13 at 12:43
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280373%2fexporting-arabic-words-to-csv-in-python-3%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Write file encoding goes in the
open
statement for that file: docs.python.org/3/howto/…– usr2564301
Nov 13 at 12:20