From michael_sweeney at agilent.com Thu Dec 1 00:55:26 2005 From: michael_sweeney at agilent.com (michael_sweeney@agilent.com) Date: Wed, 30 Nov 2005 16:55:26 -0700 Subject: [Python.NET] Nested Loops Message-ID: <5A3BA3A972B8794F9599917CD047118A03044732@wcosmb07.cos.agilent.com> I like the idea of using a dictionary as a solution to the problem. The reason you are not seeing the nested loop run twice is because of the following: >>> fd = file("C:\\defragreport.txt") >>> fd.readlines() ['11/29/2005\n', '\n', '10:32:32 PM\n', '\n', 'Drive C: Defrag completed successfully\n', '\n'] >>> fd.readlines() [] >>> When you call "readlines()" on the open file, it reads the contents of the complete file. Calling it again returns an empty list. You would have to open/read/close the file in each pass. Thus, the dictionary solution saves you from doing this. Mike > -----Original Message----- > From: pythondotnet-bounces at python.org [mailto:pythondotnet- > bounces at python.org] On Behalf Of Thane > Sent: Wednesday, November 30, 2005 2:51 PM > To: 'W G'; pythondotnet at python.org > Subject: Re: [Python.NET] Nested Loops > > Read in the first file and create a dictionary (hash) of each line. > Read in the second file and for each line see if the dictionary contains > the > item. This solution minimizes your I/O. > > Python 2.4b1 (#57, Oct 15 2004, 15:23:38) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> refsymbol = [1,2,3,4] > >>> refdict = dict() > >>> for sym in refsymbol: > ... refdict[sym] = sym > ... > >>> refdict > {'a': 'a', 'c': 'c', 'b': 'b', 'd': 'd'} > >>> showme = ['d','e','f'] > >>> for s in showme: > ... if refdict.has_key(s): > ... print s > ... > d > >>> > > > -----Original Message----- > > From: pythondotnet-bounces at python.org [mailto:pythondotnet- > > bounces at python.org] On Behalf Of W G > > Sent: Tuesday, November 29, 2005 2:53 PM > > To: pythondotnet at python.org > > Subject: [Python.NET] Nested Loops > > > > Hello, > > > > The follow code willl read lines of two text files. It supposed to take > > the > > first line of the first text file and compare it to all the lines of the > > second text file, then go to the next line of the first text file and do > > the > > same and so on. > > > > The problem is that once the inner loop is finished, it never goes in > that > > loop again. Any suggestions? > > > > Thank you, > > Wes > > > > > > The Code: > > > > > > for refSymbol in symbols.readlines(): > > for lookupSymbol in myfile.readlines(): > > showme = lookupSymbol.split('\t') > > if showme[3] == refSymbol.strip(): > > priceNew.write(refSymbol.strip()+" "+showme[10]) > > > > > > _________________________________________________ > > Python.NET mailing list - PythonDotNet at python.org > > http://mail.python.org/mailman/listinfo/pythondotnet > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet From jvm_cop at spamcop.net Thu Dec 1 17:59:11 2005 From: jvm_cop at spamcop.net (J. Merrill) Date: Thu, 01 Dec 2005 11:59:11 -0500 Subject: [Python.NET] Nested Loops In-Reply-To: <5A3BA3A972B8794F9599917CD047118A03044732@wcosmb07.cos.agil ent.com> Message-ID: <4.3.2.7.2.20051201114956.042016e0@mail.comcast.net> I'm confused. If you do (using W G's variable names) for refSymbol in symbols.readlines(): print refSymbol won't all the lines be printed? Doesn't the "for" loop process once for each item in the array returned by readlines (changing refSymbol each time through the loop), thus accomplishing what was desired? It would seem right to me to store the result of myfile.readlines before doing the outer loop, so it's not read each time through the loop through the lines of the symbols file. Isn't there an idiom to remove the trailing \n chars (and to completely remove the "lines" that are only a newline)? I've been Ruby-ing too much to remember the Python idiom for that. At 06:55 PM 11/30/2005, michael_sweeney at agilent.com wrote >I like the idea of using a dictionary as a solution to the problem. > >The reason you are not seeing the nested loop run twice is because of the following: > >>>> fd = file("C:\\defragreport.txt") >>>> fd.readlines() >['11/29/2005\n', '\n', '10:32:32 PM\n', '\n', 'Drive C: Defrag completed successfully\n', '\n'] >>>> fd.readlines() >[] >>>> > >When you call "readlines()" on the open file, it reads the contents of the complete file. Calling it again returns an empty list. You would have to open/read/close the file in each pass. Thus, the dictionary solution saves you from doing this. > >Mike > > >> > -----Original Message----- >> > From: pythondotnet-bounces at python.org [mailto:pythondotnet- >> > bounces at python.org] On Behalf Of W G >> > Sent: Tuesday, November 29, 2005 2:53 PM >> > To: pythondotnet at python.org >> > Subject: [Python.NET] Nested Loops >> > >> > Hello, >> > >> > The follow code willl read lines of two text files. It supposed to take >> > the >> > first line of the first text file and compare it to all the lines of the >> > second text file, then go to the next line of the first text file and do >> > the >> > same and so on. >> > >> > The problem is that once the inner loop is finished, it never goes in >> that >> > loop again. Any suggestions? >> > >> > Thank you, >> > Wes >> > >> > >> > The Code: >> > >> > >> > for refSymbol in symbols.readlines(): >> > for lookupSymbol in myfile.readlines(): >> > showme = lookupSymbol.split('\t') >> > if showme[3] == refSymbol.strip(): >> > priceNew.write(refSymbol.strip()+" "+showme[10]) J. Merrill / Analytical Software Corp From Raja.Sekhar at vsoint.org Tue Dec 13 07:55:14 2005 From: Raja.Sekhar at vsoint.org (Raja Sekhar) Date: Tue, 13 Dec 2005 06:55:14 -0000 Subject: [Python.NET] Can I call the aspx page from the plone. Message-ID: <50F5F5E6C8D3E445933571E817F31D933003DA@IND01> Hello, I am new to python. I am intersted to develop our intranet using plone. But I've got lot of application developed in C# running on .net. I am very new to python, is it possible to integrate the existing applications (eg to call the existing applications) into the plone site. Many thanks Raja Sekhar. ********************************************************************** VSO is an international development charity that works through volunteers. http://www.vso.org.uk This e-mail and any file/s attached are intended for the addressee only. If you are not the intended recipient please delete this e-mail. The views expressed in this e-mail are the authors own and do not necessarily reflect those of VSO. ********************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20051213/c7d82522/attachment.htm