Re: [Tutor] Handling hundreds of thousands of inserts with MySQLdb

2006-09-03 Thread Karl Pflästerer
On 2 Sep 2006, [EMAIL PROTECTED] wrote: > > Hello all. I post this here since is my first attempt to solve a > problem with python. > > I have fairly big log files that I'm doing some pre-processing to, to > cleanup the data before they go into a MySQL database. After > processing the files

Re: [Tutor] loops to assign variables

2006-07-22 Thread Karl Pflästerer
On 22 Jul 2006, [EMAIL PROTECTED] wrote: > > On Sat, 2006-07-22 at 14:11 +0100, John CORRY wrote: >> Hi, >> >> I am refactoring my code. I am trying to reduce the amount of lines >> by using more loops. I tend to use copy and paste a lot instead of >> writing a loop to do the work. >> >> For

Re: [Tutor] beginner: using optional agument in __init__ breaks my code

2006-06-25 Thread Karl Pflästerer
On 25 Jun 2006, [EMAIL PROTECTED] wrote: [...] > This code works as intended. Now my idea is to provide > an optional argument to the constructor. So I change > it to: > > def __init__(self, q =[]): > self.queue = q > > Now, something very strange happens: > a = Queue() b =

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Karl Pflästerer
On 24 Mai 2006, [EMAIL PROTECTED] wrote: > I have two Perl expressions > > > If windows: > > perl -ple "s/([^\w\s])/sprintf(q#%%%2X#, ord $1)/ge" somefile.txt > > If posix > > perl -ple 's/([^\w\s])/sprintf("%%%2X", ord $1)/ge' somefile.txt > > > > The [^\w\s] is a negated expression stating th

Re: [Tutor] Question on option parser

2006-05-16 Thread Karl Pflästerer
On 16 Mai 2006, [EMAIL PROTECTED] wrote: > Is there a way to leverage optionparser so it can accept input from both > command line and a configuration file? > > Current code block is: > > # > # Parse command line options and automatically build > # help/usage display > # > pars

Re: [Tutor] Dictionaries and aggregation

2006-04-25 Thread Karl Pflästerer
On 25 Apr 2006, [EMAIL PROTECTED] wrote: [...] > Here's the list I'm starting with: > for i in rLst: print i, type(i) > > server001 alive 17.1% 2 requests/s 14805416 total > server001 alive 27.2% 7 requests/s 14851125 total > server002 alive 22.9% 6 requ

Re: [Tutor] string formatting question

2006-04-07 Thread Karl Pflästerer
On 7 Apr 2006, [EMAIL PROTECTED] wrote: > Sorry I didn't make my question clearer. Bascially I > want to replace this line: > > address="64.41.134.60"/> > > With: > > address="64.41.134.60"/> > > So the regex grouping are that I want to keep > portNumber= and tcpORudp= and replace the values. >

Re: [Tutor] List methods/comps Best Practices

2006-04-03 Thread Karl Pflästerer
On 3 Apr 2006, [EMAIL PROTECTED] wrote: > I had several list comprehensions that I was mucking with; these lists > are working on a simple subclass of the built-in list object. They > looked liked this: > > filelist = getFilesToAdd() > filelist2 = getFilesToDel() > > adds = MyList('foo') >

Re: [Tutor] Alternative to nested loops

2006-03-19 Thread Karl Pflästerer
On 19 Mrz 2006, [EMAIL PROTECTED] wrote: > I had a feeling I could do this: > foo > [[1, 2, 3], [1, 2, 3], [1, 2, 3]] for c in foo: > ... for b in c: > ... print b > ... > 1 > 2 > 3 > 1 > 2 > 3 > 1 > 2 > 3 > > Using a list comprehension, as it seemed to me like I was sayi

Re: [Tutor] walking down directories

