New to Python: Features

Andrew Dalke adalke at mindspring.com
Tue Oct 5 01:56:41 EDT 2004


Richard Blackwood wrote:
>> exec code, glbls, lcls
>>
> 
> 
> This is a cool language, I love code chunks!!

Like I said with eval, DO NOT USE THIS!  It almost certainly
means you're doing the wrong thing.  It's full of security
holes and there are nearly always better ways to solve
the underlying problem.

> How come Python always complains when I don't include the self parameter 
> in an object method?  Your code doesn't work on my interpreter.

Remember that pointer to asking smart questions?  Remember
that part about reading the documentation?  Doing those
would seriously help your understanding and help us know
what you mean with "always complains" and "doesn't work."


> I know but that's a real bummer.  No way around that?

Python is not a functional programming language.

Do you want it because it's cool or because it's useful?

> So is the print statement ironed into the language and not a function?

Documentation.

Does it look like a function?

>>> 20. Date persistence and serialization
>>
>>
>>
>> This can mean any one of a dozen things.
>>
> 
> I'd like to store function and variables and of course objects in a form 
> that can be easily read back into the program/script.

This can mean any one of a dozen things.  They are all
available in Python.  Some are standard modules.  Read the docs.

Python doesn't support Smalltalk's system image.  That's
probably a good thing.

> Oh really??  Exciting, I'm glad of it.  Hit the docs I must!

Umm... Yes.

>>> 22. Is the self parameter hidden from me as a programmer?  Can I 
>>> hide/unhide it as I wish?
>>
>> It is not hidden, in fact, you get to name it...
>>
>> class foo:
>>     def goo(I_AM_SELF, arg):
>>         pass
>>
> Cool!


DO NOT DO THAT EVER!

Seriously not cool.

> Not fully implemented, but I guess that will have to suffice.

Is there any non-trivial language which is fully implemented
for C#?

>> Python has no static typing.
>>
> 
> Argg!

This is precisely why my first reply said this question
was way too hard to answer briefly.  You claim experience with
Smalltalk.  Smalltalk has no static typing either.  There
are many essays available (and books no doubt) on all the
nuances here.  You've used Ruby -- it's the same there too.


> I'd like to be able to use a string as an integer without an explicit 
> coerion on my part for example.

NO!  Don't do that.  Bad code.  Subtle errors.

Try Perl or Ruby instead.

> Ugly?  I disagree, but hey, what do I know?  Objective-C is OOP and 
> messaging is awesome.  I love Python though, a hybrid between the two 
> would be great.

Do some research for your own and see if such thing exists.
Hint: yes.

> That is quite a shame, no modules for this either huh?

It quite depends on your expectations of what design by
contract, protocols, etc. means.  Do some research.  Hint:
Google for 'python "design by contract"' and related topics.

>>> 34. In pure Python, can I change and add new constructs to the Python 
>>> syntax?
>>
>> Yes, if you are willing to work for it.
>>
> 
> I expect the docs will tell me how to do this.

Yes, the docs for modifying the interpreter.

>>> 37. Dynamic dispatch
>>
>> This could mean a few different things.
>>
> 
> Like virtual functions in C++

Docs.  Read.  Enjoy.

When you say "like virtual functions in C++" do you also
mean supporting the same resolution algorithm for handling
diamonds in multiple inheritance?  Do you mean are they
bound vs. unbound?  That you can use pointer arithmetic
to go up and down the vtable?  That they aren't
introspectable?

That's why I say it's easier to just read the docs rather
than have people give you short answers that aren't useful
without the entire context of how Python works.


> What I actually meant was are there any facilities (built-in or modules) 
> which allow for automatic compilation to C/C++/C#/D.  For example, 
> particular Smalltalk distros compile to C as does ObjC.

Yes.  But you'll never use them.  The problem you'll want
to solve is "how do I call Python code from a ... library"
or "how do I package Python as an executable" and not
"how do I convert Python code into C".

You are asking the wrong question.  You are asking about
technique, not goal.

>>> 43. Embedding variables in strings like: print "Hello, World. Time: 
>>> #{Time.now}"
>>
>> t = time.asctime()
>> print "Hello World %(t)s"%{'t':t}
>> print "Hello World %(t)s"%locals()
>>
> 
> That is messy, exactly why I wanted the kind of clear embedding I gave 
> an example for.  Oh well.

You asked for "embedding variables" not embedding expressions.
You got what you asked for, not what you wanted.  That's part
of being able to ask the right question.  Remember that essay
people suggested you read?

> Really?  Hmmmm, does anyone know of a bridge between Python and Ruby?

Why not just use Ruby?  It seems to fit your search criteria
much better.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list