[Tutor] Python sqlite with implicit cursor open and close

2012-05-18 Thread Dinesh B Vadhia
In the Python documentation (http://docs.python.org/library/sqlite3.html?highlight=sqlite#using-shortcut-methods) it says: "Using the nonstandard execute(), executemany() and executescript() methods of the Connection object, your code can be written more concisely because you don't have to crea

Re: [Tutor] Sorting multiple sequences

2011-03-12 Thread Dinesh B Vadhia
11:16:30 +1100 From: Steven D'Aprano To: tutor@python.org Subject: Re: [Tutor] Sorting multiple sequences Message-ID: <4d7abb5e.9080...@pearwood.info> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Dinesh B Vadhia wrote: > I want to sort two sequences with different

[Tutor] Sorting multiple sequences

2011-03-11 Thread Dinesh B Vadhia
I want to sort two sequences with different data types but both with an equal number of elements eg. f = [0.21, 0.68, 0.44, ..., 0.23] i = [6, 18, 3, ..., 45] The obvious solution is to use zip ie. pairs = zip(f,i) followed by pairs.sort(). This is fine but my sequences contain 10,000+ element

[Tutor] pickling codecs

2010-09-08 Thread Dinesh B Vadhia
I use codecs to retain consistent unicode/utf-8 encoding and decoding for reading/writing to files. Should the codecs be applied when using the pickle/unpickle function? For example, the standard syntax is: # pickle object f = open(object, 'wb') pickle.dump(object, f, 2) # unpickle object f

[Tutor] Plural words to Singular

2010-08-31 Thread Dinesh B Vadhia
Has anyone come across a quality program to turn plural words to singular words? We don't want to use a stemmer. Thanks. Dinesh___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listin

Re: [Tutor] python interpreter vs bat file

2009-07-20 Thread Dinesh B Vadhia
inesh Message: 1 Date: Sun, 19 Jul 2009 23:22:47 +0100 From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] python interpreter vs bat file Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original

Re: [Tutor] python interpreter vs bat file

2009-07-19 Thread Dinesh B Vadhia
gt; Content-Type: text/plain; charset=us-ascii On Sun, Jul 19, 2009 at 05:40:41AM -0700, Dinesh B Vadhia wrote: > >1. Run Python Programs with Batch file > >Python programs run from a Windows XP batch file (test.bat) in a CMD >window initiated from Windows Exp

Re: [Tutor] python interpreter vs bat file

2009-07-19 Thread Dinesh B Vadhia
Date: Sun, 19 Jul 2009 07:18:08 +0100 From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] python interpreter vs bat file Message-ID: Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original "Dinesh B Vadhia" wrote > No

Re: [Tutor] python interpreter vs bat file

2009-07-18 Thread Dinesh B Vadhia
before and it seems odd behavior. Dinesh From: Jeff Johnson Sent: Saturday, July 18, 2009 3:24 PM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] python interpreter vs bat file Need more information. Python works on Windows as good as anything else. Maybe even better. Dine

[Tutor] python interpreter vs bat file

2009-07-18 Thread Dinesh B Vadhia
During recent program testing, I ran a few Python programs from a Windows XP batch file which causes a memory error for one of the programs. If I run the same set of programs from the Python interpreter no memory error occurs. Any idea why this might be? Dinesh ___

Re: [Tutor] large strings and garbage collection

2009-07-17 Thread Dinesh B Vadhia
join with generator expression is what was needed. terrific! From: Rich Lovely Sent: Friday, July 17, 2009 4:19 PM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] large strings and garbage collection 2009/7/17 Dinesh B Vadhia : > This was discussed in a previous post bu

[Tutor] large strings and garbage collection

2009-07-17 Thread Dinesh B Vadhia
This was discussed in a previous post but I didn't see a solution. Say, you have for i in veryLongListOfStringValues: s += i As per previous post (http://thread.gmane.org/gmane.comp.python.tutor/54029/focus=54139), (quoting verbatim) "... the following happens inside the python interpret