2006-03-17 Thread Karl Pflästerer
On 17 Mrz 2006, [EMAIL PROTECTED] wrote: > As you see, the problem is that there is another > directory under testFiles called testDir, but the > function doesn't check the directory for files. The > function needs to find every directory (including > subdirectories within directories). Any hint

Re: [Tutor] Sorting and secondary sorting.

2006-03-11 Thread Karl Pflästerer
On 11 Mrz 2006, [EMAIL PROTECTED] wrote: > I'm trying to think of a way to sort a list of dictionaries. In pseudo-code: > > l = [ { "host":"foo", "db":"bob"}, >{ "host":"foo", "db":"dave"}, >{ "host":"fee", "db":"henry"} > ] > > l.sort( key = lambda item: item["host"], second_

Re: [Tutor] Unable to take input as a module

2006-02-22 Thread Karl Pflästerer
On 22 Feb 2006, [EMAIL PROTECTED] wrote: > my code: > .. > . > import sys, types, string, inspect > > input= sys.argv[1] > print inspect.ismodule(input) > > > here it always give false. as what ever input i take it is string . > > my problem is i am not able to take inp

Re: [Tutor] Listing all of an instances variables

2005-10-08 Thread Karl Pflästerer
On 8 Okt 2005, [EMAIL PROTECTED] wrote: > Class SomeClass: >def __init__(self,a,b): > self.a = a > self.b = b > >def report(self): > for i in dir(self): > print self.i > > > > > This is where I run into problems: How do I return all of the variables > in an in

Re: [Tutor] Newsreader list name?

2005-06-09 Thread Karl Pflästerer
On 9 Jun 2005, [EMAIL PROTECTED] wrote: > I'm switching over from email digests to a newsreader and I can't > find a reference for this tutor list. > > For example, I have the lists comp.lang.python and > comp.lang.python.announce setup, but can't find something like > comp.lang.python.tuto

Re: [Tutor] resizing an array of strings?

2005-06-06 Thread Karl Pflästerer
On 6 Jun 2005, [EMAIL PROTECTED] wrote: > > Hello, I'm having a bit of trouble resizing/reshaping an array of strings. > here's what I'm trying to do: > > myString = ['hi','my','name','is','Jeff'] > reshape(myString, (2,2)) > > What I get from this is something like: > > [['h','i'], >

Re: [Tutor] Lists of files

2005-05-17 Thread Karl Pflästerer
On 16 Mai 2005, [EMAIL PROTECTED] wrote: > Thanks to all who helped me with my questions regarding testing for > commandline arguments and list assignment. I have finished my first > Python program (included below). It is slightly more secure than the > Perl program I rewrote, but also about a t

Re: [Tutor] Lists of files

2005-05-14 Thread Karl Pflästerer
On 14 Mai 2005, [EMAIL PROTECTED] wrote: > Here's the problem - I want a list (array) of the files in a directory, > and then I want to iterate over the list testing for image-ness (with > imghdr.what()) and put all the image filenames in a global list. > > What I've tried is this: > > files = glo

Re: [Tutor] output of dictionaries

2005-05-10 Thread Karl Pflästerer
On 10 Mai 2005, [EMAIL PROTECTED] wrote: > I'm creating a small database using a dictionary of dictionaries, and I > want to output it to a file. It seems that only strings can be output to > files, and I cannot quite figure out how to quickly and simply convert my > dictionary to a list of

Re: [Tutor] scoping oddity

2005-05-07 Thread Karl Pflästerer
On 7 Mai 2005, [EMAIL PROTECTED] wrote: > I came across a rather odd issue with scoping. Can someone explain why > testa and testc works, but not testb. I am running under python 2.4.1 on [...] > x = 5 > > def testa(astr): > print astr, x > > testa(22) > > def testb(astr): > x = x - 1

Re: [Tutor] Generator function question?

