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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:03:01+00:00 2026-05-26T11:03:01+00:00

I felt like working on my network programming, threading and OOP skills. I’ve encountered

  • 0

I felt like working on my network programming, threading and OOP skills. I’ve encountered a problem though.
I have a class named IRC and a class named Pong. I want to use IRC to do stuff like connecting to the server, sending messages, etc. I want to use Pong as a thread in the background which checks for a message containing “PING”.

class IRC:
    def Connect(self):
        try:
            HOST = sys.argv[1]
            PORT = sys.argv[2]
        except IndexError:
            print "Usage: "+sys.argv[0]+" [server] [port]\n"
            sys.exit(1)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))

class Pong(threading.Thread):
    def Pong(self):
        while 1:
            IRC.s.send("Test") # IRC has no attribute 's'

Keep in mind that the code above is simplified and only for testing purposes, my question is how I can use variables in one class from another class. The variable s is declared and defined in IRC, but is needed in Pong too.
The interpreter complains that class IRC has no attribute ‘s’ (I’ve tried calling Connect() first with a sample variable to see if it works, it doesn’t).

How do I solve this? I’m new when it comes to threading and object orientation.

Thanks in advance!

  • 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-26T11:03:01+00:00Added an answer on May 26, 2026 at 11:03 am

    You’ll need to call an instance of the IRC class which you can pass to the PONG constructor:

    class IRC:
        def Connect(self):
            try:
                HOST = sys.argv[1]
                PORT = sys.argv[2]
            except IndexError:
                print "Usage: "+sys.argv[0]+" [server] [port]\n"
                sys.exit(1)
            self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.s.connect((HOST, PORT))
    
    class Pong(threading.Thread):
        def __init__(self,ircclass):
            self.myirc = ircclass
        def Pong(self):
            while 1:
                self.myirc.s.send("Test")
    
    gIRC = IRC
    gIRC.connect()
    myPong = Pong(gIRC)
    

    etc.

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

Sidebar

Related Questions

I've always felt that my graphic design skills have lacked, but I do have
I felt like I'm having the same issues as addressed here . But everything
I've always felt like SecureString was a little odd, but assumed most of my
This is related to my other question , but I felt like I should
I am python/django developer. As a part of improving my knowledge and felt like
In my years of C++ (MFC) programming in I never felt the need to
I was working on a somewhat gimmick problem in regard to tuples and finally
I am working in an Agile environment and things have gone to the state
I'm a scientist working mostly with C++, but I would like to find a
In my early days of programming, before I started working professionally, I wrote a

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.