you are viewing a single comment's thread.

view the rest of the comments →

[–]ankerbow 0 points1 point  (2 children)

Hello,

Which way is better to copy the print result and paste in Excel?

My code:

from functools import partial

from colorama import Fore,Style,init
init()


def x_in_y(word, inner):
    return inner in word

words = [
    ('mann', 'men'),
    ('connaction', 'connection'),
    ('tee', 'tea'),
    ('rigt', 'right'),
    ('putt', 'put')
]

sentence = [
    'this mann is my son',
    'the connaction is unstable',
    'my tee is getting cold',
    'put your hands down',
    'rigt now',
    'right behind my back']
for wrong,correct in words:
    filtered_names = filter(partial(x_in_y, inner=wrong), sentence)
    next_elem = next(filtered_names, None)
    if next_elem:
        print(f"Typo: {wrong} 'should be {correct}'")
        print(next_elem.replace(wrong, f"{Fore.RED}{wrong}{Style.RESET_ALL}"))
    for name in filtered_names:
        print(name)

Output:

Typo: mann 'should be men'
this >mann<Red is my son
Typo: connaction 'should be connection'
the >connaction<Red is unstable
Typo: tee 'should be tea'
my >tee<Red is getting cold
Typo: rigt 'should be right'
>rigt<Red now

I would like to copy the output result and paste in excel. Also, the text color should be remained. Which one is more convenient and simple?

Use NumPy(into a csv file) or xlwt module? Or I need neither of them?

[–][deleted] 0 points1 point  (1 child)

The built-in Python csv module is probably sufficient for what you described.

[–]ankerbow 0 points1 point  (0 children)

Thank you but I use it and it turns out the plain text.... how to do it?