[Tutor] Is there a better way

2018-11-07 Thread Dave Hill
I have an sqlite database as a source {Asset and Test data from a Megger PAT Tester}, which contains a number of tables, and I end up with an OpenOffice spreadsheet, with numerous sheets The data is proceesed in three parts, each using a separate Class. I extract the useful tables, and store t

Re: [Tutor] Is there a better way to write my code?

2018-08-14 Thread Neil Cerutti
On 2018-08-14, Alan Gauld via Tutor wrote: > - Use a list for objects(*) where you might need to > change the value of one of the objects A list is standard practice when you need an ordered collection of objects of the same type, e.g., a bunch of numbers, a bunch of chickens, etc.. It is most

Re: [Tutor] Is there a better way to write my code?

2018-08-14 Thread Alan Gauld via Tutor
On 14/08/18 07:56, Rafael Knuth wrote: > List comprehension is really cool. One thing I like about list > comprehension is that you can get a dictionary, tuples or lists as a > result by just changing the type of braces. > > # dictionary > colors = ["red", "blue", "white", "yellow"] > colors_len

Re: [Tutor] Is there a better way to write my code?

2018-08-14 Thread Nitin Madhok
Use List comprehension: animals = ["Dog", "Tiger", "SuperLion", "Cow", "Panda"] animals_lol = [[animal, len(animal)] for animal in animals] print(animals_lol) [['Dog', 3], ['Tiger', 5], ['SuperLion', 9], ['Cow', 3], ['Panda', 5]] If you want to read more about list comprehension, https://www.py

Re: [Tutor] Is there a better way to write my code?

2018-08-14 Thread Rafael Knuth
> I wrote this code below > I was wondering if there is a shorter, more elegant way to accomplish this > task. > Thanks! thank you so much everyone! List comprehension is really cool. One thing I like about list comprehension is that you can get a dictionary, tuples or lists as a result by just c

Re: [Tutor] Is there a better way to write my code?

2018-08-13 Thread Neil Cerutti
On 2018-08-13, Rafael Knuth wrote: > I wrote this code below which aims to concatenate strings with their > respective string length. I was wondering if there is a > shorter, more elegant way to accomplish this task. Thanks! > > animals = ["Dog", "Tiger", "SuperLion", "Cow", "Panda"] You can perf

Re: [Tutor] Is there a better way to write my code?

2018-08-13 Thread Mats Wichmann
On 08/13/2018 09:53 AM, Rafael Knuth wrote: > I wrote this code below which aims to concatenate strings with their > respective string length. did you mean concatenate? because you don't do any concatenation... any time you hear keeping a data element with some information associated, you should

Re: [Tutor] Is there a better way to write my code?

2018-08-13 Thread Mark Lawrence
On 13/08/18 16:53, Rafael Knuth wrote: I wrote this code below which aims to concatenate strings with their respective string length. I was wondering if there is a shorter, more elegant way to accomplish this task. Thanks! animals = ["Dog", "Tiger", "SuperLion", "Cow", "Panda"] # step one: conv

[Tutor] Is there a better way to write my code?

2018-08-13 Thread Rafael Knuth
I wrote this code below which aims to concatenate strings with their respective string length. I was wondering if there is a shorter, more elegant way to accomplish this task. Thanks! animals = ["Dog", "Tiger", "SuperLion", "Cow", "Panda"] # step one: convert the animal list into a list of lists

Re: [Tutor] is there a better way to do this?

