New to Python: Features

  • Thread starter Richard Blackwood
  • Start date
R

Richard Blackwood

Hi, I'm new to Python and I'd like to know if Python has the following
support: *please answer to each individually, thanks*

1. Multi line comments
2. Functions as variables:
a. functions can be stored in variables, passed as arguments to
other functions, and returned as results.
3. Function nesting with proper lexical scope (i.e. closures)
4. Operator overloading (inc. the ability to define new operators)
5. Can I do this? print("Hello " .. "World") --> Hello World
6. Constructors
7. "Chunks": as in a code block contained within a string, file, or
delimited by some sort of notation (such as brackets) which can be
passed to and from functions, stored in objects, with the option of
local scoping of variables declared within it.
8. "Repeat-Until" as in :
repeat
line = os.read()
until line ~= ""
print(line)
9. Generic for loops where " for i=1,f(x) do print(i) end" would print i
only once.
10. Can I call an object's method as object:method(arg) and have that
translate into object.method(object, arg)
11. Can I make dynamic statements and nature like with eval() in Javascript?
12. Can I make calls to a function with a varying number of arguments?
13. Named arguments
14. Tables with built-in methods for manipulation such as sort, etc.
15. Table filters
15. Proper Tail Call (otherwise known as Proper Tail Recursion)
16. The ability to call a function without brackets
17. Is the Python interpreter a JIT? Does it have a bytecode? Is it as
fast as Java?
18. The ability to modify the import/require functionality (how modules
can be loaded)
19. Coroutines and threads (non-preemptive)
20. Date persistence and serialization
21. May modules be stored in variables, passed to and produced from
functions, and so forth?
22. Is the self parameter hidden from me as a programmer? Can I
hide/unhide it as I wish?
23. Prototype-based OOP or the ability to extend a class without
physically modifying it
24. Manual garbage management
25. A fully implemented .NET counterpart (I should be able to write
Python scripts for both with the same code)
26. How easily can other languages access it and vice versa?
27. The option of mixing in static typing
28. Automatic type coercion
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?
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]
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)
32. Support for unplanned reuse of classes such as in TOM
(http://www.gerbil.org/tom/)
33. Function/Method overloading
34. In pure Python, can I change and add new constructs to the Python
syntax?
35. May I modify the garbage collector?
36. May I implement control structures as object messages?
37. Dynamic dispatch
38. Reflection and/or templates
39. Unicode
40. Ability to call external APIs and DLLs with relative ease
41. How easy is it to port my Python code to C/C++/C# or Java?
42. The ability to assign a method(s) to a collection/group of objects
[with a particular signature i.e.]
43. Embedding variables in strings like: print "Hello, World. Time:
#{Time.now}"
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
45. Are all things objects in Python? Do all objects have built-in
iterators and the like? i.e. can I do this:
3.times { print "Ho! " }
puts "Merry Christmas"

That's all folks!
 
A

Andrew Dalke

Richard said:
Hi, I'm new to Python and I'd like to know if Python has the following
support: *please answer to each individually, thanks*

Welcome to Python. I've been using it for almost a decade
and full time for 7 years and quite enjoy it.

However. You've asked a whole bunch of questions which
look as if you've not done any research on your own. It
has the feeling almost that you're asking us to do a
homework assignment for you. Given the question
> 39. Unicode

it means you haven't even looked at the tutorial at
http://docs.python.org/tut/tut.html
with its section 3.1.3 "Unicode strings".

much less given a cursory review of the reference manual at
http://docs.python.org/ref/ref.html

Given your questions about closure, tail recursion,
JIT, prototype-based OOP, etc. you are apparently not
new to programming. Reading through the base
documentation should be a much better use of your time
and ours than having people answer your questions point
by point. After all, some of your questions require
non-trivial amounts of contextualization to answer
correctly. Eg, your #30 assumes a Smalltalk paradigm,
while Python uses a different way to achieve similar
ends, your #28 requires explaining Python's reference
based semantics where variable have only one type,
reference to object, and your #11 requires a stern
warning that such behaviour is almost certainly a
security hole waiting to happen.

The most suspicious part about your post is your
haphazard use of so many different programming
paradigms combined with the almost pedigogical way
of describing some of them.

Please read the basic Python documentation before
asking these questions.

Andrew
(e-mail address removed)
 
R

Richard Blackwood

Andrew said:
Welcome to Python. I've been using it for almost a decade
and full time for 7 years and quite enjoy it.

However. You've asked a whole bunch of questions which
look as if you've not done any research on your own. It
has the feeling almost that you're asking us to do a
homework assignment for you. Given the question


it means you haven't even looked at the tutorial at
http://docs.python.org/tut/tut.html
with its section 3.1.3 "Unicode strings".

much less given a cursory review of the reference manual at
http://docs.python.org/ref/ref.html

Given your questions about closure, tail recursion,
JIT, prototype-based OOP, etc. you are apparently not
new to programming. Reading through the base
documentation should be a much better use of your time
and ours than having people answer your questions point
by point. After all, some of your questions require
non-trivial amounts of contextualization to answer
correctly. Eg, your #30 assumes a Smalltalk paradigm,
while Python uses a different way to achieve similar
ends, your #28 requires explaining Python's reference
based semantics where variable have only one type,
reference to object, and your #11 requires a stern
warning that such behaviour is almost certainly a
security hole waiting to happen.

The most suspicious part about your post is your
haphazard use of so many different programming
paradigms combined with the almost pedigogical way
of describing some of them.

Please read the basic Python documentation before
asking these questions.

Andrew
(e-mail address removed)

Ouch! I didn't expect such harsh replies. Thanks anyways.
 
A

Andrew Dalke

Richard said:
Ouch! I didn't expect such harsh replies. Thanks anyways.

That wasn't harsh. I answered 4 of your questions.

39. pointer to the documentation on that topic
30. no, Python uses a different style
28. that question doesn't make sense for Python -- variables
only have one type
11. don't use eval (implying that Python has such a thing)

and spent at least as much information in responding as
you did in writing the questions in the first place.

I even explained why I found your post to be problematical
and left an opportunity for you to explain why my
conjectures were wrong.

Feel free to explain why we should put a lot of effort into
replying to your email when it seems you've made no effort
in answering the questions yourself, despite seeming to be
quite capable of doing so.

Andrew
(e-mail address removed)
 
R

Richard Blackwood

Grant said:
You've _got_ to be kidding...
I don't think that that is proper english.

Anyhow, I wasn't trying to muster up anything or annoy anyone. My
sincere apologies to all who were offended.
 
G

Grant Edwards

I don't think that that is proper english.

Oh. My. Gaawwwd!

Which one, the "Rude much?" crack or the "You've got to be
kidding..." crack? The latter isn't all that improper
(especially not for Usenet). The former is colloqial US
English. More specifically it's "Valley Speak" -- made popular
outside "The Valley" by movies like "Valley Girl", "Mall Rats",
"Heathers", and just about any John Hughes movie (especially
Sixteen Candles). The first two are crap, but "Heathers" is a
good movie, and I still like "Sixteen Candles".
Anyhow, I wasn't trying to muster up anything or annoy anyone.
My sincere apologies to all who were offended.

Apology accepted on the condition that you read
how-to-ask-smart-questions, and go browse around
www.python.org for 15 minutes.
 
R

Richard Blackwood

Andrew said:
That wasn't harsh. I answered 4 of your questions.

39. pointer to the documentation on that topic
30. no, Python uses a different style
28. that question doesn't make sense for Python -- variables
only have one type
11. don't use eval (implying that Python has such a thing)

and spent at least as much information in responding as
you did in writing the questions in the first place.

I even explained why I found your post to be problematical
and left an opportunity for you to explain why my
conjectures were wrong.

Feel free to explain why we should put a lot of effort into
replying to your email when it seems you've made no effort
in answering the questions yourself, despite seeming to be
quite capable of doing so.

Andrew
(e-mail address removed)

OK. I idea was that someone who knew alot about one particular would
respond to that question, and other someone who knew alot about another
particular would respond to another question, and so forth. A poor
idea? Seeing the result, I guess so. Sorry to have bothered anyone.

When I said "harsh", I meant being accused of trolling, attempting to
annoy, stir trouble, etc. None which was my intent nor did I think that
my post would be interpreted as such (otherwise I wouldn't have posted it).

Thank you for your help.
 
G

Grant Edwards

When I said "harsh", I meant being accused of trolling,
attempting to annoy, stir trouble, etc. None which was my
intent nor did I think that my post would be interpreted as
such (otherwise I wouldn't have posted it).

If you honestly didn't think you were being rude and weren't
going to annoy anybody, you really, really do need to read how
to ask questions the smart way. c.l.p is a very kind place,
but should somebody as naive as you wander into the rest of
Usenet... well, I just don't like to think of what might
happen.
 
R

Richard Blackwood

Grant said:
Oh. My. Gaawwwd!

Which one, the "Rude much?" crack or the "You've got to be
kidding..." crack? The latter isn't all that improper
(especially not for Usenet). The former is colloqial US
English. More specifically it's "Valley Speak" -- made popular
outside "The Valley" by movies like "Valley Girl", "Mall Rats",
"Heathers", and just about any John Hughes movie (especially
Sixteen Candles). The first two are crap, but "Heathers" is a
good movie, and I still like "Sixteen Candles".




Apology accepted on the condition that you read
how-to-ask-smart-questions, and go browse around
www.python.org for 15 minutes.
I'll browse around python.org for a few hours instead of throwing in the
"how-to-ask-smart-questions" part. ;-)
 
R

Richard Blackwood

Grant said:
If you honestly didn't think you were being rude and weren't
going to annoy anybody, you really, really do need to read how
to ask questions the smart way. c.l.p is a very kind place,
but should somebody as naive as you wander into the rest of
Usenet... well, I just don't like to think of what might
happen.
Apparently it is not a matter of "smartly" but don't ask at all.

I get the point, grief.
 
A

Andrew Dalke

Richard said:
OK. I idea was that someone who knew alot about one particular would
respond to that question, and other someone who knew alot about another
particular would respond to another question, and so forth. A poor
idea? Seeing the result, I guess so. Sorry to have bothered anyone.

The reason it was poor idea was not considering that on
a project like Python with nearly 15 years of work behind
it, dozens of books, thousands of magazine articles,
millions of lines of code, etc. that those answers might
already have been collected into documentation and organized
in such a way that a person like you could find all those
answers, plus details you wouldn't get from such simple
questions, plus answers to questions you haven't even
thought of asking.

To follow up, now that someone answered all your questions
are you any more knowledgeable about Python? I suspect
not because those answers don't hang together coherently
so you'll need to read the documentation anyway.

Andrew
(e-mail address removed)
 
S

Sam Holden

Apparently it is not a matter of "smartly" but don't ask at all.

Part of asking smartly is not asking thousands of people to each spend
time reading an possibly answering a question that you could find the
answer to yourself with a minute of looking.
 
B

Brian van den Broek

Richard Blackwood said unto the world upon 2004-10-05 00:32:
I'll browse around python.org for a few hours instead of throwing in the
"how-to-ask-smart-questions" part. ;-)

Wrong order of priorities, methinks. Browsing python.org will help you a
fair bit with python. Reading
<http://www.catb.org/~esr/faqs/smart-questions.html> will help you learn
more about Python and any other thing one might ever post to a newsgroup
or mail-list about. From your various posts, it is clear that the
lessons of the second piece would be much more helpful to your future
projects than would be a browse of python.org.

Best,

Brian vdB
 
G

Grant Edwards

Apparently it is not a matter of "smartly" but don't ask at all.

You are expected to spend at least a few minutes of reading on
your own before requesting that thousands of other people
answer dozens of questions for you.
I get the point, grief.

No, I don't think you do. You really ought to read the "smart
questions" link I provided if you want to understand how the
world works.
 
R

Richard Blackwood

To follow up, now that someone answered all your questions
are you any more knowledgeable about Python? I suspect
not because those answers don't hang together coherently
so you'll need to read the documentation anyway.

Andrew
(e-mail address removed)

It gave me a good idea of whether I should use it or not. Green and Red
lights did the trick.
 
V

Ville Vainio

Richard> Hi, I'm new to Python and I'd like to know if Python has
Richard> the following support: *please answer to each
Richard> individually, thanks*

Is that enough to pass the whole course, or are you going to ask for a
"solution for this simple program" soon?
 
D

Dan Bishop

Richard Blackwood said:
Hi, I'm new to Python and I'd like to know if Python has the following
support: *please answer to each individually, thanks*

Most of your questions are answered at http://docs.python.org/
1. Multi line comments

No. But multi-line docstrings are supported.
2. Functions as variables:
a. functions can be stored in variables, passed as arguments to
other functions, and returned as results.
Yes.
.... "Centered difference approximation of f'(x)"
.... return (f(x + delta) - f(x - delta)) / (2 * delta)
....
3.9999999756901161

3. Function nesting with proper lexical scope (i.e. closures)
Yes.

4. Operator overloading (inc. the ability to define new operators)

Yes. This is done by defining the special methods __add__, __mul__,
etc.
5. Can I do this? print("Hello " .. "World") --> Hello World

If ".." is supposed to be the string concatenation operator, then yes.
Hello World!
6. Constructors

Yes. They're defined like this:

class MyClass:
def __init__(self, arg1, arg2):
# ...

and called like this:

x = MyClass(arg1, arg2)
8. "Repeat-Until" as in :
repeat
line = os.read()
until line ~= ""
print(line)

There isn't a special syntax for posttest loops. You have to write
them like

while True:
line = os.read()
if not line:
break
print line
10. Can I call an object's method as object:method(arg) and have that
translate into object.method(object, arg)
.... def foo(self, arg):
.... pass
....
11. Can I make dynamic statements and nature like with eval() in Javascript?
Yes.
3

12. Can I make calls to a function with a varying number of arguments?
Yes.
.... print "called with", 2 + len(args), "arguments"
....called with 6 arguments
13. Named arguments
Yes.
datetime.date(2004, 10, 5)
14. Tables with built-in methods for manipulation such as sort, etc.

Try the built-in "list" type. Also, "dict".
15. Table filters

I'm not quite sure what you're asking. Do you mean something like
[n for n in xrange(2, 20) if isprime(n)]
[2, 3, 5, 7, 11, 13, 17, 19]

?
15. Proper Tail Call (otherwise known as Proper Tail Recursion)
No.

16. The ability to call a function without brackets

Fortunately, no.
17. Is the Python interpreter a JIT? Does it have a bytecode? Is it as
fast as Java?

For the standard interpreter: No. Yes. No.

But try Psyco (psyco.sourceforge.net).
21. May modules be stored in variables, passed to and produced from
functions, and so forth?
Yes.
import sys
import os
modules = [sys, os]
modules[1].getcwd()
'/home/dan'

22. Is the self parameter hidden from me as a programmer? Can I
hide/unhide it as I wish?
No.

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

It's not fully implemented yet, but there is a .NET version
(http://www.ironpython.org).
33. Function/Method overloading

No, but it can often be simulated by default parameters, or by
"isinstance" checks.
34. In pure Python, can I change and add new constructs to the Python
syntax?
No.

43. Embedding variables in strings like: print "Hello, World. Time:
#{Time.now}"

No, but this can be written almost as easily using the % operator.
Hello, World. Time: 2004-10-05 03:12:14.750796

or
Hello, World. Time: 2004-10-05 03:14:01.111879
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

Python does not have a switch/case construct. Your example would
normally be written as an if...elif...else ladder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,183
Members
46,719
Latest member
login dogas.info

Latest Threads

Top