Re: [Tutor] Best way to store and access a fixed coordinate list

2011-08-19 Thread David Crisp
Dont worry! I solved this. I had a brain fade earlier today when I was
working on the problem and it wasnt untill this evening when I got
home and relaxed that what I was after came to mind.

The following code example does the basics of what I was trying to do.
  Its pretty damn simple.  so i was deep in the forest and couldnt see
the tree!


x = {(1,2),(4,4),(4,6),(3,5)}

for eachitem in x:
print eachitem,eachitem[0], eachitem[1]

Regards,


On Fri, Aug 19, 2011 at 1:14 PM, David Crisp  wrote:
> Hello,
>
> I have a large grid of numbers  100 * 100
>
> I then randomly select an X and Y to act as a "centre" point.
>
> I have a list of numbers which are coordinate offsets which are then
> applied to the centre point as per:
>
> X = (-2,2),(-4,2),(4,2),(2,2)  (The list is about 200 coordinate pairs long)
>
> The idea is that I iterate through the list of coordinates in X and do
> the following:
>
> if (Centrepoint plus x and y offset) = something then something else.
>
> So, what is the best way of storeing this within a script.
>
> What is the best way of accessing it then later so I can break out the
> first and second number in the coordinate pair and actually use them
> in a calculation.
>
> suggestions are welcome.  I have been focused on this for a few hours
> now and I think i cant see the trees for the forest (of the problem)
>
> Regards,
> David
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] file fetcher class object through http

2011-08-19 Thread Artie Ziff

Hello..

I like reading different people's implementations of python as it helps 
me decide what is necessary vs what is not.


Essentially, I want to write a class that finds, and downloads a file 
from a web server.


Of course I may add some file matching features through regex... and 
other things that I need.


mostly, I am looking for a smart class implementation that has 
well-considered API and method choices.


I tried to read through packages such as distutils and setuptools 
however I believe I may need to read some code that is less "industrial 
strength". lol!


maybe you know of one in an author's particular open source package?

pls point me to one you know about...

thank you.
az
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file fetcher class object through http

2011-08-19 Thread Steven D'Aprano

Artie Ziff wrote:

Hello..

I like reading different people's implementations of python as it helps 
me decide what is necessary vs what is not.


Essentially, I want to write a class that finds, and downloads a file 
from a web server.


Such tools already exist, although they may not be written in Python. In 
particular, google on "wget" or "curl" for two very well-known 
industrial-strength tools for downloading files from the web (and other 
places). If you just want something that works, I recommend you learn 
how to use those tools rather than re-inventing the wheel.


(A lot of my scripts that download from the web do text processing in 
Python then call wget for the actual download.)


If you add "python" to your search terms, you may find the sort of code 
you are looking for, or at least examples that will point you in the 
right direction. E.g.:



http://duckduckgo.com/?q=python+wget
http://duckduckgo.com/?q=python+curl



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file fetcher class object through http

2011-08-19 Thread Steven D'Aprano

Oh, I forgot to mention...


Artie Ziff wrote:

Essentially, I want to write a class that finds, and downloads a file 
from a web server.

[...]
mostly, I am looking for a smart class implementation that has 
well-considered API and method choices.


Have you looked at the code in the Python standard library itself? E.g.:

http://docs.python.org/library/httplib.html
http://www.voidspace.org.uk/python/articles/urllib2.shtml



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file fetcher class object through http

2011-08-19 Thread James Thornton
> Essentially, I want to write a class that finds, and downloads a file from a
> web server. mostly, I am looking for a smart class implementation that has
> well-considered API and method choices.

httplib2 (http://code.google.com/p/httplib2) by Joe Gregorio of Google
is what I use. It has an intuitive interface that's easy to use.

$ pip install httplib2

>>> import httplib2
>>> http = httplib2.Http()
>>> resp, content = http.request("http://example.org/";, "GET")

Here are more examples: http://code.google.com/p/httplib2/wiki/Examples

- James

-- 
Bulbflow: A Python framework for graph databases (http://bulbflow.com)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor