Re: istep() addition to itertool? (Was: Re: Printing n elements per line in a list)

2006-08-20 Thread Justin Azoff
Rhamphoryncus wrote: I've run into this problem a few times, and although many solutions have been presented specifically for printing I would like to present a more general alternative. [snip interesting istep function] Would anybody else find this useful? Maybe worth adding it to

Re: trouble using \ as a string

2006-08-20 Thread Justin Azoff
OriginalBrownster wrote: i want this because using python I am pulling in filenames from a mac..thus they are / in the pathways..and i want to .split it at the / to obtain the filename at the end...but its proving diffucult with this obstacle in the way. sounds like you want import posixpath

Re: variable creation

2006-08-08 Thread Justin Azoff
Alistair King wrote: Hei all, im trying to create a list of variables for further use: [snip] this works to a certain extent but gets stuck on some loop. Im a beginner and am not sure where im going wrong. You are trying to do too much in one function. Split those loops up into a few little

Re: newb question: file searching

2006-08-08 Thread Justin Azoff
[EMAIL PROTECTED] wrote: I've narrowed down the problem. All the problems start when I try to eliminate the hidden files and directories. Is there a better way to do this? Well you almost have it, but your problem is that you are trying to do too many things in one function. (I bet I am

Re: newb question: file searching

2006-08-08 Thread Justin Azoff
[EMAIL PROTECTED] wrote: I do appreciate the advice, but I've got a 12 line function that does all of that. And it works! I just wish I understood a particular line of it. You miss the point. The functions I posted, up until get_files_by_ext which is the equivalent of your getFileList,

Re: technique to enter text using a mobile phone keypad (T9 dictionary-based disambiguation)

2006-08-08 Thread Justin Azoff
Petr Jakeš wrote: I have a standard 12-key mobile phone keypad connected to my Linux machine as a I2C peripheral. I would like to write a code which allows the text entry to the computer using this keypad (something like T9 on the mobile phones) According to the

Re: Why do I require an elif statement here?

2006-08-06 Thread Justin Azoff
danielx wrote: I'm surprised no one has mentioned neat-er, more pythonic ways of doing this. I'm also surprised no one mentioned regular expressions. Regular expressions are really powerful for searching and manipulating text. [snip] I'm surprised you don't count my post as a neat and pythonic

Re: Why do I require an elif statement here?

2006-08-04 Thread Justin Azoff
Jim wrote: Could somebody tell me why I need the elif char == '\n' in the following code? This is required in order the pick up lines with just spaces in them. Why doesn't the else: statement pick this up? No idea. Look at the profile of your program: for.. if.. for.. if.. else.. if.. This

Re: help - iter dict

2006-08-03 Thread Justin Azoff
[EMAIL PROTECTED] wrote: Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that valuewhat ive done so far: [snip] short time. I was trying to define a function (its my first!) so that i could apply to several 'dictionary's and

Re: Thread Question

2006-07-28 Thread Justin Azoff
Ritesh Raj Sarraf wrote: I'd like to put my understanding over here and would be happy if people can correct me at places. ok :-) So here it goes: Firstly the code initializes the number of threads. Then it moves on to initializing requestQueue() and responseQueue(). Then it moves on to

Re: Thread Question

2006-07-27 Thread Justin Azoff
Ritesh Raj Sarraf wrote: [snip] for item in list_items: download_from_web(item) This way, one items is downloaded at a time. I'm planning to implement threads in my application so that multiple items can be downloaded concurrently. I want the thread option to be user-defined. [snip]

Re: splitting words with brackets

