[Tutor] How to log process handles and GDI objects in python

2013-02-08 Thread Pai, Yogesh M
Hi,

I would like to know how can I log system process handles and GDI objects for 
debugging memory leak issues in python.
I would like to log these inside a loop (stress test) to check if my 
application leaks handles and plot them later for my usage.
Can you suggest any built in libraries that can help in this task?

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


Re: [Tutor] How to log process handles and GDI objects in python

2013-02-08 Thread Alan Gauld

On 08/02/13 09:06, Pai, Yogesh M wrote:


I would like to know how can I log system process handles and GDI
objects for debugging memory leak issues in python.


This isn't really a question about learning Python so probably would be 
better on the main Python mailing list.


However it will help if you specify things like the OS, the Python 
version. Also be clear about what exactly you mean by process handles 
and GDI objects. I'm guessing you are talking about Windows but I can't 
be sure.



I would like to log these inside a loop (stress test) to check if my
application leaks handles and plot them later for my usage.


I imagine that means you are creating a test lop that creates and 
releases these handles? How do you get a handle? can you store it as a 
variable? can you print it? can you create a string and print that?


Sorry I can't be of more help but that's a fairly open question
about a very specific problem.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] Which pip for Ubuntu 12.04

2013-02-08 Thread Jim Byrnes

How important is it to have the latest pip installed?

Initially I want to use it to install the latest pymongo driver for 
mongoDB.  The pip version in the Ubuntu 12.04 repositories is 1.0.1. I 
see on http://www.pip-installer.org/en/latest/ the version is 1.2.1.


It certainly would be easier to install from the repositories but will 
that version work to install the latest python packages?


Thanks,  Jim

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


[Tutor] classes : post-declaration attributes

2013-02-08 Thread neubyr
I am learning Python 2.7 classes and objects. It seems like attributes
(data attributes and methods) can be added to a class/object  even after
it's first declaration. For example,


class A(object):
  def __init__(self,arg):
self.val1 = arg

a = A(1)
print a.val1


Now another data attribute val2 can be added as:

a.val2 =  2
A.val2 = 22


I understand that all attributes are stored in a dictionary, but I am not
following when adding an attribute after initial declaration approach
should be used. The official documentation also suggests that valid
attributes are all the names present when the class object was created [1].
So does it mean post-declaration attributes are invalid? Why are they
allowed to be created then (any special use cases/examples)?

1. http://docs.python.org/2/tutorial/classes.html

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


Re: [Tutor] classes : post-declaration attributes

2013-02-08 Thread Mitya Sirenef

On 02/09/2013 02:01 AM, neubyr wrote:


> I am learning Python 2.7 classes and objects. It seems like 
attributes (data attributes and methods) can be added to a class/object 
even after it's first declaration. For example,

>
> 
> class A(object):
> def __init__(self,arg):
> self.val1 = arg
>
> a = A(1)
> print a.val1
> 
>
> Now another data attribute val2 can be added as:
> 
> a.val2 = 2
> A.val2 = 22
> 
>
> I understand that all attributes are stored in a dictionary, but I am 
not following when adding an attribute after initial declaration 
approach should be used. The official documentation also suggests that 
valid attributes are all the names present when the class object was 
created [1]. So does it mean post-declaration attributes are invalid? 
Why are they allowed to be created then (any special use cases/examples)?

>
> 1. http://docs.python.org/2/tutorial/classes.html
>
> --
> thanks,
> N
>

What is meant there is that without any additional assignments, those
attributes will be valid, I think.

You can assign attributes at a later time if they don't exist at the
time class is defined, or even if it's just more convenient for your
needs. E.g. you can simply store some values in instance attributes at
various points in your program.

 -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Fanaticism consists of redoubling your effort when you have forgotten your
aim.  George Santayana

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


Re: [Tutor] classes : post-declaration attributes

2013-02-08 Thread Steven D'Aprano

On 09/02/13 18:01, neubyr wrote:


I understand that all attributes are stored in a dictionary, but I am not
following when adding an attribute after initial declaration approach
should be used. The official documentation also suggests that valid
attributes are all the names present when the class object was created [1].
So does it mean post-declaration attributes are invalid? Why are they
allowed to be created then (any special use cases/examples)?

1. http://docs.python.org/2/tutorial/classes.html


No, they are not invalid, merely unusual.

Normally you will create all the instance attributes you expect when you
initialise the instance:

class MyClass:
def __init__(self, spam, ham):
self.spam = spam
self.ham = ham


That simply makes it easier to program the class -- you don't have to worry
about coding for the case that instance.spam doesn't exist yet, because it
will be set when the instance is created.

But sometimes you might want to add an extra, optional, attribute to an
instance after it is already initialised:

instance.eggs = 12

or delete an attribute:

del instance.ham  # No ham for you!


It's your class, you can do whatever you like to it, but it's your
responsibility if you break it.


However, note that built-in types like int, str, list etc. do *not*
allow this dynamic adding and deleting of attributes. Most builtins
don't have a __dict__, in order to be as small as possible. One of
the exceptions are functions, and I sometimes add attributes to
functions:

def spam(n):
return "spam"*n

spam.surprise = 'NOBODY expects the Spanish Inquisition!'


Obviously that's a toy example, but I have done it in real code a
few times.


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