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 8248563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:13:48+00:00 2026-06-07T23:13:48+00:00

I’m a complete python n00b here and just trying to mash a few bits

  • 0

I’m a complete python n00b here and just trying to mash a few bits together to make a project work but i’m struggling with some of the syntax i think.

Here is my script i have so far:

#!/usr/bin/env python

from plugin import *
from siriObjects.systemObjects import ResultCallback
import uuid
import json
import random
import types
import urllib
import urllib2
import random
import re
import select
import socket
import struct
import sys
import thread
import time

class tivoRemote(Plugin):

        tivo_address = '192.168.0.9'
        tivo_name = ''
        tivo_swversions = {}
        have_zc = True
        captions_on = False
        sock = None
        outer = None


        def connect():
            """ Connect to the TiVo within five seconds or report error. """
            global sock
            try:
                sock = socket.socket()
                sock.settimeout(5)
                sock.connect((tivo_address, 31339))
                sock.settimeout(None)
            except Exception, msg:
                msg = 'Could not connect to %s:\n%s' % (tivo_name, msg)
                print(msg)

        def send(message):
            """ The core output function, called from irsend(). Re-connect if
                necessary (including restarting the status_update thread), send
                message, sleep, and check for errors.
                """

            if not sock:
                self.connect()
                thread.start_new_thread(status_update, ())
            try:
                sock.sendall(message)
                time.sleep(0.1)
            except Exception, msg:
                error_window(str(msg))


        def irsend(*codes):
            """ Expand a command sequence for send(). """
            for each in codes:
                self.send('IRCODE %s\r' % each)


        @register("en-US", ".*Change.*Channel.*")
        def channelChanger(self, speech, language, matchedRegex):
                if language == 'en-US':
                        answer = self.ask(u"Which channel would you like?")
                        self.say(u"Ok, one moment..".format(answer))
                        self.connect()
                        self.irsend(answer)
                self.complete_request()

and the error i’m getting is:

Traceback (most recent call last):
  File "/home/pi/SiriServerCore/plugin.py", line 150, in run
    self.__method(self, self.__speech, self.__lang,        self.__method.__dict__[__criteria_key__][self.__lang].match(self.__speech))
  File "/home/pi/SiriServerCore/plugins/tivoRemote/__init__.py", line 70, in     channelChanger
    self.irsend(format(answer))
  File "/home/pi/SiriServerCore/plugins/tivoRemote/__init__.py", line 61, in irsend
    self.send('IRCODE %s\r' % each)
NameError: global name 'self' is not defined

If i remove the ‘self.’ i get the same error but saying ‘send’ is not defined.

Thanks in advance for any help 🙂
Ryan

  • 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-07T23:13:49+00:00Added an answer on June 7, 2026 at 11:13 pm

    More likely to work:

    class tivoRemote(Plugin):
    
        def __init__(self):
            self.tivo_address = '192.168.0.9'
            self.tivo_name = ''
            self.tivo_swversions = {}
            self.have_zc = True
            self.captions_on = False
            self.sock = None
            self.outer = None
    
    
        def connect(self):
            """ Connect to the TiVo within five seconds or report error. """
            try:
                sock = socket.socket()
                sock.settimeout(5)
                sock.connect((tivo_address, 31339))
                sock.settimeout(None)
            except Exception, msg:
                msg = 'Could not connect to %s:\n%s' % (tivo_name, msg)
                print(msg)
            self.sock = sock
    
        def send(self, message):
            """ The core output function, called from irsend(). Re-connect if
                necessary (including restarting the status_update thread), send
                message, sleep, and check for errors.
            """
    
            if not self.sock:
                self.connect()
                thread.start_new_thread(status_update, ()) # status_update must be some global at this point
            try:
                self.sock.sendall(message)
                time.sleep(0.1)
            except Exception, msg:
                error_window(str(msg))
    
    
        def irsend(self, *codes):
            """ Expand a command sequence for send(). """
            for each in codes:
                self.send('IRCODE %s\r' % each)
    
    
        @register("en-US", ".*Change.*Channel.*")
        def channelChanger(self, speech, language, matchedRegex):
                if language == 'en-US':
                        answer = self.ask(u"Which channel would you like?")
                        self.say(u"Ok, one moment..".format(answer))
                        self.connect()
                        self.irsend(answer)
                self.complete_request()
    

    You need to use self when defining methods and you have to use it to access the current instance.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.