Python playing around (syntax for the first time move to python)
check : why python , why python2
Well just started playing around with it again J
Found out few nice things and surprised by few others while trying, writing them down so anyone moving to python can have a nice look and fast forward on how to write in python syntax.
Its no suprize that in python we don’t have to declare variables (common it is dynamic typed language) but that makes it a bit strange for JAVA, or C# guy see how

Well I is a integer that has the value 5 , b is an string which have the value “ali” and C is a complex number with value (4+2j) !! wow python support complex number on the very basic level ! great but how that can be helpful for me ?! don’t know but people with good math knowledge will love it I think.
For Math and science people good news is it also supports scientific notations of big numbers like 5 x 104 but that will be writer as 5E4
![]()
Another interesting and confusing thing is the semicolons “;” if you notice each line of code has a semicolon at the end of it but hay that’s not necessary at all !!! you can write the application without semicolons when ever you go to new line the python understands that it is end of command just like if there is a semicolon !!

Well but what if I need to go to new line (to make my code more readable and then finish the command? That’s ok all I have to do then is to have a “\” at the end of the first line (which is not the end of the command)
i.e

or

Well for myself I would prefer having semicolons in both the single line commands and on multiple line commands that at least make the code look better and more readable to me .
Now some interesting things regarding strings in here is

You can have single quote symbols ‘ in a string written between 2 double quotes “”

You can have double quote symbols ” in a string writer between 2 single quotes ”

You can have single quotes ‘ and double quotes ” and new lines (you can write actually multiple line String without using scape charectors like (\n) ) if you put the string between three double quotes “”" or three single quotes ”’
That was pretty interesting to me to be able to write multiple lines of sting without using scape sequences like \n , but python support these sequences like \n for new line \t for tab and others. Similarly if you like to write a \ in the string as many other programming languages you will have to scape it with another \ so you will write \\ . But there is a better way , which is to write a raw string

Having r before the quotes of the string indicate that this is a raw string so don’t apply any escape sequences on it so \n will be printed as it is and not will be interpreted as new line.
Similarly having u before the quotes of the string means that the string contain Unicode characters which could be Arabic language or some other language characters
One more interesting thing about strings is writing two strings near each other concatenate them see

Is equivalent to

I think that enough of playing around with python for now. I wish will be continuing these series of interesting things about python .
Read MoreWhy python 2
Well back to why python and should i use python as a development language or not
well there is already a post of why python which i wrote long time ago in that post i said that i will start learning it but as usual the lazy me didn’t allow me to do so
:p
recently i am back thinking about that again so wish this time i will end up doing something useful at least
well why python again in addition to what ever i wrote in why python
the following are good reasons too
- Python is growing at a faster rate than any other language (as you see in 2010 it reached the 4th place from the 7th place last year in popularity)
- Python could create console, GUI applications that run in Windows,MAC, Linux, and other OS PCs
- Python could be used to create web applications
- Python is used in Google app engine
- Work with .NET (IronPython)
- Work with JAVA (Jython)
- could be used for iphone, ipad development
- could be used for android development (not full functionality ) but enough for many things
- has good number of GUI libraries
- has good number of game development libraries
- many games used python at least at server and logic sides (i.e battlefield)
- and i am sure there many more reasons i can find if i searched enough
but this much reasons are enough for me (I hope)
see ya.
Read MoreO’Reilly, Developing Android Applications

android
Last week, O’Reilly started a free training Android course, I had the chance to attend it, all of it, unlike some of my friends who couldn’t stay up till late night
I also had the chance to take notes, .. I will post the notes of the first lecture at the end of this post (its my notes, do not expect to understand everything from it because you did not write it
)
the lecture started with the basic principles on how Android works, … you know .. the “useless things that is good to know” sort of things, than some tips on installations and some basic “flash light” program, .. and during that whole thing a lot of questions were made by the people watching the course, .. some questions are really irrelevant and useless, while others were interesting.
Before i post my notes i would like to mention my opinion about the course from the first lecture (this opinion is merely my personal opinion). It is my first time coding Android, .. but it is NOTmy first time coding
My opinion on Tony the lecturer
He seems to know somethings on Android, more than most of us obviously, but i am afraid that I expected the lecture to be more professional, I mean during the lecture, Tony was exploring the code and how things work, i did not find him mastering the language, … but in my opinion as long as he is ahead of us at least one step, than praise him
My humble opinion about the Android programming language
Android relies heavily on user-defined XML tags (or that is what i saw from the first lecture). its not a good or bad thing, .. it is just … different i guess.
It is a very interesting course and i would like to encourage anyone who has the slightest interest in developing mobile applications to attend this course
Anyways .. without further dues, … here are my notes
————————-
linux>Native Libraries > Run time + Dalvik VM > andriod framework (activity manager, content Provider, Location manager, Notification manager,..) > System apps (contacts, Phone Dialer, Email, Web Browser)
app: code + R resources (movie, xml, pic)
Activity: single screen. app have many activities
intent: code to accomplish a verb (call number, open contacts)
developer.andriod.com/sdk/eclipse-adt.html
package name > unique
min SDK Version, "API LEVEL", Andriod 1.5 > 3
manifest (Like in J2ME, configuration file)
main.XML have app configuration (like orientation, gravity position of the test")
String.XML
"@String/Hello" > Macros, u can use it for localization
"@String/Red" >> you can set Red= "Red hat" in String.XML
Color.XML
#FFFF0000
android:background="@color/red"
activity > screen > .java
R class generated automatically, each new resource will be added automaticallyin the R class
you can add new elements in main.xml like "button" and you can set its attributes (via XML Tags)
the @+id adds unique ID by default
in JAVA (RefFlashActivity.Java)
Button greenButton = (Button)findViewById(R.id.green_button);
greenButton.setOnClickListener(new View.OnClickListener(){...})
Intent intent = new intent(activ.this, act2.class);
startActivity(intent);
the above will change from one screen to another.
Here is answer to right to left: Google tracks issues and feature requests at Google Code's site. As of January 2010[update], the most requested ("starred") feature is the support for right-to-left languages such as Arabic and Hebrew.[90][91]
http://developer.android.com/reference/java/text/Bidi.html
——————-
SharePoint List data with SQL Server Reporting Services

SharePoint is becoming more populler every day, companies from around the world are starting using it as main intranet site of their headoffice.

update 16/5/2009
4- the fourth way is to map the list directly to a database (Well i didn’t wrote that because two things first it is redundancy, second it is hard to keep updating both the database and sharepoint lists when-ever any change happens to any record, but Mr. Allan seems to have a great solution for that in the comments which is “SLAM ” (http://slam.codeplex.com)
SLAM allows you to easily maintain SharePoint data by hooking up against lists (or content types!) and having the data automatically synchronized with SQL server in real time. Best of all, it converts SharePoint look-ups to associations (with any multiplicity, one to one, one to many, many to many) that you can easily built queries against.
Thanks a for letting us know about this tool
update 21/5/2009 :
Well this time i tried the 2nd way on production (it works very well while it is on my machine in visual studio) but if we need to add it to the reporting services server it didn’t work on my enviroment not sure if it works on other enviroments
Why Python
I am used to programe in Java at home and on almost all my personal projects , in my work place i am a C# guy (well in work place they only use .NET
) and this is because in college days all we have been exposed to were OO languages like C++, Java, .NET and that what we are using till now.
As scripting languages, developers around here are far away from them, may be the only scripting language used heavily in this side of the world is PHP, and the most powerfull JavaScript and thats it. I decieded that i want to learn a new programming language and it has to be a scripting language this time, i was looking for Ruby,pearl & python to learn one of them. Finally my choice was python and thats why i hope i will be able to put small tips and tricks of what ever i learn in python here on this blog.
In this blog i am just talking about why i am intrested in learning python , well first since i am used to java and C# and they are statically typed languages I don’t experiance a lot the beauty of dynamically typed language where i dont have to declare variables or specify its type, also in dynamically typed language i will be able to use a variable as integer and after few lines i will use it as string , then again i can use it as an object of my class called money, or what ever else very easily.Another benifit of dynamic typing is that i can have a set, an array that contain compeletly different types of variable that while retriving them i dont have to cast them to their types which really simplifies a lot of rutine work
Other than being dynamically typed language python is very compact compared to java & C#, so typing is less, what ever you type in python will be used to solve your problem not the language problems as in the big OO languages
lets say i want to create a class constractor that meight take a variable or two variable, or three variables.
| do that in java | do that in python |
public class MyclassName{
public MyclassName(String var1) { this(var1, 1); }
//--------- constructor #2 ------------- public MyclassName(String var1, int var2) { this(var1, var2, "single"); }
//--------- constructor #3 ------------- public MyclassName(String var1, int var2, String var3) { this.att1= var1; this.att2= var2; this.att3= var3; }
|
class MyclassName():
def __init__(self, var1, var2=1, var3="single"):
self.att1= var1 self.att2= var2 self.att3= var3
|
| to open file in java |
to open file in python |
BufferedReader br= new BufferedReader( new FileReader(filename)); |
fileName = open(filename) |
so i think if i master python or any similler language (Ruby, pearl) i will have to type less and be able to concentrate more on solving the problems i am working on.
Another new thing in this kind of language is they support functions as first class entity in the language, so functions could be stored in data structured and passed as arguments to other functions (not as pointers like in C++) Also functions could be created dynamically while the programe is running which i am sure will be very usefull, i have never though of using a dynamically created functions since none of my programe worlds supported that before. if you are new to this like me and need example check this
well i guess after all of these reasons it still didnt come to python, cause these reasons just show i want to learn an scripting language with the mentioned properties that could be any of Perl, Python, PHP, Lua, Tcl/Tk, ECMAScript (JavaScript, ActionScript), Ruby, Io, Scala, or Nemerle. I guess then it is true i wanted to learn python just because it is pythonRead Moremay be another reason is it is very known, supported heavily by Google, in their app engine ! to be honest i was thinking about ruby too. but after some search i found some information that made me like python more that are many blogs says the error messages in ruby compiler are not very much informative compared to python. Another reason is there is a lot of ways of doing the same thing in ruby which is good but can make a new language somewhat confusing. Also the fact that GUI libraries for Ruby they are very limited and in python there are a lot of libraries + default librari that comes with python itself so i prefered python .so hope fully i will be able to put some small python tips or tutorials as soon as possible.



