Re: [Tutor] Read same instance twice

2008-10-27 Thread Kent Johnson
On Mon, Oct 27, 2008 at 4:03 PM, Øyvind <[EMAIL PROTECTED]> wrote:
> Hello.
>
> I am trying to gather some information from a webpage:
>
> side = urlopen("http://www.website.no";)
> rawstr = r"""spy.target="_top">(.*?)$"""
> rawstr2 = r"""spy.target2="_top">(.*?)$"""
>
> compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
> | re.UNICODE)
> compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
> re.VERBOSE | re.UNICODE)
>
> liste = self.compile_obj.findall(side.read())
>
> liste = self.compile_obj2.findall(side.read())
>
> It works like a dream getting the first info, but the second doesn't work.
> The instance is empty.

> How can I easiest pick up more information from the site without opening
> it more than once?

Just remember the data. It's like reading a file, you can't read the
same file twice without re-opening, but you can remember the (string)
data from the file and use it however you want to:
data = side.read()
liste = self.compile_obj.findall(data)
liste2 = self.compile_obj2.findall(data)

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read same instance twice

2008-10-27 Thread Brian C. Lane
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Øyvind wrote:
> Hello.
> 
> I am trying to gather some information from a webpage:
> 
> side = urlopen("http://www.website.no";)
> rawstr = r"""spy.target="_top">(.*?)$"""
> rawstr2 = r"""spy.target2="_top">(.*?)$"""
> 
> compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
> | re.UNICODE)
> compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
> re.VERBOSE | re.UNICODE)
> 
> liste = self.compile_obj.findall(side.read())
> 
> liste = self.compile_obj2.findall(side.read())
> 
> It works like a dream getting the first info, but the second doesn't work.
> The instance is empty.
> 

That's because you read all of it and passed it to the first regex.

Change to:

side = urlopen("http://www.website.no";).read()

then:

liste = compile_obj.findall(side)
liste = compile_obj2.findall(side)

That reads the site's contents once, then you can do whatever you want
with it in your program. I'm not sure why you had the self. reference to
compile_obj, so mix to fit your circumstances :)

Brian

- --
- ---[Office 68.6F]--[Outside 54.2F]--[Server 100.6F]--[Coaster 69.6F]---
- ---[   LADY MARY (367013060) @ 47 36.3071 -122 23.1817]---
Software, Linux, Microcontrollers http://www.brianlane.com
AIS Parser SDKhttp://www.aisparser.com

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFJBi/UIftj/pcSws0RAjtiAJ45Sp++yj8jUhir6lwehLqRzBJswwCfREh7
J83jy1sN1xf8Gi+dWZs9GNM=
=8YQT
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Read same instance twice

2008-10-27 Thread Øyvind
Hello.

I am trying to gather some information from a webpage:

side = urlopen("http://www.website.no";)
rawstr = r"""spy.target="_top">(.*?)$"""
rawstr2 = r"""spy.target2="_top">(.*?)$"""

compile_obj = re.compile(rawstr,  re.IGNORECASE| re.MULTILINE| re.VERBOSE
| re.UNICODE)
compile_obj2 = re.compile(rawstr2,  re.IGNORECASE| re.MULTILINE|
re.VERBOSE | re.UNICODE)

liste = self.compile_obj.findall(side.read())

liste = self.compile_obj2.findall(side.read())

It works like a dream getting the first info, but the second doesn't work.
The instance is empty.

I have tried
side2 = side
side2 = side[:]
side2 = deepcopy(side)
side2 = copy(side)
and even side2 = cStringIO.StringIO(side)

But nothing works.

How can I easiest pick up more information from the site without opening
it more than once?

Thanks


-- 
This email has been scanned for viruses & spam by Domenebutikken - 
www.domenebutikken.no
Denne e-posten er sjekket for virus & spam av Domenebutikken - 
www.domenebutikken.no

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Immediately committing changes to shelve files

2008-10-27 Thread Kent Johnson
On Sun, Oct 26, 2008 at 10:37 PM, Mike Meisner <[EMAIL PROTECTED]> wrote:
> I'm running a number of test cases and saving their results in a shelve
> file.
>
> A full run of the test cases takes about 36 hours.  During that time, if
> something interrupts the run (e.g., a power outage, which has happened), I
> find that none of the completed test cases have been committed to the shelve
> file even though, after each run, I make sure that the results are written
> to the in-memory database (i.e., db = shelve.open(filename) at the beginning
> of the test run; and db[key] = results after each test case).
>
> Is there a way to force the results for a single test case to be written
> back to the shelve file?  Other than opening/closing the shelve after each
> test case run?

I think the sync() method might do this, depending on which
implementation of dbm your shelf is using.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scaling a Tkinter canvas widget

2008-10-27 Thread Kent Johnson
On Sun, Oct 26, 2008 at 10:20 PM, Mike Meisner <[EMAIL PROTECTED]> wrote:
> I would like to plot various datasets on a Tkinter canvas widget.
>
> The problem is that each of my datasets have different x,y extremes.  For
> instance, one dataset may have xmin = 0, xmax = 300, ymin = 0, ymax = 300;
> whereas the next dataset may have xmin = -200, xmax = 1200, ymin = 2000,
> ymax = 5000.  I need the whole canvas area to be available for plotting each
> dataset consecutively - i.e., plot one dataset, capture the image, clear the
> canvas and plot the next dataset with a new scale, etc.
>
> What I'd like to do is simply scale the canvas coordinate system to fit the
> x,y extents of a dataset.  I can write a function to do this but it would be
> costly time-wise for plotting a large dataset (to say nothing of multiple
> large datasets).

I don't know if there is a Tkinter function for this but it will have
to do the scaling itself; ultimately the points have to be converted
to window coordinates to be drawn.

You might want to look at matplotlib, it is pretty simple to make line
and scatter plots with it.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor