By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,282 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,282 IT Pros & Developers. It's quick & easy.

beginner whitespace question

P: n/a
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

Aug 9 '07 #1
Share this Question
Share on Google+
8 Replies

P: n/a
On Aug 9, 6:47 pm, eggie5 <egg...@gmail.comwrote:
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.

Aug 9 '07 #2

P: n/a
On Aug 9, 4:52 pm, Dan Bishop <danb...@yahoo.comwrote:
On Aug 9, 6:47 pm, eggie5 <egg...@gmail.comwrote:
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.
will they still be a part of the classes?

Aug 10 '07 #3

P: n/a
On Aug 9, 7:02 pm, eggie5 <egg...@gmail.comwrote:
On Aug 9, 4:52 pm, Dan Bishop <danb...@yahoo.comwrote:
On Aug 9, 6:47 pm, eggie5 <egg...@gmail.comwrote:
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.

will they still be a part of the classes?
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.

Aug 10 '07 #4

P: n/a
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
On Aug 9, 5:52 pm, Dan Bishop <danb...@yahoo.comwrote:
On Aug 9, 7:02 pm, eggie5 <egg...@gmail.comwrote:
On Aug 9, 4:52 pm, Dan Bishop <danb...@yahoo.comwrote:
On Aug 9, 6:47 pm, eggie5 <egg...@gmail.comwrote:
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.
will they still be a part of the classes?

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.

Aug 10 '07 #5

P: n/a
On Aug 9, 8:28 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
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".
"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.

Aug 10 '07 #6

P: n/a
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?)
Aug 10 '07 #7

P: n/a
James Stroud <js*****@mbi.ucla.eduwrites:
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
Aug 10 '07 #8

P: n/a
On Aug 9, 10:37 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
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?)
I'm so confused, I have no idea what's going on...

Aug 10 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.