[Tutor] how to return an object generated during a python threading code

2011-12-10 Thread Massimo Di Stefano
Hi All,

i'm tring to learn how to use threads in python to save a list of object. i'm 
starting from this code :

#
import threading
import urllib
from tempfile import NamedTemporaryFile

singlelock = threading.Lock() 

class download(threading.Thread):
def __init__(self, sitecode, lista):
threading.Thread.__init__(self)
self.sitecode = sitecode
self.status = -1

def run(self):
url = 
"http://waterdata.usgs.gov/nwis/monthly?referred_module=sw&site_no=";
url += self.sitecode 
url += 
"&PARAmeter_cd=00060&partial_periods=on&format=rdb&submitted_form=parameter_selection_list"
tmp = NamedTemporaryFile(delete=False)
urllib.urlretrieve(url, tmp.name)
print "loaded Monthly data for sitecode : ",  self.sitecode 
lista.append(tmp.name)
print lista

sitecodelist = ["01046500", "01018500", "01010500", "01034500", "01059000", 
"01066000", "0110"]
lista = []


for k in sitecodelist:
get_data = download(k,lista)
get_data.start()

#

it just print out the list generated during the thread execution, while i'm 
tring to return it. 

Trying to read the documentation, i'm looking on how to use " threading.Lock() 
" and its methods "acquire() and release()" that seems to be the solution to my 
issue 

... but i'm really far to understand how to implement it in my example code.

thanks so much for any hints!___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Translating R Code to Python-- reading in csv files, writing out to csv files

2012-05-20 Thread Massimo Di Stefano
Maybe this doc.

http://mathesaurus.sourceforge.net/matlab-python-xref.pdf

can help ?

i found it useful.

Massimo.


Il giorno May 20, 2012, alle ore 2:42 AM, Martin A. Brown ha scritto:

> 
> Benjamin,
> 
> : Thanks Martin-- this is really great.  My major question now is 
> : that I need to transition to Python for a project and I need to 
> : learn how to think in Python instead of in R.  The two strategies 
> : I have used so far are: a) going through the description and 
> : exercises in  http://www.openbookproject.net/thinkcs/python/english2e/
> : and b) trying to convert my R code into Python.
> 
> I haven't seen that before, but, of course, there ar scads of 
> resources out there for anybody learning these days.
> 
> : On a high-level, do you have any other suggestions for how I 
> : could go about becoming more proficient in Python?
> 
> Well, here is my list.  Others probably have some suggestions, too:
> 
>  * solve a specific and immediate real problem in Python, but solve 
>the problem as generally as possible; apply
> 
>  * lurk here (and on other lists) and watch how experienced Python 
>practitioners help others face a problem in Python; absorb
> 
>  * join domain-specific Python groups that discuss libraries,
>tools or techniques that apply in your area of interest; inquire
> 
>  * learn Python's common datatypes well, you will encounter them 
>often: str, int, float, list, dict, set; study
> 
>  * learn Pythonic programming idioms, and, importantly, learn 
>why they are considered Pythonic (that will give you insight 
>into thinking in Python); gain relevant experience
> 
>  * browse the standard library occasionally to learn a new module
>http://docs.python.org/py-modindex.html
> 
>  * learn how to make modules; build your code into modules (if 
>appropriate and where possible)
> 
>  * read a book (lots of options here); I'm a 'learn by example' 
>sort so I liked the O'Reilly _Python Cookbook_ [0]
> 
>  * read PEP 8 http://www.python.org/dev/peps/pep-0008/
> 
> Good luck and enjoy Python,
> 
> -Martin
> 
> [0] http://shop.oreilly.com/product/9780596007973.do
> 
> -- 
> Martin A. Brown
> http://linux-ip.net/
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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