Addition problems

2011-04-01 Thread vm
I'm analyzing some data in python. I have stumbled across unusual problem:

I have the function...

def fun1(params_used_below_except_lk_and_lk2):
lk = 0.0
lk2 = 0.0
for raw_data, hist, freq in raw_data_hist_list:
lk2 = lk2 + fun2(some_constants_and_params_from_this_scope)
q = fun2(same_args_as_before)
lk = lk + q
print lk, lk2

For some set of input parameters, This function with specific input 
prints out the same constant twice (as expected):

15377.7424582 15377.7424582 (twice the same value)

If I comment out lines q = fun2 and lk = lk + q, fun1, with the same 
parameters, prints:

0.0 3.3469936856

First value is expected, but I cannot understand how come the second 
value is different in these two cases!

Thanks in advance! 


fun1 source:

def process_measurements_beta_lk(x, raw_data_hist_list):
lk = 0.0
lk2 = 0.0
(p,q,loc,scale) = x
for raw_data, hist, freq in raw_data_hist_list:
lk2 =   lk2 + get_beta_func_fit_quality_hist_lk('beta',
(p,q,loc,scale), raw_data, hist)
#q = get_beta_func_fit_quality_hist_lk('beta',(p,q,loc,scale), 
raw_data, hist)
#   lk = lk + q

  
print lk, lk2
retrun lk






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


http POST only returning GET data

2005-06-24 Thread vm
Hi, for some reason my POST is not working properly.  I am basically
just trying to get a simple stock quote from yahoo by posting the
ticker symbol (GE as an example) into finance.yahoo.com.  However, when
I POST, I do get a response back, but it is just the main page
finance.yahoo.com and it doesn't seem as if the POST got through.  I am
using Python 2.2.  I get a status and reason of 200 and OK
respectively.  I've searched through these groups on previous POST
problems, but none have seemed to help so far.  Any help would be
greatly appreciated, or if there is a previous post that describes this
same problem, please let me know.

In addition, when I change the headers from back and forth between
"multipart/form-data" and "application/x-www-form-urlencoded", there
seems to be no change.  How do I know which Content-type to use for
each page.  When I look at the Content-type on the yahoo page, it says
"text/html; charset=iso-8859-1" -- but if I enter this in, I get other
errors.  How do I know which Content-type to use when I pass it as
headers?

Thank you very much.

##
import urllib,httplib

url = "finance.yahoo.com"
fields = { "s": "ge" }
params = urllib.urlencode(fields)
##headers = {"Content-type": "application/x-www-form-urlencoded",
##   "Accept":"text/plain"}
headers = {"Content-type": "multipart/form-data",
   "Accept":"text/plain"}

httpSess = httplib.HTTPConnection(url)
httpSess.request("POST","/",params,headers)

response = httpSess.getresponse()

print "status=%s, reason=%s" % (response.status,response.reason)

data = response.read()

print "OUTPUT = \n\n%s\n\n" % data
##

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


Re: http POST only returning GET data

2005-06-24 Thread vm
Benji - that worked like a champ - my mistake.  thanks

Vinod

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


Tkinter PhotoImage won't show ;-(

2006-01-29 Thread vm
please help!

I can't find anything wrong (except the result ofc ;-)

This:



picfile = 'logo.gif'

pic = tk.PhotoImage(file=picfile, master=root)

canpic = cv.create_image(320, 240, image=pic) #cv is is a Tkinter 
Canvas ofc



...works just fine, but when I put it in the event binding function, it 
doesn't work,

it doesn't report any errors too, I'm sure the function went all the way 
through

because I print the test-text at the end of the function... But it doesn't 
show picture!



here's the entire program I wrote to test this out:

===

import Tkinter as tk, os



root = tk.Tk()

root.title = 'Picviewer'



###setting Listbox, Canvas

lb = tk.Listbox(root,width =20, height=22)

lb.grid(column=0, row=0, columnspan = 2)



cv = tk.Canvas(root, width=640, height=480, bg='white')

cv.grid(column=2,row=0, rowspan=2)



###listing all .gifs in current working directory into the Listbox lb

cwd = os.getcwd()

filelista = os.listdir(cwd)

filelista.sort()

for element in filelista:

  if os.path.isfile(element) and '.gif' in element.lower(): lb.insert( 
lb.size() ,element)



###Load-button bind function (showing picture) - the problem seems to be in 
here somewhere I think

def putpic(event):

  picfile = lb.selection_get()

  pic = tk.PhotoImage(file=picfile, master=root)

  canpic = cv.create_image(320, 240, image=pic)

  ###just to see what's going on

  print str(picfile), "\n", str(pic), '\n', str(canpic)



###setting Load-button

load = tk.Button(root, text='Load', width=16)

load.bind('', putpic)

load.grid(column=0, row=2, columnspan=2)



###Putting the logo image at start (more like test image at start - and it 
works)

pic = tk.PhotoImage(file='logo.gif', master=root)

canpic = cv.create_image(320, 240, image=pic)



root.mainloop()



Maybe I just need a fresh pair of eyes, SOMEONE!




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


Re: Tkinter PhotoImage won't show ***SOLVED***

2006-01-29 Thread vm
I was missing "global pic" line at the begining of
putpic function. doh!


"vm" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> please help!
>
> I can't find anything wrong (except the result ofc ;-)
>
> This:
>
>
>
> picfile = 'logo.gif'
>
> pic = tk.PhotoImage(file=picfile, master=root)
>
> canpic = cv.create_image(320, 240, image=pic) #cv is is a Tkinter 
> Canvas ofc
>
>
>
> ...works just fine, but when I put it in the event binding function, it 
> doesn't work,
>
> it doesn't report any errors too, I'm sure the function went all the way 
> through
>
> because I print the test-text at the end of the function... But it doesn't 
> show picture!
>
>
>
> here's the entire program I wrote to test this out:
>
> ===
>
> import Tkinter as tk, os
>
>
>
> root = tk.Tk()
>
> root.title = 'Picviewer'
>
>
>
> ###setting Listbox, Canvas
>
> lb = tk.Listbox(root,width =20, height=22)
>
> lb.grid(column=0, row=0, columnspan = 2)
>
>
>
> cv = tk.Canvas(root, width=640, height=480, bg='white')
>
> cv.grid(column=2,row=0, rowspan=2)
>
>
>
> ###listing all .gifs in current working directory into the Listbox lb
>
> cwd = os.getcwd()
>
> filelista = os.listdir(cwd)
>
> filelista.sort()
>
> for element in filelista:
>
>  if os.path.isfile(element) and '.gif' in element.lower(): 
> lb.insert( lb.size() ,element)
>
>
>
> ###Load-button bind function (showing picture) - the problem seems to be 
> in here somewhere I think
>
> def putpic(event):
>
>  picfile = lb.selection_get()
>
>  pic = tk.PhotoImage(file=picfile, master=root)
>
>  canpic = cv.create_image(320, 240, image=pic)
>
>  ###just to see what's going on
>
>  print str(picfile), "\n", str(pic), '\n', str(canpic)
>
>
>
> ###setting Load-button
>
> load = tk.Button(root, text='Load', width=16)
>
> load.bind('', putpic)
>
> load.grid(column=0, row=2, columnspan=2)
>
>
>
> ###Putting the logo image at start (more like test image at start - and it 
> works)
>
> pic = tk.PhotoImage(file='logo.gif', master=root)
>
> canpic = cv.create_image(320, 240, image=pic)
>
>
>
> root.mainloop()
>
> 
>
> Maybe I just need a fresh pair of eyes, SOMEONE!
>
>
>
> 


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