Python Forum
typing farsi (persian) in python
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
typing farsi (persian) in python
#1
how can i type farsi text in python? i don't have any source and i don't know how i start?
i want to write farsi text in SQL table?
please help
i need a suitable source..i don't get any usable content from my search
Reply
#2
In Python 3 all strings are Unicode characters.

You can use str.encode() method too - "สวัสดีชาวโลก!".encode(encoding="UTF-8").
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
As mention bye Wavic,Python 3.x did make big changes to Unicode.
When you inside Python 3.x are strings Unicode characters.
All Unicode work like regular string,because that what they are.
Eg:
>>> s = "สวัสดีชาวโลก!"
>>> s
'สวัสดีชาวโลก!'
>>> type(s)
<class 'str'>
>>> s = s + 'a'
>>> s
'สวัสดีชาวโลก!a'
>>> s.count('ด')
1
>>> s.count('a')
1
Out and in of Python we have to use a encoding.
>>> with open('uni.txt', 'w', encoding='utf-8') as f:
...     f.write(s)
...     
14
>>> with open('uni.txt', encoding='utf-8') as f:
...     print(f.read())
... 
สวัสดีชาวโลก!a
Quote:i want to write farsi text in SQL table?
The advice is to keep utf-8 all the way in and out(also with database).
Reply
#4
i don't understand your code
this is my code...but i don get a suitable output
please helpppp
thank you
from tkinter import*
barname=Tk()

barname.geometry('200x120')
barname.title('عنوان')


tyLabel = Label(barname,text="راوند")


tyLabel.pack()
mainloop()
Reply
#5
Quote:i don't understand your code
It's just copy of farsi text from waic post,and doing test with it in interactive  shell.
You can do the same,you know that Python has a interactive shell?

Use code tag.
Here a picture of my tkinter window,running Python 3.6
Reply
#6
Maybe already the first post has the answer.
Set into your code:
barname.title('عنوان'.encode(encoding="UTF-8"))
tyLabel = Label(barname,text="راوند".encode(encoding="UTF-8"))
Could this work?
Reply
#7
(Feb-20-2017, 02:15 PM)merlem Wrote: Could this work?
No,the point is that you do not encode when you are running code inside Python 3(only in/out).
In Python 3 are all strings sequences of Unicode character.
This give you bytes:
>>> text = "راوند".encode(encoding="UTF-8")
>>> text
b'\xd8\xb1\xd8\xa7\xd9\x88\xd9\x86\xd8\xaf'

>>> # Correct
>>> text = "راوند"
>>> text
'راوند'
Look at my picture,i just copy code from @gray post and run it.
It has correct correct text in GUI window.
Reply
#8
Okay, that's no good then, sorry.

However, If I run the code gray had given, I got a different result: the text inside the window seems to be okay, but the barname is replaced by small boxes.
Reply
#9
(Feb-20-2017, 02:15 PM)merlem Wrote: Maybe already the first post has the answer.
Set into your code:
barname.title('عنوان'.encode(encoding="UTF-8"))
tyLabel = Label(barname,text="راوند".encode(encoding="UTF-8"))
Could this work?

it doesn't work...how shoud i do?
please help............
Reply
#10
In your script/program first line is something like this: #!/usr/bin/env python3. Be sure that it's python3 not just python.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  type farsi in the sql table tkinter gray 1 3,342 Feb-24-2017, 06:50 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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