[Tutor] Help : File formatting

2012-08-22 Thread rahool shelke
Hi, I am beginner to python and doing coding on UNIX platforms(AIX,Linux,HP,Solaris) I want to take the list of files present in packages. On AIX we get the files list present in packges using command "lslpp -f ". Now i want to format output of above command such that only list of files with abso

Re: [Tutor] pickle problems

2012-08-22 Thread Dave Angel
On 08/22/2012 07:32 PM, Richard D. Moores wrote: > > > My code uses gmpy2.is_prime() (lines 79 and 89). is_prime() is VERY fast. You do know that this gmpy2 function is only statistically correct ? it can false positive. I don't know what the probs are, but it uses Miller-Rabin, with a default

Re: [Tutor] subprocess.Popen help...thanks

2012-08-22 Thread Ray Jones
Thanks to all who responded. I'm deeply into some of the links provided, and my understanding has greatly increased. Ray On 08/22/2012 12:59 AM, Andreas Perstinger wrote: > On 22.08.2012 03:39, Ray Jones wrote: >> Does anyone know of a link to a really good tutorial that would help me >> with s

Re: [Tutor] pickle problems

2012-08-22 Thread Richard D. Moores
On Wed, Aug 22, 2012 at 11:54 AM, Steven D'Aprano wrote: > On 23/08/12 02:17, Richard D. Moores wrote: >> >> I've incorporated many of the suggestions I've received here, plus some >> important tips from Case Van Horsen, the gmpy2 maintainer, and I believe one >> of its developers. >> >> Here's

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
Ok thanks for the advice everyone. Cheers Pete On Thu, Aug 23, 2012 at 10:58 AM, Jerry Hill wrote: > On Wed, Aug 22, 2012 at 5:23 PM, Pete O'Connell > wrote: >> OK maybe I am wrong about it being slow (I thought for loops were >> slower than lis comprehensions). But I do know I need it to be a

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Jerry Hill
On Wed, Aug 22, 2012 at 5:23 PM, Pete O'Connell wrote: > OK maybe I am wrong about it being slow (I thought for loops were > slower than lis comprehensions). But I do know I need it to be as fast > as possible if I need to run it on a thousand files each with hundreds > of thousands of lines You'

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Alan Gauld
On 22/08/12 22:23, Pete O'Connell wrote: What makes you say it is "terribly slow"? Perhaps it is as fast as it could be under the circumstances. (Maybe it takes a long time because you have a lot of data, not because it is slow.) OK maybe I am wrong about it being slow (I thought for loops wer

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld
On 22/08/12 21:51, Cecilia Chavana-Bryant wrote: def main(fname, sheet_name): wb = xlrd.open_workbook(fname) sh = wb.sheet_by_name(sheet_name) data1 = sh.col_values(0) data2 = sh.col_values(1) return data1, data2 fname = "Cal_File_P17.xlsx" sheet_name = "RefPanelData"

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld
On 22/08/12 22:51, Cecilia Chavana-Bryant wrote: Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Yes they can, but we prefer if you just include them in the body if they are fairly short (<100 lines?) or put them on a pasteb

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread ALAN GAULD
Note uits not just that its on multiple lines, its the fact it has three distinct if statements.  All of them must be satisfied to be included in the comprehension. You could do it on 3 lines with one if statement: theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped          

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Mark Lawrence
On 22/08/2012 22:23, Pete O'Connell wrote: On Thu, Aug 23, 2012 at 2:53 AM, Steven D'Aprano wrote: Further to Steven's sound advice take a look at this http://wiki.python.org/moin/PythonSpeed/PerformanceTips IMHO the part on profiling is particulary useful. -- Cheers. Mark Lawrence. ___

[Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Cecilia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/t

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
On Thu, Aug 23, 2012 at 4:16 AM, Alan Gauld wrote: > theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped > if "vn" not in x > if "vt" not in x >

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
On Thu, Aug 23, 2012 at 2:53 AM, Steven D'Aprano wrote: > On 22/08/12 20:28, Pete O'Connell wrote: >> >> Hi. The next step for me to parse the file as I want to is to change >> lines that look like this: >> f 21/21/21 22/22/22 24/24/23 23/23/24 >> into lines that look like this: >> f 21 22 23 24 >

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
Thanks eryksun, that is a very clear example. Cheers pete On Wed, Aug 22, 2012 at 11:16 PM, eryksun wrote: > On Wed, Aug 22, 2012 at 3:06 AM, Peter Otten <__pete...@web.de> wrote: >> >> wanted = [line.strip("\n") for line in lines >> if "vn" not in line and "vt" not in line a

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Ray Jones
I highly recommend the Google Python class that is found on YouTube. The first video is found at http://www.youtube.com/watch?v=tKTZoB2Vjuk The supporting class materials and assignments are found at http://code.google.com/edu/languages/google-python-class/ . This series of videos begins at a pret

Re: [Tutor] pickle problems

2012-08-22 Thread Steven D'Aprano
On 23/08/12 02:17, Richard D. Moores wrote: I've incorporated many of the suggestions I've received here. Here's a function, factor_integer(), for quickly factoring any integer up to 1e17:. That relies on a pre-existing cache of prime numbers. If you don't use tho

[Tutor] better tools

2012-08-22 Thread Don Jennings
[slightly OT] After watching Bret Victor's talk[1], I want **much** better tools for programming (and all of the other stuff I do on the computer). John Resig, creator of jQuery, claims[2] that Victor's presentation inspired the new platform for learning javascript at Khan Academy[3]. I plan t

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Walter Prins
Hi Cecilia, You've had a lot of good replies already, but I'd like to add the following points if I may: 1) You probably should figure out as much as that's possible up front exactly you're trying to do in terms of data processing first (e.g. some idea of the stats, graphs, summaries, operations

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Alan Gauld
On 22/08/12 11:10, Cecilia Chavana-Bryant wrote: "I do not know how to programme!". Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. At t

Re: [Tutor] Thanks!!

2012-08-22 Thread Mark Lawrence
On 22/08/2012 16:48, Cecilia Chavana-Bryant wrote: Hola, Just a big THANK YOU!!! to everyone that has replied to my post. I have been so confused about how to get started and since I am working from home, it has been a very frustrating and lonely experience so far. Many, many thanks for your

Re: [Tutor] pickle problems

2012-08-22 Thread Richard D. Moores
I've incorporated many of the suggestions I've received here. Here's a function, factor_integer(), for quickly factoring any integer up to 1e17: . Larger integers will be factored eventually -- the wait can be long or short. Probably long if they require the services

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Joel Goldstick
On Wed, Aug 22, 2012 at 11:33 AM, Cecilia Chavana-Bryant wrote: > Hola Bill, > > Many thanks for your reply to my post, you seem to understand the > predicament I am in very well. Unfortunately, I am currently working from > home and do not have someone close by to help and this is why I came to t

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Alan Gauld
On 22/08/12 10:51, Pete O'Connell wrote: theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped if "vn" not in x and "vt" not in x and x!= ""] It works but what I don't understand about this line is why the ands are not ors Because 'or' would include x if any one of the condi

[Tutor] Thanks!!

2012-08-22 Thread Cecilia Chavana-Bryant
Hola, Just a big THANK YOU!!! to everyone that has replied to my post. I have been so confused about how to get started and since I am working from home, it has been a very frustrating and lonely experience so far. Many, many thanks for your empathy, encouragement and availability!! Cecilia C

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Hola Bill, Many thanks for your reply to my post, you seem to understand the predicament I am in very well. Unfortunately, I am currently working from home and do not have someone close by to help and this is why I came to this space. This is also why I asked for advise about interactive tutori

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Steven D'Aprano
On 22/08/12 20:28, Pete O'Connell wrote: Hi. The next step for me to parse the file as I want to is to change lines that look like this: f 21/21/21 22/22/22 24/24/23 23/23/24 into lines that look like this: f 21 22 23 24 In English, what is the rule you are applying here? My guess is: "Given t

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Steven D'Aprano
Hello Cecilia, My replies are below, interleaved with your comments, which are prefixed with > marks. On 22/08/12 20:10, Cecilia Chavana-Bryant wrote: By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread leon zaat
If you don't have any prior programmers skills, i would advice first to learn the basics. You will need a good foundation, before it is possible to create complex functions. Starting with complex functions is only frustrating if you don't understand the basics. From: cecilia.chavana-bry...@ou

Re: [Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Mario Cacciatore
Hello, My highest recommendation for you is to start with a simple hello world program. Study that program, each line. Think about how and most importantly, why it works. Then, extend on it. Make it write to a file instead of a terminal. Then make it read from a file and print to the terminal. Th

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Peter Otten
Pete O'Connell wrote: [Please don't to-post. Clip all text of previous posts except the portion relevant to your question] > Hi. The next step for me to parse the file as I want to is to change > lines that look like this: > f 21/21/21 22/22/22 24/24/23 23/23/24 > into lines that look like this:

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread eryksun
On Wed, Aug 22, 2012 at 3:06 AM, Peter Otten <__pete...@web.de> wrote: > > wanted = [line.strip("\n") for line in lines > if "vn" not in line and "vt" not in line and line != "\n"] Here's an equivalent expression with the negation factored out: not ("vn" in line or "vt"

[Tutor] Hello Python Tutor - help please!

2012-08-22 Thread Cecilia Chavana-Bryant
Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amaz

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
Hi. The next step for me to parse the file as I want to is to change lines that look like this: f 21/21/21 22/22/22 24/24/23 23/23/24 into lines that look like this: f 21 22 23 24 Below is my terribly slow loop for doing this. Any suggestions about how to make this code more efficient would be gre

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
Thanks Peter. This looks like what I need: with open(fileName) as lines: wanted = [line.strip("\n") for line in lines if "vn" not in line and "vt" not in line and line != "\n"] Cheers And in response to Allan's suggestion. I can see using a generator in a situation where the if statements we

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Pete O'Connell
What a great mailing list! Thanks for all the responses. I have a few questions, though, first in regards to Puneeth's code. He writes to use: >theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped if "vn" >not in x and "vt" not in x and x!= ""] It works but what I don't understa

Re: [Tutor] subprocess.Popen help

2012-08-22 Thread David Abbott
On Tue, Aug 21, 2012 at 9:39 PM, Ray Jones wrote: > > Does anyone know of a link to a really good tutorial that would help me > with subprocess.Popen? a tutorial that uses really small words and more > examples than explanation? After 15 years of scripting, I'm ashamed to > say that I'm still not

Re: [Tutor] subprocess.Popen help

2012-08-22 Thread Andreas Perstinger
On 22.08.2012 03:39, Ray Jones wrote: Does anyone know of a link to a really good tutorial that would help me with subprocess.Popen? a tutorial that uses really small words and more examples than explanation? After 15 years of scripting, I'm ashamed to say that I'm still not all that familiar wit

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Mark Lawrence
On 22/08/2012 07:29, Johann Spies wrote: #start import re exclude = re.compile('vn|vt|^$|^#') fileName = '/tmp/x' theFileOpened = open(fileName,'r') theTextAsList = theFileOpened.readlines() theTextAsListStripped = [] for aLine in theTe

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Alan Gauld
On 22/08/12 08:06, Peter Otten wrote: You can even have multiple if clauses in one list-comp (but that is rarely used): with open(filename) as lines: wanted = [line.strip("\n") for line if "vn" not in line if "vt" not in x if line !=

Re: [Tutor] list comprehension, testing for multiple conditions

2012-08-22 Thread Peter Otten
Pete O'Connell wrote: > Hi I am trying to parse a text file and create a list of all the lines > that don't include: "vn", "vt" or are empty. I want to make this as > fast as possible because I will be parsing many files each containing > thousands of lines. I though I would give list comprehensio