New to Python: Features

Richard Blackwood richardblackwood at cloudthunder.com
Tue Oct 5 07:23:55 CEST 2004


<SNIP>

> 
> 
> code = "print 'hello world'"
> glbls = {}
> lcls = {}
> 
> exec code, glbls, lcls
>


This is a cool language, I love code chunks!!

> 
>10. Can I call an object's method as object:method(arg) and have that 
>>translate into object.method(object, arg)
> 
> 
> class foo:
>     def goo(self, arg):
>         print self, arg
>     def bar(arg):
>         print arg
>     bar = staticmethod(bar)
> 
> a = foo()
> a.goo(arg) #will print information about the instance and argument
> a.bar(arg) #will only print information about the argument
> 

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.

> 
>>15. Proper Tail Call (otherwise known as Proper Tail Recursion)
> 
> 
> No, it kills tracebacks.

I know but that's a real bummer.  No way around that?
> 
> 
>>16. The ability to call a function without brackets
> 
> 
> No.
> 

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

> 
>>17. Is the Python interpreter a JIT? Does it have a bytecode?  Is it as 
>>fast as Java?
> 
yes, you can write custom import hooks.
> 

I guess I'll hit the docs with how to do this.

> 
>>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.

> 
> 
>>21. May modules be stored in variables, passed to and produced from 
>>functions, and so forth?
> 
> 
> Yes, though it isn't done very often.
> 

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

> 
>>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!

>>25. A fully implemented .NET counterpart (I should be able to write 
>>Python scripts for both with the same code)
> 
> 
> Check IronPython and PythonNET
> 

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

> 
>>26. How easily can other languages access it and vice versa?
> 
> 
> C and C++ are easy.  There is a TCL interface.
> 
> Anything with C or C++ interfaces are arguably trivial to talk to.
> 

I guess D should work then.

> 
>>27. The option of mixing in static typing
> 
> 
> Python has no static typing.
> 

Argg!
> 
>>28. Automatic type coercion
> 
> 
> Certain kinds of things can do what is known as "type coercion" in other
> languages.  What kinds of coercion did you want to do.
> 

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

> 
>>29. Is Python designed in such a way that I may merely "plugin" a 
>>C/C++/Java/D module which will then allow for mixing their syntax and 
>>perhaps even access to their facilities within Python?
> 
> 
> You can call C/C++ functions in Python (a large portion of the standard
> library is implemented in C).
> 
> Jython allows nearly transparent use of Python and Java.
> 
> You don't get other language syntaxes, generally.
> 
> 
>>30. Messaging syntax such as : [myColor setRed:0.0 green:0.5 blue:1.0] 
>>or [dog bring:paper to:me] and [[myAunt phone] setTo:[myUncle phone]] 
>><--- Nested messages and [dog perform:sel_get_uid("bark")] which is the 
>>same as [dog bark]
> 
> 
> We don't do messaging syntax.  Combining messaging and object-oriented
> syntax would make for an ugly language.

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.

> 
> 
>>31. Concepts of Protocols (whereby one may organize related methods into 
>>groups and check whether a particular object implements the methods 
>>within this protocol), or Interfaces similar to those in Java whereby 
>>classes or objects which implement the interface (sign the contract) 
>>must implement the methods and attributes as specified in the interface, 
>>and/or programming by contract such as in Eiffel (see: 
>>http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=595)
> 
> 
> No.  Test-driven development is the norm in Python.
> 

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

>>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.

> 
>>35. May I modify the garbage collector?
> 
> 
> If you really want, though it already works fine.
> 

Oh, I just like to play with garbage collectors.  It's a kind of fettish 
of mine.

> 
>>37. Dynamic dispatch
> 
> 
> This could mean a few different things.
> 

Like virtual functions in C++


>>41. How easy is it to port my Python code to C/C++/C# or Java?
> 
> 
> Depends on how experienced you are with those languages.
> 

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.

> 
>>42. The ability to assign a method(s) to a collection/group of objects 
>>[with a particular signature i.e.]
> 
> 
> No.
> 

That's no good.  I wonder if I could implement this myself with minimum 
pain.

> 
>>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.
> 
>>44. Case or Switch statements with functionality as such:
>>case score
>>when 0...40
>>   puts "Horrible!"
>>when 40...60
>>   puts "Poor"
>>when 60...80
>>   puts "You can do better!"
>>when 80...95
>>   puts "Now that's acceptable"
>>when 95..100
>>   puts "That the best you can do?  j/k"
>>else
>>   puts "Didn't take the test?"
>>end
> 
> 
> No.
> 

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

----------------

Thanks Josiah.  I'm perusing the docs right now.



More information about the Python-list mailing list