Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Alan Gauld

"Stephen McInerney" <[EMAIL PROTECTED]> wrote 

> I was asking if it's a recognized good programming practice to
> declare and initialize *all* members in the class defn.
> I think I'm hearing a general yes on that - any other opinions?

It depends on what you mean by the class definition.

In general attributes are defined in the classes methods, 
and since they are part of the class definition then I'd say 
yes its general practice.

I'd go further and say its bad practice to define class/instance 
attributes outside the class unless you have a good reason to 
do so - such as dynamically creating classes at run time.

Thus:

class foo:
def __init__(self, x, y):
self.x = x
self.y = y

f = foo(22,66)

Is preferable to

class foo: pass

f = foo()
f.x = 22
f.y = 66

But there are occasions when adding attributes dynamically
can be a sensible approach - your own example of parsing XML 
is a good example.

But because there are always exceptions you won't see many 
people making hard and fast rules about such things in Python.

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is a "symbolic debugger"

2007-08-18 Thread Alan Gauld

"Dick Moores" <[EMAIL PROTECTED]> wrote

> article I saw a term, "symbolic debugger", I  had been wondering
> about for a while. Google was of little help (to me, at least), and

Its a debugger that undestand symbols, in other words it can read
the symbol table produced by a compiler/interpreter.

Most debuggers nowadays are symbolic, but in the early days
they weren't and you had to debug all code at the assembler/memory
address level.

If you want to have fun with that try loading a simple program into
the DOS DEBUG command and stepping through it examining
the memory image as you go., It is decidedly non symbolic!

Or on Linux/Unix you may be able to use adb. adb is often using
for debugging core dumps from programs that haven't been
compiled with the -g debug flag or have had the symbol table
'strip'ed.

> that the debugger I want to learn, WinPdb, is also a symbolic
> debugger, but what's "symbolic" about it?

Yes Python debuggers are all symbolic.
They can understand your variable names etc so you can say

break foo

instead of

break [0x25698567]

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] The Python 2.5 Quick Reference

2007-08-18 Thread Dick Moores
I was wondering if the Python 2.5 Quick Reference, by Richard Gruet, 
wouldn't make a suitable addition to a list of useful Python 
references. It seems to be very well-done to me. It comes in various 
forms. See http://rgruet.free.fr/. I find I prefer 
. Using Firefox, I 
"captured"  this to my "ScrapBook" and open it with a shortcut key set to:
file:///C:/Documents%20and%20Settings/Riley/Application%20Data/Mozilla/Firefox/Profiles/7nl3fxen.default/ScrapBook/data/20070818011939/index.html

BTW Python.org references only a very early antecedent of this PQR, 
from 1995: . At least that's 
the only one I could find..

 From the "Front Matter" section of Python 2.5 Quick Reference:

Last modified on June 23, 2007
14 Dec 2006,
upgraded by Richard Gruet for Python 2.5
17 Feb 2005,
upgraded by Richard Gruet for Python 2.4
03 Oct 2003,
upgraded by Richard Gruet for Python 2.3
11 May 2003, rev 4
upgraded by Richard Gruet for Python 2.2 (restyled by Andrei)
7 Aug 2001
upgraded by Simon Brunning for Python 2.1
16 May 2001
upgraded by Richard Gruet and Simon Brunning for Python 2.0
18 Jun 2000
upgraded by Richard Gruet for Python 1.5.2
30 Oct 1995
created by Chris Hoffmann for Python 1.3

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Stephen McInerney

Kent,


I was asking if it's a recognized good programming practice to
declare and initialize *all* members in the class defn.


What do you mean by "initialize *all* members in the class defn"?

- obviously I meant to say do it in the __init__() method,
I wrote the snippet as I was rushing out the door to an exam,
but I think the intent was clear.


If you mean to initialize the variables in the __init__() method:
maybe this is more common but I don't think I have ever seen it recommended 
to initialize all variables in the __init__() method. Certainly there are 
times when it makes sense to have some of the initialization in other 
methods that are called from __init__().


I only said "make a token dummy assignment in __init__() to hint
to the static analyzer the name and expected type, I didn't say
"you must do all the actual initialization itself in __init__()".

In the context of the original question
"where and how should we assign class members in order
to flag member names and types to static analyzers like
Doxygen or pylint?"
I understood that people were agreeing
"Yes, assigning each member token values in the __init__()
method is a good practice".


> I think I'm hearing a general yes on that - any other opinions?
Not sure where you think you are hearing a yes, I am hearing a lot of 
objections.


