gooderp18绿色标准版
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

96 Zeilen
2.9KB

  1. #!C:\odoobuild\WinPy64\python-3.12.3.amd64\python.exe
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
  4. # Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
  5. # This library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. # You should have received a copy of the GNU Lesser General Public
  14. # License along with this library; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. # MA 02110-1301 USA
  17. """num2words: convert numbers into words.
  18. Usage:
  19. num2words [options] <number>
  20. num2words --list-languages
  21. num2words --list-converters
  22. num2words --help
  23. Arguments:
  24. <number> Number you want to convert into words
  25. Options:
  26. -L --list-languages Show all languages.
  27. -C --list-converters Show all converters.
  28. -l --lang=<lang> Output language [default: en].
  29. -t --to=<to> Output converter [default: cardinal].
  30. -h --help Show this message.
  31. -v --version Show version.
  32. Examples:
  33. $ num2words 10001
  34. ten thousand and one
  35. $ num2words 24,120.10
  36. twenty-four thousand, one hundred and twenty point one
  37. $ num2words 24,120.10 -l es
  38. veinticuatro mil ciento veinte punto uno
  39. $num2words 2.14 -l es --to currency
  40. dos euros con catorce céntimos
  41. """
  42. from __future__ import print_function, unicode_literals
  43. import os
  44. import sys
  45. from docopt import docopt
  46. import num2words
  47. __version__ = "0.5.13"
  48. __license__ = "LGPL"
  49. def get_languages():
  50. return sorted(list(num2words.CONVERTER_CLASSES.keys()))
  51. def get_converters():
  52. return sorted(list(num2words.CONVERTES_TYPES))
  53. def main():
  54. version = "{}=={}".format(os.path.basename(__file__), __version__)
  55. args = docopt(__doc__, argv=None, help=True, version=version, options_first=False)
  56. if args["--list-languages"]:
  57. for lang in get_languages():
  58. sys.stdout.write(lang)
  59. sys.stdout.write(os.linesep)
  60. sys.exit(0)
  61. if args["--list-converters"]:
  62. for cvt in get_converters():
  63. sys.stdout.write(cvt)
  64. sys.stdout.write(os.linesep)
  65. sys.exit(0)
  66. try:
  67. words = num2words.num2words(args['<number>'], lang=args['--lang'], to=args['--to'])
  68. sys.stdout.write(words + os.linesep)
  69. sys.exit(0)
  70. except Exception as err:
  71. sys.stderr.write(str(args['<number>']))
  72. sys.stderr.write(str(err) + os.linesep)
  73. sys.stderr.write(__doc__)
  74. sys.exit(1)
  75. if __name__ == '__main__':
  76. main()
上海开阖软件有限公司 沪ICP备12045867号-1