[Tutor] Classes Turn Strings Into Tuples for some reason
Liam Clarke
cyresse at gmail.com
Wed Oct 27 01:23:30 CEST 2004
Hi John
This part here...
self.name = name,
The comma tells Python that self.name is a tuple, similar to x=(4,5,6,7,) would.
Are you wanting to add multiple names to the same variable i.e. (Jane,
John, Jeff, Jenny)?
I
On Tue, 26 Oct 2004 17:10:31 -0600, Gooch, John <john.gooch at echostar.com> wrote:
> With the class below:
>
> #Define Classes
> class Record:
> def __init__(self, name ):
> self.name = name,
> self.lastlogon = ''
> self.ipaddress = "0"
> self.uptime = 0
> self.type = 0
> self.location = "0"
> def printName(self):
> return self.name
> def getName(self):
> print self.name
> return self.name
> #End Class Record
>
> If I create an instance of the class like so -
> joe = Record( "joe")
> and then
> print joe.name
> or
> pring joe.getName()
> Instead of printing just the name, it prints
> ( 'joe', )
>
> I have been reading up on functions and classes, and haven't found any
> information to explain this behavior. I
> want the value to be a scalar string, and not a tuple.
>
> Any ideas?
>
> John A. Gooch
> Systems Administrator
> IT - Tools
> EchoStar Satellite L.L.C.
> 9601 S. Meridian Blvd.
> Englewood, CO 80112
> Desk: 720-514-5708
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor
mailing list