Python Script Bug

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • max.caly@gmail.com

    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
  • Chris Rebert

    #2
    Re: Python Script Bug

    On Thu, Oct 23, 2008 at 11:54 AM, max.caly@gmail. com <max.caly@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:
    Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax an...


    Cheers,
    Chris
    --
    Follow the path of the Iguana...

    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
    --

    >

    Comment

    • Terry Reedy

      #3
      Re: Python Script Bug

      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.

      Comment

      Working...