Get the name of a function

2011-08-05 Thread gervaz
Hi all, is there a way to retrive the function name like with self.__class__.__name__? Using self.__dict__.__name__ I've got def test(): ... print(self.__dict__.__name__) ... test function test at 0x0178DDF8 But I really just want the function name, so 'test' Any help? Thanks, Mattia

Re: Python scoping

2011-06-21 Thread gervaz
On 21 Giu, 06:06, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Angelico ros...@gmail.com writes: On Tue, Jun 21, 2011 at 12:38 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: The *binding* is scoped. And the binding follows the exact same rules as anything else would. It has

Python scoping

2011-06-20 Thread gervaz
Hi all, can you explain me why this simple function works well (i.e. I can call the print function using txt) in py def test(value): ... if value%5: txt = hello ... else: txt = test ... print(txt) while in other languages like C the txt identifier would be undefined? Is there a way

Re: HTTPConncetion - HEAD request

2011-06-17 Thread gervaz
On 17 Giu, 01:00, Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Jun 16, 2011 at 4:43 PM, gervaz ger...@gmail.com wrote: Hi all, can someone tell me why the read() function in the following py3 code returns b''? h = http.client.HTTPConnection(www.twitter.com) h.connect() h.request(HEAD

Re: HTTPConncetion - HEAD request

2011-06-17 Thread gervaz
On 17 Giu, 12:14, Adam Tauno Williams awill...@whitemice.org wrote: On Thu, 2011-06-16 at 15:43 -0700, gervaz wrote: Hi all, can someone tell me why the read() function in the following py3 code returns b'' h = http.client.HTTPConnection(www.twitter.com) h.connect() h.request(HEAD

HTTPConncetion - HEAD request

2011-06-16 Thread gervaz
Hi all, can someone tell me why the read() function in the following py3 code returns b''? h = http.client.HTTPConnection(www.twitter.com) h.connect() h.request(HEAD, /, HTTP 1.0) r = h.getresponse() r.read() b'' Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 00:02, Chris Rebert c...@rebertia.com wrote: On Mon, Mar 21, 2011 at 2:38 AM, gervaz ger...@gmail.com wrote: Hi all, I've got to download some web pages but I'm behind a proxy. So far this is what I've used without any successful result receiving the error

Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 09:34, gervaz ger...@gmail.com wrote: On 22 Mar, 00:02, Chris Rebert c...@rebertia.com wrote: On Mon, Mar 21, 2011 at 2:38 AM, gervaz ger...@gmail.com wrote: Hi all, I've got to download some web pages but I'm behind a proxy. So far this is what I've used without any

Proxy authentication required

2011-03-21 Thread gervaz
Hi all, I've got to download some web pages but I'm behind a proxy. So far this is what I've used without any successful result receiving the error: urllib.error.HTTPError: HTTP Error 407: Proxy Authentication Required ( The ISA Server requires auth orization to fulfill the request. Access to the

Use cookies from a script in a browser

2011-03-18 Thread gervaz
Hi all, I use a scraper to retrieve data from a web page. In order to do that I need to enable cookies. The data that I'm looking for is contained in a bunch of web pages. Is there a way to show this web pages in a browser using the cookies used in the script (otherwise it doesn't work). Thanks,

Re: Use cookies from a script in a browser

2011-03-18 Thread gervaz
On 18 Mar, 22:52, Miki Tebeka miki.teb...@gmail.com wrote: You can use mechanize, which holds a cookie jar and can user the browser cookies as well. I use: opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor()) urllib.request.install_opener(opener) I start scraping from

Re: Interrput a thread

2011-01-04 Thread gervaz
On 4 Gen, 07:13, Jean-Paul Calderone calderone.jeanp...@gmail.com wrote: On Jan 3, 6:17 pm, Adam Skutt ask...@gmail.com wrote: On Jan 3, 5:24 pm, Jean-Paul Calderone calderone.jeanp...@gmail.com wrote: Of course.  The whole point here is not about threads vs processes. It's about

Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 17:47, de...@web.de (Diez B. Roggisch) wrote: gervaz ger...@gmail.com writes: On 31 Dic 2010, 23:25, Alice Bevan–McGregor al...@gothcandy.com wrote: On 2010-12-31 10:28:26 -0800, John Nagle said: Even worse, sending control-C to a multi-thread program is unreliable

Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 22:17, Adam Skutt ask...@gmail.com wrote: On Jan 3, 4:06 pm, Jean-Paul Calderone calderone.jeanp...@gmail.com wrote: Multiple processes, ok, but then regarding processes' interruption there will be the same problems pointed out by using threads? No.  Processes can be