No they didn't - they said that this cannot be done for true dynamic code,
which is true, but obviously doesn't apply to working with
static analysis tools, which is what the question was about.

Regards,
Stephen

_
Messenger Café — open for fun 24/7. Hot games, cool activities served daily. 
Visit now. http://cafemessenger.com?ocid=TXT_TAGHM_AugHMtagline


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is a "symbolic debugger"

2007-08-18 Thread Dick Moores
At 01:13 AM 8/18/2007, Alan Gauld wrote:

>"Dick Moores" <[EMAIL PROTECTED]> wrote
>
> > article I saw a term, "symbolic debugger", I  had been wondering
> > about for a while. Google was of little help (to me, at least), and
>
>Its a debugger that undestand symbols, in other words it can read
>the symbol table produced by a compiler/interpreter.

Ah. And that sent me to /


>Most debuggers nowadays are symbolic, but in the early days
>they weren't and you had to debug all code at the assembler/memory
>address level.
>
>If you want to have fun with that try loading a simple program into
>the DOS DEBUG command and stepping through it examining
>the memory image as you go., It is decidedly non symbolic!

Is that something I should be able to do on Win XP? Would I use debug 
 at the command line?

>Or on Linux/Unix you may be able to use adb. adb is often using
>for debugging core dumps from programs that haven't been
>compiled with the -g debug flag or have had the symbol table
>'strip'ed.
>
> > that the debugger I want to learn, WinPdb, is also a symbolic
> > debugger, but what's "symbolic" about it?
>
>Yes Python debuggers are all symbolic.
>They can understand your variable names etc so you can say
>
>break foo
>
>instead of
>
>break [0x25698567]

I'll take "break foo" any day.

Thanks very much, Alan!

Dick Moores
XP, Python 2.5, editor is Ulipad





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [OFF TOPIC] Re: What is a "symbolic debugger"

2007-08-18 Thread Alan Gauld
This is miles away from Python but some might find it fun/educational.

"Dick Moores" <[EMAIL PROTECTED]> wrote

>>If you want to have fun with that try loading a simple program into
>>the DOS DEBUG command and stepping through it examining
>>the memory image as you go., It is decidedly non symbolic!
>
> Is that something I should be able to do on Win XP? Would I use 
> debug
>  at the command line?

You could, but it would be complex since you would be debugging
the python interpreter while it executes your script.

Its probably easier to try it on one of the simpler DOS commands
like edlin.exe (or better still write hello world in C and compile it
and debug that. That way its small enough you should be able
to spot the string in the ASCII part of the memory dump...)

In a DOS prompt CD to C:\WINDOWS\System32
Run

> CD C:\WINDOWS\SYSTEM32
> DEBUG EDLIN.EXE
-

At the '-' prompt type '?' to get a list of commands.
Try the 'd' and 'u' commands for starters.

If you feel really bold (and patient!) you might try stepping through
using 't'. The IP register contains the Instruction Pointer for 
monitoring
progress...

Anything else is a bit risky unless you know what you are doing!

I had to write my first C program using edlin and debug it using 
DEBUG.
It's good for the soul, or so they tell me...

Shortly after I gort a copy of Wordstar and the Microsoft C compiler
with sdb - such luxury... :-)

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Kent Johnson
Stephen McInerney wrote:
> Kent,
> 
>>> I was asking if it's a recognized good programming practice to
>>> declare and initialize *all* members in the class defn.
>>
>> What do you mean by "initialize *all* members in the class defn"?
> - obviously I meant to say do it in the __init__() method,
> I wrote the snippet as I was rushing out the door to an exam,
> but I think the intent was clear.

It was definitely not clear to me. Judging from his latest reply it 
doesn't seem to be clear to Alan either.

>> If you mean to initialize the variables in the __init__() method:
>> maybe this is more common but I don't think I have ever seen it 
>> recommended to initialize all variables in the __init__() method. 
>> Certainly there are times when it makes sense to have some of the 
>> initialization in other methods that are called from __init__().
> 
> I only said "make a token dummy assignment in __init__() to hint
> to the static analyzer the name and expected type, I didn't say
> "you must do all the actual initialization itself in __init__()".

So if an attribute is initialized in a different method would you still 
put a dummy initializer in __init__()?
> 
> In the context of the original question
> "where and how should we assign class members in order
> to flag member names and types to static analyzers like
> Doxygen or pylint?"
> I understood that people were agreeing
> "Yes, assigning each member token values in the __init__()
> method is a good practice".

