Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans to make this script on python 3 #182

Open
jcabrerazuniga opened this issue Nov 16, 2022 · 4 comments
Open

Any plans to make this script on python 3 #182

jcabrerazuniga opened this issue Nov 16, 2022 · 4 comments

Comments

@jcabrerazuniga
Copy link

Any plans to make this script on python 3? Python 2 is being "decommissioned" and not supported anymore.

@sawymer
Copy link

sawymer commented Nov 16, 2022 via email

@jcabrerazuniga
Copy link
Author

jcabrerazuniga commented Nov 16, 2022 via email

@jcabrerazuniga
Copy link
Author

jcabrerazuniga commented Nov 16, 2022

Just in case, I want to help by giving you the python3 version of UnicodeCsvReader

`# -*- coding: utf-8 -*-
import csv
# python 3

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

    def __iter__(self):
        return self

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

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

class UnicodeDictReader(csv.DictReader):
    def __init__(self, f, encoding="utf-8", fieldnames=None, **kwds):
        csv.DictReader.__init__(self, f, fieldnames=fieldnames, **kwds)
        self.reader = UnicodeCsvReader(f, encoding=encoding, **kwds)



csv_lines = (
    "абв,123",
    "где,456",
)

myIterClass = UnicodeCsvReader(csv_lines)
myIter = iter(myIterClass)


for x in myIter:
  print(x)`

References:
https://stackoverflow.com/questions/36110598/nameerror-name-unicode-is-not-defined
https://www.w3schools.com/python/python_iterators.asp

@jcabrerazuniga
Copy link
Author

I forked this project to:

https://github.com/jcabrerazuniga/vivo-pump

At present I was able to upgrade this project so it now compiles and even run with python3 but more debugging/testing is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants