Monday, April 19, 2010

comp.lang.python - 26 new messages in 18 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Firefox: all I get is XML page source code - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d2e909fde1e0c95d?hl=en
* Operations on sparse matrices - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d6a3158ab1d4aba3?hl=en
* Incorrect scope of list comprehension variables - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/2b64b9a9069a324f?hl=en
* ctypes return char array with null chars - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/1a09af89ae97463f?hl=en
* Req. for feedback -- writings on error handling & cleanup (Py3) - 1 messages,
1 author
http://groups.google.com/group/comp.lang.python/t/ee2f45d66737c9d6?hl=en
* class instance customization - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/7fbdeb0c4d8af5c4?hl=en
* pyconfig.h - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d434c1898c3b4a56?hl=en
* Python 2.6 SSL module: Fails on key file error, with Errno 336265225,
without a key file. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/aeac0c7c11623fb3?hl=en
* (a==b) ? 'Yes' : 'No' - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b985d5727945d2b4?hl=en
* default value in list comprehension - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/209ac8868862d110?hl=en
* copy some files from IE temporary internet files - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/4159835748320732?hl=en
* why pylint wants only capitals identifiers? - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/bbc2dfdac68c4ad4?hl=en
* urllib2.urlopen taking way too much time - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/2fda5a840d8a7c1a?hl=en
* DLS'10 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d71ff3893d32f223?hl=en
* Write web apps in Python? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/7caab317a1d56d6e?hl=en
* extra room in Paris in your are stuck at the airport - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/0654fd83284040bd?hl=en
* Is it better to extend a class, or do something repetitious in the main part
of a program? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b737c577429b451a?hl=en
* Can someone please make it more pythonic or better? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/9d9412b8cb6d20c9?hl=en

==============================================================================
TOPIC: Firefox: all I get is XML page source code
http://groups.google.com/group/comp.lang.python/t/d2e909fde1e0c95d?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 12:19 am
From: Dennis Lee Bieber


On Sun, 18 Apr 2010 15:10:12 -0700 (PDT), Gnarlodious
<gnarlodious@gmail.com> declaimed the following in
gmane.comp.python.general:

> Thanks for that, for some reason I assumed sys.stdout.buffer.write
> sent the http header but I was wrong.
>
> Even so, Firefox still refused to render prperly, but this works/:
>
> content-type: application/xhtml+xml; charset=utf-8\n\n
>

Sorry if I gave the impression that I'd specified a valid header...
One would, of course, have to find the list of recognized types.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: Operations on sparse matrices
http://groups.google.com/group/comp.lang.python/t/d6a3158ab1d4aba3?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 12:38 am
From: pp


I tried csr_matrix.dot(A,N) where A and N are two sparse matrices.
is it correct for multiplication of two sparse matrices ?
I still do not now how to perform matrix inversion for a sparse
matrix. Can anyone please help.

Thanks!!

On Apr 19, 12:03 am, pp <parul.pande...@gmail.com> wrote:
> I am currently dealing with sparse matrices and have doubts on whether
> we can use
> 1.) dot (for matrix multiplication) and inv (inverse) operations of
> numpy on sparse matrices of CSR format.
>
> I initially constructed my sparse matrix using COO format and then
> converted it to CSR format now I want to know whether normal inverse
> and matrix multiplications work with sparse csr matrices.
>
> Also can these operations be applied directly to csr matrices
>
> Thanks a lot


==============================================================================
TOPIC: Incorrect scope of list comprehension variables
http://groups.google.com/group/comp.lang.python/t/2b64b9a9069a324f?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 2:05 am
From: Duncan Booth


Dave Angel <davea@ieee.org> wrote:

> 2) In original C, and I think in C++, the lifetime of i lasted long
> after the loop ended.
> for (int i=0; i< limit; ++i)
> {
> z += i;
> }
> i is still valid after this curly brace
>
> In C99, and at least in later C++, the scope of i ends with the curly,
> as though there were another invisible pair of braces:
> {
> for (int i=0; i< limit; ++i)
> {
> z += i;
> }}
> i is no longer valid here
>