I honestly don't see how you can conclude that. My post was the first 
one that mentioned __init__() at all. You have been talking about the 
class definition which could mean "anywhere in the scope of the class 
statement" or, as I thought you might mean, "anywhere in the scope of 
the class statement that is not in a method". I personally would never 
interpret "class definition" to mean the __init__() method.

I really am trying to understand what you are asking, it is not clear to 
me at all.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Python 2.5 Quick Reference

2007-08-18 Thread Kent Johnson
Dick Moores wrote:
> I was wondering if the Python 2.5 Quick Reference, by Richard Gruet, 
> wouldn't make a suitable addition to a list of useful Python 
> references. 

It has a link on the top-level documentation page at python.org:
http://www.python.org/doc/

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Python 2.5 Quick Reference

2007-08-18 Thread Dick Moores
At 04:42 AM 8/18/2007, Kent Johnson wrote:
>Dick Moores wrote:
>>I was wondering if the Python 2.5 Quick Reference, by Richard 
>>Gruet, wouldn't make a suitable addition to a list of useful Python 
>>references.
>
>It has a link on the top-level documentation page at python.org:
>http://www.python.org/doc/

Ah, I see it now. Good.

BTW do you think the PQR is an accurate and useful reference, Kent?

Dick


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-18 Thread Eric Brunson
Stephen McInerney wrote:
> Kent,
>
>   
>>> I was asking if it's a recognized good programming practice to
>>> declare and initialize *all* members in the class defn.
>>>   
>> What do you mean by "initialize *all* members in the class defn"?
>> 
> - obviously I meant to say do it in the __init__() method,
> I wrote the snippet as I was rushing out the door to an exam,
> but I think the intent was clear.
>
>   
>> If you mean to initialize the variables in the __init__() method:
>> maybe this is more common but I don't think I have ever seen it recommended 
>> to initialize all variables in the __init__() method. Certainly there are 
>> times when it makes sense to have some of the initialization in other 
>> methods that are called from __init__().
>> 
>
> I only said "make a token dummy assignment in __init__() to hint
> to the static analyzer the name and expected type, I didn't say
> "you must do all the actual initialization itself in __init__()".
>   

I guess my only thought is that this "static analyzer" is simply a 
holdover from your Java/C++ programming experience. It just doesn't 
really make sense in a dynamic language. I'd rather spend my time 
actually writing the documentation than litter my code so some other 
software can do it for me.

I'm not saying it isn't a good idea in Java, I'm just not sold on the 
concept in python. Just write doc strings, people have already written 
utilities to parse and display them.

> In the context of the original question
> "where and how should we assign class members in order
> to flag member names and types to static analyzers like
> Doxygen or pylint?"
> I understood that people were agreeing
> "Yes, assigning each member token values in the __init__()
> method is a good practice".
>
>   
>>> I think I'm hearing a general yes on that - any other opinions?
>>>   
>> Not sure where you think you are hearing a yes, I am hearing a lot of 
>> objections.
>> 
>
> No they didn't - they said that this cannot be done for true dynamic code,
> which is true, but obviously doesn't apply to working with
> static analysis tools, which is what the question was about.
>
> Regards,
> Stephen
>
> _
> Messenger Café — open for fun 24/7. Hot games, cool activities served daily. 
> Visit now. http://cafemessenger.com?ocid=TXT_TAGHM_AugHMtagline
>
>   
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need some help about pywin32.

2007-08-18 Thread pierre cutellic
Hi,
I'm actually working with many softwares for 3D-CAD-modeling, like Blender
and Rhino, and i have heard about pywin32 and makepy which can define
Rhinoscript command but really don't know how to do. This is something which
could be really usefull (and a super saving-time tip!!) for me to command
both Rhino and Blender by the same interface and language; and in order to
share data from softwrares in general.

Does anybody could explain me how to process? Or maybe any good tutorial
about that?

Best regards.
Pierre.

-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting the size of an open TarFile object

2007-08-18 Thread Adam A. Zajac
Hello all,

I've been working with the tarfile module and just noticed an apparent
flaw in my own logic.  I wanted to add files to the tar until it neared
a certain file size.  After every addition I would use
os.path.getsize().  What I noticed today is that I could add a file to
the tar without the tar's size changing.  I'm assuming that because the
TarFile object is not closed, finding its size that way isn't reliable.

The first thing I tried was using flush(), but TarFile objects
apparently don't do that.  I also can't close the object and reopen it
for appending because TarFile objects can't append if the tar is
compressed.  And finally, I can't predict the compression ratio, so I
can't merely keep track of the size of the individual files without a
huge gap to my target size.

I'm giving up on it for the night.  Anyone have any thoughts?

Adam
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor