Python Forum
Issue with special characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with special characters
#1
I need to use special characters such as ▒ and █ in my code, and save these to a text file.
However, I am getting an encoding error:
Error:
UnicodeEncodeError: 'charmap' codec can't encode character '\u2588' in position 2: character maps to <undefined>
I have seen so many topics on this, but they are all really confusing. Wall Is there a simple way of dealing with this? Thanks!
Reply
#2
Windows? The Windows console doesn't support Unicode. As I know. I don't use Windows at all though. See this. It may help.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
This is for Python 3.6,not Python 2.
with open('foo.txt', 'w', encoding='utf-8') as f_out:
    s = '▒ █'
    f_out.write(s)

with open('foo.txt', encoding='utf-8') as f:
    print(f.read())
cmder as i use,do i except to print correct result,but also cmd do print correct.
cmd output:
E:\1py_div>python uni1.py
▒ █
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 844 Mar-26-2024, 09:28 AM
Last Post: Nik1811
Question Special Characters read-write Prisonfeed 1 612 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Rename Multiple files in directory to remove special characters nyawadasi 9 6,364 Feb-16-2021, 09:49 PM
Last Post: BashBedlam
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,683 May-15-2020, 01:37 PM
Last Post: snippsat
  Check for a special characters in a column and flag it ayomayam 0 2,044 Feb-12-2020, 03:04 PM
Last Post: ayomayam
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 3,020 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  o365 special subject mail download issue anna 3 2,896 May-16-2019, 07:16 PM
Last Post: micseydel
  problems with python script and special characters last08 1 2,289 Mar-29-2019, 09:28 AM
Last Post: Kebap
  IDLE crash using special characters? reikonaga 6 4,746 Aug-06-2018, 07:37 AM
Last Post: keegan_010
  Finding Special Characters in a String ATXpython 4 19,731 Sep-30-2016, 10:08 PM
Last Post: ATXpython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020