New to Python: Features

Richard Blackwood richardblackwood at cloudthunder.com
Tue Oct 5 08:54:57 CEST 2004


Josiah Carlson wrote:

>>This is a cool language, I love code chunks!!
>>    
>>
>
>They can be useful, but they are a great way to introduce security
>holes.
>
>  
>
Is that a limitation of the language (the security holes I mean)?

> Modify the interpreter. There was a thread a few months back on
>
>python-dev on doing tail-call optimization, I think someone even had a
>patch for it.
>
>Python's recursion limit is around 1000 levels deep.  If you are doing
>tail-calls more than 1000 levels deep, maybe you should be looping
>instead of recursing, or even creating your own stack.
>
>  
>
>Yes.  It is a keyword, like a few others.
>
>  
>
>>>>import keyword
>>>>keyword.kwlist
>>>>        
>>>>
>['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'e
>xcept', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
>'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yiel
>  
>
Weird, I guess that means I can manipulate them in this way.  Wonder if 
I can add keywords...

>
>  
>
>>yes, you can write custom import hooks.
>>    
>>
>>I guess I'll hit the docs with how to do this.
>>    
>>
>
>I hear they aren't too hard.
>
>
>  
>
>>>>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.
>>    
>>
>
>Functions, no (security risk).
>  
>
Argg!

><SNIP>
>Don't be frustrated.  It is dynamically typed, but it is STRONGLY typed.
>
>Anything that you would want to do with a static typed language, can be
>done with Python.
>
>
>  
>
Thanks.  Doesn't this make my scripts slower though?

>There is a unittest module for encouraging test driven development.
>
>You can, of course, design by contract.  Nothing stops you from doing so.
>
>I do what could be considered design by contract in much of my contract
>work (no pun intended).  ... (roughly 1/3 of my
>code is) to verify correctness.
>
>When decorators via a syntax are introduced in Python 2.4, design by
>contract becomes easier (you can set preconditions and postconditions,
>or whatever you want).
>
>  
>
Cameron directed me to a design by contract module for Python.  My, 
imagine if you were using C, probably 4x as much code eh? --> "I also 
write extensive tests"

>Thinking about it, having never used Java, I imagine an "Interface"
>would be something like...
>
>
>class I_foo:
>    def funct1(self):
>        raise Exception, "Not Implemented"
>    def funct2(self, arg):
>        raise Exception, "Not Implemented"
>
>class foo_implementation(I_foo):
>    def funct1(self):
>        pass
>    def funct2(self, arg):
>        pass
>
>
>So, I suppose Python does, if implicitly.
>
>
>  
>
Cool.

>  
>
>>>Yes, if you are willing to work for it.
>>>
>>>      
>>>
>>I expect the docs will tell me how to do this.
>>    
>>
>
>There was another thread on this.  Check the thread on this mailing list
>with the subject of "Python Macros".
>
>
>  
>
I'm on it, thanks.

> <SNIP>
>
>  
>
>>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.
>>    
>>
>
>Pyrex can compile a subset of Python to C.
>
>
>  
>
Great, I'll check that out.  I guess that will allow me to extend the 
language in C.

>There is also...
>
>print "Hello, World %s"%time.asctime()
>
>
>  
>
I see.

><SNIP>
>It isn't as fast as a real case statement, but if that is necessary...
>
>class foo:
>    def case_1(self, arg):
>        pass
>    def case_2(self, arg):
>        pass
>    def dispatch(self, arg1, arg2):
>        getattr(self, 'case_%i'%arg1)(arg2)
>
> - Josiah
>
>  
>
AWE-SOME Josiah.  I don't know how to thank you.  If I was **** off that 
might do you some good eh?  Alright then.  Thanks.



More information about the Python-list mailing list