Re: Web page special characters encoding

2010-07-10 Thread mattia
Il Sat, 10 Jul 2010 16:24:23 +, mattia ha scritto: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the correspondi

Re: Web page special characters encoding

2010-07-10 Thread mattia
Il Sat, 10 Jul 2010 18:09:12 +0100, MRAB ha scritto: > mattia wrote: >> Hi all, I'm using py3k and the urllib package to download web pages. >> Can you suggest me a package that can translate reserved characters in >> html like "è", "ò", "é"

Web page special characters encoding

2010-07-10 Thread mattia
Hi all, I'm using py3k and the urllib package to download web pages. Can you suggest me a package that can translate reserved characters in html like "è", "ò", "é" in the corresponding correct encoding? Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: Join a thread and get the return value of a function

2009-12-25 Thread mattia
Il Fri, 25 Dec 2009 05:19:46 +1100, Lie Ryan ha scritto: > import threading > > class MyThread(threading.Thread): > def join(self): > super(MyThread, self).join() > return self.result > > class Worker(MyThread): > def run(self): > total = 0 > for i i

Re: Join a thread and get the return value of a function

2009-12-24 Thread mattia
Il Fri, 25 Dec 2009 00:35:55 +1100, Lie Ryan ha scritto: > On 12/25/2009 12:23 AM, mattia wrote: >> Hi all, is there a way in python to get back the value of the function >> passed to a thread once the thread is finished? Something like >> pthread_join() in C? >> &

Join a thread and get the return value of a function

2009-12-24 Thread mattia
Hi all, is there a way in python to get back the value of the function passed to a thread once the thread is finished? Something like pthread_join() in C? Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: dict initialization

2009-12-22 Thread mattia
Il Tue, 22 Dec 2009 23:09:04 +0100, Peter Otten ha scritto: > mattia wrote: > >> Is there a function to initialize a dictionary? Right now I'm using: >> d = {x+1:[] for x in range(50)} >> Is there any better solution? > > There is a dictionary varian

Re: dict initialization

2009-12-22 Thread mattia
Il Tue, 22 Dec 2009 23:09:04 +0100, Peter Otten ha scritto: > mattia wrote: > >> Is there a function to initialize a dictionary? Right now I'm using: >> d = {x+1:[] for x in range(50)} >> Is there any better solution? > > There is a dictionary varian

dict initialization

2009-12-22 Thread mattia
Is there a function to initialize a dictionary? Right now I'm using: d = {x+1:[] for x in range(50)} Is there any better solution? -- http://mail.python.org/mailman/listinfo/python-list

Re: console command to get the path of a function

2009-12-20 Thread mattia
Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto: > On 12/20/2009 1:45 PM, mattia wrote: >> Hi all, is there a way in the python shell to list the path of a >> library function (in order to look at the source code?). >> >> Thanks, Mattia > > some

Re: console command to get the path of a function

2009-12-20 Thread mattia
Il Sun, 20 Dec 2009 13:53:18 +0100, Irmen de Jong ha scritto: > On 12/20/2009 1:45 PM, mattia wrote: >> Hi all, is there a way in the python shell to list the path of a >> library function (in order to look at the source code?). >> >> Thanks, Mattia > > some

Re: py itertools?

2009-12-20 Thread mattia
Il Sun, 20 Dec 2009 03:49:35 -0800, Chris Rebert ha scritto: >> On Dec 19, 12:48 pm, Chris Rebert wrote: >>> On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: >>> > Hi all, I need to create the permutation of two strings but without >>> > repeat the values,

console command to get the path of a function

2009-12-20 Thread mattia
Hi all, is there a way in the python shell to list the path of a library function (in order to look at the source code?). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: py itertools?

2009-12-19 Thread mattia
Il Sat, 19 Dec 2009 10:54:58 +, mattia ha scritto: > Hi all, I need to create the permutation of two strings but without > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my > solution, but maybe the python library provides something better: > &g

py itertools?