Re: [Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
y += x >>>dd.append(y) As the lists of integers get larger (mine are in the thousands of integers per list) the list comprehension solution will get slower. Do you agree? Dinesh From: Kent Johnson Sent: Friday, July 03, 2009 1:21 PM To: Dinesh B Vadhia Cc: tutor@python.o

Re: [Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
=flowed On 7/3/2009 12:09 PM Dinesh B Vadhia said... > I'm suffering from brain failure (or most likely just being brain less!) > and need help to create a list comprehension for this problem: > > d is a list of integers: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, >

[Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
I'm suffering from brain failure (or most likely just being brain less!) and need help to create a list comprehension for this problem: d is a list of integers: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] Want to create a new list that adds the current number and the pri

[Tutor] array and int

2009-06-26 Thread Dinesh B Vadhia
Say, you create an array['i'] for signed integers (which take a minimum 2 bytes). A calculation results in an integer that is larger than the range of an 'i'. Normally, Python will convert an 'i' to a 4-byte 'l' integer. But, does the same apply for an array ie. does Python dynamically adjust

Re: [Tutor] string pickling and sqlite blob'ing

2009-06-25 Thread Dinesh B Vadhia
ling and sqlite blob'ing Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" wrote > I want to pickle (very long) strings and save them in a sqlite db. Why? Why not just store the string in the dat

Re: [Tutor] string pickling and sqlite blob'ing

2009-06-24 Thread Dinesh B Vadhia
Hi Vince That's terrific! Once a string is compressed with gzip.zlib does it make a difference whether it is stored it in a TEXT or BLOB column? Dinesh From: vince spicer Sent: Wednesday, June 24, 2009 10:49 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] s

[Tutor] string pickling and sqlite blob'ing

2009-06-24 Thread Dinesh B Vadhia
I want to pickle (very long) strings and save them in a sqlite db. The plan is to use pickle dumps() to turn a string into a pickle object and store it in sqlite. After reading the string back from the sqlite db, use pickle loads() to turn back into original string. - Is this a good approac

Re: [Tutor] unicode, utf-8 problem again

2009-06-04 Thread Dinesh B Vadhia
That was very useful - thanks! Hopefully, I'm "all Unicode" now. From: wesley chun Sent: Thursday, June 04, 2009 10:45 AM To: Dinesh B Vadhia ; tutor@python.org Subject: Re: [Tutor] unicode, utf-8 problem again >> But, I still get this error: >> Trace

Re: [Tutor] unicode, utf-8 problem again

2009-06-04 Thread Dinesh B Vadhia
Okay, I get it now ... reading/writing files with the codecs module and the 'utf-8' option fixes it. Thanks! From: Christian Witts Sent: Thursday, June 04, 2009 7:05 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] unicode, utf-8 problem again Dinesh B Va

[Tutor] Fw: unicode, utf-8 problem again

2009-06-04 Thread Dinesh B Vadhia
t already being processed as utf-8? Dinesh From: Dinesh B Vadhia Sent: Thursday, June 04, 2009 6:47 AM To: tutor@python.org Subject: unicode, utf-8 problem again Hi! I'm processing a large number of xml files that are all declared as utf-8 encoded in the header ie. My Python envir

[Tutor] unicode, utf-8 problem again

2009-06-04 Thread Dinesh B Vadhia
Hi! I'm processing a large number of xml files that are all declared as utf-8 encoded in the header ie. My Python environment has been set for 'utf-8' through site.py. Additionally, the top of each program/module has the declaration: # -*- coding: utf-8 -*- But, I still get this error: Tr

[Tutor] reading nested folders in gzip files

2009-05-18 Thread Dinesh B Vadhia
The structure of the gzip files are: gzip archive folderA folderB list of folderC's each folderC contains the target files Within the archive, I want to open the gzip archive, open folderA, openFolderB , get the list of target files in folderC, and extract

Re: [Tutor] Dictionary, integer, compression

2009-04-29 Thread Dinesh B Vadhia
Dictionary, integer, compression To: tutor@python.org Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" wrote > Say, you have a dictionary of integers, are the integers stored > in a compressed integer format or

[Tutor] Dictionary, integer, compression

2009-04-29 Thread Dinesh B Vadhia
This could be a question for the comp.lang.python list but I'll try here first: Say, you have a dictionary of integers, are the integers stored in a compressed integer format or as integers ie. are integers encoded before being stored in the dictionary and then decoded when read? Dinesh ___

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-29 Thread Dinesh B Vadhia
Lie / Alan re: If the source document was generated by a computer, and it produces invalid markup, shouldn't that be considered a bug in the producing program? Yes, absolutely but we don't have access to the producing program only the produced xhtml files. Dinesh ---

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Dinesh B Vadhia
munity as usual! Message: 5 Date: Tue, 28 Apr 2009 19:39:17 +0200 From: Stefan Behnel Subject: Re: [Tutor] finding mismatched or unpaired html tags To: tutor@python.org Message-ID: Content-Type: text/plain; charset=ISO-8859-1 A.T.Hofkamp wrote: > Dinesh B Vadhia wrote: >

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Dinesh B Vadhia
Dinesh From: Kent Johnson Sent: Tuesday, April 28, 2009 8:17 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] finding mismatched or unpaired html tags On Tue, Apr 28, 2009 at 10:41 AM, Dinesh B Vadhia wrote: > This is the error and traceback: > > Unexpected error o

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Dinesh B Vadhia
ly to secure all this information at present." Dinesh From: Kent Johnson Sent: Tuesday, April 28, 2009 7:13 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] finding mismatched or unpaired html tags On Tue, Apr 28, 2009 at 8:54 AM, Dinesh B Vadhia wrote: > I'

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Dinesh B Vadhia
e-ID: <49f70a99.3050...@mwalsh.org> Content-Type: text/plain; charset=us-ascii A.T.Hofkamp wrote: > Dinesh B Vadhia wrote: >> I'm processing tens of thousands of html files and a few of them >> contain mismatched tags and ElementTree throws the error: >> >> "U

[Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Dinesh B Vadhia
I'm processing tens of thousands of html files and a few of them contain mismatched tags and ElementTree throws the error: "Unexpected error opening J:/F2/663/blahblah.html: mismatched tag: line 124, column 8" I now want to scan each file and simply identify each mismatched or unpaired tags (b

Re: [Tutor] PDF to text conversion

2009-04-22 Thread Dinesh B Vadhia
The best converter so far is pdftotext from http://www.glyphandcog.com/ who maintain an open source project at http://www.foolabs.com/xpdf/. It's not a Python library but you can call pdftotext from with Python using os.system(). I used the pdftotext -layout option and that gave the best resul

Re: [Tutor] PDF to text conversion

2009-04-21 Thread Dinesh B Vadhia
Hi Robert I don't have an answer but can have my sympathy. I've been looking for a quality pdf to text convertor for months and not turned up anything useful. I've tried many free programs which are poor. I too wanted a Python-only solution and tried pyPdf but that didn't work. Just today I

[Tutor] parse text for paragraghs/sections

2009-04-20 Thread Dinesh B Vadhia
Hi! I want to parse text and pickup sections. For example, from the text: t = """abc DEF ghi jkl MNO pqr""" ... pickup all text between the tags and and replace with another piece of text. I tried t = re.sub(r"\[A-Za-z0-9]\", "DBV", t) ... but it doesn't work. How do you do this with

[Tutor] 32-bit libaries on 64-bit Windows

2009-03-16 Thread Dinesh B Vadhia
Does anyone know if 32-bit Python libraries will work with 64-bit Python under 64-bit Windows? For example, will 32-bit Numpy or Scipy work under 64-bit Python? Cheers ... Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailma

[Tutor] Sorting large numbers of co-ordinate pairs

2009-03-12 Thread Dinesh B Vadhia
Have a large number (> 1bn) of integer co-ordinates (i, j). The i are ordered and the j unordered. I want to create (j, i) with j ordered and i unordered ie. from: ... 6940, 22886 6940, 38277 6940, 43788 ... to: ... 38277, 567 38277, 90023 38277, 6940 ... I've tried the dictionary route and

[Tutor] Standardizing on Unicode and utf8

2009-02-20 Thread Dinesh B Vadhia
We want to standardize on unicode and utf8 and would like to clarify and verify their use to minimize encode()/decode()'ing: 1. Python source files Use the header: # -*- coding: utf8 -*- 2. Reading files In most cases, we don't know the source encoding of the files being read. Do we have to

Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
;Product ConceptsHard candy with an innovative twist, Internet Archive: Wayback Machine. [online] Mar. 25, 2004. Retrieved from the Internet http://www.confectionery-innovations.com>.' This last bit doesn't work ie. replacing the unwanted chars with " " - eg. 'ConceptsHar

Re: [Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
r: if c in set: string.replace (c, r) to give > 'Chris Perkins : $$$-' My solution is: print ''.join[string.replace(c, r) for c in str if c in set] But, this returns a syntax error. Any idea why? Ta! Dinesh From: Kent Johnson Sent: Thursday, Februar

[Tutor] Removing control characters

2009-02-19 Thread Dinesh B Vadhia
I want a regex to remove control characters (< chr(32) and > chr(126)) from strings ie. line = re.sub(r"[^a-z0-9-';.]", " ", line) # replace all chars NOT A-Z, a-z, 0-9, [-';.] with " " 1. What is the best way to include all the required chars rather than list them all within the r"" ? 2.

Re: [Tutor] Picking up citations

2009-02-10 Thread Dinesh B Vadhia
You're probably right Paul. But, my assumption is that the originators of legal documents pay a little more attention to getting the citation correct and in the right format then say Joe Bloggs does when completing an address block. I think that Kent has reached the end of his commendable eff

Re: [Tutor] Picking up citations

2009-02-10 Thread Dinesh B Vadhia
I'm guessing that '499 n. 10' is a page reference ie. page 499, point number 10. Legal citations are all a mystery - they even have their own citation bluebook (http://www.legalbluebook.com/) ! Dinesh From: Kent Johnson Sent: Tuesday, February 10, 2009 10:57 AM To: Dine

Re: [Tutor] Picking up citations

2009-02-10 Thread Dinesh B Vadhia
last citation ie. 463 U.S. 29, 43, 103 S.Ct. 2856, 2867, 77 L.Ed.2d 443 (1983). I tested it on another sample text and it missed the last citation too. Thanks! Dinesh From: Kent Johnson Sent: Tuesday, February 10, 2009 4:01 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] Pi

[Tutor] Picking up citations

2009-02-09 Thread Dinesh B Vadhia
Kent /Emmanuel I found a list of words before the first word that can be removed which I think is the only way to successfully parse the citations. Here they are: | E.g. | Accord | See |See + Also | Cf. | Compare | Contra | But + See | But + Cf. | See Generally | Citing | In | Dinesh

Re: [Tutor] Picking up citations

2009-02-09 Thread Dinesh B Vadhia
Kent /Emmanuel Below are the results using the PLY parser and Regex versions on the attached 'sierra' data which I think covers the common formats. Here are some 'fully unparsed" citations that were missed by the programs: Smith v. Wisconsin Dept. of Agriculture, 23 F.3d 1134, 1141 (7th Cir.1

Re: [Tutor] Picking up citations

2009-02-07 Thread Dinesh B Vadhia
, 493 U.S. 146, 159-60 (1934)" I didn't know about pyparsing which appears to be very powerful and have joined their list. Thank-you for your help. Dinesh From: Kent Johnson Sent: Saturday, February 07, 2009 1:19 PM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor]

Re: [Tutor] Picking up citations

2009-02-07 Thread Dinesh B Vadhia
n petit jury, he would clearly have standing to challenge the systematic exclusion of any identifiable group from jury service." Okay, I'd better get to grips with pyparsing! Dinesh From: Kent Johnson Sent: Saturday, February 07, 2009 6:21 AM To: Dinesh B Vadhia Cc: tutor@pytho

[Tutor] Picking up citations

2009-02-06 Thread Dinesh B Vadhia
Hi! I want to process text that contains citations, in this case in legal documents, and pull-out each individual citation. Here is a sample text: text = "Page 500 Carter v. Jury Commission of Greene County, 396 U.S. 320, 90 S.Ct. 518, 24 L.Ed.2d 549 (1970); Lathe Turner v. Fouche, 396 U.S. 34

[Tutor] Eliminating options

2009-02-04 Thread Dinesh B Vadhia
Hi! I'm using 32-bit Python on Windows 64-bit Vista (instead of 64-bit Python because I also use Numpy/Scipy which doesn't offer 64-bit versions yet). I'm doing some very simple text processing ie. given a string s, find a subtring using s.find(). But, the program doesn't find all instances o

[Tutor] Fw: Traversing XML Tree with ElementTree

2009-01-24 Thread Dinesh B Vadhia
i've got most of this working now so hold off (for now). thanks. dinesh From: Dinesh B Vadhia Sent: Saturday, January 24, 2009 8:31 PM To: tutor@python.org Subject: Traversing XML Tree with ElementTree I want to traverse an xml file and at each node retain the full path from the p

[Tutor] Traversing XML Tree with ElementTree

2009-01-24 Thread Dinesh B Vadhia
I want to traverse an xml file and at each node retain the full path from the parent to that node ie. if we have: this is node b this is node c this is node d this is node e ... then require: this is node b this is node c t

[Tutor] Fw: Reading gzip files

2008-12-16 Thread Dinesh B Vadhia
offending file and move on to the next file in the list. How do I achieve this with this particular type of error? Dinesh From: Dinesh B Vadhia Sent: Sunday, November 30, 2008 2:51 PM To: tutor@python.org Subject: Reading gzip files I'm reading gzip files and writing the content out

[Tutor] Python on 64-bit ...

2008-12-07 Thread Dinesh B Vadhia
I ask this question in trepidation but does anyone have experience of Python on 64-bit Windows Vista - there I said it! Feedback on performance and memory usage would be useful to know. Thanks! Dinesh___ Tutor maillist - Tutor@python.org http://ma

Re: [Tutor] Reading gzip files

2008-11-30 Thread Dinesh B Vadhia
ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > I'm reading gzip files and writing the content out to a text file > line by line. > File "C:\P

[Tutor] Reading gzip files

2008-11-30 Thread Dinesh B Vadhia
I'm reading gzip files and writing the content out to a text file line by line. The code is simply: import gzip list_zipfiles = dircache.listdir(zipfolder) writefile = "out_file.txt" fw = open(writefile, 'w') for ziparchive in list_zipfiles: zfile = gzip.GzipFile(zipfolder + ziparchive, "r

Re: [Tutor] Decimal fixed point representation

2008-11-21 Thread Dinesh B Vadhia
To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > I'm trying to get my head around the Decimal module to > understand how

[Tutor] Decimal fixed point representation

2008-11-20 Thread Dinesh B Vadhia
I'm trying to get my head around the Decimal module to understand how to represent a decimal floating point number as an integer (or integers). Am I barking mad or is this possible? Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.or

Re: [Tutor] pickling, writing, reading individual lists from a file

2008-11-03 Thread Dinesh B Vadhia
, 2008 at 6:15 AM, Lie Ryan gmail.com> wrote: > On Sun, 02 Nov 2008 23:20:47 -0800, Dinesh B Vadhia wrote: > >> I want to pickle a bunch of lists and write each list separately to a >> fileand then read them back. > To solve your problem, you have several alternative possib

[Tutor] pickling, writing, reading individual lists from a file

2008-11-02 Thread Dinesh B Vadhia
I want to pickle a bunch of lists and write each list separately to a fileand then read them back. Here is my code with the EOF error: import cPickle as pickle m = [[1, 2, 3, 4], [5, 6, 7, 8, 9, 10], [11, 12, 13, 14]] filename = 'lists.txt' fw = open(filename, 'w') for l in m: n = pick

Re: [Tutor] fast list traversal

2008-10-31 Thread Dinesh B Vadhia
Hi Kent The code is very simple: dict_long_lists = defaultdict(list) for long_list in dict_long_lists.itervalues() for element in long_list: array_a[element] = m + n + p# m,n,p are numbers The long_list's are read from a defaultdict(list) dictionary and so don't n

Re: [Tutor] fast list traversal

2008-10-30 Thread Dinesh B Vadhia
a for-loop. Btw, cannot move to Python 2.6 or 3.0 until Numpy/Scipy catches up. Dinesh From: wesley chun Sent: Thursday, October 30, 2008 3:06 PM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] fast list traversal based on the all the performance questions, i would say agree

[Tutor] unordered and ordered defaultdict(set)

2008-10-30 Thread Dinesh B Vadhia
Here is an interesting result with defaultdict(set). This program creates 2 dictionaries of sets with the first dictionary containing 10 elements per set and the second containing 25 elements. You'll see the sets in the first dictionary are unordered and in the second they are ordered. impor

Re: [Tutor] fast list traversal

2008-10-30 Thread Dinesh B Vadhia
Bob: Nothing special is being done on the elements of the list - additions/subtractions/ - and storing the results in an array. That's it. Dinesh From: bob gailer Sent: Thursday, October 30, 2008 11:40 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] fast list trav

[Tutor] fast list traversal

2008-10-30 Thread Dinesh B Vadhia
I need to process a large number (> 20,000) of long and variable length lists (> 5,000 elements) ie. for element in long_list: # the result of this operation is not a list The performance is reasonable but I wonder if there are faster Python methods? Dinesh

Re: [Tutor] XML to text

2008-10-24 Thread Dinesh B Vadhia
Yes, that's exactly what I was looking for. Brilliant! From: Kent Johnson Sent: Friday, October 24, 2008 10:59 AM To: Dinesh B Vadhia Cc: tutor@python.org Subject: Re: [Tutor] XML to text On Fri, Oct 24, 2008 at 11:54 AM, Dinesh B Vadhia <[EMAIL PROTECTED]> wrote: > I have

[Tutor] XML to text

2008-10-24 Thread Dinesh B Vadhia
I have a large number of xml files that I want to convert into text format. What is the best and easiest way to do this? Thanks! Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] defaultdict(set)

2008-09-25 Thread Dinesh B Vadhia
I'm using defaultdict(set) to store a dictionary d = {value : set_items} where value = integer and set_items = set() of characters and it works perfectly. I would like to also store the length of the set ie. l = len(set_items) with the dictionary but don't how to do it using a defaultdict(). A

Re: [Tutor] array of different datatypes

2008-09-22 Thread Dinesh B Vadhia
Thanks Steve. How do you sort on the second element of each list to get: a' = [[42, 'fish'], [1, 'hello'] [2, 'world'] ] From: Steve Willoughby Sent: Monday, September 22, 2008 8:16 PM To: Dinesh B Vadhia Cc: tutor@python.org Subj

[Tutor] array of different datatypes

2008-09-22 Thread Dinesh B Vadhia
I have looked (honestly!) and cannot see an array structure to allow different datatypes per column. I need a 2 column array with column 1 = an integer and column 2 = chars, and after populating the array, sort on column 2 with column 1 sorted relatively. Thanks! Dinesh

Re: [Tutor] array and dictionary

2008-09-21 Thread Dinesh B Vadhia
help. Dinesh Message: 5 Date: Sun, 21 Sep 2008 09:15:00 +0100 From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] array and dictionary To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; r

[Tutor] array and dictionary

2008-09-20 Thread Dinesh B Vadhia
Hi! Say, I've got a numpy array/matrix of the form: [[1 6 1 2 3] [4 5 4 7 0] [2 0 8 0 2] [8 2 6 3 0] [0 7 0 3 5] [8 0 3 0 6] [8 0 0 2 2] [3 1 0 4 0] [5 0 8 0 0] [2 1 0 5 6]] And, I want to create a dictionary of rows (as the keys) mapped to lists of non-zero numbers in that row ie. di

