Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Reading unicode from file Python

    General Talk
    python
    2
    3
    810
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      A-I
      last edited by

      Hey,

      Having an issue trying to read unicode characters from a CSV file.

      I am not very experienced with python so apologies in advance.

      Context:
      We use a CSV as a list of names, places, organisations etc read them in c4d and render them as images with the files named as per the column we select from the CSV.

      Some names of people or their tribe names are in different languages, for us locally it is Māori, which as a lot of ā,ō,ū characters.

      Our python code below. I have tried adding in "data.decode('utf8')" but this didn't help, or rather it is likely I am doing it wrong.

      import c4d
      #Welcome to the world of Python
      import csv

      def main():
      global Output
      global TotRow
      global TotCol

      data = []
      
      with open(CSV) as csv_file:
          reader = csv.reader(csv_file)
          for row in reader:
              data.append(row)
      
      
      row = max(0, min(RowSel, len(data)-1))
      col = max(0, min(ColSel, len(data[0])-1))
      
      Output = data[row][col]
      TotRow = len(data)
      TotCol = len(data[0])
      

      Any advise would be greatly appreciated

      1 Reply Last reply Reply Quote 0
      • i_mazlovI i_mazlov moved this topic from Cinema 4D SDK on
      • i_mazlovI
        i_mazlov
        last edited by

        Hello @A-I,

        Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

        • Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
        • Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
        • Forum Structure and Features: Lines out how the forum works.
        • Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.

        About your First Question

        Your question is out of the scope of the support on this forum, namely:

        We cannot provide support on learning either C++, Python or one of its popular third party libraries

        Hence the thread is moved to General Talk section.

        As a general suggestion, make sure you encode your csv data properly when creating your files, then the data.decode('utf8') that you''ve mentioned above should do the trick.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • A
          A-I
          last edited by

          Thanks, I guess..

          For anyone else coming across this issue, to decode in python you need to ensure that you're using the correct encoding when reading the CSV file. Even if the CSV file is already encoded to what you are expecting. To make it work for us we did the below:

          with open(CSV, encoding='utf-8') as csv_file:

          Rather than

          with open(CSV) as csv_file:

          1 Reply Last reply Reply Quote 0
          • First post
            Last post