2 Answers

  1. Michael- Reply





  2. Mike- Reply


    Just use the text property to see the translated text.

    >>> from googletrans import Translator
    >>> translator = Translator()
    >>> result = translator.translate('안녕하세요.')
    >>> result.text

    To see destination and source languages use the dest and src properties.

    >>> result.src
    >>> result.dest

    Seems like googletrans.models.Translated does not override the __repr__ function and so shows the default (which displays its address in memory). The docs indicate it should show the fields, but for me it doesn't. So the docs are either too old or too new.

    You can introspect the properties of the Translated object using dir, if you want to see whats available to you. Look at the properties that don't have the double underscores at each end.

    >>> dir(result)
    ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', 'dest', 'extra_data', 'origin', 'pronunciation', 'src', 'text']

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>