Language Semantics: @ symbol??

2006-01-29 Thread Enigma Curry
Sorry, for the noob question, but I haven't been able to find
documentation on this matter.

I've been looking for documentation that describes what the @function()
syntax is all about.

I've seen this on a few pages, for instance:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871

and also in TurboGears:

http://www.turbogears.com/docs/wiki20/page5.html

The general format appears to be:

@somefunction()
def a_newfunction():


What does it mean and what does it do?

Thanks!

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


Re: Language Semantics: @ symbol??

2006-01-29 Thread Enigma Curry
Awesome! Thanks.

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


In need of a virtual filesystem / archive

2006-02-20 Thread Enigma Curry
I need to store a large number of files in an archive. From Python, I
need to be able to create an archive, put files into it, modify files
that are already in it, and delete files already in it.

The easy solution would be to use a zip file or a tar file. Python has
good standard modules for accessing those types. However, I would tend
to think that modifying or deleting files in the archive would require
rewriting the entire archive.

Is there any archive format that can allow Python to modify a file in
the archive *in place*? That is to say if my archive is 2GB large and I
have a small text file in the archive I want to be able to modify that
small text file (or delete it) without having to rewrite the entire
archive to disk.

Does anything like this exist? If nothing exists for Python, is there
something written in C maybe that I could wrap (preferably you won't
suggest wrapping the ext2 filesystem driver..  ;) ?

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


Re: In need of a virtual filesystem / archive

2006-02-21 Thread Enigma Curry
Thanks for all the suggestions!

I realized a few minutes after I posted that a database would work.. I
just wasn't in that "mode" of thinking when I posted.

PyTables also looks very interesting, especially because apparently I
can read a file in the archive like a normal python file, ie one line
at a time.

Could I do the same using SQL? I'm assuming I would get the whole file
back when I did my SELECT statement. I guess I could chunk the file out
and store it in multiple rows, but that sounds complicated.

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


Re: Best way to handle exceptions with try/finally

2006-05-24 Thread Enigma Curry
We used to have a try..except..finally syntax in Python. It was taken
out a while ago for reasons unknown to me. The good news is that it is
back in Python 2.5.

I haven't tested it, but Guido said so himself:
http://video.google.com/videoplay?docid=60331183357868340

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


Re: beautiful soup library question

2006-03-10 Thread Enigma Curry
Here's how I print each line after the 's:

import BeautifulSoup as Soup
page=open("test.html").read()
soup=Soup.BeautifulSoup(page)
for br in soup.fetch('br'):
print br.next

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


Re: capturing stdout from lynx..

2006-03-10 Thread Enigma Curry
Does this do what you want?

import os
filename = "test.html"
cmd = os.popen("lynx -dump %s" % filename)
output = cmd.read()
cmd.close()
print output

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


Threads: does Thread.start() atomically set Thread.__started ?

2006-03-14 Thread Enigma Curry
Can some kind person please further my education on Threads?

When I create a thread called "t" and I do a "t.start()" am I
guaranteed that "t.isAlive()" will return True as long as the thread
hasn't already completed? Put another way, does "t.start()" ever return
before t.__started is set to True?

consider this example:

import time
import threading
class MyThread(threading.Thread):
def __init__(self):
self.completed = False
threading.Thread.__init__(self)
def run(self):
#do something
time.sleep(1)
self.completed = True

t = MyThread()
while t.isAlive() == False and t.completed == False:
t.start()

In the above code, am I guaranteed that t will only be (attempted to
be) started once?


Thanks,
Ryan

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


Re: Threads: does Thread.start() atomically set Thread.__started ?

2006-03-15 Thread Enigma Curry
Peter,

Thanks for the reference! I don't know why but for some reason I
thought that I would be wading through a bunch of C code (which I know
very little of). I haven't found my answer yet but this threading.py
does look fairly straightforward.

Thanks!

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


Re: Spidering Hacks for Python, not Perl

2006-03-20 Thread Enigma Curry
I've been looking for similar stuff recently. I haven't found much, but
this is the list of links I've come across so far:

Harvest Man - http://harvestman.freezope.org/
Mechanize - http://wwwsearch.sourceforge.net/mechanize/
Beautiful Soup - http://www.crummy.com/software/BeautifulSoup/
(Neither Beautiful Soup, nor Mechanize are complete crawlers but
probably have a lot of the nuts and bolts)

If anyone is aware of a book or other documentation like the OP would
like, I would be pleased to see it as well.

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


