Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:48:35+00:00 2026-06-09T11:48:35+00:00

I just left the PC at work (using Python 2.7) and had a script

  • 0

I just left the PC at work (using Python 2.7) and had a script that I was just finishing up (reproduced below). It ran fine at work, I just wanted to add one or two things. But I came home and am using my Mac’s version of Python (3.2.2) and I get the following error:

Traceback (most recent call last):
  File "/Users/Downloads/sda/alias.py", line 25, in <module>
    for row_2 in in_csv:
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 304: ordinal not in range(128)

My code is here:

import csv
inname = "Fund_Aliases.csv"
outname = "output.csv"

def first_word(value):
    return value.split(" ", 1)[0]

with open(inname, "r") as infile:
    with open(outname, "w") as out file:
      in_csv = csv.reader(infile)
      out_csv = csv.writer(outfile)

     column_names = next(in_csv)
     out_csv.writerow(column_names)

      id_index = column_names.index("id")
      name_index = column_names.index("name")

      try:
          row_1 = next(in_csv)
          written_row = False

          for row_2 in in_csv:
            if first_word(row_1[name_index]) == first_word(row_2[name_index]) and row_1[id_index] != row_2[id_index]:
                if not written_row:
                    out_csv.writerow(row_1)

                out_csv.writerow(row_2)
                written_row = True
            else:
                written_row = False

            row_1 = row_2
      except StopIteration:
        # No data rows!
        pass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:48:37+00:00Added an answer on June 9, 2026 at 11:48 am

    It looks like Fund_Aliases.csv is not an ascii file.

    According to the Python3 docs:

    Since open() is used to open a CSV file for reading, the file will by
    default be decoded into unicode using the system default encoding (see
    locale.getpreferredencoding()). To decode a file using a different
    encoding, use the encoding argument of open:

    with open('some.csv', newline='', encoding='utf-8') as f:
        reader = csv.reader(f)
    

    So try specifying the encoding parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a mobile site and wanted to create a rotator that would work just
I have the code block below, I deleted all unnecessary parts, just left the
I'm new to Python and after this one script I probably won't work with
I'm using jQuery's animate() and it just doesn't work. I'm trying to get a
I'm trying to set an element width using jQuery and it just won't work.
I find myself frequently using Python's interpreter to work with databases, files, etc --
I just started a game using cocos2d-iphone and I am trying to add a
I am using this script to see if a user has left any inputs
Constant height so just left/right images should be necessary instead of having 4+, right?
I just read Emacs :TODO indicator at left side , and tried it out.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.