Re: String building using join

2011-01-02 Thread gervaz
On 31 Dic 2010, 16:43, Emile van Sebille em...@fenx.com wrote: On 12/31/2010 7:22 AM gervaz said... Hi all, I would like to ask you how I can use the more efficient join operation in a code like this: class Test: ...     def __init__(self, v1, v2): ...         self.v1 = v1

Re: Interrput a thread

2011-01-02 Thread gervaz
On 31 Dic 2010, 23:25, Alice Bevan–McGregor al...@gothcandy.com wrote: On 2010-12-31 10:28:26 -0800, John Nagle said: Even worse, sending control-C to a multi-thread program is unreliable in CPython.  See http://blip.tv/file/2232410; for why.  It's painful. AFIK, that has been resolved

Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 19:14, Emile van Sebille em...@fenx.com wrote: On 1/2/2011 9:43 AM gervaz said... On 31 Dic 2010, 16:43, Emile van Sebilleem...@fenx.com  wrote: On 12/31/2010 7:22 AM gervaz said... Hi all, I would like to ask you how I can use the more efficient join operation in a code

Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 22:37, gervaz ger...@gmail.com wrote: On 2 Gen, 19:14, Emile van Sebille em...@fenx.com wrote: On 1/2/2011 9:43 AM gervaz said... On 31 Dic 2010, 16:43, Emile van Sebilleem...@fenx.com  wrote: On 12/31/2010 7:22 AM gervaz said... Hi all, I would like to ask you how I

String building using join

2010-12-31 Thread gervaz
Hi all, I would like to ask you how I can use the more efficient join operation in a code like this: class Test: ... def __init__(self, v1, v2): ... self.v1 = v1 ... self.v2 = v2 ... def prg(l): ... txt = ... for x in l: ... if x.v1 is not None: ...

Interrput a thread

2010-12-29 Thread gervaz
Hi all, I need to stop a threaded (using CTR+C or kill) application if it runs too much or if I decide to resume the work later. I come up with the following test implementation but I wanted some suggestion from you on how I can implement what I need in a better or more pythonic way. Here the

Signal handler cygwin

2010-12-25 Thread gervaz
Hi all, given the followin code snippet: import signal import time import sys import os print({0}\n.format(os.getpid())) ContinueProcessing = True def stop(signal, frame): print(\nSignal received!\n) time.sleep(1) global ContinueProcessing ContinueProcessing = False

py3.x urllib.request - HTTPCookieProcessor and header adding

2009-12-16 Thread gervaz
Hi all, I need to fetch some html pages and it is required to have cookies enabled. So, I'm using opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor ()) urllib.request.install_opener(opener) as a global instance. Is there a way to always use a default header like:

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there a pythonic way to have the -- http://mail.python.org/mailman/listinfo/python-list

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Re: Correct URL encoding

2009-03-15 Thread gervaz
On Mar 16, 12:38 am, Graham Breed x3...@cnntp.org wrote: mattia wrote: 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

Regexp

2009-01-19 Thread gervaz
Hi all, I need to find all the address in a html source page, I'm using: 'href=(?Purlhttp://mysite.com/[^]+)(b)?(?Pname[^/a]+)(/ b)?/a' but the [^/a]+ pattern retrieve all the strings not containing or / or a etc, although I just not want the word /a. How can I specify: 'do not search the string

Re: Regexp

2009-01-19 Thread gervaz
On Jan 19, 4:01 pm, Ant ant...@gmail.com wrote: A 0-width positive lookahead is probably what you want here: s = ... hdhd a href=http://mysite.com/blah.html;Test iString/i OK/ a ... ... p = r'href=(http://mysite.com/[^]+)(.*)(?=/a)' m = re.search(p, s) m.group(1)