Python questions -> compiler and datatypes etc
Richard Jones
richard at bizarsoftware.com.au
Mon Oct 8 02:47:16 EDT 2001
On Monday 08 October 2001 16:32, billy_bill_1 at yahoo.com wrote:
> I've been using php for ages for webdev and I don't like it. It lacks
> so many simple features, and I can't be bothered using Java to use
> those features. IMHO java is not suited for specific web development.
There's a lot of server-side Java programmers who would disagree with that
statement. Python is better, but Java can do the job.
> So I find python, I like python. Python has everything I need, except
> (apparently) the ability to encode it (php: Zend Encoder) or
Sorry, what do you mean by "encode it"? I'm not familiar with "Zend Encoder".
> compile
> it into Bytecode like java.
Python compiles to bytecode. Python's runtimes execute compiled bytecode.
There are several runtimes - one of which is Java. The predominant one is
written in C.
> It seems its not nearly as fast as java.
> (Acceptable in most cases though).
How did you measure this?
> Are there any products coming out involving compilation of python?
> Like a 2 stage interpreter like java... that would be tops... speed
> and ability to sheild source code from prying and tampering eyes.
Compiling python is at the impossible end of the scale of ease of
implementation. There has been a lot of discussion about this issue on this
list in the past. Search for "python compiler" and enjoy :)
> Does python have the ability to let the programmer change between
> strongly typed and loosly typed as needs be?
No, unless you venture into JPython land, where you could mix Java code
(strict, strong typing) and Python code (dynamic, strong typing) in the one
project. Why on earth you'd want to is beyond me though :)
> python support function overloading?
Traditional overloading, which allows a function to have multiple signatures
to allow different types to be passed in has no relevance in a dynamically
typed language like Python. Witness:
Python 2.1.1 (#1, Jul 20 2001, 22:37:24)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.58mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>> def foo(sequence):
... for element in sequence:
... print sequence.index(element), element
...
>>> foo(['a', 'list'])
0 a
1 list
>>> foo('a string')
0 a
1
2 s
3 t
4 r
5 i
6 n
7 g
>>>
[note: that's a cutnpaste from an inetractive session with the interpreter]
> variable length parameter lists?
Yep, and keyword arguments too. Continuing on from the previous interactive
session, we redefine foo:
>>> def foo(*args):
... print 'My args', args
...
>>> foo(1, 2, 'hello', 3, foo)
My args (1, 2, 'hello', 3, <function foo at 0x8131acc>)
>>>
Keyword args:
>>> def foo(food='spam', container='tin'):
... print '%s in a %s'%(food, container)
...
>>> foo()
spam in a tin
>>> foo(food='eggs')
eggs in a tin
>>> foo('curry', 'hurry')
curry in a hurry
>>>
I suggest spending half an hour walking through the Python Tutorial. For
added fun, type in the stuff in the tutorial into an interactive interpreter
at the same time. That's how I learnt Python.
Richard
More information about the Python-list
mailing list