Re: years later DeprecationWarning

2006-03-22 Thread Enigma Curry
> (That long-gone guy is actually me, according to the notes in the program.
> However those brain cells are long gone now, so it might as well not be me.)

I had a great long laugh with this bit. I guess it's because I can
relate so well :)

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


Re: a hobbyist's dilemma

2006-03-29 Thread Enigma Curry
I would second the vote for pythonchallenge. It's what taught me
Python.

The amazing thing about the python challenge is by the time your done
with it, you've gotten through a very large and diverse sampling of the
python docs. It really gave me a good understanding of all the things
that Python can do.  You'll still want to read more traditional
tutorials and thoery as well, but that can wait, just play around with
it for a while.

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


Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
I'm playing around with matplotlib for the first time. I'm trying to
make a very simple histogram of values 1-6 and how many times they
occur in a sequence. However, after about an hour of searching I cannot
make the histogram stay within the bounds of the grid lines.

Here is my example:

pylab.grid()
x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
pylab.hist(x_values,6)
pylab.show()

This produced the following image:
http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines.png

Starting with bar number 2, it creeps into grid 1.. and finally with
bar number 5 it's almost entirely in grid 4.. how do I make the bars
stay in their own grid lines?

I can see that hist() is somehow derived from bar() ... so it appears
that hist() has some undocumented parameters. I tried specifiying
width=1 but that just squished all of the bars together.

Also, is there a more object-oriented graphing package for Python? (How
am I supposed to know that hist() is derived from bar() if the docs
don't show proper inheritance?)

Thanks!

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
Two things:

1) I now see where width is defined in the hist() documentation... I
was expecting it to be in the definition up at the top, but instead the
definition has **kwords.. not very helpful.

2) I noticed in my original historgram, that the y scale was not the
same as the x scale.. so I updated my code:

import pylab

pylab.grid()
x_values=[1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
pylab.hist(x_values,6)
pylab.yticks(pylab.arange(3))
pylab.axis('scaled')
pylab.show()


It produced this image:
http://enigmacurry.com/usenet/historgram-bars-not-in-grid-lines2.png

It has the same problem..

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
Thank you John. Your explanation helped a lot!

In case it helps anyone else in the future, here is my code for
*exactly* what I was after:

import pylab

def ryan_hist(data, bar_width, min_x, max_x):
"""
Create a frequency histogram over a continuous interval

min_x = the low end of the interval
max_x = the high end of the interval

bar_width = the width of the bars

This will correctly align the bars of the histogram
to the grid lines of the plot
"""
#Make histogram with bars of width .9 and center
#them on the integer values of the x-axis
bins = pylab.nx.arange(1-(bar_width/2),max(data))
n,bins,patches = pylab.hist(data, bins, width=bar_width)

#Make Y axis integers up to highest n
pylab.yticks(pylab.arange(sorted(n)[-1]))
pylab.axis('scaled')
pylab.xlim(0.5,6.5)
pylab.grid()
pylab.show()

#Create a historgram
data=[1,1,2,2,2,2,2,2,3,3,3,4,4,4,5,5,6,6,6]
bar_width = 0.9
ryan_hist(data,bar_width,min(data),max(data))

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


Re: Matplotlib: Histogram with bars inside grid lines...how??

2006-03-29 Thread Enigma Curry
pylab.xlim(0.5,6.5)

should be:

pylab.xlim(min_x-(bar_width/2),max_x+(bar_width/2))

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


Python based 'Toaster' animation like Gaim or MSN Messenger?

2006-04-08 Thread Enigma Curry
I'm looking for something that can display a pop-up "toaster" like
animation like Gaim or MSN messenger does to notify of incoming
messages.

There's JToaster ( http://jtoaster.sourceforge.net/ ) for Java...
anything similar for Python?

Thanks!

Ryan McGuire

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


Re: Python based 'Toaster' animation like Gaim or MSN Messenger?

2006-04-08 Thread Enigma Curry
Ok, cool! There's one for wxPython called ToasterBox (
http://wiki.wxpython.org/index.cgi/ToasterBox )

I'm more familiar with pyGTK.. so if anyone knows one based on pyGTK,
please let me know! :)

Ryan McGuire

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


Re: How's python's web scraping capabilities (vs LWP) ...

2006-04-08 Thread Enigma Curry
I don't know much about LWP.. but Beautiful Soup is grand!

http://www.crummy.com/software/BeautifulSoup/

Ryan McGuire

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