Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 16:56, ALAN GAULD wrote: > if isinstance(dict(),typein): >try: newdict = dict(zip(dl[::2],dl[1::2])) >except TypeError: > raise ValueError("input lists must be an even length") Not sure why TypeError and ValueError is used. I would have thought StopIteration but expl

Re: [Tutor] Writing logfile data to a user opened file

2013-06-21 Thread Matt D
> > You should really switch to the "with open() as f:" idiom I keep showing > you. This will automatically close the file for you. > it just occured to me to do this: def openFile(self, evt): with wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.tx

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 16:56, ALAN GAULD wrote: > > But that doesn't answer your question about incrementing the globals! :-) > To me it looks from your sample data like it is working! Good tips, though. Those sneaky zips are useful ;') Yes, the globals works fine. I just wondered if there was a way

Re: [Tutor] Writing logfile data to a user opened file

2013-06-21 Thread Matt D
On 06/21/2013 04:44 PM, Prasad, Ramit wrote: > Matt D wrote: >> [Ramit P wrote:] >>> When you open a file the data should be written to that. If you want to >>> move existing data from logfile.txt into user opened file then you need >>> to read logfile.txt and then write it to the user opened file.

Re: [Tutor] Data persistence problem

2013-06-21 Thread ALAN GAULD
 Just a wee thought:     if isinstance(dict(), typein): >        newdict = {} >        dl = instring.split() >        if len(dl) % 2 != 0: raise Exception ("list entries must be >even") # so they match >        for idx in range(0,len(dl),2): >            newdict[dl[idx]] = dl[idx+1] >The for loo

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 14:59, ALAN GAULD wrote: > > Give us a clue, show us your code! I was hoping you wouldn't say that since it's another of my insane Lazy Typer programs to avoid typing, which are no doubt considered frivolous. Although I'm learning a lot doing them ;') Okay, I have a snippet that

Re: [Tutor] Best Code testing practice?

2013-06-21 Thread Alan Gauld
On 21/06/13 19:07, Prasad, Ramit wrote: Have you heard of the MVC model? The idea is that you separate the business logic from the "view" or UI. The "controller" contains all the business logic (or work actually being done). Being slightly picky but the business logic should sit mainly in the

Re: [Tutor] Data persistence problem

2013-06-21 Thread ALAN GAULD
> ... I need to increment three different numbers that will > persist in the function. I tried a few examples I saw but I keep > getting the same number, so I'm doing something wrong Give us a clue, show us your code!   Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/___

Re: [Tutor] Writing logfile data to a user opened file

2013-06-21 Thread Prasad, Ramit
Matt D wrote: > [Ramit P wrote:] > > When you open a file the data should be written to that. If you want to > > move existing data from logfile.txt into user opened file then you need > > to read logfile.txt and then write it to the user opened file. To make > > your life simpler, either pass in t

Re: [Tutor] Writing logfile data to a user opened file

2013-06-21 Thread Matt D
> > When you open a file the data should be written to that. If you want to > move existing data from logfile.txt into user opened file then you need > to read logfile.txt and then write it to the user opened file. To make > your life simpler, either pass in the file path or open the file save >

Re: [Tutor] Best Code testing practice?

2013-06-21 Thread Matt D
> > I suspect that you'd get better answers on a GUI specific mailing list, > like one for wxPython, but I note that you've already asked pretty much > the same question there. > Hey guys! Have decided that it is probably going to be better for my purposes to simply crack open a terminal, cd int

Re: [Tutor] Best Code testing practice?

2013-06-21 Thread Prasad, Ramit
Matt D wrote: > Sent: Thursday, June 20, 2013 6:44 AM > To: tutor@python.org > Subject: [Tutor] Best Code testing practice? > > Hey guys! > Is there a fast way test some piece of code? I would like to be able to > look at the GUI I am making with out changing the file in dir 'baz' and > running t

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 00:06, Alan Gauld wrote: > Or if you really don't like globals you could create > a generator function: Similar problem, by coincidence. Except I need a generator in a function to increment a variable each time the function is called, instead of giving it the same value every tim

Re: [Tutor] Writing logfile data to a user opened file

2013-06-21 Thread Prasad, Ramit
Matt D wrote: > Hey guys! > So now my UI panel works well with this: > > # Open file button click event binded to openfile > btn = wx.Button(self, -1, "Click me") > sizer.Add(btn, pos=(7,2)) > btn.Bind(wx.EVT_BUTTON, self.openFile) > > #set the panel layout > s

Re: [Tutor] Data persistence problem

2013-06-21 Thread Wolfgang Maier
Arijit Ukil tcs.com> writes: > > I have following random number generation > function > def > rand_int (): >     rand_num = int(math.ceil > (random.random()*1000)) >     return > rand_num > I like to make the value of rand_num > (return of rand_int) static/ unchanged after first call even if it

Re: [Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

2013-06-21 Thread Chris “Kwpolska” Warrick
On Fri, Jun 21, 2013 at 4:59 AM, SM wrote: >> # Replace stdout if needed >> sys.stdout = self.oldstdout It’s better to do it no matter what. Otherwise, hell might break loose. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail| always bottom-post http://asciirib

Re: [Tutor] Data persistence problem

2013-06-21 Thread Dave Angel
On 06/21/2013 02:21 AM, Arijit Ukil wrote: I have following random number generation function def rand_int (): rand_num = int(math.ceil (random.random()*1000)) return rand_num I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even if it is ca

Re: [Tutor] Data persistence problem

2013-06-21 Thread Peter Otten
Alan Gauld wrote: > rand_num = None > > def rand_int(): > global rand_num > if not rand_num: This will not recognize the (unlikely but possible) case that random.random() returns 0.0. So you better check for None explicitly if rand_num is None: >rand_num = int(math.ceil (

Re: [Tutor] Data persistence problem

2013-06-21 Thread Wolfgang Maier
Alan Gauld btinternet.com> writes: > > On 21/06/13 07:21, Arijit Ukil wrote: > > I have following random number generation function > > > > def*rand_int* (): > > rand_num = int(math.ceil (random.random()*1000)) > > returnrand_num > > > > I like to make the value of rand_num (return of rand_

Re: [Tutor] Best Code testing practice?

2013-06-21 Thread Oscar Benjamin
On 20 June 2013 16:11, Matt D wrote: >> Then make a small app that has just one tab (or has six dummy tabs if >> necessary). When this app runs it should use the same function from >> your main application to lay out the widgets but but it shouldn't bind >> the (same) event handlers. >> > right ma

Re: [Tutor] Playing with XML

2013-06-21 Thread Peter Otten
Danilo Chilene wrote: > Hello, > > Below is my code: > > #!/bin/env python > # -*- coding: utf-8 -*- > import requests > from lxml import etree > > url = 'http://192.168.0.1/webservice.svc?wsdl' > headers = {'Content-Type': 'text/xml;charset=UTF-8', 'SOAPAction': ' > http://tempuri.org/ITServic

Re: [Tutor] Data persistence problem

2013-06-21 Thread Alan Gauld
On 21/06/13 07:21, Arijit Ukil wrote: I have following random number generation function def*rand_int* (): rand_num = int(math.ceil (random.random()*1000)) returnrand_num I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even if it is called multi