Python Forum
is there py code to covert nums to text?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there py code to covert nums to text?
#1
is there anything that would do something along the lines of:

0 -> 'zero'
35 -> 'thirty five'
-20 -> 'minus twenty'
987654321987654 -> 'nine hundred eighty seven trillion six hundred fifty four billion three hundred twenty one million nine hundred eighty seven thousand six hundred fifty four'

?? :s

i have written this in C many years ago.  this is on the top of my "redo in python" stack.  a quick google gets lots of online tools and even an Excel macro but nothing in python. should i go ahead and do this? does someone else want to?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Hey Skaperen,
I found it after a quick search, this package might be what you are after:
https://pypi.python.org/pypi/inflect
There are examples on this site. Here's one, I didn't try it but it might work:

import inflect
p = inflect.engine()
words = p.number_to_words(1234)
Reply
#3
I was going to say if there was not a library for it, and you already wrote it in C, all you would have to do is import your own C lib into python http://python-forum.org/viewtopic.php?f=25&t=621
Recommended Tutorials:
Reply
#4
That's a very nice link, a tutorial like this would be a great addition to this forum *thumbsup*
Reply
#5
I was going to give the original authors time to move tutorials over themselves. If not, then ill jsut move it over soon
Recommended Tutorials:
Reply
#6
inflect works!

strange way to activate a function.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
Cool class - works with exponents as well

>>> import inflect
>>> p = inflect.engine()
>>> p.number_to_words(725.16e10)
'seven trillion, two hundred and fifty-one billion, six hundred million point zero'
Larz60+
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Covert Shapely Point() to (x, y) michael1789 0 1,878 Mar-26-2020, 12:33 AM
Last Post: michael1789
  How to write a code to open and read text file by clicking on the "text file" kavindu 4 4,117 Jul-06-2018, 06:55 PM
Last Post: buran

Forum Jump:

User Panel Messages

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