LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python Questions ... any gurus here? (https://www.linuxquestions.org/questions/programming-9/python-questions-any-gurus-here-332244/)

diz12 06-10-2005 12:39 PM

Python Questions ... any gurus here?
 
Hi I am learning python and I was wondering if anyone could tell me what these are and mean:
Code:

__init__(self)

__main__

basically I don't understand the self either, but I am getting into the classes and reading other peoples codes and I see these alot and self is in green when I am looking at it through ide. and if anyone has msn I would for someone to be there so I could ask for help. Thanks
Dereck

deiussum 06-10-2005 01:38 PM

I'm far from a guru, but I believe __init__ is like a constructor function in C++. If you're not familiar with C++ either, than it is basically a function that is called when an object of that type is created. The self is a reference back to the object being created. (A "this" pointer in C++ terminology.)


The __main__ is probably some sort of entry point function that is run with the script is first executed. I don't think any of the few Python scripts I've written have used that before, so I could be way off here.

diz12 06-10-2005 01:47 PM

thanks , I started out with c++ and stopped learning when I finished classes. then I began trying to learn python. I like c++ and will continue learning but, I am not ready to learn c/c++ yet.
thanks again

cb951303 06-10-2005 02:50 PM

I've just started to learn python, and I loved it, it's really very easy and practical.after c/c++, my coding speed doubled :D

diz12 06-10-2005 03:22 PM

i was reading somewhere and python is supposed to be 3 - 5 times faster than java and ?- 10 times faster than c++ ... the time it takes to develop a program, not program speed.

cb951303 06-10-2005 04:11 PM

Quote:

Originally posted by diz12
i was reading somewhere and python is supposed to be 3 - 5 times faster than java and ?- 10 times faster than c++ ... the time it takes to develop a program, not program speed.
I agree :D

needforspeed 06-10-2005 04:14 PM

Python has an excellent reputation for rapid prototyping (ie, fast coding, it's a "glue" language meaning you just kinda glue things together and go). In my software engineering class last semester, my professor wanted everyone to use python and suggested that we use the pygtk widgets. None of us had programmed in python before and it took us only a short while to become used to it.

google for dive into python, there is an online version of the book on the author's site and many people will suggest it. Also, pygtk.org for the gtk widgets provides excellent documentation for using them.

__init__ is a constructor for a class, __main__ is the main class of the program, similar to main() in a c++ program.

llama_meme 06-11-2005 04:42 AM

The usual idiom is

Code:

if __name__ == '__main__':
  # Run the main program


kapsikum 06-11-2005 06:54 AM

hi,

just visit this page and all ur initial doubts will be gone!

http://www-106.ibm.com/developerwork...y/l-pyint.html

diz12 06-11-2005 01:16 PM

thanks guys!! big help , makes the picture come together

...nice site kapsikum! thanks


All times are GMT -5. The time now is 03:10 AM.