Re: Eliminate "extra" variable

2013-12-15 Thread Igor Korot
Hi, I have the same result even with: sqlite3.connect(r'...') Any other alternatives? Thank you. On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > On 15/12/2013 22:46, Igor Korot wrote: >> >> Tim, >> >> On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase >> wrote: >>> >>> On 2013-12-15 06:17, Tim Chase

Re: Eliminate "extra" variable

2013-12-15 Thread Chris Angelico
On Mon, Dec 16, 2013 at 1:43 PM, Igor Korot wrote: > So, how do I convert my string to one of those? > I realized I can just do replace '/' to '\', but is there a better > alternative? The path is exactly the same, whether you use forward slashes or backslashes, on Windows. Most of the world use

Re: Eliminate "extra" variable

2013-12-15 Thread Dave Angel
On Sun, 15 Dec 2013 18:43:53 -0800, Igor Korot wrote: On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > When writing paths on Windows, it's a good idea to use raw string > literals or slashes instead of backslashes: > > conn = sqlite3.connect(r'c:\Documents and > Settings\Igor.FORDANWORK

Re: Eliminate "extra" variable

2013-12-15 Thread Igor Korot
Hi, On Sun, Dec 15, 2013 at 4:58 PM, MRAB wrote: > On 15/12/2013 22:46, Igor Korot wrote: >> >> Tim, >> >> On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase >> wrote: >>> >>> On 2013-12-15 06:17, Tim Chase wrote: > > conn = sqlite3.connect('x.sqlite', >> >> ... detect_types=sqli

Re: Eliminate "extra" variable

2013-12-15 Thread MRAB
On 15/12/2013 22:46, Igor Korot wrote: Tim, On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase wrote: On 2013-12-15 06:17, Tim Chase wrote: conn = sqlite3.connect('x.sqlite', ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) Your example code omitted this one crucial line. Do you s

Re: Eliminate "extra" variable

2013-12-15 Thread Igor Korot
Tim, On Sun, Dec 15, 2013 at 4:29 AM, Tim Chase wrote: > On 2013-12-15 06:17, Tim Chase wrote: >>> conn = sqlite3.connect('x.sqlite', ... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) >> >> Your example code omitted this one crucial line. Do you specify the >> detect_types

Re: Eliminate "extra" variable

2013-12-15 Thread Tim Chase
On 2013-12-15 06:17, Tim Chase wrote: >> conn = sqlite3.connect('x.sqlite', >>>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) > > Your example code omitted this one crucial line. Do you specify the > detect_types parameter to connect()? It's really the PARSE_DECLTYPES that

Re: Eliminate "extra" variable

2013-12-15 Thread Tim Chase
On 2013-12-14 23:49, Igor Korot wrote: > Tim, > > On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase wrote: > conn = sqlite3.connect('x.sqlite', >>... detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES) Your example code omitted this one crucial line. Do you specify the detect_types paramete

Re: Eliminate "extra" variable

2013-12-14 Thread Igor Korot
Tim, On Sun, Dec 8, 2013 at 2:18 PM, Tim Chase wrote: > On 2013-12-08 12:58, Igor Korot wrote: >> Also, the data comes from either SQLite or mySQL and so to eliminate >> the difference between those engines dates are processed as strings >> and converted to dates for the calculation purposes only

Re: Fwd: Eliminate "extra" variable

2013-12-08 Thread Dave Angel
On Sun, 8 Dec 2013 12:58:18 -0800, Igor Korot wrote: It's input is the query result, so there is no looping when the function is called. It is called only once. Then why save part of the result in an instance attribute? Just return all of the results as a tuple. -- DaveA -- https://mail.py

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 12:58, Igor Korot wrote: > Also, the data comes from either SQLite or mySQL and so to eliminate > the difference between those engines dates are processed as strings > and converted to dates for the calculation purposes only. > Maybe I will need to refactor SQLite processing to get th

Fwd: Eliminate "extra" variable

2013-12-08 Thread Igor Korot
-- Forwarded message -- From: Igor Korot Date: Sun, Dec 8, 2013 at 12:57 PM Subject: Re: Eliminate "extra" variable To: Roy Smith Hi, guys, Thank you for all those valuable suggestions. 2Tim Chase: I guess you missed this: "My originalData comes from the databas

Re: Eliminate "extra" variable

2013-12-08 Thread Roy Smith
In article , Mark Lawrence wrote: > On 08/12/2013 18:58, Tim Chase wrote: > > On 2013-12-07 23:14, Igor Korot wrote: > > [big snip] > > > > > Whenever I need date manipulations I always reach out to this > http://labix.org/python-dateutil The problem with dateutil is it's dog slow. Sure, I

Re: Eliminate "extra" variable

2013-12-08 Thread Mark Lawrence
On 08/12/2013 19:23, Tim Chase wrote: On 2013-12-08 19:10, Mark Lawrence wrote: On 08/12/2013 18:58, Tim Chase wrote: On 2013-12-07 23:14, Igor Korot wrote: [big snip] Whenever I need date manipulations I always reach out to this http://labix.org/python-dateutil But based on the OP's repea

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 19:10, Mark Lawrence wrote: > On 08/12/2013 18:58, Tim Chase wrote: > > On 2013-12-07 23:14, Igor Korot wrote: > > [big snip] > > Whenever I need date manipulations I always reach out to this > http://labix.org/python-dateutil But based on the OP's repeated transformations from

Re: Eliminate "extra" variable

2013-12-08 Thread Mark Lawrence
On 08/12/2013 18:58, Tim Chase wrote: On 2013-12-07 23:14, Igor Korot wrote: [big snip] Whenever I need date manipulations I always reach out to this http://labix.org/python-dateutil -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our languag

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-07 23:14, Igor Korot wrote: > def MyFunc(self, originalData): > self.dates = [] > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): > dateStr, freq, source = originalData[i] > data[str(dateStr)] = {source: freq} >

Re: Eliminate "extra" variable

2013-12-08 Thread Tim Chase
On 2013-12-08 15:04, Peter Otten wrote: > > data = dict( > > (str(date), {source: freq}) > > for date, freq, source in original_data > > ) > > or even just > > data = {str(date): {source: freq} > for date, freq, source in original_data} I maintain enough pre-2.7 c

Re: Eliminate "extra" variable

2013-12-08 Thread Peter Otten
Tim Chase wrote: > On 2013-12-06 11:37, Igor Korot wrote: >> def MyFunc(self, originalData): >> data = {} >> for i in xrange(0, len(originalData)): >>dateStr, freq, source = originalData[i] >>data[str(dateStr)] = {source: freq} > > this can be more cleanly/pytho

Fwd: Eliminate "extra" variable

2013-12-08 Thread Igor Korot
OK, here is the complete function code that I'm trying to improve. def MyFunc(self, originalData): self.dates = [] data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i] data[str(dateStr)] = {source: fr

Re: Eliminate "extra" variable

2013-12-06 Thread Ethan Furman
On 12/06/2013 03:38 PM, Joel Goldstick wrote: On Fri, Dec 6, 2013 at 2:37 PM, Igor Korot wrote: def MyFunc(self, originalData): data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i]

Re: Eliminate "extra" variable

2013-12-06 Thread Tim Chase
On 2013-12-06 11:37, Igor Korot wrote: > def MyFunc(self, originalData): > data = {} > for i in xrange(0, len(originalData)): >dateStr, freq, source = originalData[i] >data[str(dateStr)] = {source: freq} this can be more cleanly/pythonically written as def my_

Re: Eliminate "extra" variable

2013-12-06 Thread Joel Goldstick
On Fri, Dec 6, 2013 at 7:16 PM, Roy Smith wrote: > In article , > Joel Goldstick wrote: > > > Python lets you iterate over a list directly, so : > > > > for d in originalData: > > dateStr, freq, source = d > > data[source] = freq > > I would make it even simpler: > > > f

Re: Eliminate "extra" variable

2013-12-06 Thread Roy Smith
In article , Joel Goldstick wrote: > Python lets you iterate over a list directly, so : > > for d in originalData: > dateStr, freq, source = d > data[source] = freq I would make it even simpler: > for dateStr, freq, source in originalData: > data[source] = freq

Re: Eliminate "extra" variable

2013-12-06 Thread Joel Goldstick
On Fri, Dec 6, 2013 at 2:37 PM, Igor Korot wrote: > Hi, ALL, > I have following code: > > def MyFunc(self, originalData): > data = {} > dateStrs = [] > for i in xrange(0, len(originalData)): >dateStr, freq, source = originalData[i] >data[str(dateStr)] = {so

Re: Eliminate "extra" variable

2013-12-06 Thread Gary Herron
On 12/06/2013 11:37 AM, Igor Korot wrote: Hi, ALL, I have following code: def MyFunc(self, originalData): data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i] data[str(dateStr)] = {source: freq}

Eliminate "extra" variable

2013-12-06 Thread Igor Korot
Hi, ALL, I have following code: def MyFunc(self, originalData): data = {} dateStrs = [] for i in xrange(0, len(originalData)): dateStr, freq, source = originalData[i] data[str(dateStr)] = {source: freq} dateStrs.append(dateStr) for i in xrange(0