2009-12-19 Thread mattia
else: ... return mcd(b, a % b) ... >>> def mcm(a, b): ... return int((a * b) / mcd(a, b)) ... >>> s1 = 'abc' >>> s2 = 'wt' >>> m = mcm(len(s1), len(s2)) >>> set(zip(s1*m, s2*m)) {('a', 'w'), ('

Re: Sort the values of a dict

2009-12-19 Thread mattia
Il Sat, 19 Dec 2009 17:30:27 +1100, Lie Ryan ha scritto: > On 12/19/2009 9:34 AM, mattia wrote: >> Can you provide me a much pythonic solution (with comments if possible, >> so I can actually learn something)? > > If you only need to get i'th element sometimes,

Re: Sort the values of a dict

2009-12-18 Thread mattia
Il Fri, 18 Dec 2009 18:00:42 -0500, David Robinow ha scritto: > On Fri, Dec 18, 2009 at 5:34 PM, mattia wrote: >> Hi all, I have a dictionary that uses dates and a tuples ad key, value >> pairs. I need to sort the values of the dict and insert everything in a >> tuple. The

Re: Sort the values of a dict

2009-12-18 Thread mattia
Actually, in order to use duplicate values I need something like: >>> import copy >>> d = {1:('a', 1, 12), 5:('r', 21, 10), 2:('u', 9, 8), 3:('u', 9, 8) } >>> dc = copy.deepcopy(d) >>> t = [x for x in d.values()] >>> def third(mls): ... return mls[2] ... >>> s = sorted(t, key=third) >>> pres =

Sort the values of a dict

2009-12-18 Thread mattia
in s: ... for k in d.keys(): ... if d[k] == x: ... pres.append(k) ... break ... >>> res = [] >>> for x in pres: ... res.append((x, d[x])) ... >>> res [(2, ('u', 9, 8)), (5, ('r', 21, 10)), (1, ('a', 1

Re: insert unique data in a list

2009-12-14 Thread mattia
Il Mon, 14 Dec 2009 21:53:38 +, Steven D'Aprano ha scritto: > On Mon, 14 Dec 2009 17:13:24 +, mattia wrote: > >> Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto: >> >>> On 12월14일, 오후12시42분, Steven D'Aprano >>> wrote: >>>

print format

2009-12-14 Thread mattia
Hi all, I wanto to print just the first 5 characters of a string, why this doesn't work (py3.1)? >>> print("{0:5}".format("123456789")) 123456789 I know I could use print("123456789"[:5]), yeah it's a stupid example, but isn't

Re: insert unique data in a list

2009-12-14 Thread mattia
Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto: > On 12월14일, 오후12시42분, Steven D'Aprano > wrote: >> On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: >> > this makes the set type hashable. >> >> > class Set(set): >> >     __hash__ = lambda self: id(self) >> >> That's a *seriously* b

Re: insert unique data in a list

2009-12-13 Thread mattia
Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: > How can I insert non-duplicate data in a list? I mean, is there a > particular option in the creation of a list that permit me not to use > something like: > def append_unique(l, val): > if val not in l: >

insert unique data in a list

2009-12-13 Thread mattia
How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val) Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: KeyboardInterrupt

2009-12-10 Thread mattia
Il Wed, 09 Dec 2009 16:19:24 -0800, Jon Clements ha scritto: > On Dec 9, 11:53 pm, mattia wrote: >> Hi all, can you provide me a simple code snippet to interrupt the >> execution of my program catching the KeyboardInterrupt signal? >> >> Thanks, >> Mattia >

Re: KeyboardInterrupt

2009-12-10 Thread mattia
Il Thu, 10 Dec 2009 23:10:02 +, Matthew Barnett ha scritto: > mattia wrote: >> Il Thu, 10 Dec 2009 04:56:33 +, Brad Harms ha scritto: >> >>> On Thu, 10 Dec 2009 00:29:45 +, mattia wrote: >>> >>>> Il Wed, 09 Dec 2009 16:19:24 -0800, Jon Cl

Re: KeyboardInterrupt

2009-12-10 Thread mattia
Il Thu, 10 Dec 2009 04:56:33 +, Brad Harms ha scritto: > On Thu, 10 Dec 2009 00:29:45 +0000, mattia wrote: > >> Il Wed, 09 Dec 2009 16:19:24 -0800, Jon Clements ha scritto: >> >>> On Dec 9, 11:53 pm, mattia wrote: >>>> Hi all, can you provide me

Re: Working threads progress

2009-10-31 Thread mattia
Il Wed, 28 Oct 2009 20:04:45 -0700, ryles ha scritto: > On Oct 28, 7:02 pm, mattia wrote: >> Now, I would like to know the activity done (e.g. every two seconds) so >> I create another thread that checks the queue size (using .qsize()). >> Have you any suggestion to improv

Working threads progress

2009-10-28 Thread mattia
hi all, I have a simple program that uses multiple threads to carry out some work. Every threads share the same queue.Queue() (that is synchronized) in order to get some data and then carry out the work. Suppose I have something like: q = queue.Queue() for x in range(100): q.put(x) then I ha

Re: print()

2009-10-18 Thread mattia
Il Sun, 18 Oct 2009 20:04:11 -0200, Gabriel Genellina ha scritto: > En Sun, 18 Oct 2009 10:35:34 -0200, mattia escribió: > >> Il Sat, 17 Oct 2009 10:02:27 -0400, Dave Angel ha scritto: >>> mattia wrote: >>>> Il Fri, 16 Oct 2009 21:04:08 +, mattia ha sc

Re: print()

2009-10-18 Thread mattia
Il Sat, 17 Oct 2009 10:02:27 -0400, Dave Angel ha scritto: > mattia wrote: >> Il Fri, 16 Oct 2009 21:04:08 +0000, mattia ha scritto: >> >> >>> Is there a way to print to an unbuffered output (like stdout)? I've >>> seen that something like sys.stdout

Re: print()

2009-10-18 Thread mattia
Il Sat, 17 Oct 2009 10:38:55 -0400, Dave Angel ha scritto: > mattia wrote: >> Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: >> >> >>> On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel >>> declaimed the following in gmane.comp.python.gene

Re: print()

2009-10-17 Thread mattia
Il Fri, 16 Oct 2009 21:04:08 +, mattia ha scritto: > Is there a way to print to an unbuffered output (like stdout)? I've seen > that something like sys.stdout.write("hello") works but it also prints > the number of characters! Another question (always py3). How ca

Re: putchar(8)

2009-10-17 Thread mattia
Il Sat, 17 Oct 2009 06:48:10 -0400, Dave Angel ha scritto: > Dave Angel wrote: >> >> Jason Tackaberry wrote: >>> On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: >>> Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). >

Re: print()

2009-10-17 Thread mattia
Il Fri, 16 Oct 2009 22:40:34 -0700, Dennis Lee Bieber ha scritto: > On Fri, 16 Oct 2009 23:39:38 -0400, Dave Angel > declaimed the following in gmane.comp.python.general: > > >> You're presumably testing this in the interpreter, which prints extra >> stuff. In particular, it prints the result

print()

2009-10-16 Thread mattia
Is there a way to print to an unbuffered output (like stdout)? I've seen that something like sys.stdout.write("hello") works but it also prints the number of characters! -- http://mail.python.org/mailman/listinfo/python-list

() vs []

2009-10-15 Thread mattia
Any particular difference in using for a simple collection of element () over [] or vice-versa? Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Download and save a picture - urllib

2009-09-11 Thread mattia
Hi all, in order to download an image. In order to correctly retrieve the image I need to set the referer and handle cookies. opener = urllib.request.build_opener(urllib.request.HTTPRedirectHandler (), urllib.request.HTTPCookieProcessor()) urllib.request.install_opener(opener) req = urllib.reques

Re: Download and save a picture - urllib

2009-09-10 Thread mattia
You were right, the problem was with the print function, using a normal write everythong works fine. Il Thu, 10 Sep 2009 18:56:07 +0200, Diez B. Roggisch ha scritto: > mattia wrote: > >> Hi all, in order to download an image. In order to correctly retrieve >> the image

lxml question

2009-09-09 Thread mattia
I would like to click on an image in a web page that I retrieve using urllib in order to trigger an event. Here is the piece of code with the image that I want to click: I don't know how to do it (I'm trying using lxml, but any suggestion can help). Thanks, Mattia -- http://mail.

Screenshot of a web page

2009-04-29 Thread mattia
Are you aware of any python module that automatically gives you a screenshot of a web page? -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with dict and iter

2009-04-02 Thread mattia
Il Thu, 02 Apr 2009 13:44:38 +, Sion Arrowsmith ha scritto: > mattia wrote: >> So, I'm looking for a way to "reset" the next() value every >>time i complete the scan of a list. > > itertools.cycle ? Perfect, thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with dict and iter

2009-03-29 Thread mattia
Il Sun, 29 Mar 2009 12:00:38 -0400, andrew cooke ha scritto: > mattia wrote: >>[i wrote]: >>> don't you just want to have a new job machine? >>> >>> for job_list in job_list_list: >>> job_machine = dict((x+1, iter(JOBS[x])) for x in range(N

Re: Help with dict and iter

2009-03-29 Thread mattia
Il Sun, 29 Mar 2009 11:17:50 -0400, andrew cooke ha scritto: > mattia wrote: >> Hi all, I a list of jobs and each job has to be processed in a >> particular order by a list of machines. >> A simple representation is: >> # Ordering of machines >> JOB1 = [3, 1, 2,

Help with dict and iter

2009-03-29 Thread mattia
chine = empty.copy() Can you suggest me a more python way? Ciao, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Code anntotations (copyright, autor, etc) in your code

2009-03-26 Thread mattia
Hi all, which are the usual comments that you put at the beginning of your code to explain e.g. the author, the usage, the license etc? I've found useful someting like: #- # Name:About.py # Purpose: # # Author:

Re: Generator

2009-03-22 Thread mattia
Il Sun, 22 Mar 2009 16:52:02 +, R. David Murray ha scritto: > mattia wrote: >> Can you explain me this behaviour: >> >> >>> s = [1,2,3,4,5] >> >>> g = (x for x in s) >> >>> next(g) >> 1 >> >>>

Generator

2009-03-22 Thread mattia
Can you explain me this behaviour: >>> s = [1,2,3,4,5] >>> g = (x for x in s) >>> next(g) 1 >>> s [1, 2, 3, 4, 5] >>> del s[0] >>> s [2, 3, 4, 5] >>> next(g) 3 >>> Why next(g) doesn't give me 2? -- http://mail.python.org/mailman/listinfo/python-list

Simple question about yyyy/mm/dd

2009-03-19 Thread mattia
Hi all, I need to receive in input a date represented by a string in the form "/mm/dd" (or reversed), then I need to assure that the date is >= the current date and then split the dates in variables like year, month, day. Is there some module to do this quickly? -- http://mail.python.org/mail

Re: Roulette wheel

2009-03-19 Thread mattia
Il Wed, 18 Mar 2009 23:31:09 -0200, Gabriel Genellina ha scritto: > En Wed, 18 Mar 2009 18:49:19 -0200, mattia escribió: >> Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto: >>> In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>, mattia >>> wrote: >

Re: Roulette wheel

2009-03-18 Thread mattia
Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto: > In article <49c1562a$0$1115$4fafb...@reader1.news.tin.it>, mattia > wrote: >> >>Yeah, and I believe that we can say the same for: 1 - t = [x*2 for x in >>range(10)] >>2 - t = list(x*2 for x in range(10)

Re: Roulette wheel

2009-03-18 Thread mattia
Il Wed, 18 Mar 2009 09:34:57 -0700, Aahz ha scritto: > In article , Peter Otten > <__pete...@web.de> wrote: >>mattia wrote: >>> >>> cpop += [nchromosome1] + [nchromosome2] >> >>I'd write that as >> >>cpop.append

Re: urllib2 (py2.6) vs urllib.request (py3)

2009-03-17 Thread mattia
Il Tue, 17 Mar 2009 15:40:02 +, R. David Murray ha scritto: > mattia wrote: >> Il Tue, 17 Mar 2009 10:55:21 +, R. David Murray ha scritto: >> >> > mattia wrote: >> >> Hi all, can you tell me why the module urllib.request (py3) add >> >&g

Re: urllib2 (py2.6) vs urllib.request (py3)

2009-03-17 Thread mattia
Il Tue, 17 Mar 2009 10:55:21 +, R. David Murray ha scritto: > mattia wrote: >> Hi all, can you tell me why the module urllib.request (py3) add extra >> characters (b'fef\r\n and \r\n0\r\n\r\n') in a simple example like the >> following and urllib2 (py2

Re: urllib2 (py2.6) vs urllib.request (py3)

2009-03-17 Thread mattia
Il Tue, 17 Mar 2009 10:55:21 +, R. David Murray ha scritto: > mattia wrote: >> Hi all, can you tell me why the module urllib.request (py3) add extra >> characters (b'fef\r\n and \r\n0\r\n\r\n') in a simple example like the >> following and urllib2 (py2

Re: Lists aggregation

2009-03-17 Thread mattia
Il Tue, 17 Mar 2009 08:18:08 +0100, Peter Otten ha scritto: > Mensanator wrote: > >> On Mar 16, 1:40 pm, Peter Otten <__pete...@web.de> wrote: >>> mattia wrote: >>> > I have 2 lists, like: >>> > l1 = [1,2,3] >>> > l2 = [4,5] >>

urllib2 (py2.6) vs urllib.request (py3)

2009-03-17 Thread mattia
Hi all, can you tell me why the module urllib.request (py3) add extra characters (b'fef\r\n and \r\n0\r\n\r\n') in a simple example like the following and urllib2 (py2.6) correctly not? py2.6 >>> import urllib2 >>> f = urllib2.urlopen("http://www.google.com";).read() >>> fd = open("google26.html

Lists aggregation

2009-03-16 Thread mattia
: - I wanted to use the zip function, but the new list will not aggregate (3,4) and (3,5) - Once I've the new list, I'll apply a map function (e.g. the exp of the values) to speed up the process Some help? Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: Correct URL encoding

2009-03-15 Thread mattia
Il Sun, 15 Mar 2009 17:05:16 -0700, Chris Rebert ha scritto: > On Sun, Mar 15, 2009 at 4:54 PM, gervaz wrote: >> On Mar 16, 12:38 am, Graham Breed wrote: >>> mattia wrote: >>> > I'm using urlopen in order to download some web pages. I've always >>

Correct URL encoding

2009-03-15 Thread mattia
I'm using urlopen in order to download some web pages. I've always to replace some characters that are in the url, so I've come up with: url.replace("|", "%7C").replace("/", "%2F").replace(" ", "+").replace (":", "%3A") There isn't a better way of doing this? -- http://mail.python.org/mailman/list

Set overlapping

2009-03-15 Thread mattia
How can I determine the common values found in two differents sets and then assign this values? E.g. dayset = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] monthset = ["Jan", "Feb", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] this are the "fixed and standard" sets. Then I

List the moduels of a package

2009-03-15 Thread mattia
Hi all, how can I list the modules provided by a package? -- http://mail.python.org/mailman/listinfo/python-list

Re: String to sequence

2009-03-15 Thread mattia
Il Sat, 14 Mar 2009 15:30:29 -0500, Tim Chase ha scritto: >> How can I convert the following string: >> >> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', >> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ' >> >> into this sequence: >> >> ['AAR','ABZ','AGA','AHO','ALC','LEI','AOC', >> EGC','SXF','BZR','BIQ'

Re: String to sequence

2009-03-14 Thread mattia
Il Sat, 14 Mar 2009 12:13:31 +0100, Peter Otten ha scritto: > mattia wrote: > >> Il Sat, 14 Mar 2009 10:35:59 +0100, Peter Otten ha scritto: >> >>> mattia wrote: >>> >>>> How can I convert the following string: >>>> >>>&g

Re: String to sequence

2009-03-14 Thread mattia
Il Sat, 14 Mar 2009 10:35:59 +0100, Peter Otten ha scritto: > mattia wrote: > >> How can I convert the following string: >> >> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', >> EGC','

Re: String to sequence

2009-03-14 Thread mattia
Il Sat, 14 Mar 2009 10:30:43 +0100, Vlastimil Brom ha scritto: > 2009/3/14 mattia : >> How can I convert the following string: >> >> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', >> EGC','S

Re: String to sequence

2009-03-14 Thread mattia
Il Sat, 14 Mar 2009 10:24:38 +0100, Ulrich Eckhardt ha scritto: > mattia wrote: >> How can I convert the following string: >> >> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', >> EGC','SXF

String to sequence

2009-03-14 Thread mattia
How can I convert the following string: 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC', EGC','SXF','BZR','BIQ','BLL','BHX','BLQ' into this sequence: ['

Re: Is there a better way of doing this?

2009-03-07 Thread mattia
Il Sat, 07 Mar 2009 00:05:53 -0200, Gabriel Genellina ha scritto: > En Fri, 06 Mar 2009 21:31:01 -0200, mattia escribió: > >> Thanks, I've found another solution here: >> http://www.obitko.com/tutorials/ >> genetic-algorithms/selection.php >> so here is my i

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 14:13:47 -0800, Scott David Daniels ha scritto: > mattia wrote: >> Here is my last shot, where I get rid of all the old intermediate >> functions: >> >> def selection(fitness, population): >> lp = len(population) >> roulett

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 18:46:44 -0300, andrew cooke ha scritto: > i have not been following this discussion in detail, so someone may have > already explained this, but it should not be necessary to actually > construct the roulette wheel to select values from it. what you are > doing is selecting f

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 22:28:00 +0100, Peter Otten ha scritto: > mattia wrote: > >> Il Fri, 06 Mar 2009 14:06:14 +0100, Peter Otten ha scritto: >> >>> mattia wrote: >>> >>>> Hi, I'm new to python, and as the title says, can I improve this >

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 14:06:14 +0100, Peter Otten ha scritto: > mattia wrote: > >> Hi, I'm new to python, and as the title says, can I improve this >> snippet (readability, speed, tricks): >> >> def get_fitness_and_population(fitness, population): >

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 03:43:22 -0800, Chris Rebert ha scritto: > On Fri, Mar 6, 2009 at 3:07 AM, mattia wrote: >> Great, the for statement has not to deal with fap anymore, but with >> another sequence, like this: >> >> def get_roulette_wheel(weight_value_p

Re: Is there a better way of doing this?

2009-03-06 Thread mattia
Il Fri, 06 Mar 2009 10:19:22 +, mattia ha scritto: > Hi, I'm new to python, and as the title says, can I improve this snippet > (readability, speed, tricks): > > def get_fitness_and_population(fitness, population): > return [(fitness(x), x) for x in population] >

Is there a better way of doing this?

2009-03-06 Thread mattia
Hi, I'm new to python, and as the title says, can I improve this snippet (readability, speed, tricks): def get_fitness_and_population(fitness, population): return [(fitness(x), x) for x in population] def selection(fitness, population): ''' Select the parent chromosomes from a popula

Re: Roulette wheel

2009-03-05 Thread mattia
Il Thu, 05 Mar 2009 18:07:29 +0100, Peter Otten ha scritto: > mattia wrote: > >> The last question: how can I improve readability in this piece of code? >> >> def crossover(pop, prob=0.6): >> """ >> With a crossover probability cross o

Re: Roulette wheel

2009-03-05 Thread mattia
> for a, b in zip(*[iter(pop)]*2): In the python documentation there is a similar example, well, the obscure thing here is the usage of *[iter(pop)]! Then I believe that I can safely say that you iterate over the values 0 and 1, 2 and 3 etc. because the zip automatically updates the index, i

Re: Roulette wheel

2009-03-05 Thread mattia
Il Thu, 05 Mar 2009 15:48:01 +, mattia ha scritto: > Il Wed, 04 Mar 2009 21:30:54 +0100, Peter Otten ha scritto: > >> mattia wrote: >> >>> Hi everyone, I'm new to python and I want to create some simple code >>> in order to code the cla

Re: Roulette wheel

2009-03-05 Thread mattia
Il Wed, 04 Mar 2009 21:30:54 +0100, Peter Otten ha scritto: > mattia wrote: > >> Hi everyone, I'm new to python and I want to create some simple code in >> order to code the classical genetic algorithm example: given a >> population of chromosomes, encoded using

Re: Roulette wheel

2009-03-05 Thread mattia
Il Thu, 05 Mar 2009 12:54:39 +0100, Peter Otten ha scritto: > mattia wrote: > >> Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto: >> >>> mattia wrote: >>> >>>>> Note how get_roulette_wheel() is now completeley independent

Re: Roulette wheel

2009-03-05 Thread mattia
Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto: > mattia wrote: > >>> Note how get_roulette_wheel() is now completeley independent of the >>> concrete problem you are using it for. >> >> Ok, but also a lot more memory consuming ;-) > > I

Re: Roulette wheel

2009-03-04 Thread mattia
> Note how get_roulette_wheel() is now completeley independent of the > concrete problem you are using it for. Ok, but also a lot more memory consuming ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Roulette wheel

2009-03-04 Thread mattia
Il Wed, 04 Mar 2009 21:30:54 +0100, Peter Otten ha scritto: > mattia wrote: > >> Hi everyone, I'm new to python and I want to create some simple code in >> order to code the classical genetic algorithm example: given a >> population of chromosomes, encoded using

Roulette wheel

2009-03-04 Thread mattia
Hi everyone, I'm new to python and I want to create some simple code in order to code the classical genetic algorithm example: given a population of chromosomes, encoded using 1 and 0, find the chromosome with the maximum number of 1s. Now, despite all the code used to implement the solution, I

Re: Library similar to UserAgent (perl)

2009-02-12 Thread mattia
Il Thu, 12 Feb 2009 13:47:09 +0100, Diez B. Roggisch ha scritto: > mattia wrote: > >> Hi everybody, I'm looking for an easy way to put data in a form, then >> click the button and follow the redirect. Also I need to use cookies. I >> read that using perl this can be

Library similar to UserAgent (perl)

2009-02-12 Thread mattia
Hi everybody, I'm looking for an easy way to put data in a form, then click the button and follow the redirect. Also I need to use cookies. I read that using perl this can be done using the UserAgent lib, that also provide th browser functionality to let the site believe that you are getting th

Re: How to do this in python with regular expressions

2007-05-25 Thread Mattia Gentilini
Thorsten Kampe ha scritto: >> I'm trying to parsing html with re module. > Just don't. Use an HTML parser like BeautifulSoup Or HTMLParser/htmllib. of course you can mix those and re, it'll be easier than re only. -- |\/|55: Mattia Gentilini e 55 = log2(che_pal

Re: How to do this in python with regular expressions

2007-05-25 Thread Mattia Gentilini
Thorsten Kampe ha scritto: >> I'm trying to parsing html with re module. > Just don't. Use an HTML parser like BeautifulSoup Or HTMLParser/htmllib -- |\/|55: Mattia Gentilini e 55 = log2(che_palle_sta_storia) (by mezzo) |/_| ETICS project at CNAF, INFN, Bologna, Italy |\/|

Re: just a bug

2007-05-25 Thread Mattia Gentilini
ain why it accepts that. -- |\/|55: Mattia Gentilini e 55 = log2(che_palle_sta_storia) (by mezzo) |/_| ETICS project at CNAF, INFN, Bologna, Italy |\/| www.getfirefox.com www.getthunderbird.com * Using Mac OS X 10.4.9 powered by Cerebros (Core 2 Duo) * -- http://mail.python.org/mailman/listinfo/python-list

Re: Python on Vista installation issues

2007-05-23 Thread Mattia Gentilini
will ha scritto: > Vista is a 64 bit OS and there is no port of pywin32 for either Vista > or 64-bit XP Vista exists in BOTH 32 bit and 64 bit versions. -- |\/|55: Mattia Gentilini e 55 curve di seguito con gli sci |/_| ETICS project at CNAF, INFN, Bologna, Italy |\/| www.getfiref

Re: 32 OS on 64-bit machine

2007-05-03 Thread Mattia Gentilini (CNAF)
ight", "credits" or "license" for more information. >>> import platform >>> print platform.processor() i386 >>> print platform.architecture() ('32bit', '') >>> -- Mattia Gentilini Collaborator for ETICS project - http://eu-etics.org/ INFN - CNAF - R&D Division - Bologna, Italy * Using Mac OS X 10.4.9 powered by Cerebros (Core 2 Duo) * -- http://mail.python.org/mailman/listinfo/python-list

security

2005-10-25 Thread Mattia Adami
Hi to all. I'm intristing in write a plugin for browsers that can execute python code. I know the main problem is security. Many thread were opened about this in the ng. I would know if fork python rewriting some library could avoid problems. I.e. one problem is the possibility to access files. If

Re: c/c++ and python

2005-09-29 Thread Mattia Adami
Thanks a lot, very clear and usefull anser! Yes, I know PyGTK and wxPython, but I want to develop a plugin for another application that requires c++. I guess that embedding is the appropriate way. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

c/c++ and python

2005-09-29 Thread Mattia Adami
Hi to all! I have a little problem. I want to develop an application in c/c++ that creates a window with gtk+ accordinly to the information on a xml file. The funcions that are called for manage the event should be written in python. I don't know how to do it, can you help me? Is it possible? Thank