Re: Semi-Newbie needs a little help

2009-07-07 Thread Nile
Thanks all for your help. I appreciate it.  The problem was in the
function.  A simple bug which I should have caught but I had my mental
blinders on and was sure the problem was outside the function.  The
answers have given me a lot to learn so thanks for that as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Semi-Newbie needs a little help

2009-07-06 Thread Nile
I am trying to write a simple little program to do some elementary
stock market analysis.  I read lines, send each line to a function and
then the function returns a date which serves as a key to a
dictionary. Each time a date is returned I want to increment the value
associated with that date. The function seems to be working properly.
By means of a print statement I have inserted just before the return
value I can see there are three dates that are returned which is
correct.  The dictionary only seems to capture the last date. My test
data consists of five stocks, each stock with five days. The correct
answer would be a count of 5 for the second day, the third day, and
the last day -- 11/14/2008.

Here is the a code, followed by a portion of the output.  I know
enough to write simple little programs like this with no problems up
until now but I don't know enough to figure out what I am doing
wrong.

Code

for x in range(len(file_list)):
d = open(file_list[x] , r)
data = d.readlines()
k = above_or_below(data)# This
function seems to work correctly
print here is the value that was returned  , k
dict[k] = dict.get(k,0) + 1

dict_list = dict.values()
print here is a list of the dictionary values , dict_list
print the length of the dictionary is , len(dict)

And here is some output
Function will return k which = 11/11/2008   #  These 3 lines are
printed from the function just before the return
Function will return k which = 11/12/2008   #   This sample shows
stocks 4 and 5 but 1,2,3 are the same.
Function will return k which = 11/14/2008
here is the value that was returned 11/14/2008 # printed from
code above  - only the last day seems to be
Function will return k which = 11/11/2008 #
recognized.
Function will return k which = 11/12/2008
Function will return k which = 11/14/2008
here is the value that was returned 11/14/2008
here is a list of the dictionary values [5] # dict has
counted only the last day for 5 stocks
the length of the dictionary is 1
Exit code: 0



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semi-Newbie needs a little help

2009-07-06 Thread Nile
On Jul 6, 5:30 pm, Pablo Torres N. tn.pa...@gmail.com wrote:
 On Mon, Jul 6, 2009 at 17:02, Nilenile_mcad...@yahoo.com wrote:
  Code

     for x in range(len(file_list)):
     d = open(file_list[x] , r)
     data = d.readlines()
     k = above_or_below(data)                                # This
  function seems to work correctly
     print here is the value that was returned  , k
     dict[k] = dict.get(k,0) + 1

     dict_list = dict.values()
     print here is a list of the dictionary values , dict_list
     print the length of the dictionary is , len(dict)

 Correcting your indentation errors and moving your comments above the
 line they reference will attract more help from others in this list
 ;-)

 Also, I'd recommend limiting your line length to 80 chars, since lines
 are wrapped anyway.

 --
 Pablo Torres N.

Yup - Sorry, first post ever - next ones will be better formatted
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semi-Newbie needs a little help

2009-07-06 Thread Nile
On Jul 6, 5:22 pm, Chris Rebert c...@rebertia.com wrote:
 On Mon, Jul 6, 2009 at 3:02 PM, Nilenile_mcad...@yahoo.com wrote:
  I am trying to write a simple little program to do some elementary
  stock market analysis.  I read lines, send each line to a function and
  then the function returns a date which serves as a key to a
  dictionary. Each time a date is returned I want to increment the value
  associated with that date. The function seems to be working properly.
  By means of a print statement I have inserted just before the return
  value I can see there are three dates that are returned which is
  correct.  The dictionary only seems to capture the last date. My test
  data consists of five stocks, each stock with five days. The correct
  answer would be a count of 5 for the second day, the third day, and
  the last day -- 11/14/2008.

  Here is the a code, followed by a portion of the output.  I know
  enough to write simple little programs like this with no problems up
  until now but I don't know enough to figure out what I am doing
  wrong.
     for x in range(len(file_list)):

 for filename in file_list:
 #I'm assuming the lack of indentation on the subsequent lines is a
 mere transcription error...

     d = open(file_list[x] , r)

     d = open(filename , r)

     data = d.readlines()
     k = above_or_below(data)                                # This
  function seems to work correctly
     print here is the value that was returned  , k
     dict[k] = dict.get(k,0) + 1

 `dict` is the name of a builtin type. Please rename this variable to
 avoid shadowing the type.
 Also, where is this variable even initialized? It's not in this code
 snippet you gave.
 Further, I would recommend using a defaultdict
 (http://docs.python.org/dev/library/collections.html#collections.defau...)
 rather than a regular dictionary; this would make the
 count-incrementing part nicer.

 Taking these changes into account, your code becomes:

 from collections import defaultdict

 counts = defaultdict(lambda: 0)

 for filename in file_list:
     d = open(filename , r)
     data = d.readlines()
     k = above_or_below(data) # This function seems to work correctly
     print here is the value that was returned  , k
     counts[k] += 1

     values = counts.values()
     print here is a list of the dictionary values , values
     print the length of the dictionary is , len(counts)

 I don't immediately see what's causing your problem, but guess that it
 might've be related to the initialization of the `dict` variable.

 Cheers,
 Chris
 --http://blog.rebertia.com- Hide quoted text -

 - Show quoted text -

I initialized the dictionary earlier in the program like this -

  hashtable = {}

I changed the dict to hashtable but I still get the same result
I will try to learn about the defaultdict but I'm just trying to keep
it as simple as I can for now

Revised code

for x in range(len(file_list)):
d = open(file_list[x] , r)
data = d.readlines()
k = 0
k = above_or_below(data)
print here is the value that was returned ,k
hashtable[k] = hashtable.get(k,0) + 1


hashtable_list = hashtable.values()
print here is a list of the dictionary values , hashtable_list
print the length of the dictionary is , len(hashtable)

Output
# The first 3 lines are printed from the function
# right before the return statement.  This output
# snippet shows the last two stocks.  The function
# SAYS it is returning the correct value but only
# the last date seems to make it to the hashtable
Function will return k which = 11/11/2008
Function will return k which = 11/12/2008
Function will return k which = 11/14/2008

# this line is printed from the code above
# I don't understand why all three dates don't
# seem to make it to the main program.  Only
# the last date seems to be recognized
here is the value that was returned 11/14/2008

Function will return k which = 11/11/2008
Function will return k which = 11/12/2008
Function will return k which = 11/14/2008
here is the value that was returned 11/14/2008
here is a list of the dictionary values [5]
the length of the dictionary is 1
Exit code: 0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will 2.5.1 be released?

2007-03-06 Thread Nile
On Mar 6, 1:12 pm, A. Lloyd Flanagan [EMAIL PROTECTED]
wrote:
 On Mar 4, 2:49 pm, Nile [EMAIL PROTECTED] wrote:

  This is not a big deal but I would like to use Tix with 2.5.  My
  understanding is this bug will be fixed in the 2.5.1 release. Does

 And while we're waiting for 2.5.1, can somebody post a clear (as
 opposed to the one that comes with Tix ;)) explanation of how to
 manually install Tix into python 2.5?  It should be possible...

LLoyd
-Not possible - this is a known bug and won't be fixed until 2.5.1

-- 
http://mail.python.org/mailman/listinfo/python-list


When will 2.5.1 be released?

2007-03-04 Thread Nile
This is not a big deal but I would like to use Tix with 2.5.  My
understanding is this bug will be fixed in the 2.5.1 release. Does
anyone know when this will be out ?  What is the best guess?

Thanks,

Nile

-- 
http://mail.python.org/mailman/listinfo/python-list