2005-05-07 Thread Karl Pflästerer
On 7 Mai 2005, [EMAIL PROTECTED] wrote: > It's clear that your code is a more elegant implementation of > neverEndingStatus() but I am still having to initialize a global variable > and call .next() when I want to get the next value... So the generator > function has been cleaned up, but the clie

Re: [Tutor] Smtp

2005-05-06 Thread Karl Pflästerer
On 6 Mai 2005, [EMAIL PROTECTED] wrote: >I tried to use the mailserver script in library reference to send > mails but it gives an error:The script and the error are below.Why > does it give this error?How can i fix? [...] > ERROR: > > Traceback (most recent call last): > File "D:\Python23\

Re: [Tutor] Class and Scope Question

2005-05-06 Thread Karl Pflästerer
On 6 Mai 2005, [EMAIL PROTECTED] wrote: > > The following test script is kind of got me baffled: >#!/usr/local/bin/python > class Eval: > def __getitem__(self,key): > return eval(key) >##def test(): >## i = 100 >## b = ["My", "name", "is", "Tim"] >## test = "this is number %(str(i)

Re: [Tutor] Subract Month From Date

2005-05-03 Thread Karl Pflästerer
On 3 Mai 2005, [EMAIL PROTECTED] wrote: > What would be the simplest way to extract the Month and Year for one month > prior to the current month? I have been looking for a way to create a Date > object with the current date, and then subtract a month from it. Say it is > currently "January 1st,

Re: [Tutor] permutations using list comprehensions

2005-05-01 Thread Karl Pflästerer
On 1 Mai 2005, [EMAIL PROTECTED] wrote: > I'm trying to produce something of a similar structure to generate the > permutations of a sequence by translating the ffg bit of Haskell:- > perms [] = [[]] > perms xs = [ x : ps | x <- xs , ps <- perms ( xs\\[x]) ] > > '\\' applies to lists & means ele

Re: [Tutor] List comprehensions

2005-03-24 Thread Karl Pflästerer
On 23 Mrz 2005, [EMAIL PROTECTED] wrote: > map is (probably) going to be removed in Python3000 :-( So it's > probably better to not get into the habit of using it. Au contraire. If enough people use it and are used using it the risk for `map' getting removed will be a lot lower. Furthermore t

Re: [Tutor] primes (generator)

2005-03-19 Thread Karl Pflästerer
On 19 Mrz 2005, [EMAIL PROTECTED] wrote: [Code] > Maybe sombody likes to compare these algorithms to the > ones mentioned before in this thread. I would be > interested in the results. I did it and on my machine here (a slow one) the following straight forward version is the fastest one. It's no

Re: [Tutor] Re: Accessing local variables from nested functions.

2005-02-13 Thread Karl Pflästerer
On 13 Feb 2005, [EMAIL PROTECTED] wrote: > > Karl Pflästerer wrote on Sun, 13 Feb 2005 12:15:03 +0100: > >> what's the Python way of accessing local variables in nesting functions? For I didn't wrote that; please quote correctly. Thanks. Karl -- Please do *not*

Re: [Tutor] Accessing local variables from nested functions.

2005-02-13 Thread Karl Pflästerer
On 13 Feb 2005, [EMAIL PROTECTED] wrote: > what's the Python way of accessing local variables in nesting functions? For The way you want to work with closures the Python way is not to do it but use a class to hold the state. That's sometimes sad but true. > example if I have: > > def p(): >  

Re: [Tutor] default argument frustration

2005-02-11 Thread Karl Pflästerer
On 11 Feb 2005, [EMAIL PROTECTED] wrote: >> FOR THE LOVE OF MIKE can someone tell me even one reason why this >> isn't a misfeature?!?! > Its the only sane way to implement default arguments. The whole > point of function definitions is that they provide a single concise > interface. The funct

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Karl Pflästerer
On 6 Feb 2005, [EMAIL PROTECTED] wrote: > Actually, generating the digits from the right complicates the algorithm quite > a bit. It's hidden in > the Python version, but s = str(i % 2) + s is a relatively expensive > operation here - it has to copy > all of s to make room for the new dig

Re: [Tutor] help with regexps/filename parsing

2005-01-31 Thread Karl Pflästerer
On 31 Jan 2005, [EMAIL PROTECTED] wrote: > > Slight correction which I realized after sending, see below for > version/release seperation, which I should have seen but blame lack of > sleep ;-) > corrected versions: > 4.3.0 > 3.2.3d > 3 > 5.42a > 1.10 > > (new) rel