Leading to the wonderful header declaration:

#define for if(0);else for

which moves the entire for loop including the declaration inside another
statement and therefore 'fixes' the variable scope for older compilers.

Ah, those were the days. :^)

--
Duncan Booth http://kupuguy.blogspot.com

==============================================================================
TOPIC: ctypes return char array with null chars
http://groups.google.com/group/comp.lang.python/t/1a09af89ae97463f?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 19 2010 2:29 am
From: chris cannady


Hi all,

I am passing a ctypes struct byref to a dll. When I get the struct
back, it looks like the char array in the struct was truncated at the
first null char. It should be 192 bytes long, but I know the 3rd
through 6th byte are null chars and the array was truncated right
before byte 3.

Is there any way to get the full array back including null chars?

Thanks


== 2 of 2 ==
Date: Mon, Apr 19 2010 8:01 am
From: "Mark Tolonen"

"chris cannady" <booog35@gmail.com> wrote in message
news:b103e85a-05d5-4195-a18f-bd143e9f57b8@b33g2000yqc.googlegroups.com...
> Hi all,
>
> I am passing a ctypes struct byref to a dll. When I get the struct
> back, it looks like the char array in the struct was truncated at the
> first null char. It should be 192 bytes long, but I know the 3rd
> through 6th byte are null chars and the array was truncated right
> before byte 3.
>
> Is there any way to get the full array back including null chars?
>
> Thanks

It could depend on how your struct is declared. Maybe this demo will help?

>>> x=(c_char*10)()
>>> x
<__main__.c_char_Array_10 object at 0x00A049E0>
>>> x.raw
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>> x.value
''

'value' prints it is a string, stopping at the first null. 'raw' dumps the
whole array.

-Mark

==============================================================================
TOPIC: Req. for feedback -- writings on error handling & cleanup (Py3)
http://groups.google.com/group/comp.lang.python/t/ee2f45d66737c9d6?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 2:29 am
From: "Alf P. Steinbach"


After at least 3 false starts on my programming introduction's chapter 3, and
some good and bad feedback from this group[1], I finally think the present
chapter 3 approach is Good (enough).

So no, I haven't given up in this book project, even though 4 months to produce
these chapter 3's first 30 pages or so might seem excessive!

This is a PDF document [03 - asd.pdf] at Google Docs, available via

<url: http://tinyurl.com/programmingbookP3>

I've tried to take earlier feedback to heart. E.g. verbosity: earlier attempt's
1+ page intro reduced to 1 line. And example selection: no scary math here.


Contents so far:

<contents>
3 [chapter title, undecided].
3.1 Error handling.
3.1.1 Error, failure, success (terminology).
3.1.2 The concept of exceptions.
3.1.3 Routine call hierarchies, call stack unwinding and stack traces.
3.1.4 Raising an exception / exception types / exception objects.
3.1.5 Handling an exception by using a try statement.
3.1.6 Interlude I: numerical input in a console program.
3.1.7 Exception translation and chained exceptions.
3.2 Cleanup handling.
3.2.1 Why automatic cleanup via object destruction (RAII) is ungood in Python.
3.2.2 Performing cleanup by using a finally clause (low level technique).
3.2.3 Performing cleanup by using a with statement.
</contents>


Comments welcome!


Cheers,

- Alf

Notes:
[1] I'm posting this only to [comp.lang.python], for now seeking feedback mainly
on the language aspects and general approach. Partially that's because,
empirically, there is some risk of a flame war erupting in this group, and I
don't want that spilling over into some other group. If/when the chapter's draft
is complete I'll cross-post a request for feedback to [comp.programming], or
perhaps post only to that group for the more pedagogical aspects.

==============================================================================
TOPIC: class instance customization
http://groups.google.com/group/comp.lang.python/t/7fbdeb0c4d8af5c4?hl=en
==============================================================================

