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 example, I

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 = Queue()

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 that any character

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 # parser =

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 type 'str' server001 alive 27.2% 7 requests/s 14851125 total type 'str' server002 alive 22.9%

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: srm:socket portNumber=138 tcpORudp=UDP address=64.41.134.60/ With: srm:socket portNumber=2 tcpORudp=TCP address=64.41.134.60/ So the regex grouping are that I want

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') dels =

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 saying: b I wouldn't use a

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_key = lambda item: item[db])

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.tutor?

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

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 =

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] 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))s for a test %('

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

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 elements of

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] 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():   var1

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* send copies of replies to me

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 digit.

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] 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) releases:

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,100)

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 sapiens small muscle

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 power of