[Tutor] removing whole numbers from text

2008-08-02 Thread Dinesh B Vadhia
I want to remove whole numbers from text but retain numbers attached to words. All whole numbers to be removed have a leading and trailing space. For example, in "the cow jumped-20 feet high30er than the lazy 20 timing fox who couldn't keep up the 865 meter race." remove the whole numbers 20 an

Re: [Tutor] endless processing through for loop

2008-06-22 Thread Dinesh B Vadhia
There is no thrashing of disk as I have > 2gb RAM and I'm not keeping the file contents in memory. One line is read at a time, some simple string processing and then writing out the modified line. From: Kent Johnson Sent: Sunday, June 22, 2008 5:39 PM To: Dinesh B Vadhia C

[Tutor] endless processing through for loop

2008-06-22 Thread Dinesh B Vadhia
I have a program with 2 for loops like this (in pseudocode): fw = open(newLine.txt, 'w') for i in xrange(0, 700,000, 1): read a file fname from folder for line in open(fname, 'r'): do some simple string processing on line fw.write(newline) fw.close() That's it. Very simpl

[Tutor] Extracting text from XML document

2008-06-08 Thread Dinesh B Vadhia
I want to extract text from XML (and SGML) documents. I found one program by Paul Prescod (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65128) from 2001. Does anyone know of any programs that are more recent? Cheers Dinesh ___ Tutor maill

