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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:08:20+00:00 2026-05-24T11:08:20+00:00

For convenience, I wanted to subclass socket to create an ICMP socket: class ICMPSocket(socket.socket):

  • 0

For convenience, I wanted to subclass socket to create an ICMP socket:

class ICMPSocket(socket.socket):
    def __init__(self):
        socket.socket.__init__(
            self, 
            socket.AF_INET,
            socket.SOCK_RAW,
            socket.getprotobyname("icmp"))

    def sendto(self, data, host):
        socket.socket.sendto(self, data, (host, 1))

However, I can’t override socket.sendto:

>>> s = icmp.ICMPSocket()
>>> s.sendto
<built-in method sendto of _socket.socket object at 0x100587f00>

This is because sendto is a “built-in method”. According to the data model reference, this is “really a different disguise of a built-in function, this time containing an object passed to the C function as an implicit extra argument.”

My question: is there anyway to override built-in methods when subclassing?

[Edit] Second question: if not, why not?

  • 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-24T11:08:22+00:00Added an answer on May 24, 2026 at 11:08 am

    I know this doesn’t answer your question, but you could put the socket into an instance variable. This is what Nobody also suggested in the comments.

    class ICMPSocket():
        def __init__(self):
            self.s = socket.socket(
                socket.AF_INET,
                socket.SOCK_RAW,
                socket.getprotobyname("icmp"))
        def sendto(self, data, host):
            self.s.sendto(data, (host, 1))
        def __getattr__(self, attr):
            return getattr(self.s, attr)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a convenience class for encoding URI's. In it I've created three methods
Spring has a very handy convenience class called PropertyPlaceholderConfigurer , which takes a standard
I'm using Sinatra, and I wanted to set up some of the convenience rake
I have a convenience collection class in my Flex project called HashMap, which is
Is there a convenience method available in the java standard libraries to check whether
I am developing some convenience wrappers around another software package that defines a bash
For the sake of convenience I am trying to assign multiple values to a
I often use convenience functions that return pointers to static buffers like this: char*
With regards to security and convenience which cookies are better the PHP ones or
Do you put unit tests in the same project for convenience or do you

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.