My Technical Blog
Posts tagged CS
I’m Learning Python part 2
Oct 7th

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.
- Google uses Python in its web search system, and it employs the Python’s
creator. - YouTube is largely written in Python.
- BitTorrent file sharing system is a Python program.
- Intel, Cisco, HP, Seagate, Qualcomm and IB< use Python for hardware
testing. - Industrial Light & Magic, Pixar, and others use Python in the production
of movie animation. - NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific
programming. - iRobot uses Python to develop commercial robotic vacuum cleaners
- 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:
- Open the editor you use (Emacs, Notepad, Notepad++, …).
- Write this line inside it:
- print “Hello World, It’s My First Python Program”
- Save the file as .py file.
- 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). - In Windows open a command prompt and guide it to the location of your
Python. - In Linux open a terminal and go to the location of your Python interpreter.
- Now you can execute the following command on both platforms:python [FILE]
Where [File] is the location of your .py file.
- 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
.
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
Cheers.
I'm Learning Python part 1
Oct 4th

I’ll start posting this series of blogs on WordPress and CSC, here I’ll write what I’m gonna learn on my way to learning Python.
If you don’t know what Python is, or you’ve heard about it but you’re not sure what it is, my first blog will cover it for you.
What is Python?
Python is a programming language, this programming language was created in 1990, this programming language has proved its power through the last 18 years she’s been with us.
Why should I be interested in learning a new language?
The most points that will catch your interest in this language are:
- It’s Object Oriented:
Python supports classes, inheritance, multiple inheritance, polymorphism, operator overloading and more.
Python is OOP from ground up, besides it’s like C++ supports both object oriented and procedural programming, so it may be used for scripting applications.
- It’s Free:
Python is completely free to use and redistribute, it is also widely supported through web portals where millions of users world-wide can help you find solutions for your problems.
- It’s Portable:
Python first was written in C, and because of that it can be run on almost every platform, you can run it on (Windows, Linux, Mac OS, BeOS, PDAs, Cell Phones, Gaming Consoles, …).
Everything is portable, that’s because Python code is compiled into byte-code (Like .NET and Java), and so it can be run on any platform with a Python interpreter.
- It’s Powerful:
Python sits on the chair along with Perl, Tcl and Scheme as a powerful scripting language, while also it sits on the chair with Java and .NET as a powerful Pure OOP language, and of course it shares the chair with C and C++ as a powerful programming language that is capable of doing everything.
While sitting on more than one chair at the same time, Python provides the simplicity in writing a fully readable code.
From its most powerful features I’ll write some and I’ll explain them deeply when I understand them
- Dynamic Typing.
- Automatic Memory Management:
This one I already know from .NET, Python has its own garbage collector which runs automatically and deallocates space from unused objects in the memory. - Programming for large systems using OOP allows you to develop components and systems so you can reuse them in most of your applications.
- Built-in tools used for manipulating built-in types such as lists and collections.
- Libraries from regular expressions to networking, all libraries can be used easily.
- Third-party utilities: since Python is open source developers from around the globe can build their tools and libraries and everybody can use them.
- It’s Mixable:
You can use Python and call your programs and methods from inside C and C++ and even Java and .NET, you can also call C and C++ methods and tools from Python along with Java and .NET.
- It’s easy to use and learn:
You’ll notice just like I have that Python is an easy yet powerful language which can be used in every technical field without losing it simplicity.
What can I do with Python?
Here I’ll tell you what fields you can use Python in, but in a glance ‘cuz I don’t know how to use it yet.
- System Programming:
Because it can be used as scripting language, Python can be used to develop shell tools, which can communicate with system shell and provide a layer for you to search files and folders, launch applications and even do parallel processing using processes and threads.
- GUIs:
Using Tk GUI, Qt, GTK, MFC and Swing you can make your application have a GUI, but not any GUI, your GUI is cross-platform and you’d be able to run your application on any platform.
- Internet Scripting:
You can develop web applications using Python, you can do Server scripting, Server-Client Scripting and Client Scripting.
A lot of websites already use Python now.
You can use FTP to transfer files, parse XML files, parse HTML and you can generate HTML based on Python code.
- Gluing:
Python can be glued to C, C++, .NET and Java applications.
Python now has 3 major implementations: CPython which is the base implementation, Jython which can be run inside the JVM (Java Virtual Machine), and IronPython .NET which can be run inside .NET Framework.
- Database Applications:
Python can use Sybase, Oracle, Informix, ODBC, MySql, PostgreSQL, SQLite and more.
Python even has a built in database API which can be used with any database system, you can easily change it from anyone to anyone by just switching the used interface.
- Numeric and Scientific Programming:
Python can be used easily to create scientific applications, there is an extension called NumPy which can do more than Matlab!
You can calculate 22000 in milliseconds:
114813069527425452423283320117768198402231770208869
520047764273682576626139237031385665948631650626991
844596463898746277344711896086305533142593135616665
318539129989145312280000688779148240044871428926990
063486244781615463646388363947317026040466353970904
996558162398808944629605623311649536164221970332681
344168908984458505602379484807914058900934776500429
002716706625830522008132236281291761267883317206598
995396418127021779858404042159853183251540889433902
091920554957783589672039160081957216630582755380425
583726015528348786419432054508915275783882625175435
528800822842770817965453762184851149029376.
You don’t have to wait to get this value
- More:
Python can be used in more fields, XML, Gaming, Graphics, Robots, Networking and more, everything is possible
Bottom Line:
That’s enough for today, hope I’ll tell you more on my next blog.
For now I’d suggest you to read more about the language and its features from the language website: www.Python.org.
And also don’t forget to download the appropriate built for your platform.
Cheers.






