I'm Learning Python part 2

صورة mpcabd
أرسل من قبل mpcabd في الثلاثاء, 2008/10/07 - 9:49am.

I'm Learning Python (part 2)
Python Logo

Who Uses Python?


In the world there are more than 1 million Python user, that's because it's open source, and because it is implemented for every platform, and it comes included within Linux distributions and Macintosh computers and more.
  1. Google uses Python in its web search system, and it employs the Python's creator.
  2. YouTube is largely written in Python.
  3. BitTorrent file sharing system is a Python program.
  4. Intel, Cisco, HP, Seagate, Qualcomm and IB< use Python for hardware testing.
  5. Industrial Light & Magic, Pixar, and others use Python in the production of movie animation.
  6. NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming.
  7. iRobot uses Python to develop commercial robotic vacuum cleaners Smile
  8. NSA uses Python for cryptography and intelligence analysis.
See Python website for more.

How Does Python work?


Python is not compiled (almost), it is interpreted. So when you run the program the interpreter will run it line by line without compilation.
You might say "Why did you say almost?", the answer is, Python as described before can be compiled into byte code, so it'll be faster for the interpreter to execute it than the source code, just like Java's byte code and .NET's MSIL.
Python files have a .py extension normally, so when you write Python code you should save it with a .py extension.
Let's try and write our first Hello World Python program:
  1. Open the editor you use (Emacs, Notepad, Notepad++, …).
  2. Write this line inside it:
  3. print "Hello World, It's My First Python Program"
  4. Save the file as .py file.
  5. Now you should tell the Python interpreter to run your file, depending on your platform you should have the Python interpreter in ("C:\Python[VER]\" in Windows where [VER] is the version of the Python release you have [24, 25, 26,…]) or in ("/usr/bin/" in Linux).
  6. In Windows open a command prompt and guide it to the location of your Python.
  7. In Linux open a terminal and go to the location of your Python interpreter.
  8. Now you can execute the following command on both platforms:
    python [FILE]
    Where [File] is the location of your .py file.
  9. Now you should see some thing like this:
    python [FILE]
    Hello World, It's My First Python Program
Very easy, right?
Although it is not that big program but you can run your files this way Smile.
Now let's understand what happened:
The Python interpreter was given a file to run.
If it has write privileges it'll compile it into byte code and you'll see that a new file was created next to your file with a .pyc extension, if it doesn't it'll run it as source code.
It reads the first line (which is a print statement) and runs it and you see the result, the execution takes place inside the PVM – Python Virtual Machine, which handles the execution of Python byte code and source code to run on more than one platform without change in code.

If you have a background in C or C++ you might find a change in the way of running and compiling code, 'cuz there is no making and linking in Python, and it is not compiled into machine code (binary file), instead it runs inside a virtual machine, that's why some Python code will run faster in C++ and C.
But don't be afraid, 90% of the time you'll be running your programs as if they were written in C or C++, there won't be any difference in the time of execution, and that’s because of the Python simplicity which makes the program in Python shorter and simpler than C or C++, and because it's optimization which we'll describe later.
In Python you'll notice that the compiler and the execution environment are one thing, the compiler always present in runtime, and that leads to rapid development cycle, with no linking and making stage.
CPython runs inside the PVM, while Jython runs inside the JVM and IronPython .NET runs inside .NET Framework or Mono.
Jython and IronPython .NET allows the Python program to use Java and .NET classes respectively.
If you don't wanna use Java or .NET classes you should use CPython, 'cuz it's faster and the most complete, CPython runs like C and C++ so it is the fastest.
In Jython the Python byte code is translated into Java byte code to be run inside the JVM, while in .NET it is translated to MSIL.

What Are The Frozen Binaries?


Python has something called Frozen Binaries, which are the executables, if you chose to create a frozen binary for your program, you'd end up with an executable that runs on a specified platform (exe for Windows).
This executable has a great feature; it includes your program along with its dependencies and the Python interpreter. Yes you don't have to tell the user to install a Python interpreter to be able to use your program, he/she doesn't have to know that your program is a Python program.
You can use Py2Exe to get an exe of your program (Which runs only in Windows), or PyInstaller which gives you the ability to create a frozen binary for Windows, Linux or UNIX. And you can use Freeze the original one. Those are available free of charge, you can check Python website or Vaults of Parnassus (http://www.vex.net/parnassus).

What IDE's To Use With Python?

Python comes with a simple IDE called IDLE you can use it, or you can use Emacs, but IMHO Eclipse with PyDev make a great IDE for you and Python.

Bottom Line:


Today it was just a description on how Python runs your program, and we wrote our Hello World program.
For the next part, try to use the ** operator - which is the power operator in Python – to see how much you can do in Python, e.g.:
print 2 ** 10
1024
Try huge numbers and see Wink
Cheers.


خيارات عرض التعليقات

اختر طريقتك المفضلة لعرض التعليقات و اضغط "حفظ الإعدادات" لتفعيل تغييراتك.
صورة bayrn
أرسل من قبل bayrn في الثلاثاء, 2008/10/07 - 11:15am.

و الله هاد من أحلى المواضيع يلي قرأتها بالمنتدى من وقت سجلت
( من غابر الأزمان ) Laughing :

على كل حال أنا رح أعمل بنصيحتك و حاول أشتغل على eclips

بس في حوليك مصادر تعليم لهذه اللغة جيدة للمبتدئين فيها

 


صورة bayrn
أرسل من قبل bayrn في الثلاثاء, 2008/10/07 - 1:22pm.

يعني أنا فهمت من المقالة أنه ملف كود هذه اللغة يمكن أن :
- يترجم
أو أن
- يفسر

و الآن أصبح عندي شغف كبير لتعلم هذه اللغة و خصوصا مثل مو مذكور بالمقالة قوة هذه اللغة لكن هالشي على مسؤوليتك mpcabd أنت بدك تلاقيلي شغل فيها Money mouth

ياريت تكمل هذا الموضوع و أنا معك خطوة بخطوة ، معليش لو تعبت شوي الله يعطيك العافية ( صدقة العلم التعليم )


صورة mpcabd
أرسل من قبل mpcabd في الثلاثاء, 2008/10/07 - 2:22pm.

كتب bayrn:
يعني أنا فهمت من المقالة أنه ملف كود هذه اللغة يمكن أن :
- يترجم
أو أن
- يفسر
مو بهالشكل, الملف رح يتفسر بالحالتين, بس يا رح يتفسر وهو Python Code يا رح يتفسر وهو Python Byte Code وهالشي حسب إذا الـ Interpreter معو صلاحيات كتابة ولا لاء.


صورة Renwar
أرسل من قبل Renwar في الأربعاء, 2008/10/08 - 8:55pm.

كتب bayrn:
على كل حال أنا رح أعمل بنصيحتك و حاول أشتغل على eclips
هو يلي انا شفتو بس ما بعرف عنا بالبلد شو الوضع
انو جماعة eclipse بتعمل نسخ مخصصة لكل شركة Neutral يعني هو الهدف الاساسي منو توحيد ال IDE لأكتر من لغة برمجة وبتجي الشركات بتخصصو كتير بالشكل يلي بيناسب سياستها.
رأيي انو اذا في IDE غيرو و يكون مرتب بفضل يلي غيرو Smile


صورة mpcabd
أرسل من قبل mpcabd في الأربعاء, 2008/10/08 - 9:15pm.

ما فهمت, شو قصدك؟


صورة bayrn
أرسل من قبل bayrn في الأربعاء, 2008/10/08 - 9:37pm.

كتب mpcabd:
ما فهمت, شو قصدك؟


صورة BlackSigma
أرسل من قبل BlackSigma في الخميس, 2008/10/09 - 12:27am.

كتب Renwar:
كتب bayrn:
على كل حال أنا رح أعمل بنصيحتك و حاول أشتغل على eclips
هو يلي انا شفتو بس ما بعرف عنا بالبلد شو الوضع
انو جماعة eclipse بتعمل نسخ مخصصة لكل شركة Neutral يعني هو الهدف الاساسي منو توحيد ال IDE لأكتر من لغة برمجة وبتجي الشركات بتخصصو كتير بالشكل يلي بيناسب سياستها.
رأيي انو اذا في IDE غيرو و يكون مرتب بفضل يلي غيرو Smile

حكيك صح بس هاد ما بيعني إنو الشركات عم تحذف منو ميزات بالعكس هنن عم يضيفوا ميزات تناسب عملهم و بالتالي في مجموعة من الخصائص والميزات المتوفرة بيئة eclipse ما عم تتغير .
يعني فرضا شركة oracle لما طلعت الـ weblogic صحيح هي خصصتو ليدعم متطلباتها و منتجاتها بس بنفس الوقت لسا في إمكانية تشتغل عليه الشي اللي كنت تشتغلو بيئة eclipse الإفتراضية


صورة Renwar
أرسل من قبل Renwar في الخميس, 2008/10/09 - 10:53am.

تماما وهاد قصدي Smile
جميع الشركات بكل العالم ما بتسأل اذا انت شاغل على بيئة eclipse او لاء.
لأنو يلي عندها بتختلف عن يلي غيرها بما يرضي هالشركة و كل الشركات على علمي. بتعمل دورات للموظفين قبل ما يبلشو ب eclipse الخاص فيها.
طبعا اذا كان الشخص familiar معو رح يتعود عالميزات المضافة بيجوز اسرع.
بس الكل اخر شي متل بعض Smile يلي بيعرف و يلي لاء Razz


صورة mpcabd
أرسل من قبل mpcabd في الخميس, 2008/10/09 - 12:34pm.

هلق العبرة مو بالـ IDE لأنو فيك تكتب برنامجك عالـ Notepad لذلك أول شي اتعرف عاللغة بعدين خصص يلي بدك ياه بالـ IDE يلي بيريحك.
وعلى حسب ما شفت أغلب الناس بتشتغل عالـ Eclipse مع PyDev فبهي اللغة ما في هيك مشاكل.