Syntax error in WindowedRangeQuery example code
Issue #2968
resolved
The code in:
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/WindowedRangeQuery
contains the line:
intervals = [for id, in q](id)
That's not valid Python 2.7 syntax. I don't think it is valid Python 3.x either. What expression is missing?
Comments (5)
-
repo owner -
repo owner yeah this is bad, i might have to re-do the wiki export again. here's a diff:
--- a.txt 2014-02-20 11:44:07.000000000 -0500 +++ b.txt 2014-02-20 11:44:20.000000000 -0500 @@ -34,12 +34,12 @@ if windowsize > 1: q = q.filter("rownum %% %d=1" % windowsize) - intervals = [id for id, in q] + intervals = [for id, in q](id) while intervals: start = intervals.pop(0) if intervals: - end = intervals[0] + end = intervals[0](0) else: end = None yield int_for_range(start, end) @@ -72,14 +72,13 @@ Base.metadata.create_all(e) # get some random list of unique values - data = set([random.randint(1, 1000000) for i in xrange(10000)]) + data = set([1000000) for i in xrange(10000)](random.randint(1,)) s = Session(e) - s.add_all([Widget(id=i, data=j) for i, j in enumerate(data)]) + s.add_all([data=j) for i, j in enumerate(data)](Widget(id=i,)) s.commit() q = s.query(Widget) for widget in windowed_query(q, Widget.data, 1000): print "data:", widget.data
-
repo owner oh, heh, it turned all the list comprehensions into markdown links. heh.
-
repo owner - changed status to resolved
OK thanks very much for reporting this, I've fixed my export script to not process text within {{{}}} blocks and as you can see in https://bitbucket.org/zzzeek/sqlalchemy/wiki/commits/34b950178e98584dfbf6468e647f8f15e837fc2b there was a lot of code that was corrupted. I think its OK now.
-
reporter Thanks for the quick response (and the original code too!)
- Log in to comment
If I had to guess that's probably something that got hosed when I transferred from trac. Ill take a look to see what it used to say...