== 1 of 2 ==
Date: Mon, Apr 19 2010 2:32 am
From: Jean-Michel Pichavant


Alexander wrote:
> On 17.04.2010 18:32, Steven D'Aprano wrote:
>
>> On Sat, 17 Apr 2010 13:09:43 +0400, Alexander wrote:
>>
>>
>>
>>> Hi, list.
>>>
>>> I've some nontrivial class implementation MyClass and its instance my:
>>>
>>> my = MyClass(args)
>>>
>>> MyClass uses in internals some variable which is not defined in MyClass
>>> itself. I want to extend instance of MyClass at runtime defining this
>>> variable and making new instance. It is like a class inheritance in a
>>> static way
>>>
>>>
>> I'm afraid I don't understand what you are asking. MyClass uses a
>> variable which is not defined in MyClass. Where is it defined? Is it a
>> global variable?
>>
>> What do you mean, "like a class inheritance in a static way"?
>>
>> Perhaps you should give an example of what you want to happen.
>>
>>
>
> Ok, I'll try to explain on the following example. Let's consider class
> MyClass that holds one string and concatenate it with other not defined
> in this class:
>
> class MyClass(object):
> def __init__(s): pass
> def set(s, key):
> s.__key = key
> def __str__(s):
> return s.__key + ' ' + s.__other
> def new(s, value):
> return SubClass(s, value)
>
> The problem is how to implement class SubClass which inherits MyClass,
> define new variable __other accessible from MyClass intance and with
> working application:
>
> a = MyClass()
> a.set('key1')
>
> b1 = a.new('value1')
> b2 = a.new('value2')
>
> print b1, "," ,b2 # give 'key1 value1 , key1 value2'
>
> a.set('key2')
>
> print b1, ",", b2 # give 'key2 value1 , key2 value2'
>
>
>
Unfortunately I'm not sure you description clarifies anything.
My *guess* is that you would need a Factory class.

class Factory: # this is a Factory class

class MyClass: # the class you actually need

redFactory = Factory('red')
blueFactory = Factory('blue')


ex1 = redFactory.new('value1') # use the factory to return an instance
of MyClass initialized with the proper parameters
ex2 = blueFactory.new('value1')

print ex1
'red value1'
print ex2
'blue value1'

Is that want you want to do ? If so, I may elaborate a little more...

JM


== 2 of 2 ==
Date: Mon, Apr 19 2010 8:07 am
From: Alexander


On 18.04.2010 13:23, Steven D'Aprano wrote:
> On Sat, 17 Apr 2010 19:55:44 +0400, Alexander wrote:
>
>
>> Ok, I'll try to explain on the following example. Let's consider class
>> MyClass that holds one string and concatenate it with other not defined
>> in this class:
>>
> [...]
>
>> and with working application:
>>
>> a = MyClass()
>> a.set('key1')
>>
>> b1 = a.new('value1')
>> b2 = a.new('value2')
>>
>> print b1, "," ,b2 # give 'key1 value1 , key1 value2'
>>
>> a.set('key2')
>>
>> print b1, ",", b2 # give 'key2 value1 , key2 value2'
>>
> Looking at your design, I can't see any reason for SubClass to be a
> subclass of MyClass. It doesn't inherit any behaviour, and the
> constructor takes completely different arguments. Why make it a Subclass?
>
It was a very simple example that express the crux of my question. There
isn't any sense discuss design on it. In real implementation SubClass
has almost the same functionality and methods as MyClass, the difference
only in a state variable (one instance has one state and second the
other, see example below).
> MyClass is dangerous: creating an instance doesn't fully initialise the
> instance, it leaves it in a half-initialised state that can cause
> exceptions from simple operations like:
>
> instance = MyClass()
> print instance
>
> This is very bad design.
>
This actualy depends on practical implementation of class. There could
be a checkup in __str__() member for presence of variable in instance
and result of each evaluation of instance.__str__() could be a valid:

