Vim capable IDE?

2005-10-17 Thread Chris Lasher
Hello,
  Is there a Python-sensitive, Linux compatible IDE out there with
standard bells and whistles (source browser, symbolic debugger, etc.)
but with the action-per-keystroke editing capabilities of Vim? I have
failed to turn up such an IDE in my Googling and IDE project-page
browsing. :-(

Thanks very much in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vim capable IDE?

2005-10-18 Thread Chris Lasher
Thanks for your responses, guys. I can't get the PIDA page to come up
for me; server timeout error. I'll have to look into Eclipse more, but
I've been warned that it's resource greedy and that the VI plugin
doesn't provide very much functionality. Still, that's hearsay, so I'll
have to find out for myself.

I would have figured Vim or VI editing behavior would be a lot more
prevalent in IDEs but it seems to be quite rare. I don't understand
that, because a lot of people seem to use IDEs, and a lot of people
seem to use VI/Vim or Emacs. Is it the young guns that are tied to the
IDEs, never knowing powerful text-editors exist, and old dogs sticking
to their favorite editors, not giving in to all those "distracting"
bells and whistles of IDEs? What's the deal? A marriage of the two
would seem like the best of both worlds.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vim capable IDE?

2005-10-18 Thread Chris Lasher
Thanks again for your responses, guys. To answer the question,the
features I'd love to see in a Python IDE are:

* First and foremost, Vim editing behavior. Let me keep my fingers on
the homerow. I'm lazy. Point and click and CTRL + SHIFT has its
moments, but text editing is not one of them.

* Graphical symbolic debugger: the course I'm auditing, Software
Carpentry, by Greg Wilson of University of Toronto, devoted a whole
lecture to debuggers. See
http://www.third-bit.com/swc/www/debugging.html . So now I want to try
this crazy thing. I love the idea of being able to watch the values of
variables change in "realtime" as the program runs, from the
convenience of a little side window. I also love the concept of not
having to insert debugging code into the production code--just a click
in the left column and you set the debugging command. Keep the
production code clean by putting the debugging commands outside the
program.

* Source browser: the ability to jump back and forth between specific
blocks of code very quickly, and to see the overall layout of the file
in terms of classes, methods, functions, etc. I want the big picture in
a side window to keep me on task and remind me of how far I've come
when I start feeling bogged down in details.

* Autocompletion: PythonWin by ActiveState has nice autocompletion.
When I import a module, it can dive down into those namespaces and
allow autocompletion on them. That's a nice, productive feature.

* Usage tips/tooltips: Also something I found in PythonWin. During the
writing of the method, a little tip box pops up advising me what the
inputs are for a method or an instance construction for a class. Very
nice, very productive.

* Linux compatibility: Nothing against Microsoft, or Apple, I just like
to use a Linux box more.

It seems like the IDEs I've looked at have most of the features, but
none do Vim. Crazy.

I agree that you can do all your coding using just Vim. That's how I've
been doing it. But following along with Greg Wilson's Software
Carpentry has made me realize that I could be more productive using the
additional, apparently now-standard tools of a good IDE. I just don't
want to sacrifice productivity in in keystrokes. It just seems like a
compromise programmers shouldn't have to make.

the other Chris

Chris Lambacher wrote:
> I would second that.  I use Vim for editing.  I find I don't need an IDE (not
> even for C/C++).  Vim does everything I need.  If I want a debugger I will use
> the shell debugger.  Most other things can be added to Vim, though I tend to
> run with very few plugins.
>
> -Chris
>
>
> On Tue, Oct 18, 2005 at 05:12:30PM +, Ron Adam wrote:
> > What features are you looking for.  I think most Vim users just add what
> > they want to Vim.
> >

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vim IS a capable IDE [was Re: Vim capable IDE?]

2005-10-19 Thread Chris Lasher
Thanks for the replies, guys! I had no idea Vim was capable of doing
some of those things. The source browser in Vim is slick--I never would
have known about that. As far as the GDB goes, it doesn't look like it
has support for Python, but it's nice to know it's there for C if I get
the chance to learn that language. Where do you guys go to learn all
the capabilities of Vim? Just browsing through vim.org?

The PIDA site is back up and running. It looks like a real winner! I'll
have to download it and give it a whirl.

Thanks again,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


What strategy for random accession of records in massive FASTA file?

2005-01-12 Thread Chris Lasher
Hello,
I have a rather large (100+ MB) FASTA file from which I need to
access records in a random order. The FASTA format is a standard format
for storing molecular biological sequences. Each record contains a
header line for describing the sequence that begins with a '>'
(right-angle bracket) followed by lines that contain the actual
sequence data. Three example FASTA records are below:

>CW127_A01
TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
GCATTAAACAT
>CW127_A02
TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
GCATTAAACATTCCGCCTAGTACGGTCGCAAGATTCTCAAAGGAATAGACGG
>CW127_A03
TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
GCATTAAACATTCCGCCTGGG
...

Since the file I'm working with contains tens of thousands of these
records, I believe I need to find a way to hash this file such that I
can retrieve the respective sequence more quickly than I could by
parsing through the file request-by-request. However, I'm very new to
Python and am still very low on the learning curve for programming and
algorithms in general; while I'm certain there are ubiquitous
algorithms for this type of problem, I don't know what they are or
where to look for them. So I turn to the gurus and accost you for help
once again. :-) If you could help me figure out how to code a solution
that won't be a resource whore, I'd be _very_ grateful. (I'd prefer to
keep it in Python only, even though I know interaction with a
relational database would provide the fastest method--the group I'm
trying to write this for does not have access to a RDBMS.)
Thanks very much in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
>Before you get too carried away, how often do you want to do this and
>how grunty is the box you will be running on?

Oops, I should have specified this. The script will only need to be run
once every three or four months, when the sequences are updated. I'll
be running it on boxes that are 3GHz/100GB Ram, but others may not be
so fortunate, and so I'd like to keep that in mind.

>BTW, you need to clarify "don't have access to an RDBMS" ... surely
>this can only be due to someone stopping them from installing good
>free software freely available on the Internet.

I understand your and others' sentiment on this. I agree, the
open-source database systems are wonderful. However, keeping it
Python-only saves me hassle by only having to assist in instances where
others need help downloading and installing Python. I suppose if I keep
it in Python, I can even use Py2exe to generate an executable that
wouldn't even require them to install Python. A solution using
interaction with a database is much sexier, but, for the purposes of
the script, seems unnecesary. However, I certainly appreciate the
suggestions.

>My guess is that you don't need anything much fancier than the
>effbot's index method -- which by now you have probably found works
>straight out of the box and is more than fast enough for your needs.

I think Mr. Lundh's code will work very well for these purposes. Thanks
very much to him for posting it. Many thanks for posting that! You'll
have full credit for that part of the code. Thanks very much to all who
replied!

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
Thanks for your reply, Larry. I thought about this, but I'm worried the
dictionary will consume a lot of resources. I think my 3GHz/1GB RAM box
could handle the load fine, but I'm not sure about others' systems.
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
>Others have probably solved your basic problem, or pointed
>the way. I'm just curious.

>Given that the information content is 2 bits per character
>that is taking up 8 bits of storage, there must be a good reason
>for storing and/or transmitting them this way? I.e., it it easy
>to think up a count-prefixed compressed format packing 4:1 in
>subsequent data bytes (except for the last byte which have
>less than 4 2-bit codes).

My guess for the inefficiency in storage size is because it is
human-readable, and because most in-silico molecular biology is just a
bunch of fancy string algorithms. This is my limited view of these
things at least.

>I'm wondering how the data is actually used once records are
>retrieved.

This one I can answer. For my purposes, I'm just organizing the
sequences at hand, but there are all sorts of things one could actually
do with sequences: alignments, BLAST searches, gene annotations, etc.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
>And besides, for long-term archiving purposes, I'd expect that zip et
>al on a character-stream would provide significantly better
>compression than a 4:1 packed format, and that zipping the packed
>format wouldn't be all that much more efficient than zipping the
>character stream.

This 105MB FASTA file is 8.3 MB gzip-ed.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Chris Lasher
Forgive my ignorance, but what does using mmap do for the script? My
guess is that it improves performance, but I'm not sure how. I read the
module documentation and the module appears to be a way to read out
information from memory (RAM maybe?).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-15 Thread Chris Lasher
Roy, thank you for your reply. I have BioPython installed on my box at
work and have been browsing through the code in there, some of which I
can follow, and most of which will take more time and experience for me
to do so. I have considered BioPython and databases, and have chosen to
forego those routes for the reasons above, here summarized: this script
has a limited scope of what I hope it will acheive, and it should be as
convenient as possible for the end-user to execute it (even at the
expense of convenience to me as the coder). Again, thanks for your
input, though. It's very helpful to me to be able to learn from other
perspectives that I wouldn't have seen from, myself.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unfortunate newbie questions!

2005-09-13 Thread Chris Lasher
I would have to say that never having done any OO programming before in
my life, I found _Learning_Python_ by Lutz & Ascher had a great couple
of chapters on it. The diagrams about inheritance and subclassing
really helped a lot and they describe the purpose of using OOP quite
well. I see you already have that book, so perhaps you are not far
enough into it yet to hit those chapters. I think they did a great job
getting me off to a good start.

For a follow-up book, I second the recommendation of Mark Hammond's
_Dive_Into_Python_, which is mentioned above. It's a wonderful way to
learn by example. I absolutely ate up the chapters about Unit Testing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Conversion to string: how do `s work?

2005-03-14 Thread Chris Lasher
I'm working my way through _Learning_Python_ 2nd ed., and I saw
something peculiar which is not explained anywhere in the text.

print " " + file + " size=" + `size`

The `s appear to somehow automagically convert the integer to a string
for concatenation. How does this work? Is this just a shortcut for
str(size)? Is it considered bad practice to use `s?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conversion to string: how do `s work?

2005-03-14 Thread Chris Lasher
Ah, repr. Did not cross my mind. Good to see my suspicions about the
use of ` being poor practice were correct. "Explicit is better than
implicit."

Thanks for the reply.

-- 
http://mail.python.org/mailman/listinfo/python-list


Difficulties POSTing to RDP Hierarchy Browse Page

2004-12-03 Thread Chris Lasher
Hello,
  I'm trying to write a tool to scrape through some of the Ribosomal
Database Project II's (http://rdp.cme.msu.edu/) pages, specifically,
through the Hierarchy Browser. (http://rdp.cme.msu.edu/hierarchy/)
  The Hierarchy Browser is accessed first through a page with a form.
There are four fields with several options to be chosen from (Strain,
Source, Size, and Taxonomy) and then a submit button labeled "Browse".
The HTML of the form is as follows (note, I am also including the
Javascript code, as it is called by the submit button):

excerpted HTML


function resetHiddenVar(){
var f_form = document.forms['hierarchyForm']; 
f_form.action= "HierarchyControllerServlet/start";
return ;
}




 

Hierarchy Browser - Start[ help ]

 

 

  
  


Strain:

 Type

Non Type 

Both 



Source:

 Uncultured 

 Isolates

 Both



Size:

 >1200

 <1200

 Both



Taxonomy:

 Bergey's

 NCBI

  

   
  









--end excerpted HTML--


The options I would like to simulate are browsing by strain=type,
source=both, size = gt1200, and taxonomy = bergeys. I see that the
form method is POST, and I read through the urllib documentation, and
saw that the syntax for POSTing is urllib.urlopen(url, data). Since
the submit button calls HierarchyControllerServlet/start (see the
Javascript), I figure that the url I should be contacting is
http://rdp.cme.msu.edu/hierarchy/HierarchyControllerServlet/start
Thus, I came up with the following test code:

Python test code---
#!/usr/bin/python

import urllib

options = [("strain", "type"), ("source", "both"),
   ("size", "gt1200"), ("taxonomy", "bergeys"),
   ("browse", "Browse")]

params = urllib.urlencode(options)

rdpbrowsepage = urllib.urlopen(
"http://rdp.cme.msu.edu/hierarchy/HierarchyControllerServlet/start";,
params)

pagehtml = rdpbrowsepage.read()

print pagehtml
-end Python test code--


However, the page that is returned is an error page that says the
request could not be completed. The correct page should show various
bacterial taxonomies, which are clickable to reveal greater detail of
that particular taxon.

I'm a bit stumped, and admittedly, I am in over my head on the subject
matter of networking and web-clients. Perhaps I should be using the
httplib module for connecting to the RDP instead, but I am unsure what
methods I need to use to do this. This is complicated by the fact that
these are JSP generated pages and I'm unsure what exactly the server
requires before giving up the desired page. For instance, there's a
jsessionid that's given and I'm unsure if this is required to access
pages, and if it is, how to place it in POST requests.

If anyone has suggestions, I would greatly appreciate them. If any
more information is needed that I haven't provided, please let me know
and I'll be happy to give what I am able. Thanks very, very much in
advance.

Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Possible to insert variables into regular expressions?

2004-12-09 Thread Chris Lasher
Hello,
I would like to create a set of very similar regular expression. In
my initial thought, I'd hoped to create a regular expression with a
variable inside of it that I could simply pass a string into by
defining this variable elsewhere in my module/function/class where I
compile the regular expression, thus making for an easy substitution.
However, still after JFGI'ing, I still cannot find the syntax to place
a variable inside a regular expression in Python. Is such a thing
possible, and if so what is the syntax to do it? If this is not
possible, what would be the Python way of swapping a small part of the
insides of a regexp without having to copy and paste the code to create
as many variations as necessary?

To make this more concrete, I think an example is in order. Let's say
I have a document like this

The Beatles
Rubber Soul
Track Listings
1. Drive My Car
2. Norwegian Wood (This Bird Has Flown)
3. You Won't See Me
4. Nowhere Man
5. Think for Yourself
6. Word
7. Michelle
8. What Goes On
9. Girl
10. I'm Looking Through You
11. In My Life
12. Wait
13. If I Needed Someone
14. Run for Your Life
Original Release Date: December 3, 1965
Number of Discs: 1
Label: Capitol
...

and I want to look for tracks that contain 'oo'. Then, maybe later, I
want to look for 'ee', or maybe 'ou'. All the regular expressions would
start by searching for a digit at the beginning of the line, and they
would allow for characters up until the desired two-letter vowel
combination, and then search for the two-letter vowel combination. How
can I provide for a way to "drop-in" the two-letter combination I want?
Thanks very much for your help and assistance in advance.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible to insert variables into regular expressions?

2004-12-09 Thread Chris Lasher
Thanks for the reply, Steve! That ought to work quite nicely! For some
reason, I hadn't thought of using %-formatting. I probably should have,
but I'm still learning Python and re-learning programming in general.
This helps a lot, so thanks again.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible to insert variables into regular expressions?

2004-12-10 Thread Chris Lasher
Robert, Craig, thanks for your replies.  I'll only be dealing with
alphanumerics for this project, I think, but it's good to be aware of
this possible problem for later projects. The re.escape(...) is a handy
method to know about. Thanks very much.

-- 
http://mail.python.org/mailman/listinfo/python-list


Troubleshooting: re.finditer() creates object even when no match found

2004-12-17 Thread Chris Lasher
Hello,
I really like the finditer() method of the re module. I'm having
difficulty at the moment, however, because finditer() still creates a
callable-iterator oject, even when no match is found. This is
undesirable in cases where I would like to circumvent execution of code
meant to parse out data from my finditer() object.

I know that if I place a finditer() object in an iterative for loop,
the loop will not execute, but is there some way I can test to see if
the object contains no matches in the first place? I thought about
using .next() but I don't want to lose the ability to process the first
(sometimes only) match in the finditer() object.
Thanks in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Troubleshooting: re.finditer() creates object even when no match found

2004-12-17 Thread Chris Lasher
Thanks Steve,
That's odd that there's no built-in method to do this. It seems like
it would be a common task. Is there any way to request a feature like
this from the RE module keepers, whomever they may be?
In the meantime, may I use your code, with accredation to you?
Thanks,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie with some doubts.

2006-01-05 Thread Chris Lasher
Learning Python by Ascher and Lutz has a very good introduction to
objects and object-oriented programming. If you're new to programming,
I definitely recommend the text. Also, check out Mark Pilgrim's chapter
on OOP in Dive Into Python at
http://www.diveintopython.org/object_oriented_framework/index.html
(Incidentally, Dive Into Python is my favorite programming book,
tremendously well written, and free to read online at
http://www.diveintopython.org. I loved the book so much I went out to
the bookstore and bought a copy.)

-- 
http://mail.python.org/mailman/listinfo/python-list


Duplicate entries in a matrix

2006-01-18 Thread Chris Lasher
Hello Pythonistas!
  I'm looking for a way to duplicate entries in a symmetrical matrix
that's composed of genetic distances. For example, suppose I have a
matrix like the following:

  ABC
A 0.00 0.50 1.00
B 0.50 0.00 0.50
C 1.00 0.50 0.00

Say I want to duplicate entry B; the resulting matrix would look like:

  ABBC
A 0.00 0.50 0.50 1.00
B 0.50 0.00 0.00 0.50
B 0.50 0.00 0.00 0.50
C 1.00 0.50 0.50 0.00

The cases I'd like to do this for are more complicated, naturally,
where I want to duplicate different entries different numbers of times.
I'm aware of Numeric, Numarray, and NumPy, though I've not used any of
them, but I am not sure if any of them possess a simple means to
duplicate entries in a matrix. I started writing code on my own but I
can see it is becoming exponentially more complex, and before I proceed
any further, I want to make sure I'm not reinventing any wheels. If
anyone here has any advice on how to manipulate matrices in this
manner, I'd _greatly_ appreciate it!

Thanks in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Duplicate entries in a matrix

2006-01-19 Thread Chris Lasher
Hey Gerard,

Thanks for the suggestion! It took me a while to figure out how to get
this to work. Two things were important: I needed to use the
matrixmultiply() function, and the order of the two matrices being
multiplied is critcial. Here's how I got the example to work.

>>> from Numeric import *
>>> array1 = array([[0.00, 0.50, 1.00],
... [0.50, 0.00, 0.50],
... [1.00, 0.50, 0.00]])
>>> array1
array([[ 0. ,  0.5,  1. ],
   [ 0.5,  0. ,  0.5],
   [ 1. ,  0.5,  0. ]])
>>> premul = array([[1, 0, 0], [0, 1, 0], [0, 1, 0], [0, 0, 1]])
>>> premul
array([[1, 0, 0],
   [0, 1, 0],
   [0, 1, 0],
   [0, 0, 1]])
>>> res1 = matrixmultiply(premul, array1)
>>> res1
array([[ 0. ,  0.5,  1. ],
   [ 0.5,  0. ,  0.5],
   [ 0.5,  0. ,  0.5],
   [ 1. ,  0.5,  0. ]])
>>> postmul = array([[1, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]])
>>> postmul
array([[1, 0, 0, 0],
   [0, 1, 1, 0],
   [0, 0, 0, 1]])
>>> array2 = matrixmultiply(res1, postmul)
>>> array2
array([[ 0. ,  0.5,  0.5,  1. ],
   [ 0.5,  0. ,  0. ,  0.5],
   [ 0.5,  0. ,  0. ,  0.5],
   [ 1. ,  0.5,  0.5,  0. ]])

Now I have to figure out how to expand this concept to more complex
cases, and how to generate appropriate pre- and post-multiply
matrices... Hmm...

Thanks so much for getting me started,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Duplicate entries in a matrix

2006-01-19 Thread Chris Lasher
Now that's definitely what I'm looking for! Thanks!

By the way, was this line

In [5]: C = repeat(B, [1,2,1], axis=-1)

supposed to have a positive 1 value for axis? It works either way, I
see. Is it like a lookup, where an index of -1 returns the last value?
If that were true, I supposed the evaluation would be 1, and thus gives
the same result.

Thanks again, very much. You guys are super-helpful!

-- 
http://mail.python.org/mailman/listinfo/python-list


Regular expression for not-group

2006-06-15 Thread Chris Lasher
Is it possible to write a regular expression such that a "match" is
found provided the string does not match a group in the regex? Let me
give a concrete example.

Suppose I want to find a match to any filename that does not end in
.py, (ignoring the obvious use of the .endswith('.py') string method).
I tried the things that were obvious to me, none of which worked.

\.^(py)
\.(^py)
\.[^p][^y]

The last one deceived me at first because it will match "spam.spam",
but not "spam.parrot". I'm a bit stumped at this point. If this can be
done with a regular expression, I'd love to know how, and even if it
can't be, that would be very helpful to know, too.

Many thanks in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression for not-group

2006-06-15 Thread Chris Lasher
Man, that's a headslap-worthy overlooking of the obvious. Ha! =-)

I was using the redemo.py that comes standard with Python but that
Kodos app looks even neater! Thanks for the tip. Thanks Paddy.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Interacting with keyboard LEDs

2006-12-08 Thread Chris Lasher
Is there a way to interact with keyboard LEDs (for Caps/Scroll/Num
Lock) in Python? I'd like to achieve an effect similar to the *NIX
command "setleds -L", but I'm not sure where to start, but I figured
someone out there would have an idea or maybe experience with something
similar. Thanks very much in advance for your help!

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interacting with keyboard LEDs

2006-12-09 Thread Chris Lasher
Jonathan Curran wrote:
> Spur of the moment answer: call setleds program from within your program
>
> better answer (fox X11):
> http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html
>
> Take a look at get_keyboard_control() and change_keyboard_control(). As far as
> knowing how to properly invoke them, I have no idea, maybe you could google
> for examples or take a look at the setleds source?
>
> - Jonathan

Thanks for your reply, Jonathan. The difficulty with setleds is that
only works from a virtual console (e.g., tty, CTRL+ALT+F1 through F6,
etc.), not from a terminal emulator inside X (e.g., pts, Xterm, Gnome
Terminal, Konsole, etc.), which is the environment where I'd like to
interact with the LEDs. The xlib package looks promising, though. One
thing I don't understand is the 32-bit mask. How does this represent
the LED states? I profess my ignorance.

Thanks!
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mining strings from a HTML document.

2006-01-25 Thread Chris Lasher
I think Jay's advice is solid: you shouldn't rule out HTML parsing.
It's not too scary and it's probably not overboard. Using a common HTML
parsing library saves you from having to write and debug your own
parser. Try looking at Dive Into Python's chapter on it, first.
http://www.diveintopython.org/html_processing/index.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope/Plone - Is it the right solution?

2006-02-21 Thread Chris Lasher
You may want to look at either of the popular frameworks, TurboGears
http://www.turbogears.org/ or Django http://www.djangoproject.com/

I have very little experience with both, but I decided to try learning
the Django framework after watching the Snakes and Rubies videos. (See
http://www.djangoproject.com/snakesandrubies/ ) I am working my way
through the Django tutorials and am very impressed and looking forward
to deploying it on my own site. The admin interface that you get
basically "free" is a very slick touch, especially with all the
widgets. My recommendation is to check out Django's admin interface
(see Adrian Holovaty's presentation of Django in Snakes and Rubies and
http://www.djangoproject.com/documentation/tutorial2/ ) and see if that
won't do the trick for allowing easy content contribution without the
contributors having to know any of the Python, HTML, or CSS behind the
pages.

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Priority Queue with Mutable Elements

2007-06-15 Thread Chris Lasher
Hello,

I am working with large graphs (~150,000 to 500,000 nodes) which I
need decompose node-by-node, in order of a node's value. A node's
value is determined by the sum of its edge weights. When a node is
removed from the graph, its neighbors' values must be updated to take
into account the removed edges.

I was told to look for a priority queue in Python. I had a look at the
heapq module. It looks like it supports ordering on insertion, but I'm
unsure how to update the queue once a node's value changes.
Additionally, I need the queue to be sorted on a particular attribute
of the node objects, and don't see a way to do that other than
override the __cmp__ method. Should I just use a list and use .sort()
or sorted()? That seems like it could be horribly inefficient.

I found Andrew Snare's PQueue extension module [1] , which supports
updating values in the priority queue by reassignment. It appeared to
be broken in Python2.5 [2] but I found the offending line (a call to
PyMem_DEL) and changed it (to PyObject_FREE) and it appears to be
working fine. I would prefer to limit external depedencies for my
modules, however.

Many thanks for your insight and advice,
Chris

[1] http://py.vaults.ca/apyllo.py/514463245.769244789.44776582
[2] http://tinyurl.com/363dg9 or 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Priority Queue with Mutable Elements

2007-06-16 Thread Chris Lasher
On Jun 15, 5:52 pm, Josiah Carlson <[EMAIL PROTECTED]>
wrote:
> See this implementation of a "pair heap":
>http://mail.python.org/pipermail/python-dev/2006-November/069845.html
> ...which offers the ability to update the 'priority' of an entry in the
> heap.  It requires that the 'value' in (priority, value) pairs be unique
> (to the heap) and hashable.
>
>   - Josiah

Hmm. I won't be able to use that heap, as I can guarantee that the
value will be identical for two nodes when they have edges to each
other and no other nodes. Any suggestions on structures that can
accompany identical priority values?

Thanks,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


How to list current line in pdb?

2007-03-23 Thread Chris Lasher
Hi all,

Using the pdb shell, after repeatedly entering 'l' (lowercase 'L'),
how do I jump back to listing the current line again if I don't
remember exactly what line my current line is? Do I just have to list
an early line in the code and repeatedly list from there until I see
the '->' indicating the current line?

Thanks,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to list current line in pdb?

2007-03-23 Thread Chris Lasher
On Mar 23, 11:56 am, Duncan Booth <[EMAIL PROTECTED]>
wrote:
> "Chris Lasher" <[EMAIL PROTECTED]> wrote:
> > Using the pdb shell, after repeatedly entering 'l' (lowercase 'L'),
> > how do I jump back to listing the current line again if I don't
> > remember exactly what line my current line is? Do I just have to list
> > an early line in the code and repeatedly list from there until I see
> > the '->' indicating the current line?
>
> Try:
>
> (Pdb) alias ll u;;d;;l
>
> and thereafter the 'll' command will list the current line (unless you are
> in the uppermost stack frame in which case it goes down one stackframe
> instead).
>
> Save the alias in your .pdbrc file.

Alright. Thanks, Duncan!

-- 
http://mail.python.org/mailman/listinfo/python-list


PDB does not allow jumping to first statement?

2007-03-26 Thread Chris Lasher
Hi all,

I have a simple script:

---
#!/usr/bin/env python

a = 1
b = 2

c = a + b

print c
---

I launch said script with pdb:

python -m pdb simple.py

I noticed that I absolutely cannot jump back to the first statement
(line 3, "a = 1") using the jump command. I can jump to any other line
BUT the first statement's using the "jump " command. I
experience the same behavior with Winpdb and rpdb2. Why is this?

Stumped,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: build python on Celeron D

2007-03-26 Thread Chris Lasher
On Mar 26, 10:48 pm, Christian <[EMAIL PROTECTED]> wrote:
> Traceback (most recent call last):
>   File "setup.py", line 89, in ?
> setup_package()
>   File "setup.py", line 59, in setup_package
> from numpy.distutils.core import setup
>   File "/mnt/home/ck/prog/scipy/numpy-1.0.1/numpy/__init__.py", line 36, in ?
>   File "numpy/core/__init__.py", line 5, in ?
> import multiarray
> ImportError:
> /media/hda6/home/ck/prog/scipy/numpy-1.0.1/numpy/core/multiarray.so: undefined
> symbol: Py_InitModule4
>
> which is related to 32<->64 issues, right?



Do you have more than one Python installation on this machine? The
link above indicates that if you build NumPy with a different build of
Python than you will run it from, you will get this same error.
Granted, I'm sure there are many ways to get said error, but that was
the most obvious from a five minute search.

Alternatively, if you haven't done so already, you may want to mail
the numpy-discussion list.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PDB does not allow jumping to first statement?

2007-03-27 Thread Chris Lasher
On Mar 27, 5:59 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I tried on GNU/Linux and Python versions 2.4 and 2.5 and get the same
> behavior. Best as I can tell, it looks like a bug in Python. pdb,
> pydb, rpdb2 all handle the "jump" command by changing the frame
> f_lineno value. When the corresponding code pointer has offset 0 (or
> equivalently and more simlply as you put it, is the first statement)
> this doesn't seem to work properly. But this also implies that all you
> need to do is add something as the first statement. A docstring
> comment, e.g.
> "this is what my program does..."
> comes to mind :-)

I started implementing this, but it's a hack. Looks like it's time for
me to file a bug report!

> Lastly, I'll mention that I what most folks want to do is not jump to
> the beginning of the program but rather *restart* it. The difference
> here as applied to your example is seen in the way variables (e.g. a,
> b, and c) are handled. In a "restart", those names would go back to
> being undefined and referring to them before assigning to them would
> cause a NameError exception. With "jump", they retain their existing
> values.

In the case I was working with, I really did want to "jump" and retain
the values, rather than restart and clear those values.

Just as an aside, Rocky, I really like your ShowMeDo on pydb. Thanks
for making that. (For those who haven't seen it, check out the
"Introducing the pydb Debugger" at )

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python automatic testing: mocking an imported module?

2007-03-27 Thread Chris Lasher
On Mar 27, 6:18 pm, "Silfheed" <[EMAIL PROTECTED]> wrote:
> Heyas
>
> So we have the following situation: we have a testee.py that we want
> to automatically test out and verifiy that it is worthy of being
> deployed.  We want our tester.py to test the code for testee.py
> without changing the code for testee.py.  testee.py has a module in it
> that we want to mock in some tests and in others use the real module.

I think you mean "testee.py *imports* a module", rather than "has a
module in it". Semantics but I was thrown off by this at first.

Why not write tests for the module that testee.py imports (here called
"foo.py")? If you write out the tests and foo.py passes to spec, then
you should feel confident it will work correctly with testee.py. Never
trust it; always play paranoid coder, but feel comfortable enough
using it.

After all, why should you feel comfortable using modules in the
standard library? Nobody guarantees bugs don't still lurk in there
(heck, c.l.p just found one in pdb today), however, they have unit
tests out the wazzoo that demonstrate, to the best of our knowledge,
the module works to spec. If that approach is good enough for the
standard library, wouldn't it be good enough for you?

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PDB does not allow jumping to first statement?

2007-03-28 Thread Chris Lasher
I have submitted this as a bug via SourceForge:

or if munged


The Python folks would like a test case and/or a patch. This is well
beyond my ken as a humble Python user. Could anybody more
knowledgeable please contribute one or both? Duncan or Rocky, would
you be able to spare time and effort?

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Why NOT only one class per file?

2007-04-04 Thread Chris Lasher
A friend of mine with a programming background in Java and Perl places
each class in its own separate file in . I informed him that keeping
all related classes together in a single file is more in the Python
idiom than one file per class. He asked why, and frankly, his valid
question has me flummoxed.

I tried to rationalize this Python idiom by claiming a file--a single
module--makes for a great container of code which is logically tied
together, such as a class and its subclasses. He posited that
directories (packages) can tie the files together just as well, and by
having the classes as separate files, he can "diff" them to see how
they differ, something he wouldn't be able to do with the code all in
one file.

I also offered that having related classes under one file gives more
direct access to those classes, e.g.:

--
file: foo.py
===
class Bar(object):
pass
===

file demo1.py
===
import foo

barinstance = foo.Bar()
===
--

versus

--
file: foopkg/bar.py
===
class Bar(object):
pass
===

file: demo2.py
===
import foopkg.bar

barinstance = foopkg.bar.Bar()
===
--

He doesn't find my arguments convincing, so I thought I'd ask here to
see why the Python idiom is the way it is: why should we NOT be
placing classes in their own separate files?

Thoughts, comments, and insight much appreciated,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why NOT only one class per file?

2007-04-08 Thread Chris Lasher
On Apr 4, 5:23 pm, "Chris Lasher" <[EMAIL PROTECTED]> wrote:
> A friend of mine with a programming background in Java and Perl places
> each class in its own separate file in . I informed him that keeping
> all related classes together in a single file is more in the Python
> idiom than one file per class. He asked why, and frankly, his valid
> question has me flummoxed.
>
> [snip]
>
> Thoughts, comments, and insight much appreciated,
> Chris

Thanks to all who replied and made this a very interesting and
informative discussion! It gave my friend, and myself, plenty to think
about.

Much appreciated,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Shebang or Hashbang for modules or not?

2007-04-11 Thread Chris Lasher
Should a Python module not intended to be executed have shebang/
hashbang (e.g., "#!/usr/bin/env python") or not? I'm used to having a
shebang in every .py file but I recently heard someone argue that
shebangs were only appropriate for Python code intended to be
executable (i.e., run from the command line).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - Python Newcomer Starting with Coding

2006-03-21 Thread Chris Lasher
And there's always Mark Pilgrim's very good and very free "Dive Into
Python".
http://www.diveintopython.org/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: years later DeprecationWarning

2006-03-22 Thread Chris Lasher
Two things:
1) math.floor returns a float, not an int. Doing an int() conversion on
a float already floors the value, anyways. Try replacing
math.floor(...) with int(...)
e.g.
>>> math.floor(5.9)
5.0
>>> int(5.9)
5

2) What kind of data is in f2m? If f2m is a float, you will get float
values in the expressions that f2m is a multiplicand.

-- 
http://mail.python.org/mailman/listinfo/python-list


Counting all permutations of a substring

2006-04-05 Thread Chris Lasher
Hi all,
How can one count all the permutations of a substring in a string? For
a more concrete example, let's say
targetstr = 'AAA'
and
probestr = 'AA'

I want to consider how many times one can count probestr ('AA') in
targetstr ('AAA'). The value in this example is, obviously, 2: you can
match the first and second A's as 'AA' and also the second and third
A's as 'AA'. Compiling a regular expression of the probestr and doing a
findall(targetstr) will not work because the RE stops on the first
combination of 'AA' that it finds (the first and second A's of the
targetstr). The regular expression re.compile(r'A{2,}'} will not work,
either; it simply consumes all three A's as one match. The string
method count('AA') acts similarly to the findall of the 'AA' RE,
returning 1, as it only matches the first and second A's.

Any suggestions on how to get at that 2nd pair of A's and count it?
Humbly, I'm a bit stumped. Any help would be appreciated.

Many thanks in advance,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting all permutations of a substring

2006-04-06 Thread Chris Lasher
Great suggestions, guys! Thanks so much!

And yes, I stand corrected. A better suited subject title would have
been "Counting all overlapping substrings".

Thanks again,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Regular expression intricacies: why do REs skip some matches?

2006-04-11 Thread Chris Lasher
Hey guys and gals,
This is a followup of my "Counting all permutations of a substring"
thread (see
http://groups.google.com/group/comp.lang.python/browse_thread/thread/60ebeb7ae381b0a9/7657235b3fd3966f#7657235b3fd3966f
in Google Groups) I'm still having a difficult time figuring out the
intricacies of regular expressions and consecutive matches. Here's a
brief example:

In [1]: import re

In [2]: aba_re = re.compile('aba')

In [3]: aba_re.findall('abababa')
Out[3]: ['aba', 'aba']

The return is two matches, whereas, I expected three. Why does this
regular expression work this way?

Using redemo.py, one can see that the matches are occurring at the
following spots:
abababa
^   ^   (where ^ indicates the start of a match)
Ideally, there'd be a way to create the regular expression to get at
this match, too:
abababa
  ^
So that the total matches are:
abababa
^ ^ ^

Is this simply not the way REs work? Does this sort of matching really
have to be home-coded?

Confusedly yours,
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression intricacies: why do REs skip some matches?

2006-04-12 Thread Chris Lasher
Diez, John, Tim, and Ben, thank you all so much. I now "get it". It
makes logical sense now that the difficulty was actually in the
implementation of findall, which does non-overlapping matches. It also
makes sense, now, that one can get around this by using a lookahead
assertion. Thanks a bunch, guys; this really helped!

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list