returning results from function

Discussion in 'Python' started by Neil Berg, Nov 11, 2010.

  1. Neil Berg

    Neil Berg Guest

    Hi Python community,

    In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the "returned" loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the "return" command to just return the values to me in the main script so I can work with them! Any help is appreciated.

    Thanks in advance,
    Neil

    _________
    Mac OS X 10.6.4
    Python 2.6
    _________

    from datetime import datetime
    from pytz import timezone
    import pytz

    def utc_to_local(yr,mo,dy,hr):
    fmt = '%Y-%m-%d %H %Z'
    utc = pytz.utc
    local = pytz.timezone("US/Pacific")
    utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc)
    loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ
    #print utc_dt.strftime(fmt), " = ", loc_dt.strftime(fmt)

    loc_y = loc_dt.year # local year
    loc_m = loc_dt.month # local month
    loc_d = loc_dt.day # local day
    loc_h = loc_dt.hour # local hour

    return loc_y, loc_m, loc_d, loc_h
     
    Neil Berg, Nov 11, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Monique Y. Mudama
    Replies:
    1
    Views:
    458
    Monique Y. Mudama
    Jun 28, 2005
  2. Daniel Rudy
    Replies:
    15
    Views:
    573
    Dave Thompson
    May 16, 2005
  3. lovecreatesbeauty
    Replies:
    8
    Views:
    1,671
    Old Wolf
    Sep 12, 2005
  4. Ken Fine
    Replies:
    3
    Views:
    541
    Steven Cheng [MSFT]
    Jul 23, 2008
  5. Marc Walgren
    Replies:
    3
    Views:
    165
    Marc Walgren
    Aug 23, 2004
Loading...

Share This Page