class MyClass(object):
def __init__(s):
s.__default = 'value3'
def set(s, key):
s.__key = key
def __str__(s):
if '__other' in s.__dict__:
return s.__key + ' ' + s.__other
else:
return s.__key + ' ' + s.__default
def new(s, value):
return SubClass(s, value)


Assume MyClass implementation is already given and SubClass have to be
implemented in some way.

==============================================================================
TOPIC: pyconfig.h
http://groups.google.com/group/comp.lang.python/t/d434c1898c3b4a56?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 2:55 am
From: omnia neo


Hi All,

I am working on porting python on vxworks and hence was updating the PC
\pyconfig.h file for configurng python. As I am reading the file and
updating manually I come across lot many preprocessor directives which
I dont understand e.g. HAVE_NICE etc. May be this is standard
nomenclature and I am not aware of it.
My point and qwery is that how can I get info about all these
directives. I am perplexed to enable or disable any of them with half
knowledge.

regards,

==============================================================================
TOPIC: Python 2.6 SSL module: Fails on key file error, with Errno 336265225,
without a key file.
http://groups.google.com/group/comp.lang.python/t/aeac0c7c11623fb3?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 3:52 am
From: Antoine Pitrou


Le Sun, 18 Apr 2010 22:37:30 -0700, John Nagle a écrit :
>
> The cert file is the same PEM file I use with M2Crypto, and it's derived
> from Firefox's cert file.
>
> Why am I getting a "private key" related error? I'm not submitting a
> keyfile, just a cert file.

I'm not an expert but this is what the SSL doc says:

« The keyfile and certfile parameters specify optional files which
contain a certificate to be used to identify the local side of the
connection. »

>From that, I understand that you need to specify both at the same time,
and that one of them (probably the keyfile) needs to be a private key.
Otherwise how would the local side identify itself?

Perhaps you are using the wrong parameters and looking for ca_certs
instead:

« The ca_certs file contains a set of concatenated "certification
authority" certificates, which are used to validate certificates passed
from the other end of the connection. »

==============================================================================
TOPIC: (a==b) ? 'Yes' : 'No'
http://groups.google.com/group/comp.lang.python/t/b985d5727945d2b4?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 5:16 am
From: Dotan Cohen


On 30 March 2010 18:40, gentlestone <tibor.beck@hotmail.com> wrote:
> Hi, how can I write the popular C/JAVA syntax in Python?
>
> Java example:
>    return (a==b) ? 'Yes' : 'No'
>
> My first idea is:
>    return ('No','Yes')[bool(a==b)]
>
> Is there a more elegant/common python expression for this?
>

I'm a little late to the party, but I just saw this in Dive Into Python:
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000

It's kind of sloppy as the condition is between the possible values,
but it works.

--
Dotan Cohen

http://bido.com
http://what-is-what.com

Please CC me if you want to be sure that I read your message. I do not
read all list mail.

==============================================================================
TOPIC: default value in list comprehension
http://groups.google.com/group/comp.lang.python/t/209ac8868862d110?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Apr 19 2010 5:20 am
From: AlienBaby


Hi,

just a quick one,

Is it possible to achieve a default value in a list comprehension
where the if-clause is false?

Ie, something similar to:

[ a for a in b if something(a) else 'default' ]

the idea being that, rather than skip a value if the if-clause is
false, to place a default value at that position in the returned list
instead.

?

Thanks,


Matt.


== 2 of 4 ==
Date: Mon, Apr 19 2010 5:23 am
From: eb303


On Apr 19, 2:20 pm, AlienBaby <matt.j.war...@gmail.com> wrote:
> Hi,
>
> just a quick one,
>
> Is it possible to achieve a default value in a list comprehension
> where the if-clause is false?
>
> Ie, something similar to:
>
> [ a for a in b if something(a) else 'default' ]
>
> the idea being that, rather than skip a value if the if-clause is
> false, to place a default value at that position in the returned list
> instead.
>
> ?
>
> Thanks,
>
> Matt.

