Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

beginner whitespace question

0 views
Skip to first unread message

eggie5

unread,
Aug 9, 2007, 7:47:41 PM8/9/07
to
I keep getting an error for line 7, what's wrong with this?

from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question

def was_published_today(self):
return self.pub_date.date() == datetime.date.today()

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

def __unicode__(self):
return self.choice

Dan Bishop

unread,
Aug 9, 2007, 7:52:05 PM8/9/07
to
On Aug 9, 6:47 pm, eggie5 <egg...@gmail.com> wrote:
> I keep getting an error for line 7, what's wrong with this?
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def __unicode__(self):
> return self.question
>

The "def" statements have to be at the same indentation level as
what's before it.

eggie5

unread,
Aug 9, 2007, 8:02:41 PM8/9/07
to

will they still be a part of the classes?

Dan Bishop

unread,
Aug 9, 2007, 8:52:44 PM8/9/07
to

If you indent them twice, it's a syntax error.
If you indent them once, they'll be methods of the class.
If you don't indent them at all, they'll be global functions.

eggie5

unread,
Aug 9, 2007, 9:13:24 PM8/9/07
to
But this still isn't valid:

from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question

class Choice(models.Model):


poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

def __unicode__(self):
return self.choice

James Stroud

unread,
Aug 9, 2007, 9:28:35 PM8/9/07
to
eggie5 wrote:
> But this still isn't valid:
>
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def __unicode__(self):
> return self.question
>
>
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice = models.CharField(max_length=200)
> votes = models.IntegerField()
>
> def __unicode__(self):
> return self.choice


You want this:


from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

def __unicode__(self):
return self.choice


But this mixes tabs and spaces.

Rules:

1. Don't use tabs!
2. If you are clueless enough to violate (1), then don't mix tabs and
spaces.
3. Don't use tabs!

Tabs are for tables, hence the name. "Use spaces for space and use tabs
for tables" can be a little mnemonic to help you remember the rules. We
can make a little song together if you can think of some things that
rhyme with "don't" and "use" and "tabs".

You have been warned. Next time I'll piont and laugh as I answer.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

James Stroud

unread,
Aug 9, 2007, 9:31:10 PM8/9/07
to
James Stroud wrote:
> def __unicode__(self):
> return self.choice

Laughing to hard at the tab & spaces thing to notice the lack of
indentation here.

eggie5

unread,
Aug 9, 2007, 10:28:34 PM8/9/07
to
On Aug 9, 6:31 pm, James Stroud <jstr...@mbi.ucla.edu> wrote:
> James Stroud wrote:
> > def __unicode__(self):
That's so goofy.....

Dan Bishop

unread,
Aug 9, 2007, 11:25:19 PM8/9/07
to

"won't"

"blues", "booze", "bruise", "choose", "cruise", "fuse", "hues",
"Jews", "lose", "muse", "news", "snooze", "views", etc.

"abs", "cabs", "crabs", "dabs", "grabs", "labs", "scabs", "slabs",
"stabs", etc.

James Stroud

unread,
Aug 10, 2007, 1:37:43 AM8/10/07
to
Dan Bishop wrote:
>> Tabs are for tables, hence the name. "Use spaces for space and use tabs
>> for tables" can be a little mnemonic to help you remember the rules. We
>> can make a little song together if you can think of some things that
>> rhyme with "don't" and "use" and "tabs".
>
> "won't"
>
> "blues", "booze", "bruise", "choose", "cruise", "fuse", "hues",
> "Jews", "lose", "muse", "news", "snooze", "views", etc.
>
> "abs", "cabs", "crabs", "dabs", "grabs", "labs", "scabs", "slabs",
> "stabs", etc.
>


When you want to screw your whitespace--don't!
Take this little pledge and I know you won't:

When I was in school I would take of booze
While my typing teacher said I'm free to use
Space or formfeed or even tabs
And I punched so hard with my pinkie that scabs
Covered my Jake and Elwood tatoos.
(You didn't see that one coming did yous?)

Ben Finney

unread,
Aug 10, 2007, 6:05:45 AM8/10/07
to
James Stroud <jst...@mbi.ucla.edu> writes:

> When you want to screw your whitespace--don't!
> Take this little pledge and I know you won't:

James, you're a poet
And you don't even realise

--
\ "[...] a Microsoft Certified System Engineer is to information |
`\ technology as a McDonalds Certified Food Specialist is to the |
_o__) culinary arts." —Michael Bacarella |
Ben Finney

eggie5

unread,
Aug 10, 2007, 2:46:03 PM8/10/07
to

I'm so confused, I have no idea what's going on...

0 new messages