Re: Delete lines containing a specific word

2008-01-07 Thread mik3l3374
On Jan 7, 1:21 am, Francesco Pietra <[EMAIL PROTECTED]> wrote: > Please, how to adapt the following script (to delete blank lines) to delete > lines containing a specific word, or words? > > f=open("output.pdb", "r") > for line in f: > line=line.rstrip() > if line: >

Re: idiom for RE matching

2007-07-22 Thread mik3l3374
On Jul 19, 12:52 pm, Gordon Airporte <[EMAIL PROTECTED]> wrote: > I have some code which relies on running each line of a file through a > large number of regexes which may or may not apply. For each pattern I > want to match I've been writing > > gotit = mypattern.findall(line) > if gotit: >

Re: list comparison help?

2007-04-14 Thread mik3l3374
On Apr 14, 5:36 pm, "Dropkick Punt" <[EMAIL PROTECTED]> wrote: > Hi. I have a list of common prefixes: > > >>> prefixes = [ "the", "this", "that", "da", "d", "is", "are", "r", "you", > >>> "u"] > > And I have a string, that I split() into a list. > > >>> sentence = "what the blazes is this" > >>>

Re: split and regexp on textfile

2007-04-13 Thread mik3l3374
On Apr 13, 6:08 pm, "Flyzone" <[EMAIL PROTECTED]> wrote: > On 13 Apr, 11:30, "Flyzone" <[EMAIL PROTECTED]> wrote: > > > all together :( > > Damn was wrong mine regexp: > pat = re.compile("[A-Z][a-z][a-z][ ][A-Z][a-z][a-z][ ][0-9| ][0-9][ ] > [0-9][0-9][:][0-9][0-9]",re.M|re.DOTALL) > > now is worki

Re: Try problem

2007-04-13 Thread mik3l3374
On Apr 13, 5:14 pm, "SamG" <[EMAIL PROTECTED]> wrote: > import sys > try: > s=1 > if s==1: > sys.exit(0) > else: > sys.exit(1) > except SystemExit,s: > if (s==0): > print s > else: > print "Hello" > > How come i always end up getting

Re: split and regexp on textfile

2007-04-13 Thread mik3l3374
On Apr 13, 4:55 pm, "Flyzone" <[EMAIL PROTECTED]> wrote: > On 13 Apr, 10:40, [EMAIL PROTECTED] wrote: > > > you trying to match the date part right? if re is what you desire, > > here's one example: > > Amm..not! I need to get the text-block between the two data, not the > data! :) change to pat.s

Re: split and regexp on textfile

2007-04-13 Thread mik3l3374
On Apr 13, 3:59 pm, "Flyzone" <[EMAIL PROTECTED]> wrote: > Hi, > i have a problem with the split function and regexp. > I have a file that i want to split using the date as token. > Here a sample: > - > Mon Apr 9 22:30:18 2007 > text > text > Mon Apr 9 22:31:10 2007 > text > text > > > I

Re: os.path.isfile() error

2007-04-07 Thread mik3l3374
On Apr 7, 4:56 pm, "7stud" <[EMAIL PROTECTED]> wrote: > Here's the code: > > import os, os.path, pprint > > mydir = "/Users/me/2testing" > > files = [file for file in os.listdir(mydir)] > pprint.pprint(files) > > print os.path.join(mydir, "helloWorld.py") > > files = [file > for file i

Re: elementary tuple question. (sorry)

2007-04-06 Thread mik3l3374
On Apr 6, 5:31 am, "7stud" <[EMAIL PROTECTED]> wrote: > On Apr 5, 3:08 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > > > I have a tuple that I got from struct.unpack. Now I want to pass the data > > from the returned tuple to struct.pack > > > >>> fmt > > > 'l 10l 11i h 4h c 47c 0l'>>>struct.pac

Re: shelve error

2007-04-04 Thread mik3l3374
On Apr 5, 12:14 pm, "7stud" <[EMAIL PROTECTED]> wrote: > test1.py: > > import shelve > > s = shelve.open("/Users/me/2testing/dir1/aaa.txt") > s['x'] = "red" > s.close() > output:-- > > $ python test1.py > Traceback (most recent call last): > File "test1.py", line

Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread mik3l3374
On Apr 4, 2:20 am, "bahoo" <[EMAIL PROTECTED]> wrote: > Hi, > > I have a list like ['0024', 'haha', '0024'] > and as output I want ['haha'] > > If I > myList.remove('0024') > > then only the first instance of '0024' is removed. > > It seems like regular expressions is the rescue, but I couldn't fin

Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread mik3l3374
7stud wrote: > On Apr 3, 3:53 pm, "bahoo" <[EMAIL PROTECTED]> wrote: > > > target = "0024" > > > l = ["0024", "haha", "0024"] > > > > > > > for index, val in enumerate(l): > > > if val==target: > > > del l[index] > > > > > print l > > > > This latter suggestion (with the for loop) seem