From Dag.Nummedal at ime.ntnu.no Tue Nov 1 13:34:09 2005 From: Dag.Nummedal at ime.ntnu.no (Dag Nummedal) Date: Tue, 01 Nov 2005 13:34:09 +0100 Subject: [Python.NET] Bugs in PythonDotNet RC2 Message-ID: <436760C1.5000909@ime.ntnu.no> I've recently downloaded the .Net extensions for Python, and I've found some bugs regarding constructors and exceptions. My test code is below, with two classes. The first takes a single integer argument, and generates a division by zero exception if this is zero. The second class will always generate an exception. Both constructors will write a line to stdout when run. MyTest.cs: ---------------------------------------------------------------------- using System; using System.Collections; using System.Management; namespace MyTest { public class Bad { public Bad(int i) { Console.WriteLine("Test"); int i2 = 1; int i1 = i; i2 = i2 / i1; } } public class Bad2 { public Bad2() { Console.WriteLine("Test"); int i2 = 1; int i1 = 0; i2 = i2 / i1; } } } ---------------------------------------------------------------------- test.py: ---------------------------------------------------------------------- import CLR.MyTest import sys, traceback try: print repr(CLR.MyTest.Bad(1)) except: print '-'*60 traceback.print_exc() print '-'*60 try: print repr(CLR.MyTest.Bad(0)) except: print '-'*60 traceback.print_exc() print '-'*60 try: print repr(CLR.MyTest.Bad2()) except: print '-'*60 traceback.print_exc() print '-'*60 try: print repr(CLR.MyTest.Bad2(1)) except: print '-'*60 traceback.print_exc() print '-'*60 ---------------------------------------------------------------------- Output from test.py: ---------------------------------------------------------------------- Test Test ------------------------------------------------------------ Traceback (most recent call last): File "test.py", line 12, in ? print repr(CLR.MyTest.Bad(0)) TypeError: no constructor matches given arguments ------------------------------------------------------------ Test Test ------------------------------------------------------------ Traceback (most recent call last): File "test.py", line 19, in ? print repr(CLR.MyTest.Bad2()) DivideByZeroException: Attempted to divide by zero. at MyTest.Bad2..ctor() ------------------------------------------------------------ Test ------------------------------------------------------------ Traceback (most recent call last): File "test.py", line 26, in ? print repr(CLR.MyTest.Bad2(1)) DivideByZeroException: Attempted to divide by zero. at MyTest.Bad2..ctor() ------------------------------------------------------------ ---------------------------------------------------------------------- The problems are as follows: CLR.MyTest.Bad(0) -> Wrong traceback, wrong exception CLR.MyTest.Bad2() -> Seems to call constructor twice (prints "Test" twice.) CLR.MyTest.Bad2(1) -> Calls constructor instead of raising TypeError for bad number of arguments. -- Dag Nummedal (Dag.Nummedal at ime.ntnu.no) From nonjunk at hotmail.com Tue Nov 29 20:52:44 2005 From: nonjunk at hotmail.com (W G) Date: Tue, 29 Nov 2005 12:52:44 -0700 Subject: [Python.NET] Nested Loops Message-ID: 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]) From thane at magna-capital.com Wed Nov 30 23:51:00 2005 From: thane at magna-capital.com (Thane) Date: Wed, 30 Nov 2005 17:51:00 -0500 Subject: [Python.NET] Nested Loops In-Reply-To: Message-ID: <20051130225108.8229F1E400D@bag.python.org> 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