Re: [Tutor] Getting os.walk output into a list

2013-03-14 Thread Dave Angel
On 03/15/2013 01:53 AM, Paradox wrote: There is something I can't figure out about the following code (using python 2.7.3): def return_tree_files(rootpath, pattern): for root, dirs, files in os.walk(rootpath): i = [os.path.join(root, filename) for filename in fnmatch.filter(files,

[Tutor] Getting os.walk output into a list

2013-03-14 Thread Paradox
There is something I can't figure out about the following code (using python 2.7.3): def return_tree_files(rootpath, pattern): for root, dirs, files in os.walk(rootpath): i = [os.path.join(root, filename) for filename in fnmatch.filter(files, pattern)] return i I thought th

Re: [Tutor] Designing a program (File-Fetcher)

2013-03-14 Thread Christopher Emery
Hello Alan, Thank you for your feedback. I will break it down in the order that I had stated in my quick steps, work on each pice getting one part work at a time build like lays (smile) Thank You, will post as I do to get advise on improvements or corrections. Sincerely in Christ, Christopher

Re: [Tutor] break

2013-03-14 Thread Dave Angel
On 03/14/2013 07:23 PM, Matthew Ngaha wrote: if Enemy.ships: for missile in self.missiles: flag = False for rect in Enemy.rects: assert(!flag) if QPoint(miss

Re: [Tutor] Designing a program (File-Fetcher)

2013-03-14 Thread Alan Gauld
On 14/03/13 21:25, Christopher Emery wrote: Okay, I know the best way to learn how to do something is to jump in so I have decided I would like to make a program (command line) to get files from a website that will be then used later on by another program. OK, thats a good place to start. Next

Re: [Tutor] break

2013-03-14 Thread Mitya Sirenef
On 03/14/2013 08:45 PM, Matthew Ngaha wrote: thanks guys ive finally got it working. even though i didnt use the flag due to invalid syntax i realized since i was getting no errors i wasnt actually doing anything wrong. My mistake was i removed the ememy ship but for some reason forgot to remove

Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
thanks guys ive finally got it working. even though i didnt use the flag due to invalid syntax i realized since i was getting no errors i wasnt actually doing anything wrong. My mistake was i removed the ememy ship but for some reason forgot to remove the missile so it was still active on the next

Re: [Tutor] break

2013-03-14 Thread Mitya Sirenef
On 03/14/2013 08:08 PM, Matthew Ngaha wrote: One good approach is to have a separate function or method with >> both loops: >> >> def attack(self, Enemy): >> >> for missile in self.missiles: >> for rect in Enemy.rects: >> if QPoint(missile.x + 5, missile.y) in rect: >> explosion = Explosion(rec

Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
> One good approach is to have a separate function or method with > both loops: > > def attack(self, Enemy): > > for missile in self.missiles: > for rect in Enemy.rects: > if QPoint(missile.x + 5, missile.y) in rect: > explosion = Explosion(rect.x(), rect.y()

Re: [Tutor] break

2013-03-14 Thread Matthew Ngaha
>> if Enemy.ships: >> for missile in self.missiles: > >flag = False >> >> for rect in Enemy.rects: > >assert(!flag) > >> if QPoint(missile.x + 5, missile.y) in rect: >>

Re: [Tutor] break

2013-03-14 Thread Dave Angel
On 03/14/2013 06:38 PM, Matthew Ngaha wrote: i cant seem to break out of this loop. let me explain the variables you see: if Enemy.ships: for missile in self.missiles: flag = False for rect in Enemy.rects:

Re: [Tutor] break

2013-03-14 Thread Mitya Sirenef
On 03/14/2013 06:38 PM, Matthew Ngaha wrote: i cant seem to break out of this loop. let me explain the variables you see: > > Enemy.ships = [] #an Enemy class variable that contains enemy ships > self.missiles = [] an instance variable that appends how many Visible > missiles my ship has fired

Re: [Tutor] Passing a config file to Python

2013-03-14 Thread Dave Angel
On 03/14/2013 02:22 PM, Irina I wrote: Hi all, I'm new to Python and am trying to pass a config file to my Python script. The config file is so simple and has only two URLs. The code should takes that configuration file as input and generates a single file in HTML format as output. The progr

[Tutor] break

2013-03-14 Thread Matthew Ngaha
i cant seem to break out of this loop. let me explain the variables you see: Enemy.ships = [] #an Enemy class variable that contains enemy ships self.missiles = [] an instance variable that appends how many Visible missiles my ship has fired Enemy.rects = [] an Enemy class variable that represents

[Tutor] Designing a program (File-Fetcher)

2013-03-14 Thread Christopher Emery
Hello All, Okay, I know the best way to learn how to do something is to jump in so I have decided I would like to make a program (command line) to get files from a website that will be then used later on by another program. Program idea - quick steps to do *** file-fetcher (within zip file) get

Re: [Tutor] Passing a config file to Python

2013-03-14 Thread Prasad, Ramit
Irina I > Hi all, > > I'm new to Python and am trying to pass a config file to my Python script. > The config file is so > simple and has only two URLs. > > The code should takes that configuration file as input and generates a single > file in HTML format as > output. > > The program must ret

[Tutor] Passing a config file to Python

2013-03-14 Thread Irina I
Hi all, I'm new to Python and am trying to pass a config file to my Python script. The config file is so simple and has only two URLs. The code should takes that configuration file as input and generates a single file in HTML format as output. The program must retrieve each web page in the lis

Re: [Tutor] Text Processing Query

2013-03-14 Thread Prasad, Ramit
Spyros Charonis wrote: > Hello Pythoners, > > I am trying to extract certain fields from a file that whose text looks like > this: > > COMPND   2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; > COMPND   3 CHAIN: A, B; > > COMPND  10 MOL_ID: 2; > COMPND  11 MOLECULE: ANTIBODY FAB FRAGMENT LI

Re: [Tutor] Text Processing Query

2013-03-14 Thread Spyros Charonis
Yes, the elif line need to have **flag_FAB ==1** as is conidition instead of **flag_FAB=1**. So: for line in scanfile: if line[0:6]=='COMPND' and 'FAB' in line: flag_FAB = 1 elif line[0:6]=='COMPND' and 'CHAIN' in line and flag_FAB == 1: print line flag_FAB = 0 On Th

Re: [Tutor] Text Processing Query

2013-03-14 Thread Mark Lawrence
On 14/03/2013 11:28, taserian wrote: Top posting fixed On Thu, Mar 14, 2013 at 6:56 AM, Spyros Charonis mailto:s.charo...@gmail.com>> wrote: Hello Pythoners, I am trying to extract certain fields from a file that whose text looks like this: COMPND 2 MOLECULE: POTASSIUM CHA

Re: [Tutor] Text Processing Query

2013-03-14 Thread Mitya Sirenef
On 03/14/2013 07:28 AM, taserian wrote: Since the identifier and the item that you want to keep are on different lines, you'll need to set a "flag". > > with open(filename) as file: > > scanfile=file.readlines() > > flag = 0 > > for line in scanfile: > > if line[0:6]=='COMPND' and 'FAB FRAGMENT

Re: [Tutor] increment a counter inside generator

2013-03-14 Thread David Knupp
On Thu, 14 Mar 2013, Steven D'Aprano wrote: If you have some unknown, arbitrary iterable that doesn't support len(), then you can use the sum() trick: it = some_unknown_iterable() sum(1 for x in it) Yes, of course you are correct. This was my intention, but I chose an especially poorly contri

Re: [Tutor] Text Processing - Questions/Help.

2013-03-14 Thread Alan Gauld
On 14/03/13 10:30, David Bradshaw wrote: I have written some code that logs into a list of hosts and runs a couple of commands to find out some information. Which I then save to a file and process. A cut down version of the information I generate and save can be found here - http://pastebin.com/

Re: [Tutor] Text Processing Query

2013-03-14 Thread Bod Soutar
On 14 March 2013 10:56, Spyros Charonis wrote: > Hello Pythoners, > > I am trying to extract certain fields from a file that whose text looks like > this: > > COMPND 2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; > COMPND 3 CHAIN: A, B; > COMPND 10 MOL_ID: 2; > COMPND 11 MOLECULE: ANTIB

Re: [Tutor] Text Processing Query

2013-03-14 Thread taserian
Since the identifier and the item that you want to keep are on different lines, you'll need to set a "flag". with open(filename) as file: scanfile=file.readlines() flag = 0 for line in scanfile: if line[0:6]=='COMPND' and 'FAB FRAGMENT' in line: flag = 1 elif line[

[Tutor] Text Processing Query

2013-03-14 Thread Spyros Charonis
Hello Pythoners, I am trying to extract certain fields from a file that whose text looks like this: COMPND 2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; COMPND 3 CHAIN: A, B; COMPND 10 MOL_ID: 2; COMPND 11 MOLECULE: ANTIBODY FAB FRAGMENT LIGHT CHAIN; COMPND 12 CHAIN: D, F; COMPN

[Tutor] Text Processing - Questions/Help.

2013-03-14 Thread David Bradshaw
I have written some code that logs into a list of hosts and runs a couple of commands to find out some information. Which I then save to a file and process. A cut down version of the information I generate and save can be found here - http://pastebin.com/4ePz3Z7m The code I have written to proc

Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-14 Thread Alan Gauld
On 14/03/13 01:39, DoanVietTrungAtGmail wrote: You don't. You create a second table to hold the list. Then in the second table you include be reference back to the first. assuming I do it that way, how to deal with variable-length list? Most lists have 10^3, but some can grow to perhaps

Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-14 Thread Peter Otten
DoanVietTrungAtGmail wrote: >> You don't. You create a second table to hold the list. >> Then in the second table you include be reference back to the first. >> > > I thought about that but thought it seemed a roundabout way. But assuming > I do it that way, how to deal with variable-length list?