[Tutor] Fwd: Re: From C to Python
Dhruva Kulkarni
dhruva_lives at yahoo.com
Thu Jul 5 15:24:52 CEST 2007
Dhruva Kulkarni <dhruva_lives at yahoo.com> wrote: Date: Thu, 5 Jul 2007 06:12:13 -0700 (PDT)
From: Dhruva Kulkarni <dhruva_lives at yahoo.com>
Subject: Re: [Tutor] From C to Python
To: Kent Johnson <kent37 at tds.net>
Thanks for the link, i was afraid it might be something like that :-)
Ok, i get the idea about the referencing, but i got some (;-)) doubts :
1.if I want to duplicate some 'mutable object' , then just assignment wont work, so i'm sure there must be some way of explicitly telling the interp to duplicate ( or do i have create another list and then copy and... ) also, as an afterthought, can i also do some operator-overloading ?
2.The scoping rules in C go from innermost to outermost, does this also happen in Python? Also, i couldn't find the keywords for data encapsulation ( private protected in c++ )..
3. I guess this list will never end, so if you could just point me to some sort of reference guide to Python....
From what Py scripts i've seen , i guess Python is capable of doing tasks easily, as compared to C, at the expense of hiding some lower details from the programmer. Very cool for applications.
But, ( talking at a *very* high level), supposing i have to build an application that has to do some concurrent tasks ( each task is a diff process/thread ), and some sort of IPC is necessary(signals etc) , and also performance profiling of each thread is necessary ( for balancing sub-system bandwidths etc ), then is Python the way to go for this too?
I had originally intended to use Python just for some cosmetic UI applets that look and feel nice and are a pain to code in C/c++, and do the *real* thing in C/C++, but i would like to know if Python can be used here as well...( I read some *scary* comments about the multi-threading module of Python and the Global Interpreter Lock... )
Thnks for your time,
dhruva
Kent Johnson <kent37 at tds.net> wrote: Dhruva Kulkarni wrote:
> Hi,
> I am a C guy wanting to switch to Python for some
> application-type-tasks that might be done in Python much quicker and
> sooner and smaller than in C...I have fiddled around with Python and
> looked through the tutorial, but i'm a bit lost when there are no
> pointers ( pun intended! ). I could not find any material on
> 'what-happens-when' type questions, e.g.( how functions are implemented
> --> stack-frame struct , parameter passing by value / reference ? ),
> and the whole 'identity vs equality' thing, plus the
> dynamic-typing-of-objects...
> So i can see that Python programers must be thinking in a very
> un-'byte'-ly way, so do I need to unlearn the C way of wandering in
> 'byteland' ? And where can i find the ten commandments for Pythonland>?
Yes, you need to leave your C ways behind. Don't worry, you'll like it
here :-)
The biggest shift is in the way you think about variables. In C, a
variable is a container for a value. In Python, a variable is a name for
a value; a reference. In C terms, think of it as a pointer to a value.
This might help, especially the introduction :-)
http://effbot.org/zone/python-objects.htm
There is a lot of dispute over what to call the semantics of argument
passing (pass by value? pass by reference?), but the concept is pretty
simple. Function arguments are references that are bound to names in the
local scope of the function. The reference is passed by value. One name
for this is "call by object reference". In C terms, if you think of
variables as pointers to values, and argument passing as copying the
pointer, you will get the idea.
BTW the semantics of assignment and those of argument passing are
identical - they both bind a name to a value in the local scope.
One consequence of this is that aliasing happens all the time. If two
names are bound to the same mutable object, any changes to the object
are visible through either name:
In [11]: a=[1, 2, 3]
In [12]: b=a
In [13]: a.append(4)
In [14]: a
Out[14]: [1, 2, 3, 4]
In [15]: b
Out[15]: [1, 2, 3, 4]
You really don't have to worry about stack frames and how functions are
implemented (they are objects too), at least not initially, just let
Python take care of it for you. I wouldn't worry about identity vs
equality, either; usually you are interested in equality.
I don't know about ten commandments, but you can see the Zen of Python
by typing 'import this' at the Python interpreter prompt.
Kent
---------------------------------
Don't get soaked. Take a quick peak at the forecast
with theYahoo! Search weather shortcut.
---------------------------------
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070705/9cc6bce4/attachment.htm
More information about the Tutor
mailing list