Re: [Tutor] help with regexps/filename parsing

2005-01-31 Thread Karl Pflästerer
On 31 Jan 2005, [EMAIL PROTECTED] wrote: > I've got an issue that's been driving me a bit nuts. I'm sure it _can_ > be done with a regexp, although I'm missing a piece needed to tie it > together to work for all cases. > > I need to parse out a list of RPMs in this case, but it seems the RPM >

Re: [Tutor] Should this be a list comprehension or something?

2005-01-26 Thread Karl Pflästerer
On 26 Jan 2005, [EMAIL PROTECTED] wrote: > The following Python code works correctly; but I can't help but wonder if > my for loop is better implemented as something else: a list comprehension > or something else more Pythonic. [Code] > > > w1 = Water(50,0) > w2 = Water(50,

Re: [Tutor] Selecting text

2005-01-19 Thread Karl Pflästerer
On 19 Jan 2005, [EMAIL PROTECTED] wrote: > I have two lists: > > 1. Lseq: > len(Lseq) > 30673 Lseq[20:25] > ['NM_025164', 'NM_025164', 'NM_012384', 'NM_006380', > 'NM_007032','NM_014332'] > > > 2. refseq: len(refseq) > 1080945 refseq[0:25] > ['>gi|10047089|ref|NM_014332.1| Homo

Re: [Tutor] Regular expression re.search() object . Please help

2005-01-13 Thread Karl Pflästerer
On 13 Jan 2005, [EMAIL PROTECTED] wrote: > My list looks like this: List name = probe_pairs > Name=AFFX-BioB-5_at > Cell1=96 369 N control AFFX-BioB-5_at > Cell2=96 370 N control AFFX-BioB-5_at > Cell3=441 3 N control AFFX-BioB-5_at > Cell4=441 4

Re: [Tutor] Re: Soem list operation questions?

2004-12-28 Thread Karl Pflästerer
On 28 Dez 2004, [EMAIL PROTECTED] wrote: > Karl, > The ''.join() method was the first one suggested. Roel then suggested > a math-based method, which I attempted to improve upon. I know. I read it all; ''.join() was suggested together with a list comprehension (in such simple situations map() is

Re: [Tutor] Re: Soem list operation questions?

2004-12-28 Thread Karl Pflästerer
On 28 Dez 2004, [EMAIL PROTECTED] wrote: > Though, of course, by modifying your way (using str() ), it will still work: > def listtoint(digits): > result = 0 > for digit in digits: > result *= (10**len(str(digit))) ## just multiply it by 10 > result += digit ## to the

Re: [Tutor] sorting a list of dictionaries

2004-12-09 Thread Karl Pflästerer
On 9 Dez 2004, [EMAIL PROTECTED] wrote: > I have a list of dictionaries, each representing info about a file, > something like: > > [{'name':'foo.txt','size':35}, {'name':'bar.txt','size':35}, ...] > > I want to present a sorted list of all the files' data, sorting on the > keys 'name' or 'size'.

Re: [Tutor] Printing two elements in a list

2004-12-07 Thread Karl Pflästerer
On 7 Dez 2004, [EMAIL PROTECTED] wrote: > I have two lists names x and seq. > > I am trying to find element of x in element of seq. I > find them. However, I want to print element in seq > that contains element of x and also the next element > in seq. [...] > 3. TRIAL 3: > I just asked to prin