0

I want to plot in the csv file the symbol gamma in greek letter. I tried Unicode and the CSS code but I got errors or not the desired result.

For instance, the CSS-code for gamma is the following one:\03B3

Home=[['home','\03B3 ']]

if glass_type!=3:
    with open('Output.csv', 'w', newline='') as csvFile:       

    thewriter.writerows(Home) 

The expected result is the symbol Gamma in Greek letter; but, I get the following result: B3

Consider that the CSS code works for the degree symbol with the following code: \xb0

chrisis
  • 119
  • 1
  • 1
  • 9

1 Answers1

1

You're specifying the unicode CSS code wrong:

Home=[['home','\u03B3 ']] # note the \u

printing Home results in:

[['home', 'γ']]

Note, however, that since python 3's default strings are unicode, you could just use the gamma symbol in your script (this improves readability a lot too, btw):

Home = [['home', 'γ']]
GPhilo
  • 18,519
  • 9
  • 63
  • 89
  • Do I have to import something? – chrisis Jun 25 '19 at 08:18
  • UnicodeEncodeError: 'charmap' codec can't encode character '\u03b3' in position 2: character maps to – chrisis Jun 25 '19 at 08:25
  • Put the full error output (including the line and trace) in your question. Also, add the output of running `python --version` in a terminal window – GPhilo Jun 25 '19 at 08:28
  • File "C:\Users\BE110924\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/BE110924/Desktop/Fd_/INPUT_OUTPUT_fd.py", line 364, in thewriter.writerows(Line_1) File"C:\Users\BE110924\AppData\Local\Continuum\anaconda3\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u03b3' in position 2: character maps to – chrisis Jun 25 '19 at 08:39
  • I am using Anaconda 3 – chrisis Jun 25 '19 at 08:40
  • What version of python are you using **exactly**? This is important, because versions prior to python 3.6 require you to install the package `win-unicode-console` (see [this answer](https://stackoverflow.com/a/32176732/3214872) for more details). You can get python's versions importing `sys` and printing `sys.version`, or by running in a console `python --version` – GPhilo Jun 25 '19 at 08:44
  • Actually, does `print('\u03B3')` raise any error? Or is the error coming from inside `writerows` (in which case I can't help you further without seeing the implementation of `writerows`)? – GPhilo Jun 25 '19 at 08:46
  • Hi, you are right. It works fine.The implementation in writerows are attached above – chrisis Jun 25 '19 at 08:49
  • Hi I found, I just have to add encoding='utf-8-sig' in this line with open('Output.csv', 'w', newline='', encoding='utf-8-sig') as csvFile: – chrisis Jun 25 '19 at 09:28