Re: [Tutor] zip and rar files

2008-06-08 Thread Dinesh B Vadhia
the zipfile module does work or rar zip archives. - Original Message - From: Dinesh B Vadhia To: tutor@python.org Sent: Saturday, June 07, 2008 8:27 AM Subject: zip and rar files Does the Python zipfile module work on rar archives? If not, does a similar module exist for rar

[Tutor] zip and rar files

2008-06-07 Thread Dinesh B Vadhia
Does the Python zipfile module work on rar archives? If not, does a similar module exist for rar archives? Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] finding special character string

2008-06-03 Thread Dinesh B Vadhia
Yes, I'm happy because I found a non-regex way to solve the problem (see below). No, I'm not a student or worn out but wish I was back at college and partying! Yes, this is an interesting problem and here is the requirement: - A text document contains special words that start and end with a peri

Re: [Tutor] finding special character string

2008-06-01 Thread Dinesh B Vadhia
Thank-you Kent - it works a treat! - Original Message - From: Kent Johnson To: Dinesh B Vadhia Cc: tutor@python.org Sent: Sunday, June 01, 2008 4:25 AM Subject: Re: [Tutor] finding special character string On Sun, Jun 1, 2008 at 6:48 AM, Dinesh B Vadhia <[EMAIL PROTECTED]>

