← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #231065]: HowTo: Pasting non-ASCII/unicode/UTF-8 text (special endcoding) from CSV file

 

Question #231065 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/231065

Description changed to:
*** solution ------------------------------

If someone has to paste a large number of unicode text items from the CSV 
and wants a reusable function for this:

class UnicodeCsvReader(object):
    def __init__(self, f, encoding="utf-8", **kwargs):
        self.csv_reader = csv.reader(f, **kwargs)
        self.encoding = encoding

    def __iter__(self):
        return self

    def next(self):
        # read and split the csv row into fields
        row = self.csv_reader.next()
        # now decode
        return [unicode(cell, self.encoding) for cell in row]

    @property
    def line_num(self):
        return self.csv_reader.line_num

To initilize use:

with codecs.open(inputFileName, 'rb') as file:
    myreader = UnicodeCsvReader(file)

------------------------------------------------------------------

Hello,
 When i try to import utf-8 encoded file and use paste function to paste text with special characters into a box, i get distorted special characters such as boxes, squares etc.

Here is what I am doing

with codecs.open(inputFileName, 'rb', 'utf-8') as file:
    myreader = csv.reader(file) 

 headers = myreader.next()

    for row in myreader:
        clipboardContent = clipboard.getContents(None).getTransferData(DataFlavor.stringFlavor)

SMS = row[7]


click ("SubjectIEEEA.png")
paste(("" + SMS + ""))


I tried to use the encoding without BOM and it still gives me distorted data.

Please help.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.