I can't figure out -what- is going wrong here. When the code reaches
the 'return' line, there is data to be returned, but when it exits out
to the calling function, 'None' is returned!
import mx.DateTime
def get_weeks(weeks, year, dates, date_list={}):
if dates.has_key(year):
date_list[year] = dates[year].keys()[-weeks:]
if len(dates[year].keys()) >= weeks:
return date_list
else:
weeks = weeks - len(dates[year].keys())
get_weeks(weeks, str(int(year) -1), dates, date_list)
def get_report_dates(weeks, dates):
today = mx.DateTime.now()
this_week = today.iso_week[1]
rpt_dates = get_weeks(weeks, str(today.year), dates)
print rpt_dates
def main():
dates = {'2006': {'50': [50, 'This is the 50th week'],
'51': [51, 'This is the 51st week'],
'52': [52, 'This is the 52nd week']},
'2007': {'25': [1, 'This is the 1st week'],
'26': [2, 'This is the 2nd week'],
'27': [3, 'This is the 3rd week'],
'28': [4, 'This is the 4th week'],
'29': [5, 'This is the 5th week']}}
get_report_dates(6, dates) 2 1043
On 7/5/07, ro**********@gmail.com <ro**********@gmail.comwrote:
I can't figure out -what- is going wrong here. When the code reaches
the 'return' line, there is data to be returned, but when it exits out
to the calling function, 'None' is returned!
import mx.DateTime
def get_weeks(weeks, year, dates, date_list={}):
if dates.has_key(year):
date_list[year] = dates[year].keys()[-weeks:]
if len(dates[year].keys()) >= weeks:
return date_list
else:
weeks = weeks - len(dates[year].keys())
Right here.
get_weeks(weeks, str(int(year) -1), dates, date_list)
You have to change that line to:
return get_weeks(weeks, str(int(year) -1), dates, date_list)
Otherwise, if len(dates[year.keys()) < weeks, it doesn't return anything.
>
def get_report_dates(weeks, dates):
today = mx.DateTime.now()
this_week = today.iso_week[1]
rpt_dates = get_weeks(weeks, str(today.year), dates)
print rpt_dates
def main():
dates = {'2006': {'50': [50, 'This is the 50th week'],
'51': [51, 'This is the 51st week'],
'52': [52, 'This is the 52nd week']},
'2007': {'25': [1, 'This is the 1st week'],
'26': [2, 'This is the 2nd week'],
'27': [3, 'This is the 3rd week'],
'28': [4, 'This is the 4th week'],
'29': [5, 'This is the 5th week']}}
get_report_dates(6, dates)
-- http://mail.python.org/mailman/listinfo/python-list
--
Kelvie ro**********@gmail.com wrote:
I can't figure out -what- is going wrong here. When the code reaches
the 'return' line, there is data to be returned, but when it exits out
to the calling function, 'None' is returned!
import mx.DateTime
def get_weeks(weeks, year, dates, date_list={}):
if dates.has_key(year):
date_list[year] = dates[year].keys()[-weeks:]
if len(dates[year].keys()) >= weeks:
return date_list
else:
weeks = weeks - len(dates[year].keys())
get_weeks(weeks, str(int(year) -1), dates, date_list)
So if the else branch is taken here you end up dropping of the end of
the function's code, which will return None.
def get_report_dates(weeks, dates):
today = mx.DateTime.now()
this_week = today.iso_week[1]
rpt_dates = get_weeks(weeks, str(today.year), dates)
print rpt_dates
def main():
dates = {'2006': {'50': [50, 'This is the 50th week'],
'51': [51, 'This is the 51st week'],
'52': [52, 'This is the 52nd week']},
'2007': {'25': [1, 'This is the 1st week'],
'26': [2, 'This is the 2nd week'],
'27': [3, 'This is the 3rd week'],
'28': [4, 'This is the 4th week'],
'29': [5, 'This is the 5th week']}}
get_report_dates(6, dates)
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading ------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: M-a-S |
last post by:
Can anybody explain this:
Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> None = 3
<stdin>:1: SyntaxWarning:...
|
by: Martin DeMello |
last post by:
It seems to be a fairly common pattern for an object-modifying method to
return None - however, this is often quite inconvenient.
For instance
def f(lst1, lst2):
g((lst1 + lst2).reverse()) #...
|
by: Steven Bethard |
last post by:
I have lists containing values that are all either True, False or None,
e.g.:
etc.
For a given list:
* If all values are None, the function should return None.
|
by: noahlt |
last post by:
I'm trying to write a website updating script, but when I run the
script, my function to search the DOM tree returns None instead of what
it should.
I have this program:
--------
import sys...
|
by: z. f. |
last post by:
sorry about the previous post, by mistake not completed.
i have an asp.net page with the line
<%@ OutputCache Duration="30" VaryByParam="none" %>
but when i make requests to the page with...
|
by: Raymond Hettinger |
last post by:
I am evaluating a request for an alternate version of itertools.izip()
that has a None fill-in feature like the built-in map function:
>>> map(None, 'abc', '12345') # demonstrate map's None...
|
by: Corey Wallis |
last post by:
Dear All,
I'm currently working on a project that needs to collect the output of
the JHOVE application. More information about the application is
available at this website:
...
|
by: sam |
last post by:
i am starting to experiment with recursion, and decided to write a
fairly trivial little program which took a float as input, then called
a function to halve it recursively until it was less than...
|
by: Paddy |
last post by:
Iam wondering why the peculiar behavior of map when the function in
given as None:
Help on built-in function map in module __builtin__:
map(...)
map(function, sequence) -list
Return a list...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |