[Tutor] Can't figure out why this is printing twice

Andre Engels andreengels at gmail.com
Mon Jun 8 12:03:09 CEST 2009


On Mon, Jun 8, 2009 at 11:57 AM, Mike Hoy<hoym74 at gmail.com> wrote:
> I have the following code:
>
> import gzip
> import datetime
> date = datetime.date.today()
> name = date.strftime('%m-%d-%Y')+'.gz'
> date.strftime('%m-%d-%Y')+'.gz'
> print "The name of the file will be", name
>
> the output is:
> The name of the file will be
> The name of the file will be 06-08-2009.gz
>
>
> I can't figure out why 'The name of the file will be' is printing twice. Any
> help appreciated.

How exactly are you running this? It seems to work correctly for me.

Looking at your code, the following couple of lines look strange:

> name = date.strftime('%m-%d-%Y')+'.gz'
> date.strftime('%m-%d-%Y')+'.gz'

The first calculates a name based on the current date, and puts the
result in the variable 'name'. The second calculates the name again,
then throws the result away. Why not remove the second line?




-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list