Re: [Tutor] trouble with function-- trying to check
a, b, c, or d is a type('str') not boolean which is what (c in "crab") is. The [in] operator takes presedence, the first 3 times (c in "crab") returns true and the last returns false; but the strings a, b, c, or d do not == true or false - therefore the test (c == (c in "crab")) always returns false. (I think) cheers -Isaac reference: http://docs.python.org/ref/summary.html Terry wrote: for c in "abcd": ...print (c == c in "crab"), (c == (c in "crab")) ... True False True False True False False False ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with function-- trying to check
a, b, c are all in crab but d is not. >>> for c in 'abcd': ...print (c == c in 'crab') ... True True True False Message: 5 Date: Tue, 13 Mar 2007 13:01:48 -0700 (PDT) From: Terry Carroll <[EMAIL PROTECTED]> Subject: Re: [Tutor] trouble with function-- trying to check differences btwn 2 strings To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 6 Mar 2007, Alan Gauld wrote: > But I've been up since 4:30am and am too tired to try > figuring it out just now, so maybe someone else will > explain! :-) > > >>> for c in 'abcd': > ...print (c == c in 'crab') > ... > True > True > True > False Trying to understand that, I tried this, which left me even more confused: >>> for c in "abcd": ...print (c == c in "crab"), (c == (c in "crab")) ... True False True False True False False False ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] declaring decaration on ul list
It just occurred to me that when my wiki does a backsearch it is useful to list the results with a * for decorating the unordered list results, so I can mousecopy it to update the category(foo) page, /the normal bullet is mousecopied as a poundsign (#}. How does one specify what to render as a item decoration in an unordered list? -- Salute! -Kirk Bailey Think +-+ | BOX | +-+ knihT Fnord. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HTTP file download
How do you handle a binary file? Message: 4 Date: Tue, 13 Mar 2007 13:23:44 +0100 From: "Jean-Philippe Durand" <[EMAIL PROTECTED]> Subject: Re: [Tutor] HTTP file download To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" Hello Ronaldo, Try this : import urllib mysock = urllib.urlopen("http://www.somesite.com/file";) htmlSource = mysock.read() mysock.close() print htmlSource Regards. Jean-Philippe DURAND ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Lexicographic ordering (or something simpler)
Matt Williams wrote: > Dear All, > > I'm trying to write something to calculate rule priorities, based on > their provenance (ultimately I'm after a lexicographic ordering) I don't understand your problem description at all but maybe this will help. If you sort a list of lists or a list of tuples it will be a lexicographical sort. And the sort() method takes an optional key= parameter which is a function that creates a sort key. So if you can create a key off your terms then you can sort off that. > > I have a set of terms (the provenances) I'm try to sort. I've done it by > associating each possible set of terms with a dictionary, and then using > the elements of the set as keys of the dictionary, so that it can look > up the values. This is (almost certainly) sub-optimal, but ok for now If you have some working code it would probably be helpful to see it. Then we can help you improve it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Roman to digital (pseudocode)
Bob Gailer wrote: > Deep breath and big step back. > > The problem is not just how to code this in Python, but how to parse a > language (in this case Roman Numbers). > > I have studied formal language theory but am not an expert. So here's my > take on an algorithm that would save a lot of stress. > > Create a dictionary with > keys for each roman letter and each "pair" (iv, ix, xl, xc, etc) > values are the corresponding decimal values. > Starting at the left of the roman_input and repeating until the end of > the roman_input > Take the next pair of roman_input. > If it is in the dictionary > add the decimal value and step to the next letter. > Else > take the leftmost letter of that pair > If it is in the dictionary > add the decimal value and step to the next letter. >Else > complain about bad letter Or make a list of all the pairs and values, followed by all the single letters and values, and just find the first match from the list against the start of the test string. Neither of these is really a parser, though; they allow badly formed numbers like IICCXM. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Roman to digital (pseudocode)
Alan Gilfoy wrote: > This, I heard, is more difficult than digital-to-Roman, since you have > to "read" the subtractive cases, with a smaller numeral placed before > a larger numeral, without simply adding all the numerals' values up > > I'm going to use a raw_input prompt to ask the user which Roman > numeral he/she wants to convert. How do I "screen" for inputs that > have characters besides "I", "V", "X", "L", "C", "D", or "M"? You could have a string containing all the allowed characters and make sure each input character is in the allowed list. > > Second Python question: > > I know there's a way to "find out" the name of the first item in a list > (ListName[0]), but is there a way to find out the first character of a string? Lists and strings are both sequences and many of the same operations work on both. (All of the immutable sequence operations work on both.) So MyString[0] is the first character in a string. > > Also, is there a way to "ask" Python what characters are before and > after the character in the string that you're asking about? > > For example, usign the sample string "MCMXVII" (1917): > > How would you ask Python: > "What's the 3rd character in this string?" (returns "M") s[2] > "What's before that character?" (returns "C") s[1] or maybe s[2-1] if the 2 is actually in a variable. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Lexicographic ordering (or something simpler)
Dear All, I'm trying to write something to calculate rule priorities, based on their provenance (ultimately I'm after a lexicographic ordering) I have a set of terms (the provenances) I'm try to sort. I've done it by associating each possible set of terms with a dictionary, and then using the elements of the set as keys of the dictionary, so that it can look up the values. This is (almost certainly) sub-optimal, but ok for now Where I get stuck is that each rule is compared pairwise to each other; the precedence of the set of rules is then based on that. Since there can be ties between the rules, the result of each pairwise comparison for two rules a & ) is either 1,0 or -1, where 1 == a beats b, -1 == b beats a and 0 == tie. At the moment I get back a list of results from testing one set of rules against the other. I now need to make a decision based on all the results. I've tried coding it as if...elif statements, but that all gets horrible. Given a list of the form [1,0,0,1,-1] I need to make decision (in this, it is undecided, so we drop down to the next criteria). Any ideas/ pointers as to how I implement this? Thanks, Matt -- http://acl.icnet.uk/~mw http://adhominem.blogsome.com/ +44 (0)7834 899570 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Roman to digital (pseudocode)
I am new to python and programming, so not sure if I should weigh in here. Nonetheless . . . Creating a dictionary seems fair, but I wonder about using pairs rather than single letters. Roman numerals are constructed from strict rules other than the allowable letter set -- here is the relevant wikipedia bit: Rules regarding Roman numerals often state that a symbol representing 10x may not precede any symbol larger than 10x+1. For example, C cannot be preceded by I or V, only by X (or, of course, by a symbol representing a value equal to or larger than C). Thus, one should represent the number "ninety-nine" as XCIX, not as the "shortcut" IC. However, these rules are not universally followed. Although the shortcut may be easier for people, the universal notation may be easier to define programmatically. I am wondering what would be the best way to create the rules - A dictionary will help you look up values, but not rules. It does not retain its order and order is essential. Instead, create a tuple of the roman numerals in ascending order (roman). Create a paired tuple with the base 10 value (baseten). Now get an element from the string you want to test -- use the index value in roman to test the rules -- you will know what is higher, lower, and the same Then look for things like the following: - does the following element have a lower index in roman? if yes, you know the value (match indexes from the tuples) -- step forward - what if the follower is the same? then check the one after, if it is the same (and the following digit is lower) then you have a value. -- step over the last matching digit - if the following value is higher, it must be by only one unit, if so you have a value, but also a new rule: the following digit must be lower than the last digit of the pair. and so on. not pseudocode I know, and I am certain there are better ways to do this, but maybe something here helps. -c On 3/13/07, Bob Gailer <[EMAIL PROTECTED]> wrote: > Deep breath and big step back. > > The problem is not just how to code this in Python, but how to parse a > language (in this case Roman Numbers). > > I have studied formal language theory but am not an expert. So here's my > take on an algorithm that would save a lot of stress. > > Create a dictionary with > keys for each roman letter and each "pair" (iv, ix, xl, xc, etc) > values are the corresponding decimal values. > Starting at the left of the roman_input and repeating until the end of > the roman_input > Take the next pair of roman_input. > If it is in the dictionary > add the decimal value and step to the next letter. > Else > take the leftmost letter of that pair > If it is in the dictionary > add the decimal value and step to the next letter. >Else > complain about bad letter > > -- > Bob Gailer > 510-978-4454 > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- - - - - - - - Clay S. Wiedemann voice: 718.362.0375 aim: khlav wii: 3905 4571 6175 2469 twitter: seastokes ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Roman to digital (pseudocode)
Deep breath and big step back. The problem is not just how to code this in Python, but how to parse a language (in this case Roman Numbers). I have studied formal language theory but am not an expert. So here's my take on an algorithm that would save a lot of stress. Create a dictionary with keys for each roman letter and each "pair" (iv, ix, xl, xc, etc) values are the corresponding decimal values. Starting at the left of the roman_input and repeating until the end of the roman_input Take the next pair of roman_input. If it is in the dictionary add the decimal value and step to the next letter. Else take the leftmost letter of that pair If it is in the dictionary add the decimal value and step to the next letter. Else complain about bad letter -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with function-- trying to check differences btwn 2 strings
On Tue, 6 Mar 2007, Alan Gauld wrote: > But I've been up since 4:30am and am too tired to try > figuring it out just now, so maybe someone else will > explain! :-) > > >>> for c in 'abcd': > ...print (c == c in 'crab') > ... > True > True > True > False Trying to understand that, I tried this, which left me even more confused: >>> for c in "abcd": ...print (c == c in "crab"), (c == (c in "crab")) ... True False True False True False False False ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Quicktime & Python
Miguel Oliveira, Jr. wrote: > Hello, > > Just wondering: is there a way to play quicktime .mov files from > python? I am trying to run an experiment and would like to have > Python to play the .mov files I have in a given sequence (or in > random), in full screen and to record a log of the files that were > played, the order and the time. Any help will be very much appreciated. > I would use mplayer. You can control mplayer through a simple text interface called slave mode and log what you send to it. I've got some code you could use, using the subprocess module if you want it. Hugo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Numpy
Hello, I've just intalled [manually] numpy into a Mac Intel OS 10.4. I'm running Python version 2.5. Whenever I import numpy, I get the following message: Running from numpy source directory Does anyone know if this is normal? In Python 2.4, no such message pops up when numpy is imported. But then there is a nice setup file for Python 2.4 that automaticall install numpy in the correct directories. Thanks for any thoughts on this. Miguel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Quicktime & Python
Hello, Just wondering: is there a way to play quicktime .mov files from python? I am trying to run an experiment and would like to have Python to play the .mov files I have in a given sequence (or in random), in full screen and to record a log of the files that were played, the order and the time. Any help will be very much appreciated. Thanks, Miguel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the minimum value in a multidimensional array
On 3/13/07, Geoframer <[EMAIL PROTECTED]> wrote: > I don't see a solution here... It is not conclusive on what's the minimum > for an array. > > ln [1]: import numpy > In [2]: a = > numpy.array([[1,2,3,0],[2,3,4,5],[6,5,4,3],[-1,2,-4,5]]) Well, what exactly is it that you'd like the answer to be? The samples page Eike pointed you to show a couple of ways to do it, depending on exactly what piece of data you're looking for. Here's a bit more along the same lines. If this doesn't help, perhaps you could show us a bit of sample data and tell us exactly what answer you'd like to extract. >>> a = numpy.array([[1,2,3,0],[2,3,4,5],[6,5,4,3],[-1,2,-4,5]]) >>> a.argmin() 14 >>> a.ravel()[14] -4 >>> divmod(14, 4) (3, 2) >>> a[3][2] -4 -- Jerry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the minimum value in a multidimensional array
I don't see a solution here... It is not conclusive on what's the minimum for an array. ln [1]: import numpy In [2]: a = numpy.array([[1,2,3,0],[2,3,4,5],[6,5,4,3],[-1,2,-4,5]]) In [3]: a Out[3]: array([[ 1, 2, 3, 0], [ 2, 3, 4, 5], [ 6, 5, 4, 3], [-1, 2, -4, 5]]) In [4]: a.argmin(0) Out[4]: array([3, 0, 3, 0]) In [5]: a.argmin(1) Out[5]: array([3, 0, 3, 2]) a.argmin(0) shows where the minimum is for each row a.argmin(1) shows whree the minimum is for each column Which combined gives (row, column) : (0,3), (1,0), (2,3) and (3,2). So basically 4 values which i still need to compare. In a small array this might not be a hefty computational effort. In a n*n array this will lead to N values which need both indexing and comparing. Perhaps this is the only solution around but i hope not. In either way thanks for your time and suggestion. Regards Geofram On 3/13/07, Eike Welk <[EMAIL PROTECTED]> wrote: On Tuesday 13 March 2007 11:57, Geoframer wrote: > Hey everyone, > > I've been trying to locate a way to find the location of the > minimum value in an n*n array. The 'argmin' function is probably what you are looking for. See the examples at: http://www.scipy.org/Numpy_Example_List Regards Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the minimum value in a multidimensional array
On Tuesday 13 March 2007 11:57, Geoframer wrote: > Hey everyone, > > I've been trying to locate a way to find the location of the > minimum value in an n*n array. The 'argmin' function is probably what you are looking for. See the examples at: http://www.scipy.org/Numpy_Example_List Regards Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] number generator
So sorry. I meant this for the python list. Dick Moores At 05:49 AM 3/13/2007, Dick Moores wrote: >At 02:52 AM 3/13/2007, Duncan Booth wrote: > >Dick Moores <[EMAIL PROTECTED]> wrote: > > > > > But let's say there is one more constraint--that for each n of the N > > > positive integers, there must be an equal chance for n to be any of > > > the integers between 1 and M-N+1, inclusive. Thus for M == 50 and N > > >== 5, the generated list of 5 should be as likely to be [1,46,1,1,1] > > > as [10,10,10,10,10] or [14, 2, 7, 1, 26]. > > > >I don't think what you wrote actually works. Any combination including a 46 > >must also have four 1s, so the digit 1 has to be at least 4 times as likely > >to appear as the digit 46, and probably a lot more likely than that. > >Yes, I see you're right. Thanks. > > >On the other hand, making sure that each combination occurs equally often > >(as your example might imply) is doable but still leaves the question > >whether the order of the numbers matters: are [1,46,1,1,1] and [1,1,46,1,1] > >the same or different combinations? > >If the added constraint is instead that the probability of generating >a given list of length N be the same as that of generating any other >list of length N, then I believe my function does the job. Of course, >[1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinct. I ran >this test for M == 8 and N == 4: >== >def sumRndInt(M, N): > import random > while True: > lst = [] > for x in range(N): > n = random.randint(1,M-N+1) > lst.append(n) > if sum(lst) == M: > return lst > >A = [] >B = [] >for x in range(10): > lst = sumRndInt(8,4) > if lst not in A: > A.append(lst) > B.append(1) > else: > i = A.index(lst) > B[i] += 1 > >A.sort() >print A >print B >print len(A), len(B) >=== >a typical run produced: >[[1, 1, 1, 5], [1, 1, 2, 4], [1, 1, 3, 3], [1, 1, 4, 2], [1, 1, 5, >1], [1, 2, 1, 4], [1, 2, 2, 3], [1, 2, 3, 2], [1, 2, 4, 1], [1, 3, 1, >3], [1, 3, 2, 2], [1, 3, 3, 1], [1, 4, 1, 2], [1, 4, 2, 1], [1, 5, 1, >1], [2, 1, 1, 4], [2, 1, 2, 3], [2, 1, 3, 2], [2, 1, 4, 1], [2, 2, 1, >3], [2, 2, 2, 2], [2, 2, 3, 1], [2, 3, 1, 2], [2, 3, 2, 1], [2, 4, 1, >1], [3, 1, 1, 3], [3, 1, 2, 2], [3, 1, 3, 1], [3, 2, 1, 2], [3, 2, 2, >1], [3, 3, 1, 1], [4, 1, 1, 2], [4, 1, 2, 1], [4, 2, 1, 1], [5, 1, 1, 1]] > >[2929, 2847, 2806, 2873, 2887, 2856, 2854, 2825, 2847, 2926, 2927, >2816, 2816, 2861, 2919, 2820, 2890, 2848, 2898, 2883, 2820, 2820, >2829, 2883, 2873, 2874, 2891, 2884, 2837, 2853, 2759, 2761, 2766, 2947, 2875] > >35 35 > >Dick Moores > > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] number generator
At 02:52 AM 3/13/2007, Duncan Booth wrote: >Dick Moores <[EMAIL PROTECTED]> wrote: > > > But let's say there is one more constraint--that for each n of the N > > positive integers, there must be an equal chance for n to be any of > > the integers between 1 and M-N+1, inclusive. Thus for M == 50 and N > >== 5, the generated list of 5 should be as likely to be [1,46,1,1,1] > > as [10,10,10,10,10] or [14, 2, 7, 1, 26]. > >I don't think what you wrote actually works. Any combination including a 46 >must also have four 1s, so the digit 1 has to be at least 4 times as likely >to appear as the digit 46, and probably a lot more likely than that. Yes, I see you're right. Thanks. >On the other hand, making sure that each combination occurs equally often >(as your example might imply) is doable but still leaves the question >whether the order of the numbers matters: are [1,46,1,1,1] and [1,1,46,1,1] >the same or different combinations? If the added constraint is instead that the probability of generating a given list of length N be the same as that of generating any other list of length N, then I believe my function does the job. Of course, [1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinct. I ran this test for M == 8 and N == 4: == def sumRndInt(M, N): import random while True: lst = [] for x in range(N): n = random.randint(1,M-N+1) lst.append(n) if sum(lst) == M: return lst A = [] B = [] for x in range(10): lst = sumRndInt(8,4) if lst not in A: A.append(lst) B.append(1) else: i = A.index(lst) B[i] += 1 A.sort() print A print B print len(A), len(B) === a typical run produced: [[1, 1, 1, 5], [1, 1, 2, 4], [1, 1, 3, 3], [1, 1, 4, 2], [1, 1, 5, 1], [1, 2, 1, 4], [1, 2, 2, 3], [1, 2, 3, 2], [1, 2, 4, 1], [1, 3, 1, 3], [1, 3, 2, 2], [1, 3, 3, 1], [1, 4, 1, 2], [1, 4, 2, 1], [1, 5, 1, 1], [2, 1, 1, 4], [2, 1, 2, 3], [2, 1, 3, 2], [2, 1, 4, 1], [2, 2, 1, 3], [2, 2, 2, 2], [2, 2, 3, 1], [2, 3, 1, 2], [2, 3, 2, 1], [2, 4, 1, 1], [3, 1, 1, 3], [3, 1, 2, 2], [3, 1, 3, 1], [3, 2, 1, 2], [3, 2, 2, 1], [3, 3, 1, 1], [4, 1, 1, 2], [4, 1, 2, 1], [4, 2, 1, 1], [5, 1, 1, 1]] [2929, 2847, 2806, 2873, 2887, 2856, 2854, 2825, 2847, 2926, 2927, 2816, 2816, 2861, 2919, 2820, 2890, 2848, 2898, 2883, 2820, 2820, 2829, 2883, 2873, 2874, 2891, 2884, 2837, 2853, 2759, 2761, 2766, 2947, 2875] 35 35 Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HTTP file download
Hello Ronaldo, Try this : import urllib mysock = urllib.urlopen("http://www.somesite.com/file";) htmlSource = mysock.read() mysock.close() print htmlSource Regards. Jean-Philippe DURAND 2007/3/13, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: Hello all, How can I download a file using HTTP? For example: There is a file at: http://www.somesite.com/file. I need to get this file using HTTP from a python script. I'm not sure but I think httplib could be used to do that. Can anyone confirm that? or Can anyone suggest me something else? Thank you? -- Ronaldo Z. Afonso Phone: 55+11+82619082 www.netf2r.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Squlite3 problem
I found a similar discussion on the pysqlite mailing list ( http://lists.initd.org/pipermail/pysqlite/2005-August/000127.html) Try committing your changes and then closing your cursor. db.commit() cur.close() db.close() On 3/13/07, Jim Roush <[EMAIL PROTECTED]> wrote: I'm geting the following error message and I'm stumped Traceback (most recent call last): File "C:\markets\source\QuantScan\QuantScan4_3.py", line 1362, in db.close() sqlite3.OperationalError: Unable to close due to unfinalised statements Here 's the relevant code db = sqlite.connect('c:/markets/db/market_2.db') cur_stocks = db.cursor() cur_quant = db.cursor() cur_subind = db.cursor() # update ROC table in db print '\nupdate ROC table in db...\n' cur = db.cursor() cur.execute("delete from subind_ROC") for row in range(0, num_of_subinds): (subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, si_ROC_20, si_ROC_20_1, \ si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2) = si_ROC[row] cur.execute("INSERT INTO subind_ROC (subind, ROC_10, ROC_10_1, ROC_10_2, ROC_20, ROC_20_1, ROC_20_2, ROC_30, ROC_30_1, ROC_30_2) Values (?,?,?,?,?,?,?,?,?,?)", (subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, si_ROC_20, si_ROC_20_1, si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2)) cur.close() db.commit() db.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Squlite3 problem
I'm geting the following error message and I'm stumped Traceback (most recent call last): File "C:\markets\source\QuantScan\QuantScan4_3.py", line 1362, in db.close() sqlite3.OperationalError: Unable to close due to unfinalised statements Here 's the relevant code db = sqlite.connect('c:/markets/db/market_2.db') cur_stocks = db.cursor() cur_quant = db.cursor() cur_subind = db.cursor() # update ROC table in db print '\nupdate ROC table in db...\n' cur = db.cursor() cur.execute("delete from subind_ROC") for row in range(0, num_of_subinds): (subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, si_ROC_20, si_ROC_20_1, \ si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2) = si_ROC[row] cur.execute("INSERT INTO subind_ROC (subind, ROC_10, ROC_10_1, ROC_10_2, ROC_20, ROC_20_1, ROC_20_2, ROC_30, ROC_30_1, ROC_30_2) Values (?,?,?,?,?,?,?,?,?,?)", (subind, si_ROC_10, si_ROC_10_1, si_ROC_10_2, si_ROC_20, si_ROC_20_1, si_ROC_20_2, si_ROC_30, si_ROC_30_1, si_ROC_30_2)) cur.close() db.commit() db.close() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] HTTP file download
Hello all, How can I download a file using HTTP? For example: There is a file at: http://www.somesite.com/file. I need to get this file using HTTP from a python script. I'm not sure but I think httplib could be used to do that. Can anyone confirm that? or Can anyone suggest me something else? Thank you? -- Ronaldo Z. Afonso Phone: 55+11+82619082 www.netf2r.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Finding the minimum value in a multidimensional array
Hey everyone, I've been trying to locate a way to find the location of the minimum value in an n*n array. For instance suppose we have a 10x10 array. In [1]: import numpy In [2]: a = numpy.zeros((10,10)) In [3]: a Out[3]: array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) And we set a value in that array to be the smallest just for illustration purposes. In [4]: a[9][8] = -1 In [5]: a Out[5]: array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., -1., 0.]]) I can find this minimum using the 'min' function, but is there a way to find the index to that position? In [6]: a.min() Out[6]: -1.0 Any help is appreciated. Please keep in mind that this is only a 'small' example. What i'm trying to accomplish is to find the location of the minimum value in a huge n*n array and quickly and efficiently finding the index to that position. Regards - Geofram ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor