Python interpreter says thing in str() is int -- ?

This is the place for queries that don't fit in any of the other categories.

Python interpreter says thing in str() is int -- ?

Postby XndrK » Fri Nov 01, 2013 1:00 am

My code is as follows:

Code: Select all
class Male(Person):
    """Describes male.
    """
    def __init__(self, name, age):
        self.name = name
        self.age = age
        self.gender = "male"

    def __repr__(self):
        return "This guy's name is " + self.name + ". He is " + \
        str(self.age) + " years old."


When I try to call it with
Code: Select all
me = Male(13, "Alex")
print me
it yells at me about not being able to concatenate str and int objects.

?!
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 169
Joined: Sat Jun 15, 2013 7:57 pm

Re: Python interpreter says thing in str() is int -- ?

Postby stranac » Fri Nov 01, 2013 1:11 am

Code: Select all
    def __init__(self, name, age):

Code: Select all
me = Male(13, "Alex")


See something wrong there?

Btw, you should know you're supposed to paste the full error traceback instead of "it yells at me"
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1092
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python interpreter says thing in str() is int -- ?

Postby ochichinyezaboombwa » Fri Nov 01, 2013 3:51 am

... or here:
Code: Select all
"Everything is göing to ße fine" + 18
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Python interpreter says thing in str() is int -- ?

Postby micseydel » Fri Nov 01, 2013 5:37 am

Unless you're trying to separate sex and gender (in which case kudos), then the gender attribute of your class is redundant.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1111
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Python interpreter says thing in str() is int -- ?

Postby XndrK » Fri Nov 01, 2013 3:49 pm

To be clear, I'm pro-family. Just thought I'd get that out of the way. I don't want to get into a debate about it, but I did say in the welcome page that I am a fiscal and social conservative.

Stranac, oops. :oops: I just realized that.

Micseydel: I know next to nothing about classes. >_<
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 169
Joined: Sat Jun 15, 2013 7:57 pm

Re: Python interpreter says thing in str() is int -- ?

Postby micseydel » Fri Nov 01, 2013 4:25 pm

XndrK wrote:To be clear, I'm pro-family. Just thought I'd get that out of the way. I don't want to get into a debate about it, but I did say in the welcome page that I am a fiscal and social conservative.

I'm not sure what you're trying to accomplish other than to alienate yourself from hacker-oriented communities like this. Communities that offer free help using a language that is available for free tend toward much more liberal views in both of those domains. You might want to look into Matlab or something.

Micseydel: I know next to nothing about classes. >_<

Classes are used as a way to implement object oriented programming. Some people hate it but it's heavily used in industry and I personally love it. I have yet to find a satisfactory tutorial about OOP and I actually learned it at university. I've made a note to look for one and if I can't find one I guess I'll take a whack at it in the tutorials section, since with a quick glance they're all about "classes" rather than OOP and start off with a large block of code.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1111
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Python interpreter says thing in str() is int -- ?

Postby XndrK » Mon Nov 04, 2013 5:21 pm

micseydel wrote:Unless you're trying to separate sex and gender (in which case kudos), then the gender attribute of your class is redundant.


That's what I was replying to. Let's drop the subject right now. I don't need a lynching. Thank you.

I know classes are powerful, but I'm trying to figure out what I can do with classes that I can't do with dicts and functions. I was thinking about making a swarm intelligence program using a class Bee, but somebody else said that dicts would be better in the situation.

Where are classes better?
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 169
Joined: Sat Jun 15, 2013 7:57 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests