469,282 Members | 1,808 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Very, Very Green Python User

I have used Perl for a long time, but I am something of an experimental
person and mean to try something new. Most of my 'work' with Vector
Linux entails the use of Perl (a bit of a misnomer as it is not now a
paid position -- I am not yet even out of K-12), and there a lot of
things I love about it. I can look past a number of misfeatures in
Perl, but I am surprised to see that Python has very few (that I know
of). Most of them are documented here, it would seem:
http://www.c2.com/cgi/wiki?PythonProblems. Is the Python debugger
fairly stable? The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ass.

A couple blemishes I'm concerned about, though:

Python closures are apparently very poor, but from what I can surmise
of the PyGTK2 page, instances of objects are dynamic enough to add new
methods, so you get your callbacks, at least.

Double-underscore methods are rewritten with the class name? That's an
ugly hack, but remember I'm coming from Perl. If the language doesn't
pull many other hijinks, that's OK.

I have plenty of docs and stuff, now I'm just looking for wisdom. As a
seasoned Python user, what do you have to impart?

Mar 13 '06 #1
17 1445
ha********@gmail.com wrote:
... Is the Python debugger fairly stable? Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.
The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking .... Do watch your language on this newsgroup. Lots of people read this
group and there is no good reason to offend them. In turn, you will be
cut some slack.
A couple blemishes I'm concerned about, though:

Python closures are apparently very poor, but from what I can surmise
of the PyGTK2 page, instances of objects are dynamic enough to add new
methods, so you get your callbacks, at least.
What do you mean by "very poor"? Python prefers you to use functions
defined with a suitable name in places other languages provide stronger
lambda expressions, if that's what you mean. Also, there is no easy way
to affect the variables of an encasing function, if that is what you
mean.
Double-underscore methods are rewritten with the class name? That's an
ugly hack, but remember I'm coming from Perl. If the language doesn't
pull many other hijinks, that's OK.
Double-underscore is a strong language convention and warning. Names
both beginning and ending with double-underscore may be "magic" in
that interacting with them affects more behavior than the same code
using a different name. Instance variables with double-underscore as
a leading convention get "mangled" just so that when you are designing
"mixin" classes you can easily choose names that should not collide
with the instance variable names of classes using your "mixin" classes.
I have plenty of docs and stuff, now I'm just looking for wisdom. As a
seasoned Python user, what do you have to impart?


I think if you spend the effort to learn to use Python you'll have a
wonderful experience. Welcome to the newsgroup.
--Scott David Daniels
sc***********@acm.org
Mar 13 '06 #2
Scott David Daniels wrote:
... Is the Python debugger fairly stable?

Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.


combined with a modular design, so you can make sure that individual
functions, classes, and modules work as expected before you use them
to build larger stuff...

</F>

Mar 13 '06 #3
> Python closures are apparently very poor, but from what I can surmise
of the PyGTK2 page, instances of objects are dynamic enough to add new
methods, so you get your callbacks, at least.
It's true that Python's "lambda" is somewhat limited, but this is
rarely a problem because you can define named functions on-the-fly.
Double-underscore methods are rewritten with the class name? That's an ugly hack


Yes, it is. But in practice, you will rarely need to pay attention to
this. I'd been using Python for two years before I noticed this odd
behavior.

I heartily applaud shopping around for new languages. Coming from
Perl, I think you'll find Python to be a figurative breath of fresh
air, but you might also want to look at languages like Ruby, Haskell,
etc.

Mar 13 '06 #4
On 12 Mar 2006 17:58:43 -0800
ha********@gmail.com wrote:
Double-underscore methods are rewritten with the class
name? That's an ugly hack, but remember I'm coming from
Perl. If the language doesn't pull many other hijinks,
that's OK.


This is GvR's way of saying "do not use double-underscore
methods". ;-)

You shouldn't ever see the mangled _<classname>__<method>
form, unless you've been very, very naughty.

And if you have been, well, we promise not to tell anybody,
but it's Your Problem [TM].

Seriously, truly private methods are generally not something
you want to mess with in Python. Quite frequently, people
with a C++ or Java background come here and ask for them. A
Frequently Repeated Thread ensues:

0) I want private methods in Python

1) you don't need 'em

2) C++ and Java have 'em and the book says you have to
have 'em, or you aren't doin' OOP

3) total hogwash -- I can use compiler directives to
defeat C++/Java "private" variables anyday, so it
doesn't accomplish anything that isn't easier to
do by putting "__" in front of it to tell the client
programmer not to use it.

Then we all go back to coding.

Cheers and good luck with your project, ;-)
Terry

--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Mar 14 '06 #5

Scott David Daniels wrote:
ha********@gmail.com wrote:
> The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ....

Do watch your language on this newsgroup. Lots of people read this
group and there is no good reason to offend them. In turn, you will be
cut some slack.


What exactly is your problem with the language used here ?

"Suck" rhymes too closely ?

Are "luck", "ruck", and "puck" offensive too?
And who gets to decide how easily offended "lots of people" are ?

Why do you think *anyone* else is as offended by hanumizzle's language
as others are by your sanctimoniousness ?

--
Alan
http://aivipi.blogspot.com

Mar 14 '06 #6
Scott David Daniels wrote:
ha********@gmail.com wrote:
... Is the Python debugger fairly stable?


Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.


Well, the fact is that I haven't used pdb on more than two or three
occasions, and I'm using Python since the 1.5.x.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Mar 14 '06 #7
ha********@gmail.com wrote:
I have used Perl for a long time, but I am something of an experimental
person and mean to try something new. Most of my 'work' with Vector
Linux entails the use of Perl (a bit of a misnomer as it is not now a
paid position -- I am not yet even out of K-12), and there a lot of
things I love about it. I can look past a number of misfeatures in
Perl, but I am surprised to see that Python has very few (that I know
of). Most of them are documented here, it would seem:
http://www.c2.com/cgi/wiki?PythonProblems.
Seems that this page is sometimes just plain wrong and somewhat
outdated. Let's see some of them:

1/Memory Management The reference implementation uses reference
counting, the worst-performing memory management scheme there is

Actually, Python uses *both* reference-counting and a garbage collector.

2/ No Ternary If
Well... actually true, but not such a major annoyance.
NB : the "tuple_dispatch" option works well if you know how-to python.
IOW, you can avoid useless evaluation with a simple lambda :

result = (lambda: action_if_true, lambda : action_if_false)[test]()

3/ Dynamic Typing
Err... Actually, this is not a problem, Sir, it's a feature.

4/ Speed
Never been a problem for me so far.

5/ Ugly mechanism for privates
This is *not* a mechanism for "privates". This is a mechanism to protect
some crucial implementation attributes from being *accidentally*
overriden in a child class.

6/ SelfDotSyndrome
As for 3, this is definitively a feature. I've always used the implicit
'this' in Java and C++ anyway.

Is the Python debugger
fairly stable?
can't tell, almost never had a use for it.
More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ass.
What makes you think you have such a need for a debugger ?
A couple blemishes I'm concerned about, though:

Python closures are apparently very poor,
In Python, encapsuling state is better done with objects. Once you'll
get a better understanding of Python's object model, you'll find out
that there's not such a need for more powerfull closures (well, that's
MHO at least). Amongst other things, functions and methods are objects,
and any other class can be made callable if you implement a method for
the call operator...
but from what I can surmise
of the PyGTK2 page, instances of objects are dynamic enough to add new
methods, so you get your callbacks, at least.
You don't even need this to use callbacks. Remember, functions and
methods are objects, and other objects can be callable too...
Double-underscore methods are rewritten with the class name? That's an
ugly hack,
Ever looked at what a C++ compiler do to symbols ?-)
but remember I'm coming from Perl.


Talking about ugky hacks... !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Mar 14 '06 #8

Scott David Daniels wrote:
ha********@gmail.com wrote:
... Is the Python debugger fairly stable?

Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.
> The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ....


Do watch your language on this newsgroup. Lots of people read this
group and there is no good reason to offend them. In turn, you will be
cut some slack.


As one who avidly studies language, I have observed that the meaning of
a word slip out of its original context through idiomatic usage. If I
had included the implicit object of 'sucks', then you would have more
grounds for complaint. However, 'sucks', used in the intransitive
sense, is no worse than 'bites the bag'.

Think about the word 'mogul'. Like 'oil mogul' or 'software mogul'.
Well, the **Mughals**, whence comes the word, were mass-murderers:

http://www.geocities.com/hindoo_humanist/mughal.html

If you were a Hindu in those times, saying 'oil mogul', would be
equivalent to saying 'oil Stalin' or 'oil Hitler' today. But this isn't
about human rights so much as it is about semantics. (Nobody likes
long-winded, abstract philosophical discussions on a technology NG.)
'Sucks' doesn't mean what it used to, at least how I used it there.

Unless one is willing to investigate the etymology of every word he
uses (like mogul, Christian, or juggernaut), there needs to be a more
lenient attitude towards use of language.

Mar 15 '06 #9
Exactly...this is how most of my Perl modules are written and tested,
actually.

Mar 15 '06 #10
ha********@gmail.com wrote:
Nobody likes long-winded, abstract philosophical discussions on a
technology NG.


not even on comp.lang.python ? ;-)

</F>

Mar 15 '06 #11
Fredrik Lundh wrote:
ha********@gmail.com wrote:

Nobody likes long-winded, abstract philosophical discussions on a
technology NG.

not even on comp.lang.python ? ;-)

I wish :-)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 15 '06 #12
ha********@gmail.com wrote:
Scott David Daniels wrote:
ha********@gmail.com wrote:
... Is the Python debugger fairly stable? Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.
> The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ....

Do watch your language on this newsgroup. Lots of people read this
group and there is no good reason to offend them. In turn, you will be
cut some slack.


As one who avidly studies language, I have observed that the meaning of
a word slip out of its original context through idiomatic usage. If I
had included the implicit object of 'sucks',


In fact I elided the "ass" from your original "sucks ass" in my original
quote, and now you carefully forget it in order to bolster your case.
then you would have more grounds for complaint. However, 'sucks',
used in the intransitive sense, is no worse than 'bites the bag'.


Comp.lang.python is an unusually well-mannered group. If you look at
the messages over the past year (and exclude any chain with Xah Lee),
I think you will find your language, while not obscene, was well below
the standard for the newsgroup. Some of us value that, and are happy
enough to leave it to other groups to express themselves more fervently.
Here you'll find even strong disagreement is usually expressed with a
careful consideration that the other person may well get offended.

By the by, you will notice I did not simply chide you about your use
of language, but rather answered your questions as best I understood
them.

Don't worry, this is the last I have to say on the subject.

--Scott David Daniels
sc***********@acm.org
Mar 15 '06 #13

Scott David Daniels wrote:
ha********@gmail.com wrote:
Scott David Daniels wrote:
ha********@gmail.com wrote:
... Is the Python debugger fairly stable?
Yes, but it is not massively featured. The "Pythonic" way is to
rarely use a debugger (test first and straightforward code should
lead to "shallow" bugs). Often for most of us judiciously placed
print statements suffice.

> The one you get with Perl stinks on ice. More than
anything else, I would like to have a powerful OO environment where I
do not have to worry about the debugger sucking ....
Do watch your language on this newsgroup. Lots of people read this
group and there is no good reason to offend them. In turn, you will be
cut some slack.


As one who avidly studies language, I have observed that the meaning of
a word slip out of its original context through idiomatic usage. If I
had included the implicit object of 'sucks',


In fact I elided the "ass" from your original "sucks ass" in my original
quote, and now you carefully forget it in order to bolster your case.


D'oh! You are right.

That's why I always liked BB Forums. You get to pull Big Brother
'rectifications'.

Mar 15 '06 #14

Dennis Lee Bieber wrote:
On 12 Mar 2006 17:58:43 -0800, ha********@gmail.com declaimed the
following in comp.lang.python:

Double-underscore methods are rewritten with the class name? That's an
ugly hack, but remember I'm coming from Perl. If the language doesn't
pull many other hijinks, that's OK.
Compared to a language that added OO by requiring the user to
"bless" things to make it behave as an object, you find name-mangling
for "private" methods to be ugly?


I saw the duplicity in my own post; mai ben rai. :D
I suggest you never look under the hood of a C++ compiler...They
not only name-mangle, but add such crud as type/size codes for arguments
and return value -- all to be able to invoke the correct method due to
overloading.


I've heard about the brain damages of C++. Never programmed in it;
don't need to. If I were ever forced to program C++ as a result of a
career, I think I would probably quit.

Mar 15 '06 #15

bruno at modulix wrote:
ha********@gmail.com wrote:
I have used Perl for a long time, but I am something of an experimental
person and mean to try something new. Most of my 'work' with Vector
Linux entails the use of Perl (a bit of a misnomer as it is not now a
paid position -- I am not yet even out of K-12), and there a lot of
things I love about it. I can look past a number of misfeatures in
Perl, but I am surprised to see that Python has very few (that I know
of). Most of them are documented here, it would seem:
http://www.c2.com/cgi/wiki?PythonProblems.
Seems that this page is sometimes just plain wrong and somewhat
outdated. Let's see some of them:


I doubt it not. The C&C wiki is full of blowhards.
1/Memory Management The reference implementation uses reference
counting, the worst-performing memory management scheme there is

Actually, Python uses *both* reference-counting and a garbage collector.
....that, and ORO is the worst-performing memory management scheme there
is. Look at NewLISP for an implementation.
2/ No Ternary If
Well... actually true, but not such a major annoyance.
NB : the "tuple_dispatch" option works well if you know how-to python.
IOW, you can avoid useless evaluation with a simple lambda :

result = (lambda: action_if_true, lambda : action_if_false)[test]()
Ternary if, in itself, is a lame substitute for the free combination of
expressions available in Lisp, where all flow-control statements are,
in fact, functions (or special forms for the pedantic; the semantics
I'm talking about are the same regardless).

You can regress with that argument to the logical conclusion that
everyone should be a 'SmugLispWeenie'.
4/ Speed
Never been a problem for me so far.
Yeah, as I say, the bottleneck in speed is usually user interaction.
5/ Ugly mechanism for privates
This is *not* a mechanism for "privates". This is a mechanism to protect
some crucial implementation attributes from being *accidentally*
overriden in a child class.


I get it now. It would be kind of nice if these 'isolated' methods had
their own 'namespace', but I can't complain too much.

Perl can use closures as private methods, which is pretty nifty. I
never used them like this though, because I don't really believe in the
concept of private methods. (Although what you described above is
reasonable enough.) After I stopped programming C, I quickly adopted
this maxim: validation occurs only on user (or cracker, as the case may
be) input.

If the programmer is being a dick, that's his/her problem.
A couple blemishes I'm concerned about, though:

Python closures are apparently very poor,


In Python, encapsuling state is better done with objects. Once you'll
get a better understanding of Python's object model, you'll find out
that there's not such a need for more powerfull closures (well, that's
MHO at least). Amongst other things, functions and methods are objects,
and any other class can be made callable if you implement a method for
the call operator...


I used to kind of / sort of program Lisp and Scheme, so I just like
first-class everything. I also disagree with the sentiment against deep
binding in lambdas (lambdae?) that seems to prevail in the Python
community. I used deep binding like this once in my .emacs (my .emacs
is SICK); I had to (require 'cl) just to use lexical-let. It was in
fact quite useful and no mutation of values in the lexical environment
was necessary.
but from what I can surmise
of the PyGTK2 page, instances of objects are dynamic enough to add new
methods, so you get your callbacks, at least.


You don't even need this to use callbacks. Remember, functions and
methods are objects, and other objects can be callable too...


Eh?? I need an example.
Double-underscore methods are rewritten with the class name? That's an
ugly hack,


Ever looked at what a C++ compiler do to symbols ?-)


I'm afraid I don't want to know.
but remember I'm coming from Perl.


Talking about ugky hacks... !-)


Not all hacks are ugly.

Mar 15 '06 #16
ha********@gmail.com a écrit :
bruno at modulix wrote:

(snip)
You don't even need this to use callbacks. Remember, functions and
methods are objects, and other objects can be callable too...


Eh?? I need an example.


Of callables ?

class FuncInDisguise(object):
def __init__(self, name):
self.name = name

def __call__(self, who):
return "Hello, %s, my name is %s" % (who, self.name)

hello_from_bruno = FuncInDisguise("bruno")
print hello_from_bruno("hanumizzle")

It's somewhat equivalent to a more functional :

def curry(fun, *args):
def _curried(*moreargs):
return fun(*(args + moreargs))
_curried.func_name = "curried(%s) of %r" % (", ".join(args), fun)
return _curried

def greeting(name, who):
return "Hello, %s, my name is %s" % (who, name)

hello_from_bruno2 = curry(greeting, "bruno")
print hello_from_bruno2("hanumizzle")
Now when it comes to callbacks, just pass around any callable with a
compatible signature, and this should Just Work(tm):

def test(callback):
result = callback('baaz')
print "in test, got: '%s'" % result
return result

class Foo(object):
def __init__(self, name):
self.name = name

def doit(self, arg):
return "%s %s" % (self.name, arg)

f = Foo('bar')

print test(f.doit)
print test(hello_from_bruno)
print test(hello_from_bruno2)
print test(FuncInDisguise)
print test(lambda n: "what should I do with %s ?" % n)
print test(lambda n: ("what should I do with %s ?" % n).split)

And why we're at it, why not have some fun calling the result of a
callback ?-)

print test(FuncInDisguise)('madman')
print test(lambda n: ("what should I do with %s ?" % n).split)()

HTH
Mar 16 '06 #17
Dhanyavaad (thank you)

Mar 18 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Syver Enstad | last post: by
16 posts views Thread by Eric | last post: by
2 posts views Thread by Peter Kleiweg | last post: by
8 posts views Thread by York | last post: by
6 posts views Thread by Greg | last post: by
17 posts views Thread by Steve R. Hastings | last post: by
50 posts views Thread by diffuser78 | last post: by
16 posts views Thread by Durumdara | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.