2006-07-26 Thread Justin Azoff
faulkner wrote: er, ...|\[[^\]]*\]|... ^_^ That's why it is nice to use re.VERBOSE: def splitup(s): return re.findall(''' \( [^\)]* \) | \[ [^\]]* \] | \S+ ''', s, re.VERBOSE) Much less error prone this way -- - Justin --

Re: splitting words with brackets

2006-07-26 Thread Justin Azoff
Paul McGuire wrote: Comparitive timing of pyparsing vs. re comes in at about 2ms for pyparsing, vs. 0.13 for re's, so about 15x faster for re's. If psyco is used (and we skip the first call, which incurs all the compiling overhead), the speed difference drops to about 7-10x. I did try

Re: Nested function scope problem

2006-07-22 Thread Justin Azoff
Josiah Manson wrote: I just did some timings, and found that using a list instead of a string for tok is significantly slower (it takes 1.5x longer). Using a regex is slightly faster for long strings, and slightly slower for short ones. So, regex wins in both berevity and speed! I think the

Re: Nested function scope problem

2006-07-22 Thread Justin Azoff
Bruno Desthuilliers wrote: Justin Azoff a écrit : if len(tok) 0: should be written as if(tok): actually, the parenthesis are useless. yes, that's what happens when you edit something instead of typing it over from scratch :-) -- - Justin -- http://mail.python.org/mailman

Re: Python newbie needs constructive suggestions

2006-07-21 Thread Justin Azoff
[EMAIL PROTECTED] wrote: What is the idiomatically appropriate Python way to pass, as a function-type parameter, code that is most clearly written with a local variable? For example, map takes a function-type parameter: map(lambda x: x+1, [5, 17, 49.5]) What if, instead of just having

Re: Nested function scope problem

2006-07-21 Thread Justin Azoff
Simon Forman wrote: That third option seems to work fine. Well it does, but there are still many things wrong with it if len(tok) 0: should be written as if(tok): tok = '' tok = toc + c should be written as tok = [] tok.append(c) and later ''.join(toc) anyway, the

Re: Dictionary question

2006-07-18 Thread Justin Azoff
Brian Elmegaard wrote: for a, e in l[-2].iteritems(): # Can this be written better? if a+c in l[-1]: if l[-1][a+c]x+e: l[-1][a+c]=x+e else: l[-1][a+c]=x+e # I'd start with something like for a, e in l[-2].iteritems(): keytotal =

Re: Howto Determine mimetype without the file name extension?

2006-07-18 Thread Justin Azoff
Phoe6 wrote: Hi all, I had a filesystem crash and when I retrieved the data back the files had random names without extension. I decided to write a script to determine the file extension and create a newfile with extension. [...] but the problem with using file was it recognized

Re: compiling 2.3.5 on ubuntu

2006-07-17 Thread Justin Azoff
Steve Holden wrote: I'm quessing because (s)he wants to test programs on less recent versions of Python. Ubuntu 5.10 was already up to Python 2.4.2, so I can't imagine there's anything older on Ubuntu 6.06. regards Steve Both are avaiaible... -- - Justin --

RFC: my iterthreader module

2006-07-17 Thread Justin Azoff
I have this iterthreader module that I've been working on for a while now. It is similar to itertools.imap, but it calls each function in its own thread and uses Queues for moving the data around. A better name for it would probably be ithreadmap, but anyway... The short explanation of it is if

Re: compiling 2.3.5 on ubuntu

2006-07-16 Thread Justin Azoff
Py PY wrote: (Apologies if this appears twice. I posted it yesterday and it was held due to a 'suspicious header') I'm having a hard time trying to get a couple of tests to pass when compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's not too far removed from the desktop

Re: Deferred imports

2006-07-14 Thread Justin Azoff
Tom Plunket wrote: I'm using this package that I can't import on startup, instead needing to wait until some initialization takes place so I can set other things up so that I can subsequently import the package and have the startup needs of that package met. [...] So as y'all might guess, I

Re: String handling and the percent operator

2006-07-13 Thread Justin Azoff
Tom Plunket wrote: boilerplate = \ [big string] return boilerplate % ((module,) * 3) My question is, I don't like hardcoding the number of times that the module name should be repeated in the two return functions. Is there an straight forward (inline-appropriate) way to

Re: Regular Expression problem

2006-07-13 Thread Justin Azoff
John Blogger wrote: That I want a particular tag value of one of my HTML files. ie: I want only the value after 'href=' in the tag 'link href=mystylesheet.css rel=stylesheet type=text/css' here it would be 'mystylesheet.css'. I used the following regex to get this value(I dont know if it

Re: Regular Expression problem

2006-07-13 Thread Justin Azoff
Justin Azoff wrote: from BeautifulSoup import BeautifulSoup html='link href=mystylesheet.css rel=stylesheet type=text/css' page=BeautifulSoup(html) page.link.get('href') 'mystylesheet.css' On second thought, you will probably want something like [link.get('href') for link in page.fetch

Re: how can I avoid abusing lists?

2006-07-07 Thread Justin Azoff
Thomas Nelson wrote: This is exactly what I want to do: every time I encounter this kind of value in my code, increment the appropriate type by one. Then I'd like to go back and find out how many of each type there were. This way I've written seems simple enough and effective, but it's very

Re: Built-in Exceptions - How to Find Out Possible Errno's

2006-07-05 Thread Justin Azoff
Gregory Piñero wrote: Hi Guys, I'm sure this is documented somewhere, I just can't locate it. Say I have this code: try: myfile=file('greg.txt','r') except IOError, error: [...] So basically I'm looking for the document that tells me what possible errors I can catch and their

Re: smtplib problem for newbie

2006-06-22 Thread Justin Azoff
Noah Gift wrote: [snip] a = long(time.time() * 256) # use fractional seconds TypeError: 'module' object is not callable Part of your program includes a file or directory that you called 'long'. You should not re-use names of built-ins in your programs.. they cause you to get errors like

Re: Python to PHP Login System (HTTP Post)

2006-06-22 Thread Justin Azoff
Jeethu Rao wrote: You need to use httplib. http://docs.python.org/lib/httplib-examples.html Jeethu Rao Not at all. They need to read the documentation for urrlib: http://docs.python.org/lib/module-urllib.html http://docs.python.org/lib/node483.html The following example uses the POST method

Re: newb: comapring two strings

2006-05-18 Thread Justin Azoff
manstey wrote: Hi, Is there a clever way to see if two strings of the same length vary by only one character, and what the character is in both strings. E.g. str1=yaqtil str2=yaqtel they differ at str1[4] and the difference is ('i','e') something like this maybe? str1='yaqtil'

Re: best way to determine sequence ordering?

2006-04-29 Thread Justin Azoff
John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something like: if L.index('A')

Re: a simple regex question

2006-03-31 Thread Justin Azoff
John Salerno wrote: Ok, I'm stuck on another Python challenge question. Apparently what you have to do is search through a huge group of characters and find a single lowercase character that has exactly three uppercase characters on either side of it. Here's what I have so far: pattern =

Re: Counting number of each item in a list.

2006-03-19 Thread Justin Azoff
Bruno Desthuilliers wrote: And of course, I was right. My solution seems to be faster than Paul's one (but slower than bearophile's), be it on small, medium or large lists. Your version is only fast on lists with a very small number of unique elements. changing mklist to have items = range(64)

Re: general coding issues - coding style...

2006-02-18 Thread Justin Azoff
Dylan Moreland wrote: I would look into one of the many Vim scripts which automatically fold most large blocks without the ugly {{{. Who needs a script? set foldmethod=indent works pretty well for most python programs. -- http://mail.python.org/mailman/listinfo/python-list

Re: append to the end of a dictionary

2006-01-25 Thread Justin Azoff
Magnus Lycka wrote: orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())] orderedListOfTuples = sorted(mydict.items()) It's great that many people try to help out on comp.lang.python, the community won't survive otherwise, but I think it's important to test answers before

Re: Multiway Branching

2006-01-09 Thread Justin Azoff
[EMAIL PROTECTED] wrote: I need to look at two-byte pairs coming from a machine, and interpret the meaning based on the relative values of the two bytes. In C I'd use a switch statement. Python doesn't have such a branching statement. I have 21 comparisons to make, and that many if/elif/else

Re: Multiway Branching

2006-01-09 Thread Justin Azoff
[EMAIL PROTECTED] wrote: I need to look at two-byte pairs coming from a machine, and interpret the meaning based on the relative values of the two bytes. In C I'd use a switch statement. Python doesn't have such a branching statement. I have 21 comparisons to make, and that many if/elif/else

Re: Number set type

2005-12-28 Thread Justin Azoff
You could use IPy... http://svn.23.nu/svn/repos/IPy/trunk/IPy.py is one location for it... I wonder where you get O(n) and O(n^2) from... CIDR blocks are all sequential.. All you need to store is the starting and ending address or length. Then any set operation only has to deal with 4 numbers,

Re: Number set type

2005-12-28 Thread Justin Azoff
Heiko Wundram wrote: Union of two IP4Ranges is simply normalizing a concatenated list of both IP4Range ranges. Normalizing takes O(log n)+O(n) = O(n) steps, where n is the number of ranges in the combined IP4Range. I see now :-) If the ranges are sorted, I bet you could just iterate through

Re: Number set type

2005-12-28 Thread Justin Azoff
Justin Azoff wrote: Yes.. if they are sorted, something like this should work: Oops, that was almost right, but it would skip some ranges. This should always work: ... while 1: try : if a.intersects(b): ret.append(a.intersection(b

Re: python coding contest

2005-12-27 Thread Justin Azoff
Tim Hochberg wrote: Note that in principle it's possible to encode the data for how to display a digit in one byte. Thus it's at least theoretically possible to condense all of the information about the string into a string that's 10 bytes long. In practice it turns out to be hard to do that,

Re: python coding contest

2005-12-26 Thread Justin Azoff
Tim Hochberg wrote: In the 130's is definately possible, but I haven't heard of anyone doing better than that. I have a version that is 127, but only if you strip extra whitespace :-( -- - Justin -- http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2005-12-25 Thread Justin Azoff
c=open(seven_seg.py).read() len(c) 251 len(c.replace( ,)) 152 :-) Knowing me, I'll forget to submit it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Some simple performace tests (long)

2005-08-06 Thread Justin Azoff
How much ram does your machine have? the main point is except when a very large range is used on a memory-starved machine run x = range(10 ** 6) and look at the memory usage of python.. what happens when you run this program: import time def t(func, num): s = time.time() for x in