469,889 Members | 1,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Python Script Bug

Hello everyone,
I would like to know what isn't good in my script.
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
from time import strftime
import datetime
t = input(datetime.date)
global t
print t.strftime("Day %w of the week a %A . Day %d of the month (%B).
")
print t.strftime("Day %j of the year (%Y), in week %W of the year.")
raw_input()
i get error :
print t.strftime("Day %w of the week a %A . Day %d of the month
(%B). ")
AttributeError: 'tuple' object has no attribute 'strftime'
Thanks for your Help
Oct 23 '08 #1
2 1525
On Thu, Oct 23, 2008 at 11:54 AM, ma******@gmail.com <ma******@gmail.comwrote:
Hello everyone,
I would like to know what isn't good in my script.
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
from time import strftime
import datetime
t = input(datetime.date)
input() does not do what you think it does. You want raw_input().
raw_input() takes a string to prompt the user with and returns the
string the user enters.
You'll then pass the string to time.strptime() (along with a format
string) to parse it into a time tuple. You'll then pass part of the
time tuple to the datetime.date() constructor to get a date object.
global t
'global' declarations are only allowed (and only make sense) inside a
function. Remove the above line.

Based on some of the errors you've made, I'd recommend reading through
Python's fine tutorial before going any further:
http://docs.python.org/tutorial/index.html

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
print t.strftime("Day %w of the week a %A . Day %d of the month (%B).
")
print t.strftime("Day %j of the year (%Y), in week %W of the year.")
raw_input()
i get error :
print t.strftime("Day %w of the week a %A . Day %d of the month
(%B). ")
AttributeError: 'tuple' object has no attribute 'strftime'
Thanks for your Help
--
http://mail.python.org/mailman/listinfo/python-list
Oct 23 '08 #2
Chris Rebert wrote:
>global t

'global' declarations are only allowed (and only make sense) inside a
function. Remove the above line.
Global statements are *allowed* anywhere (by BDFL decision - does not
hurt and he wants to keep code in and out of functions as identical as
possible), but rest of statement I agree with.

Oct 24 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Erik Johnson | last post: by
2 posts views Thread by DeepBleu | last post: by
52 posts views Thread by Olivier Scalbert | last post: by
4 posts views Thread by Tom Purl | last post: by
17 posts views Thread by Paul Rubin | last post: by
3 posts views Thread by krzychu | last post: by
6 posts views Thread by manatlan | last post: by
37 posts views Thread by John Salerno | last post: by
6 posts views Thread by tatamata | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.