[a if something(a) else 'default' for a in b]

HTH
- Eric -


== 3 of 4 ==
Date: Mon, Apr 19 2010 5:26 am
From: AlienBaby


On Apr 19, 1:23 pm, eb303 <eric.brunel.pragma...@gmail.com> wrote:
> On Apr 19, 2:20 pm, AlienBaby <matt.j.war...@gmail.com> wrote:
>
>
>
>
>
> > Hi,
>
> > just a quick one,
>
> > Is it possible to achieve a default value in a list comprehension
> > where the if-clause is false?
>
> > Ie, something similar to:
>
> > [ a for a in b if something(a) else 'default' ]
>
> > the idea being that, rather than skip a value if the if-clause is
> > false, to place a default value at that position in the returned list
> > instead.
>
> > ?
>
> > Thanks,
>
> > Matt.
>
> [a if something(a) else 'default' for a in b]
>
> HTH
>  - Eric -- Hide quoted text -
>
> - Show quoted text -

Ahh. Gotcha, thankyou :)


== 4 of 4 ==
Date: Mon, Apr 19 2010 6:20 am
From: Bruno Desthuilliers


eb303 a écrit :
> On Apr 19, 2:20 pm, AlienBaby <matt.j.war...@gmail.com> wrote:
>> Hi,
>>
>> just a quick one,
>>
>> Is it possible to achieve a default value in a list comprehension
>> where the if-clause is false?
>>
>> Ie, something similar to:
>>
>> [ a for a in b if something(a) else 'default' ]
>>
>> the idea being that, rather than skip a value if the if-clause is
>> false, to place a default value at that position in the returned list
>> instead.
>>
>> ?
>>
>> Thanks,
>>
>> Matt.
>
> [a if something(a) else 'default' for a in b]

Or you could have "something" taking a "default" argument and returning
either it's argument (instead of True) or the "default" one (instead of
False), and get rid of the if/else test in the list comp, ie:

def something(obj, default=False):
if whatever(obj):
return obj
else:
return default

results = [something(a, default="default") for a in b]


==============================================================================
TOPIC: copy some files from IE temporary internet files
http://groups.google.com/group/comp.lang.python/t/4159835748320732?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 5:29 am
From: Tim Golden


On 19/04/2010 10:49, CHEN Guang wrote:
> Hi friends,
> I want to program Python to copy some video files (.flv) from the IE folder "temporary internet files", but
>
> os.listdir('C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files')
>
> seemed unable to find any video file (although they really exist and can be manually copied with Windows explorer).
> I googled and found that "temporary internet files" is not a normal folder. Will any friend tell me how to do this?

Have a look at the win32inet module from the pywin32 package

TJG

==============================================================================
TOPIC: why pylint wants only capitals identifiers?
http://groups.google.com/group/comp.lang.python/t/bbc2dfdac68c4ad4?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Apr 19 2010 5:32 am
From: Giacomo Boffi


i have this code

def example(a):
return lambda b: a+b+1

fun = example(10)
k_1 = fun(7)
...

and pylint tells me

[...]
C: 4: Invalid name "fun" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 5: Invalid name "k_1" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
[...]

afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
i don't think of fun or k_1 as constants... what's going on?

tia,
g
--
la lenza penzola
-- PMF, in IHC


== 2 of 4 ==
Date: Mon, Apr 19 2010 5:58 am
From: Alexandre Fayolle


top level "variables" in real code are often constants and pylint tries to help you get rid of global variables.

---
frmsrcurl: http://compgroups.net/comp.lang.python/-pylint-why-pylint-wants-only-capitals-identifiers


== 3 of 4 ==
Date: Mon, Apr 19 2010 7:21 am
From: Jean-Michel Pichavant


