The .tag attribute returns the pymorphy2.tagset.OpencorporaTag object, which contains a lot of additional information:
In [266]: tag = morph.parse("слово")[0].tag In [267]: tag Out[267]: OpencorporaTag('NOUN,inan,neut sing,nomn') In [268]: type(tag) Out[268]: pymorphy2.tagset.OpencorporaTag In [269]: tag. tag.ANIMACY tag.GENDERS tag.NUMBERS tag.RARE_CASES tag.add_grammemes_to_known tag.ASPECTS tag.INVOLVEMENT tag.PARTS_OF_SPEECH tag.TENSES tag.animacy tag.CASES tag.KNOWN_GRAMMEMES tag.PERSONS tag.TRANSITIVITY tag.aspect > tag.FORMAT tag.MOODS tag.POS tag.VOICES tag.case
As @insolor already said in his answer, you can use the tag.POS (Part Of Speach) attribute to get the name of a part of speech as a string.
Example:
from pathlib import Path from itertools import groupby from pymorphy2 import MorphAnalyzer infile = Path(r"C:\Temp\slovar.txt") words = infile.read_text(encoding="utf-8").splitlines() print(words) #['каждый', 'охотник', 'желает', 'знать', 'где', 'сидит', 'фазан'] morph = MorphAnalyzer() items = [(str(morph.parse(w)[0].tag.POS), w) for w in words] print(items) #[('ADJF', 'каждый'), ('NOUN', 'охотник'), ('VERB', 'желает'), ('INFN', 'знать'), ('ADVB', 'где'), ('VERB', 'сидит'), ('NOUN', 'фазан')] for g, it in groupby(sorted(items), key=lambda x: x[0]): otufile = infile.parent / f"{g}.txt" otufile.write_text("\n".join([word for pos, word in it]), encoding="utf-8")
Result:
NOUN.txt:
охотник фазан
VERB.txt:
желает сидит
...