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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:34:41+00:00 2026-06-04T13:34:41+00:00

In order to make an extension really clean looking I’m trying to implement the

  • 0

In order to make an extension really clean looking I’m trying to implement the “>>” operator in python as a class method. I’m not sure how to go about it though. I don’t want to have to create an instance since I am really operating on the class itself.

>>> class C:
...     @classmethod
...     def __rshift__(cls, other):
...         print("%s got %s" % (cls, other))
...
>>> C.__rshift__("input")
__main__.C got input
>>> C() >> "input"
__main__.C got input
>>> C >> "input"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for >>: 'classobj' and 'str'

Background information:

I am trying to implement views in the peewee ORM (Similar to Django). Peewee allows you to define database tables and their relations as classes, like so:

class Track(Model):
    title = CharField()
    artist = ForeignKeyField(Artist)

class Artist(Model):
    name = CharField(unique = True)
    location = ForeignKeyField(Location)

class Location(Model):
    state = CharField(size = 2)
    city = CharField()

Note: For clarity’s sake the order is reversed.

I’m trying to extend this with an implementation of views. One of the most difficult parts is setting on a clean way to indicate the joins. So far I have implemented the following:

class Song(View):
    title = Track.title
    artist = Track.artist >> "name"
    state = Track.artist >> "location" >> "state"

This is ok, but I would really like to eliminate the “.” to further simplify:

class Song(View):
    title = Track >> "title"
    artist = Track >> "artist" >> "name"
    state = Track >> "artist" >> "location" >> "state"

Which would you rather use? Or both?

As a side note, can anyone think of a good way to indicate a backwards join? Something like the following is a bit awkward for me:

class LocWithSong(View):
    state = Location >> "state"
    title = Location >> Track.title
  • 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-04T13:34:43+00:00Added an answer on June 4, 2026 at 1:34 pm

    Define the method on the metaclass.

    class MC(type):
      def __rshift__(self, other):
        return something(self, other)
    
    class C(object):
      __metaclass__ = MC
    
    print C >> None
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in order to make sure all form submission and all data submitted to server
I'm trying to solve the relational model in order to make a Django app.
I'm currently trying to create a subclass of UIImageView in order to make it
I am trying to make SaveFileDialog and FileOpenDialog enforce an extension to the file
I'm trying to make an extension for google chrome. It will automatically click on
I'm using JSONP in a google chrome extension. In order to make it work,
I'm using JSONP in a google chrome extension. In order to make it work,
I am having some issues with an extension that i am trying to make.
I am trying to build an extension method that will Paginated a query. But
in order to make things easier for users i want to add multiple keyword

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.