Giacomo Boffi wrote:
> i have this code
>
> def example(a):
> return lambda b: a+b+1
>
> fun = example(10)
> k_1 = fun(7)
> ...
>
> and pylint tells me
>
> [...]
> C: 4: Invalid name "fun" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
> C: 5: Invalid name "k_1" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
> [...]
>
> afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
> i don't think of fun or k_1 as constants... what's going on?
>
> tia,
> g
>
Pylint default rules need some tuning, it's highly configurable for that
purpose.
Some ppl like to think 'module variables' are constants thus should be
upper case. If you disagree with that statement like I do, you can
simply rewrite the regexp for module variables.

However, given you example, you should not insert code execution at you
module level, unless it's required only at the module import. I dont
know what is your module purpose but I bet it has no legitimate
attribute 'fun'.

JM


== 4 of 4 ==
Date: Mon, Apr 19 2010 8:32 am
From: Giacomo Boffi


Jean-Michel Pichavant <jeanmichel@sequans.com> writes:

> Giacomo Boffi wrote:
>> i have this code
>>
>> def example(a):
>> return lambda b: a+b+1
>>
>> fun = example(10)
>> k_1 = fun(7)
>> ...
>>
>> and pylint tells me
>>
>> [...]
>> C: 4: Invalid name "fun" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
>> C: 5: Invalid name "k_1" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
>> [...]
>> g
>>
> Pylint default rules need some tuning

ok, but maybe it's not my specific problem (see below)

> However, given you example, you should not insert code execution at
> you module level, unless it's required only at the module import. I
> dont know what is your module

module? this was not well specified in my OP, but i'd rather speak of
a "script" instead of a module...

maybe should i use the

if __name__ == "__main__":
main()

idiom to keep happy my pylint? oh, let's do it... it should be easy
isn't it?

thanks,
g
--
I wish we'd come to our senses and see there is no truth
In those who promote the confusion for this ever changing mood.
(people get ready people get ready people get ready people get ready)

==============================================================================
TOPIC: urllib2.urlopen taking way too much time
http://groups.google.com/group/comp.lang.python/t/2fda5a840d8a7c1a?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 5:44 am
From: Phonethics Mobile Media


