472,119 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

beginner whitespace question

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
8 1100
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
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
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
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
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
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
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
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.

Similar topics

13 posts views Thread by Hadi | last post: by
4 posts views Thread by Dwayne Epps | last post: by
4 posts views Thread by dld_id | last post: by
3 posts views Thread by David Pratt | last post: by
9 posts views Thread by amattie | last post: by
1 post views Thread by bryan rasmussen | last post: by
5 posts views Thread by John Gordon | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.