[Tutor] finding special character string

2008-06-01 Thread Dinesh B Vadhia
A text document has special character strings defined as "." + "set of characters" + ".". For example, ".sup." or ".quadbond." or ".degree." etc. The length of the characters between the opening "." and closing "." is variable. Assuming that you don't know beforehand all possible special char

Re: [Tutor] Equivalent 'case' statement

2008-05-24 Thread Dinesh B Vadhia
The dictionary of functions was the way to go and does perform much faster than if/elif's. Thank-you! - Original Message - From: inhahe To: Dinesh B Vadhia Cc: tutor@python.org Sent: Thursday, May 22, 2008 4:15 PM Subject: Re: [Tutor] Equivalent 'case' statement

[Tutor] Equivalent 'case' statement

2008-05-22 Thread Dinesh B Vadhia
Is there an equivalent to the C/C++ 'case' (or 'switch') statement in Python? Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Loading and using large sparse matrices under Windows

2008-04-27 Thread Dinesh B Vadhia
Hi! Does anyone on this list have experience of using the Scipy Sparse matrix library for loading and using very large datasets (>20,000 rows x >1m columns of integers) under Windows? I'm using a recent Scipy svn that supports (sparse) integer matrices but it still causes the pythonw.exe progr

Re: [Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
x27;, what='fieldB', where='fieldB LIKE $q', limit=limit, vars={'q':q}): r = row['fieldB']# get encode'd unicode through dict key value print r # works perfec

[Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
Here is a program that SELECT's from a pysqlite database table and encode's the returned unicode strings: import sys import os import sqlite3 con = sqlite3.connect("testDB.db") cur = con.cursor() a = u'99 Cycling Swords' b = a.encode('utf-8') print b q = '%wor%' limit = 25 query = "SELECT fiel

Re: [Tutor] in-memory pysqlite databases

2008-04-13 Thread Dinesh B Vadhia
Alan Your last paragraph is the gist of my note ie. it's the documentation, documentation, documentation. In addition to Python, we use Numpy/Scipy/webpy at the server - all of them Python libraries written in Python and/or C - and have faced no end of problems with these libraries. We also u

Re: [Tutor] in-memory pysqlite databases

2008-04-13 Thread Dinesh B Vadhia
3:30 +0100 From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] in-memory pysqlite databases To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original "Dinesh B Vadhia&q

Re: [Tutor] in-memory pysqlite databases

2008-04-12 Thread Dinesh B Vadhia
is that it cannot find the database table. After reading your note, it hit me that an execution thread is created by pysqlite and another thread by webpy and hence webpy is not seeing the table. What a pain! Dinesh - Original Message - From: bob gailer To: Dinesh B Vadhia Cc: tutor@

[Tutor] in-memory pysqlite databases

2008-04-12 Thread Dinesh B Vadhia
Say, you have already created a pysqlite database "testDB". In a Python program, you connect to the database as: > con = sqlite3.connect("testDB") > cur = con.cursor() To use a database in memory (ie. all the 'testDB' tables are held in memory) the pysqlite documentation says the declaration i

Re: [Tutor] SQLite LIKE question

2008-04-12 Thread Dinesh B Vadhia
OTECTED]> Subject: Re: [Tutor] SQLite LIKE question Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Dinesh B Vadhia wrote: > Okay, I've got this now: > >> con = sqlite3.connect(":memory:") >> c

[Tutor] pysqlite and functions

2008-04-12 Thread Dinesh B Vadhia
I'm using a pysqlite select statement within a def function and it's not working because (I suspect) the pysqlite variables are not being declared corrrectly to be used within a def function or the def function is not setup correctly. Here is the code followed by the errors: code co

[Tutor] Old School

2008-04-11 Thread Dinesh B Vadhia
I belong to the Old School where getting my head around OO is just one big pain. I write software by modularization executed as a set of functions - and it works (some call this functional programming!). Whenever I review Python books (eg. Lutz's excellent Programming Python, 3ed) the code is

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
Okay, I've got this now: > con = sqlite3.connect(":memory:") > cur = con.cursor() > cur.execute("""CREATE TABLE db.table(col.a integer, col.b text)""") > con.executemany("""INSERT INTO db.table(col.a, col.b) VALUES (?, ?)""", m) > con.commit() > for row in con.execute("""SELECT col.a, col.b FROM

[Tutor] Fw: SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
'$q%', '%q%', '%q' and 'q%' and none of them return what I expect ie. all strings with the characters "dog" in them. Cheers! Dinesh - Original Message - From: Dinesh B Vadhia To: tutor@python.org Sent: Thursday, April 10, 2008 3:24 P

[Tutor] SQLite LIKE question

2008-04-10 Thread Dinesh B Vadhia
I'm reading a text file into an in-memory pysqlite table. When I do a SELECT on the table, I get a 'u' in front of each returned row eg. > (u'QB VII',) > (u'Quackser Fortune Has a Cousin in the Bronx',) I've checked the data being INSERT'ed into the table and it has no 'u'. The second problem

Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Dinesh B Vadhia
Ignore the 'adjacent items' remark. The rest is correct ie. looking for all strings containing a substring x. - Original Message - From: Kent Johnson To: Dinesh B Vadhia Cc: tutor@python.org Sent: Thursday, April 10, 2008 6:32 AM Subject: Re: [Tutor] Searching through la

Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Dinesh B Vadhia
mance (and it has!). I'll try the binary search and let you know. I'll also look at the trie structure. An alternative is to create an in-memory SQLite database of the string items. Any thoughts on that? Dinesh - Original Message - From: Kent Johnson To: Dinesh B Vadhia Cc: t

Re: [Tutor] List comprehensions

2008-04-09 Thread Dinesh B Vadhia
ed sensible that replacing the for loop with a built-in would help. Maybe not? Hope that helps. Dinesh - Original Message - From: Kent Johnson To: Dinesh B Vadhia Cc: tutor@python.org Sent: Wednesday, April 09, 2008 1:48 PM Subject: Re: [Tutor] List comprehensions Dinesh B Vadhia wr

Re: [Tutor] List comprehensions

2008-04-09 Thread Dinesh B Vadhia
he result is printed (in fact, the result is sent from the server to a browser one result line at a time) The for loop will be called continuously and this is another reason to look for a potentially better structure preferably a built-in. Hope this makes sense! Thank-you. Dinesh - Origina

  1   2   >