handler = urllib2.urlopen(req) is taking way too much time to retrieve
the URL. The same code using sockets in PHP doesn't delay this long.
I had 'Authorization':'Basic ' + base64.b64encode("username:password")
in my header though.
[ I didnt use HTTPPasswordMgr & HTTPPasswordMgrWithDefaultRealm
because I was unable to send headers with the example shown here :
http://docs.python.org/howto/urllib2.html#id6 ]

I have data = handler.readline() in a loop - this is an endless
network script (twitter streaming) so cant really wait for the entire
url contents to finish loading.

I had to socket.setdefaulttimeout to 30 to make it work.
Is it because python is getting chunks in high number of KBs ?

Python 2.6.2

--
Phonethics

==============================================================================
TOPIC: DLS'10
http://groups.google.com/group/comp.lang.python/t/d71ff3893d32f223?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 5:56 am
From: Pascal Costanza


Dynamic Languages Symposium 2010

October 18, 2010

Co-located with SPLASH (OOPSLA) 2010
In cooperation with ACM SIGPLAN
John Ascuaga's Nugget, Reno/Tahoe, Nevada, USA

http://www.dynamic-languages-symposium.org/dls-10/

***** Call for papers *****

The 6th Dynamic Languages Symposium (DLS) at the conference formerly
known as OOPSLA is a forum for discussion of dynamic languages, their
implementation and application. While mature dynamic languages
including Smalltalk, Lisp, Scheme, Self, Prolog, and APL continue to
grow and inspire new converts, a new generation of dynamic scripting
languages such as Python, Ruby, PHP, Tcl, and JavaScript are
successful
in a wide range of applications. DLS provides a place for researchers
and practitioners to come together and share their knowledge,
experience, and ideas for future research and development.

DLS 2010 invites high quality papers reporting original research,
innovative contributions or experience related to dynamic languages,
their implementation and application. Accepted Papers will be
published
in the ACM Digital Library.

Areas of interest include but are not limited to:

* Innovative language features and implementation techniques
* Development and platform support, tools
* Interesting applications
* Domain-oriented programming
* Very late binding, dynamic composition, and runtime adaptation
* Reflection and meta-programming
* Software evolution
* Language symbiosis and multi-paradigm languages
* Dynamic optimization
* Hardware support
* Experience reports and case studies
* Educational approaches and perspectives
* Object-oriented, aspect-oriented, and context-oriented programming

=== Submissions and proceedings ===

We invite original contributions that neither have been published
previously nor are under review by other refereed events or
publications. Research papers should describe work that advances the
current state of the art. Experience papers should be of broad
interest
and should describe insights gained from substantive practical
applications. The program committee will evaluate each contributed
paper based on its relevance, significance, clarity, and originality.

Accepted papers will be published in the ACM Digital Library.

Papers are to be submitted electronically at
http://www.easychair.org/conferences?conf=dls2010 in PDF format.
Submissions must not exceed 12 pages and need to use the ACM format,
templates for which can be found at
http://www.acm.org/sigs/pubs/proceed/template.html.

=== Important dates ===

Submission of papers: June 1, 2010 (hard deadline)
Author notification: July 15, 2010
Final versions due: August 13, 2010
DLS 2010: October 18, 2010
SPLASH/OOPSLA 2010: October 17-21, 2010

=== Program chair ===

William Clinger, Northeastern University, Boston, Massachusetts, USA

=== Program committee ===

Robby Findler (Northwestern University)
Jeffrey S. Foster (University of Maryland)
Lars Thomas Hansen (Adobe Systems)
Charlotte Herzeel (University of Brussels)
S. Alexander Spoon (Google)
Eric Tanter (University of Chile)
Jan Vitek (Purdue University)
Alessandro Warth (Viewpoints Research Institute)

[to be completed]

==============================================================================
TOPIC: Write web apps in Python?
http://groups.google.com/group/comp.lang.python/t/7caab317a1d56d6e?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 6:15 am
From: Bruno Desthuilliers


Gilles Ganault a écrit :
> On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
> <bruno.42.desthuilliers@websiteburo.invalid> wrote:
>> The PHP execution model (mostly based on CGI FWIW) tends to be a bit
>> unpractical for non-trivial applications since you have to rebuild the
>> whole world for each and any incoming request, while with a long-running
>> process, you load all your libs, parse your config etc only once.
>
> Apart from the ease of having the application run at all times, I'd be
> curious to read about an application that was written in PHP and then
> a long-running process and see if performance improved.

I'm not sure there's a way to do such a thing in PHP, at least in a way
that wouldn't make the whole benchmark totally meaningless. And trying
to compare a PHP app with a similar non-PHP would also be (mostly)
meaningless.

Now there are a couple Symfony / Django benchmarks around (Symfony being
probably the closest thing to Django in the PHP world). They are just as
reliable as most benchmarks (that is, at best a rough indicator once you
understand what's effectively being measured), but it seems that they
confirm the empirical evidence that PHP is not well suited for such
"heavy" OO frameworks.

>
> Regardless, Python has an easier syntax, so AFAIC, that's already a
> good enough reason to use this to write web apps.

Indeed !-)

==============================================================================
TOPIC: extra room in Paris in your are stuck at the airport
http://groups.google.com/group/comp.lang.python/t/0654fd83284040bd?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 12:40 am
From: Jean Daniel


Hello,

I live in Paris, my roommate and I would gladly host a poor soul
blocked at the airport due to the ash cloud.

See me for details,

Cheers,


PS: disambiguation: talking about real physical cloud here... :)

==============================================================================
TOPIC: Is it better to extend a class, or do something repetitious in the main
part of a program?
http://groups.google.com/group/comp.lang.python/t/b737c577429b451a?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 7:45 am
From: J


First, before I get farther,

