Abd Allah Diab's Blog
My Technical Blog
My Technical Blog
Mar 20th

Classes in Python are defined like this:
Feb 21st

Since the last time I wrote an article Python many changes happened in my life, one of them is the release of Python 3.0 (Which is known also as Python3K and Python3000).
Python 3.0 is the first intentionally backwards incompatible Python release, which means that there are some changes you must notice before start coding in Python 3.0.
Don’t worry that much, the language has become more useful, and also there is 2to3 source-to-source conversion tool which converts your Python 2.x code to meet the requirements of Python 3.0
To find more about change in Python please refer to Python website.
P.S.
From now on all the code will be written in Python 3.0.
Please try the following code in your python console:
d = 0.1You’d get this output:
print(d)
print(str(d))
0.1
Strange ain’t it?
The second value is the one you put in the variable.
The first one is the real value represented in memory. This is not Python’s fault, this happens because of the way computer store float values in memory as 0′s and 1′s, computers use floating point IEEE-745 representation.
Using this representation unfortunately we can’t represent any float value using 0′s and 1′s, and 0.1 is one of those poor values (The reason is that it can’t be represented in sum of powers of 0.5).
So what all programming languages do is that they ignore the small fraction so it would be 0.1 instead of 0.10000000000000001, but Python doesn’t.
Try this code in Java if you have:
public class NoDifference{You’d get this output:
public static void main(String[] args){
double a = 0.1;
System.out.println(a);
a = 0.10000000000000001;
System.out.println(a);
}
}
0.1
So Java doesn’t differ those two values while they’re different. (Such a difference could make a disaster in a nuclear reactor
)
If you want to go with the flow and ignore this difference in your calculations you’d have to use another data type than float, you’ll have to use Decimal.
from decimal import Decimal
d = Decimal("0.1")
print(d)
0.1
Decimal data type allows you to represent any decimal value you want
It also supports addition, subtraction, multiplication, division and modulo, but the two sides must be Decimals.
Let’s write a function that prints Fibonacci series to a given boundary:
def fib(n):1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
"""Prints Fibonacci series up to n"""
a, b = 0, 1
while b < n:
print(b, end = " ")
a, b = b, a + b
#Now we can call the function by its name
fib(2000)
Now let’s describe what we have done:
The previous code defines a procedure (not a function) because it doesn’t return a value, let’s modify the code so it builds an array of Fibonacci values instead of printing them:
def fib(n):[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
"""Prints Fibonacci series up to n"""
a, b = 0, 1
result = []
while b < n:
result.append(b)
a, b = b, a + b
return result
f = fib(100)
print(f)
What we have added is the return statement only, which returns a value to the caller.
One more thing to be told is default arguments:
def askYesNoQuestion(question, retries = 4, complaint = "Please write Yes or No only!"):Default arguments are assigned a default value if they aren’t when called.
while retries > 0:
answer = raw_input(question)
if answer in ['y', 'ye', 'yes', 'yep']: return True
if answer in ['n', 'no', 'nop']: return False
retries -= 1
print(complaint)
raise IOError, "stupid user"
#Now we can call it
askYesNoQuestion("Are you sure?", 1, "What?!")
askYesNoQuestion("Overwrite?", 1)
#Same as askYesNoQuestion("Overwrite?", 1, "Please write Yes or No only!")
askYesNoQuestion("Do you know me?")
#Same as askYesNoQuestion("Do you know me?", 4, "Please write Yes or No only!")
askYesNoQuestion("Do you have a pen?", complaint = "You can say no if you want!")
#Same as askYesNoQuestion("Do you have a pen?", 4, "You can say no if you want!")
You can set arguments values when calling by writing Name = Value.
Default parameters can’t be followed by non-default arguments.
Important note:
Default arguments are evaluated only once, so the following code will accumulate the values:
def f(a, L = []):[1]
L.append(a)
return L
f(1)
print(f)
f(2)[1, 2]
print(f)
f(3)[1, 2, 3]
print(f)
If you don’t want the function to behave like this you can write:
def f(a, L = None):Let’s explain what I meant by saying “are evaluated only once”:
if L is None:
L = []
L.append(a)
return L
When the Python interpreter reaches the line that defines the method, it allocates a list in the memory and assigns its address to L the reference.
Next time you call the function L will reference the same list it referenced the time it was created in memory, so it will always reference the same object.
The second code actually referenced to None, so every time you call the function it will assign None to L.
By understanding what I meant you can consider the following example:
i = 1012
def f(a, b = i):
return a + b
i = 11
print(f(2)) #Will it print 12 or 13?
That’s because b was given the value of i before the interpreter reached the line in which i was give the value of 11.
Not that much I presented in this part, but you should consider upgrading your Python knowledge to Python 3.0 for the next time.
And by the way, I’m sorry, I’ve betrayed you and learned a lot during the last month, I have also started creating GUI Applications using Python and Qt, so please forgive me ![]()
Cheers.
Feb 8th
I mentioned many times before that I was planning to make a workshop about Free Open Source Software (FOSS) in Damascus, and thankfully I did
The idea was to spread the culture of FOSS between the interested people here in Damascus.
What I noticed was that almost 99% of computer science students didn’t know what Free Software is and what Open Source software is!
So I started contacting engineers and people who I know that they’re capable of teaching this culture to our faculty students, and I managed to make 3 people agree on lecturing in the workshop.
After a while I realized that I can’t make the workshop as I thought, I won’t be able to make lectures inside the faculty because of some freaky stupid bureaucracy.
So the solution came with the idea of iCommunity, and thankfully it solve the problem.
iCommunity is a committee inside SCS – Syrian Computer Society, which is responsible of connecting the youth
computer science interested people with the SCS and other governmental offices.
It has the power that SCS gave to it, which is to think and prepare for projects that young people want to do and they can’t.
By having iCommunity we can achieve almost what we want with some powerful support from SCS.
And I’m one of the 6 managers of iCommunity, together we decieded that we will make this FOSS Workshop a reality.
The workshop took place in Damascus, Tishreen Park, SCS Center. From February 3rd to February 5th.
Everyday had lectures, coffee break and installation festival.
We had 3 lectures:
We had 2 lectures:
We had 3 lectures:
We told people to bring their laptops so we can teach them how to install Ubuntu 8.10 Intrepid Ibex on it.
There were many interested people so the festival was great.
My friends in the college helped us in the festival, I can’t find any way to thank them.
We also played this video, that describes what would have happened if The Matrix was real and ran on Windows
We distributed two DVD’s to the audience, the first one was Ubuntu 8.10 Desktop Edition DVD i386, and the other was an Open DVD which included a debian repository and free open source software for both operating systems Linux and Windows.
Creative Commons website wrote about Zyiad’s lecture in the worksop:
Ziad Maraqa, co-Project Lead from CC Jordan, spoke yesterday in Damascus at the iCommunity FOSS Workshop, a notable gathering for the Syrian Free Software community.
Al Watan Newspaper in Syria wrote about the workshop daily (Arabic):
http://www.alwatan.sy/dindex.php?idn=50788
http://www.alwatan.sy/dindex.php?idn=50843
eSyria, Syria blog website wrote about the workshop daily in its Damascus website (Arabic):
http://www.edamascus.sy/_activities.php?filename=200902021845011
http://www.edamascus.sy/_business.php?filename=200902031620011
http://www.edamascus.sy/_news.php?filename=200902041650013
http://www.edamascus.sy/_news.php?filename=200902060300011
This is a photo of the iCommunity Managers:
This is a photo of the installation team, 4 iCommunity managers, and some students:
I’m the one with the gray suit and glasses in the middle
And this one is from above of more students, 5 iCommunity Managers (the 6th is the one behind the camera) and the installation team
We had wonderful time, and we got great feedback of people attended the workshop.
Feb 6th
After a month of not blogging, I’m back to blogging for Python.
This month had a lot in it:
After finishing my Scientific Calculations Project I made the choice of removing Windows for good from my computer, I’m going to make Ubuntu my only operating system to use.
The workshop was more than I expected, I witnessed the great participation and work from my friends to make this workshop a successful story to be told.
You can see here that the FOSS workshop was a notable event in Damascus and Syria.
Ziad Maraqa, co-Project Lead from CC Jordan, spoke yesterday in Damascus at the iCommunity FOSS Workshop, a notable gathering for the Syrian Free Software community.
And here are some articles about the event but they’re in Arabic:
Al Watan Newspaper:
http://www.alwatan.sy/dindex.php?idn=50788
http://www.alwatan.sy/dindex.php?idn=50843
eDamscus:
http://www.edamascus.sy/_activities.php?filename=200902021845011
http://www.edamascus.sy/_business.php?filename=200902031620011
http://www.edamascus.sy/_news.php?filename=200902041650013
http://www.edamascus.sy/_news.php?filename=200902060300011
Thank you all for waiting a month
I’m Learning Python part 8 will be here soon.
Dec 28th
Hello, if you don’t know already, I’m a Computer Science student from Damascus University Syria.
My friends and I are working on an Open Source Free Software workshop here at the faculty of Computer Science, the workshop will take place on February 2009, but we are gathering some resources and information from now.
The workshop will have lectures about Open Source, Free Software, Licenses, Open Source Free alternative for Commercial Proprietary software, and of course Linux OS.
The workshop will also contain an Installation Festival where we are going to install Ubuntu 8.10 Intrepid Ibex for students on their devices and teach them how to use it.
I’m gonna put some questions here and I’ll ask you to answer it, whether you own an Open Source company or you work for one.
I’m neither a journalist nor an analyst seeker, but I want some answers from you to introduce you the way you want to students, please don’t waste this message because I’m not a journalist, we want to spread the culture of Free Open Source Software here between students and contributing to the workshop would be very kind of you.
Please allow me to ask you to answer the following questions:
1. When did you start your company and who started it?
2. How did you start your company?
3. Why Free Open Source Software? What was the base idea of your company? Did you consider that offering Free Open Source Software might not give you much money? Or money wasn’t your concern at first?
4. What problems did you have to go through till the first line of code was written?
5. Most people ask; where and how do you make money? This question needs to be fully described because in my humble opinion it is the most question people and especially students would care about.
6. Starting a company needs a hard working faithful staff, how did you start collecting your staff? How did you convinced people to work with you knowing that you offer Free Open Source Software?
7. After you finished your first prototype, how did you advertise it?
8. What was the reaction of people who tested the first software of yours?
9. How many people contributed to the first version of your product? And how many downloaded it and used it?
10. You must have received thousands of feedback messages after your first product; do you remember the approximate count?
11. Competition with know software is indeed hard, how did you manage to make your path between your competitors?
12. What are the phases that your company had been in till now? What difficulties and problems did you face?
13. How many people contributed to the second version of your product?
14. How many people contributed to the last version of your product?
15. How many people did you count using your software?
16. Do you advice students to start their companies and follow your path, or do you advice them to look for jobs in companies like yours?
17. What must the student of Computer Science study to be able to work for you? What techniques? Programming Languages? Tools? What do you seek in your workers to have and know?
18. If by any means you had the chance to talk to our students and give them a message, what would it be?
You can of course answer as much as you want of the questions above, but I hope you answer all of them for the sake of Free Open Source Software and knowledge.
Thank you from all my heart, and on behalf of my friends and colleagues I thank you, we appreciate your efforts and your contributions.
Abd Allah Diab
Computer Science Faculty
Damascus University
Syria