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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:19:34+00:00 2026-06-16T02:19:34+00:00

I have this project for college and I’m running into a couple of errors

  • 0

I have this project for college and I’m running into a couple of errors in the test file provided by the teachers.

Most of them are related to this. For example, doing the following:

caminho(posicao(0,0)).caminho_junta_posicao('este').caminho_origem()

returns:

Traceback (most recent call last):
  File "<string>", line 1, in <fragment>
builtins.AttributeError: 'NoneType' object has no attribute 'caminho_origem'

However, doing this:

c1 = caminho(posicao(0,0))
c1.caminho_junta_posicao('este')
c1.caminho_origem()

doesn’t return any errors but the intended position.

And I can’t figure out why that happens.
Bellow is the code defining both of the classes from the example, as my problem with others lies in very similar. Any help would really be appreciated. Thanks.

class posicao:
    def __init__(self,l,c):
        self.posicao=(l,c)
    def posicao_linha(self):
        return self.posicao[0]
    def posicao_coluna(self):
        return self.posicao[1]
    def posicao_igual(self,p2):
        return self.posicao[0] == p2.posicao_linha() and self.posicao[1]\
               == p2.posicao_coluna()
    def posicao_relativa(self,d):
        if d=='norte':
            return posicao(self.posicao_linha()-1,self.posicao_coluna())
        elif d=='sul':
            return posicao(self.posicao_linha()+1,self.posicao_coluna())
        elif d=='este':
            return posicao(self.posicao_linha(),self.posicao_coluna()+1)
        elif d=='oeste':
            return posicao(self.posicao_linha(),self.posicao_coluna()-1)




class caminho:
    def __init__(self,p):
        self.caminho = [p]
    def caminho_junta_posicao(self,d):
        p = self.caminho[-1]
        self.caminho = self.caminho + [p.posicao_relativa(d)]
    def caminho_origem(self):
        return self.caminho[0]
    def caminho_destino(self):
        return self.caminho[-1]
    def caminho_antes_destino(self):
        return self.caminho[:-1]
    def caminho_apos_origem(self):
        return self.caminho[1:]
    def caminho_comprimento(self):
        return len(self.caminho)
    def caminho_contem__ciclos(self):
        for p in range(len(self.caminho)):
            for p2 in self.caminho[p:]:
                if p2.posicao_igual(self.caminho[p]):
                    return True
        return False 
    def caminho_elimina_ciclos(self):
        caminho = self.caminho
        if self.caminho_contem_ciclos():
            for p in caminho:
                for p2 in caminho[caminho.index(p):]:
                    if p.posicoes_iguas(p2):
                        caminho = caminho[:index(p)]+caminho[index(p2):]
  • 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-16T02:19:35+00:00Added an answer on June 16, 2026 at 2:19 am

    This method:

    def caminho_junta_posicao(self,d):
        p = self.caminho[-1]
        self.caminho = self.caminho + [p.posicao_relativa(d)]
    

    doesn’t explicitly return anything, so the result of calling it is None. Therefore,

     caminho(posicao(0,0)).caminho_junta_posicao('este')
    

    will give None, and None doesn’t have a caminho_origem() method, hence your error.

    Python convention is usually that methods which act in-place (like .append, .extend, and here your .caminho_junta_posicao) return None, which makes chaining like this impossible. On the other hand, it makes accidentally modifying the original object in a chain which you think is working on copies much harder. Sometimes chaining does come in handy, though (see the pandas library, for example, which makes extensive use of it to great benefit.)

    I don’t recommend doing this, but if you modified the method to return self at the end, i.e.

    def caminho_junta_posicao(self,d):
        p = self.caminho[-1]
        self.caminho = self.caminho + [p.posicao_relativa(d)]
        return self
    

    then the result of caminho(posicao(0,0)).caminho_junta_posicao('este') would be your (now-modified) caminho object, and you could chain it the way you tried.

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

Sidebar

Related Questions

I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I have a college programming project in C++ divided into two parts. I beggining
This is related to a Think-A-Dot college project. I have a list of objects
This is a college project: I have a database ( mysql or postgresql doesn't
I have this Project model: class Project < ActiveRecord::Base validates :status, :inclusion => {
I have this project that it's due in a few hours and I still
So I have this project in PHP where I have some include files next
Okay so, I have this project structure: package A.B class SuperClass (this class is
I have this WinForms project (based on this one , but modified for SharePoint
I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code

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.