Is there a way for the logging module to natively handle lists and
dict objects when logging?

e.g. take this {'key1':'val1','key2':'val2'} and have it logged like this:

INFO: key1: val1
INFO: key2: val2

If I pass the dict or list directly to the logger, it is logged the
same as if you simply did this:

mydict={1:1, 2:2}
mylist=[1,2,3]

print mydict
print mylist

>>> {1:1,2:2}
>>> [1,2,3]

It came up that I wanted to have logging present command line options
from optparse if the log level was set to debug... so they'd look
something like this in the output:

debug: True
sleep_time: 30
log_file: /tmp/testlog

So the options I've managed to work out are to either parse the list
or dict object item by item and feed those items one at a time into
the logger:

for i in mylist:
logging.info(i)

Or to extend the StreamHandler class to handle this by creating a new
report.msg...

Then the discussion came up: which is better? To parse a dictionary
or list in the main code and pass each item to the logger one at a
time, or to extend the logger to handle it natively?

Any thoughts on which is the more proper way to handle cases like this?

==============================================================================
TOPIC: Can someone please make it more pythonic or better?
http://groups.google.com/group/comp.lang.python/t/9d9412b8cb6d20c9?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Apr 19 2010 8:30 am
From: J Kenneth King


Oltmans <rolf.oltmans@gmail.com> writes:

> Greetings Python superstars,
>
> I've a directory structure like following
>
> tests /
> __init__.py
> testfile.py
>
> testfile.py contains following code
>
> import unittest
>
> class Calculator(unittest.TestCase):
> def test_add(self):
> print 'just add'
> def test_divide(self):
> print 'diviide'
> def test_multiply(self):
> print 'mul'
>
>
> class Car(unittest.TestCase):
> def test_start(self):
> print 'start'
> def test_move_right(self):
> print 'move right'
> def test_move_left(self):
> print 'move left'
> def test_stop(self):
> print 'stop'
>
>
> Now give the following user-input I want to get all test-names.
> user-input = tests.testfile (get all test-names from all
> unittest.TestCase derived classes in test.testfile)
> user-input = tests.testfile.Car (get all test-names from the Car
> class)
> user-input = tests.testfile.Cacr.test_stop
>
> and I'm doing it this the following way and I really think there has
> to be more readable, more pythonic and more possibly short way to do
> it
>
> import unittest
> import sys
> import inspect
>
> def get_test_names(full_name,module):
> name = full_name.split('.')
> loader = unittest.TestLoader()
> if len(name) == 4:
> return full_name
> elif len(name) == 3:
> exec "from %s.%s import %s" %(module,name[1],name[2])
> return loader.getTestCaseNames(eval(name[2]))
> elif len(name) == 2:
> exec 'from %s import %s' % (module,name[1])
> tests = []
> for _name, obj in inspect.getmembers(sys.modules[full_name]):
> if inspect.isclass(obj) and
> issubclass(obj,unittest.TestCase):
> exec "from %s.%s import %s" %
> (module,name[1],obj.__name__)
> tests.append(loader.getTestCaseNames(obj))
> return tests
>
>
>
> if __name__ == "__main__":
> input = "tests.testfile"
> module = input.split('.')[0]
> _tests = get_test_names(input,module)
> print _tests
>
>
> So guys, can you kindly point me to a more Pythonic, more readable and
> possible more short way to acheive this? I will really appreciate any
> help. Many thanks in advance.

First of all, exec is bad if it's going to be processing user input.

You might want to:

>> help(__import__)

It will give you an idea on how to hook into python's import machinery
for tasks such as this.

You could also modify the function's arglist to remove the
string-splitting you're doing. Those "magic numbers" stick out a bit.
One can understand what they're for after reading the code in this case,
but it's not quite necessary if you make a keyword argument for package
names you can pass into the 'fromlist' argument in __import__.

ie:

def get_test_names(module_name, packagelist=[]):
...

hth,

j_king

>
> Best regards,
> Oltmans


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate