beginner whitespace question

James Stroud jstroud at mbi.ucla.edu
Fri Aug 10 03:28:35 CEST 2007


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/



More information about the Python-list mailing list