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

  • SEARCH
  • Home
  • 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 6957485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:00:33+00:00 2026-05-27T15:00:33+00:00

One day I found a page on the web that covers interpreting input from

  • 0

One day I found a page on the web that covers interpreting input from game pads on Linux. The code is this:

import sys
pipe = open('/dev/input/js0','r')
while 1:
    for character in pipe.read(1):
        sys.stdout.write(repr(character))
        sys.stdout.flush()

The program is used to open the character device file for a Logitech Dual Action game pad connected to a USB port. When I run the program under Python 2.7, I get the expected output:

'\x0c''\xe0''E''\x00''\x01''\x00''\x01''\x01''D''\xe0''E''\x00''\x00''\x00'
'\x01''\x01''\xbc''^''F''\x00''\x01''\x00''\x01''\x05''<''_''F''\x00''\x00'
'\x00''\x01''\x05'

And the like, with button presses generating bytes that are fed to standard output. However, when I run the exact same script with 3.2, I get this:

Traceback (most recent call last):
  File "js.py", line 6, in <module>
    for character in pipe.read(1):
  File "/usr/lib/python3.2/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8d in position 1: invalid start byte

The exact byte location varies, as well as the position of the byte and whether it is a starting or ending byte, but otherwise that’s pretty much all I get. I would like to know what is causing the error and how to fix it. Now, I understand that Python 2 is a great language and that Python 3 builds off of it, but I started learning and am continuing to learn Python 3, and I just would like to stick with that for now.
I am running Ubuntu GNU/Linux 11.10 with Python 2.7 and 3.2.

  • 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-05-27T15:00:33+00:00Added an answer on May 27, 2026 at 3:00 pm

    If you want raw bytes then you need to open it in binary mode.

    pipe = open('/dev/input/js0','rb')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One day I suspect I'll have to learn hadoop and transfer all this data
I'm scared that one day, I'm going to put a space or miss out
A sysadmin teacher told me one day that I should learn to use make
I was looking through someone's code one day and I was annoyed how they
I have the following command which deletes files that are one day old and
This is a really strange issue. One day my project started to do a
I have a RESTful web service deployed at http://example.com/v1/SomeResource . One day, a new
One day I decided to start writing a video game in plain old C.
I have a chart in excel that represents some value over a one day
One day our java web application goes up to 100% CPU usage. A restart

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.