2016-05-10 Thread Chris Roy-Smith
On 10/05/16 07:03, Ondřej Rusek wrote: Dne 9.5.2016 v 10:13 Chris Roy-Smith napsal(a): Hi Python 3.4 Linux (ubuntu) This code does what I want. curs is the result of a mysql query data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[

Re: [Tutor] is there a better way to do this?

2016-05-10 Thread Chris Roy-Smith
On 10/05/16 12:01, Steven D'Aprano wrote: On Mon, May 09, 2016 at 06:13:32PM +1000, Chris Roy-Smith wrote: data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[row][0]=ddate data[row][1]=mood data[row][2]=walk

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Steven D'Aprano
On Mon, May 09, 2016 at 06:13:32PM +1000, Chris Roy-Smith wrote: > data = [[" " for x in range(9)] for y in range(count)] > for (ddate, mood, walk, lag, sleep) in curs: > data[row][0]=ddate > data[row][1]=mood > data[row][2]=walk > data[row][3]=lag > data[ro

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Joel Goldstick
On Mon, May 9, 2016 at 6:49 PM, Alan Gauld via Tutor wrote: > On 09/05/16 22:03, Ondřej Rusek wrote: > >> but for 'tuples in list'... simple: >> >> data = [] >> for record in curs: >>data += [record] > > Couldn't that be abbreviated to: > > date = list(curs) > I thought I nailed it earlier (an

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Alan Gauld via Tutor
On 09/05/16 22:03, Ondřej Rusek wrote: > but for 'tuples in list'... simple: > > data = [] > for record in curs: >data += [record] Couldn't that be abbreviated to: date = list(curs) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/al

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Ondřej Rusek
Dne 9.5.2016 v 10:13 Chris Roy-Smith napsal(a): Hi Python 3.4 Linux (ubuntu) This code does what I want. curs is the result of a mysql query data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[row][0]=ddate data[row][1]=mood

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Peter Otten
Chris Roy-Smith wrote: > Hi > Python 3.4 Linux (ubuntu) > > This code does what I want. > curs is the result of a mysql query > > > data = [[" " for x in range(9)] for y in range(count)] > for (ddate, mood, walk, lag, sleep) in curs: > data[row][0]=ddate > data[row][1]=mood >

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Joel Goldstick
On Mon, May 9, 2016 at 4:13 AM, Chris Roy-Smith wrote: > Hi > Python 3.4 Linux (ubuntu) > > This code does what I want. > curs is the result of a mysql query > > does this work (untested)? data = [] for stuff in curs: data.append(stuff) > > While I don't know a better way to do this, i

[Tutor] is there a better way to do this?

2016-05-09 Thread Chris Roy-Smith
Hi Python 3.4 Linux (ubuntu) This code does what I want. curs is the result of a mysql query data = [[" " for x in range(9)] for y in range(count)] for (ddate, mood, walk, lag, sleep) in curs: data[row][0]=ddate data[row][1]=mood data[row][2]=walk data[row][3]=la

Re: [Tutor] Is there a better way?

2012-01-11 Thread Marco Casazza
On 2012-01-11 07:57, Joel Goldstick wrote: On Wed, Jan 11, 2012 at 7:34 AM, Marco Casazza wrote: Hello, I've been slowly teaching myself python, using it for small projects when it seems appropriate. In this case, I was handed a list of email addresses for a mailing but some of them had been t

Re: [Tutor] Is there a better way?

2012-01-11 Thread Joel Goldstick
On Wed, Jan 11, 2012 at 7:34 AM, Marco Casazza wrote: > Hello, > > I've been slowly teaching myself python, using it for small projects when it > seems appropriate. In this case, I was handed a list of email addresses for > a mailing but some of them had been truncated. There are only 21 possible

[Tutor] Is there a better way?

2012-01-11 Thread Marco Casazza
Hello, I've been slowly teaching myself python, using it for small projects when it seems appropriate. In this case, I was handed a list of email addresses for a mailing but some of them had been truncated. There are only 21 possible email "suffixes" so I planned to just identify which it sho

Re: [Tutor] is there a better way to organise this code

2011-12-01 Thread bob gailer
On 11/30/2011 8:46 PM, Dave Angel wrote: On 11/30/2011 07:49 PM, Steven D'Aprano wrote: Norman Khine wrote: hello, is there a better way to organise this code or optimise it. http://pastie.org/2944797 I stopped looking at his pastie once the background turned black. I'd have had to copy i

Re: [Tutor] is there a better way to organise this code

2011-12-01 Thread Norman Khine
hi On Thu, Dec 1, 2011 at 12:49 AM, Steven D'Aprano wrote: > Norman Khine wrote: >> >> hello, >> >> is there a better way to organise this code or optimise it. >> http://pastie.org/2944797 > > > Is that a question? Because I get a syntax error in my brain when I parse it > without the question ma

Re: [Tutor] is there a better way to organise this code

2011-12-01 Thread Joel Goldstick
On Wed, Nov 30, 2011 at 8:46 PM, Dave Angel wrote: > On 11/30/2011 07:49 PM, Steven D'Aprano wrote: > >> Norman Khine wrote: >> >>> hello, >>> >>> is there a better way to organise this code or optimise it. >>> http://pastie.org/2944797 >>> >> >> Is that a question? Because I get a syntax error i

Re: [Tutor] is there a better way to organise this code

2011-11-30 Thread Dave Angel
On 11/30/2011 07:49 PM, Steven D'Aprano wrote: Norman Khine wrote: hello, is there a better way to organise this code or optimise it. http://pastie.org/2944797 Is that a question? Because I get a syntax error in my brain when I parse it without the question mark. Sorry to pick on you, but

Re: [Tutor] is there a better way to organise this code

2011-11-30 Thread Steven D'Aprano
Norman Khine wrote: hello, is there a better way to organise this code or optimise it. http://pastie.org/2944797 Is that a question? Because I get a syntax error in my brain when I parse it without the question mark. Sorry to pick on you, but it astonishes me when people don't bother with

Re: [Tutor] is there a better way to organise this code

2011-11-30 Thread Wayne Werner
On Wed, Nov 30, 2011 at 3:34 PM, Norman Khine wrote: > hello, > > is there a better way to organise this code or optimise it. > > http://pastie.org/2944797 > > After glancing at it the only change that I would recommend (possibly) making is lines 58 and 39 - you can wrap the dictionaries (line li

[Tutor] is there a better way to organise this code

2011-11-30 Thread Norman Khine
hello, is there a better way to organise this code or optimise it. http://pastie.org/2944797 thanks norman ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is there a better way to use scientific notation in an equation?

2010-05-02 Thread Eike Welk
On Sunday May 2 2010 22:44:42 David Hutto wrote: > Q1 and Q2 are to be entered as base ten scientific notation. > When I try to input Q1 as raw input, entering in ((2*(10**7)), I get: > > ValueError: invalid literal for int() with base 10: '((2)*(10**7))' > > Which is why I broke it down into it'

Re: [Tutor] Is there a better way to use scientific notation in an equation?

2010-05-02 Thread Steven D'Aprano
On Mon, 3 May 2010 06:44:42 am David Hutto wrote: > In the following code I'm trying to do basic calculations with > coulumb's law > > #Coulombs Law > ''' > F = (9*(10**9)) * (Q1*Q2) / (d**2) > ''' > base = 10 > Q1mult = raw_input('First enter multiplier of base 10 > charge/coloumb(Q1):') Q1exp = r

[Tutor] Is there a better way to use scientific notation in an equation?

2010-05-02 Thread David Hutto
In the following code I'm trying to do basic calculations with coulumb's law #Coulombs Law ''' F = (9*(10**9)) * (Q1*Q2) / (d**2) ''' base = 10 Q1mult = raw_input('First enter multiplier of base 10 charge/coloumb(Q1):') Q1exp = raw_input('Now enter exponent of base 10(Q1):') Q1 = int(Q1mult)*(10**

Re: [Tutor] Is there a better way to get a current mid-rate Yen

2008-07-25 Thread Lie Ryan
> Date: Fri, 25 Jul 2008 05:14:32 -0700 > From: Dick Moores <[EMAIL PROTECTED]> > Subject: [Tutor] Is there a better way to get a current mid-rate Yen > quote with Python? > To: Python Tutor List > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/

Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Dick Moores
At 04:11 PM 7/25/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote Certainly Beautiful Soup will not be muh longer and a lot more elegant and probably more resilient. Alan, expand a bit, please. Longer? Resilient? Longer as in lines of code. BS is good for extracting several di

Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote Certainly Beautiful Soup will not be muh longer and a lot more elegant and probably more resilient. Alan, expand a bit, please. Longer? Resilient? Longer as in lines of code. BS is good for extracting several different parts from the soup, but just to

Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Dick Moores
At 09:47 AM 7/25/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote Here's one opinion, an answer to my second question. Dick And to answer your first: It depends on how you define better. Certainly Beautiful Soup will not be muh longer and a lot more elegant and probably more r

Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote Here's one opinion, an answer to my second question. Dick And to answer your first: It depends on how you define better. Certainly Beautiful Soup will not be muh longer and a lot more elegant and probably more resilient. But to extract a single piec

Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Dick Moores
Here's one opinion, an answer to my second question. Dick Date: Fri, 25 Jul 2008 08:54:53 -0500 From: "W W" <[EMAIL PROTECTED]> To: "Dick Moores" <[EMAIL PROTECTED]> Subject: Re: [Tutor] Is there a better way to get a current mid-rate Yen quote with Pyt

[Tutor] Is there a better way to get a current mid-rate Yen quote with Python?

2008-07-25 Thread Dick Moores
Better than this? I've heard about BeautifulSoup. . Is it worth learning? Is it crummy? ;-) So 2 questions. Thanks, Dick Moores ___ Tutor maillist - Tutor

[Tutor] Is there a better way to write this function?

2006-06-09 Thread Paul D. Kraus
This is a second... the first one never hit the list. *shrug* should i be using a different interface to post? is this a gateway to newsgroup?I am writing my first python program(at least in a really long time). Its purpose is to take csv or pipe delimintaed files and convert them to html pages. Wa

Re: [Tutor] Is there a "better" way to do this?

2004-12-22 Thread Kent Johnson
John, In this case I think using a class is overkill. You can write a simple procedural version like this: def getOption(): while True: print """ Please choose from the following options. 1) - Normal Unit test with static data. 2) - Normal Unit test with missing

Re: [Tutor] Is there a "better" way to do this?

2004-12-22 Thread Alan Gauld
> procedural programming to object oriented. Is this a good approach for > such a check? It seems to me this is more work then needed. Its a valid approach but whether its the best approach depends on what else you intend to do. For example will there be multiple types of greeting? or several i

[Tutor] Is there a "better" way to do this?

2004-12-22 Thread Ertl, John
I am trying to do the usual thing of asking for an input and then checking it to see if it is valid. If the entry is not valid then ask again until you get the correct answer. I have come up with this class. I am trying to make a transition from procedural programming to object oriented. Is th