diff --git a/pot/Appendix.pot b/pot/Appendix.pot index 397c314..c51ff66 100644 --- a/pot/Appendix.pot +++ b/pot/Appendix.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/Author_Group.pot b/pot/Author_Group.pot index c96d112..b61746b 100644 --- a/pot/Author_Group.pot +++ b/pot/Author_Group.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/Book_Info.pot b/pot/Book_Info.pot index 6350c40..016a8ad 100644 --- a/pot/Book_Info.pot +++ b/pot/Book_Info.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -17,13 +17,13 @@ msgstr "" msgid "Python for you and me" msgstr "" -#. Tag: para +#. Tag: subtitle #, no-c-format -msgid "This book is for the python newbies" +msgid "A book to learn Python in a quick way" msgstr "" -#. Tag: phrase +#. Tag: para #, no-c-format -msgid "Logo" +msgid "This book is for the python newbies" msgstr "" diff --git a/pot/Chapter.pot b/pot/Chapter.pot index 5a5df5a..1eff158 100644 --- a/pot/Chapter.pot +++ b/pot/Chapter.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/Preface.pot b/pot/Preface.pot index 5a75d34..926bf42 100644 --- a/pot/Preface.pot +++ b/pot/Preface.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/Python_for_you_and_me.pot b/pot/Python_for_you_and_me.pot index 104013a..2afb359 100644 --- a/pot/Python_for_you_and_me.pot +++ b/pot/Python_for_you_and_me.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/Revision_History.pot b/pot/Revision_History.pot index 3397469..edbf320 100644 --- a/pot/Revision_History.pot +++ b/pot/Revision_History.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -22,6 +22,11 @@ msgstr "" msgid "Das" msgstr "" +#. Tag: member +#, no-c-format +msgid "Work in progress" +msgstr "" + #. Tag: member #, no-c-format msgid "First release" diff --git a/pot/acknowledgment.pot b/pot/acknowledgment.pot index 33a9942..6f57db5 100644 --- a/pot/acknowledgment.pot +++ b/pot/acknowledgment.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/classes.pot b/pot/classes.pot index 1426f78..0161af5 100644 --- a/pot/classes.pot +++ b/pot/classes.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -37,11 +37,9 @@ msgstr "" msgid "Before writing your first class, you should know the syntax. We define a class in the following way.." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"class nameoftheclass:\n" +msgid "class nameoftheclass:\n" " statement1\n" " statement2\n" " statement3\n" @@ -54,11 +52,9 @@ msgstr "" msgid "in the statements you can write any python statement, you can define functions (which we call methods of a class)." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> class MyClass:\n" +msgid ">>> class MyClass:\n" "... a = 90\n" "... b = 88\n" "...\n" @@ -74,11 +70,9 @@ msgstr "" msgid "In the above example you can see first we are declaring a class called MyClass, writing some random statements inside that class. After the class definition, we are creating an object p of the class MyClass.If you do a dir on that..." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> dir(p)\n" +msgid ">>> dir(p)\n" "['__doc__', '__module__', 'a', 'b']\n" "\n" "" @@ -99,21 +93,36 @@ msgstr "" msgid "__init__ is a special method in python classes, it is the constructor method for a class. In the following example you can see how to use it" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" +msgid "class Student(object):\n" +" \"\"\"\n" +" Returns a ```Student``` object with the given name, branch and year. \n" +" \n" +" \"\"\"\n" +" def __init__(self, name, branch, year):\n" +" self.name = name\n" +" self.branch = branch\n" +" self.year = year\n" +" print \"A student object is created\"\n" "\n" -">>> class Student:\n" -"... def __init__(self, name, branch, year):\n" -"... self.name = name\n" -"... self.branch = branch\n" -"... self.year = year\n" -"... print \"A student object is created\"\n" -"... def getName(self):\n" -"... return self.name\n" -"... def setName(self, name):\n" -"... self.name = name\n" -"...\n" +" def set_name(self, name):\n" +" \"\"\"\n" +" Sets the name of the student.\n" +"\n" +" :arg name: new name ofthe student.\n" +" \n" +" \"\"\"\n" +" self.name = name\n" +"\n" +" def get_name(self):\n" +" \"\"\"\n" +" Returns the name of the student.\n" +" \n" +" :return: a string contain the student's name\n" +"\n" +" \"\"\"\n" +" return self.name\n" "\n" "" msgstr "" @@ -123,11 +132,9 @@ msgstr "" msgid "__init__ is called when ever an object of the class is constructed.That means when ever we will create a student object we will see the message \"Creating a new student\" in the prompt. You can see the first argument to the method is self. It is a special variable which points to the current object (like `this` in C++). The object is passed implicitly to every method available in it , but we have to get it explicitly in every method while writing the methods. Example shown below." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> std1 = Student()\n" +msgid ">>> std1 = Student()\n" "Traceback (most recent call last):\n" " File \"<stdin>\", line 1, in <module>\n" "TypeError: __init__() takes exactly 4 arguments (1 given)\n" @@ -147,18 +154,16 @@ msgstr "" msgid "Now we are going to call getName() and setName() methods." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> std1.getName()\n" +msgid ">>> std1.get_name()\n" "'Kushal'\n" -">>> std1.setName()\n" +">>> std1.set_name()\n" "Traceback (most recent call last):\n" " File \"<stdin>\", line 1, in <module>\n" -"TypeError: setName() takes exactly 2 arguments (1 given)\n" -">>> std1.setName('Shreyank Gupta')\n" -">>> std1.getName()\n" +"TypeError: set_name() takes exactly 2 arguments (1 given)\n" +">>> std1.set_name('Shreyank Gupta')\n" +">>> std1.get_name()\n" "'Shreyank Gupta'\n" "\n" "" @@ -189,46 +194,58 @@ msgstr "" msgid "student_teacher.py" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" +msgid "#!/usr/bin/env python\n" "\n" -"#!/usr/bin/env python\n" +"class Person(object):\n" +" \"\"\"\n" +" Returns a ```Person``` object with given name.\n" "\n" -"class Person:\n" +" \"\"\"\n" " def __init__(self,name):\n" " self.name = name\n" "\n" -" def getDetails(self):\n" +" def get_details(self):\n" +" \"Returns a string containing name of the person\"\n" " return self.name\n" "\n" "\n" "class Student(Person):\n" +" \"\"\"\n" +" Returns a ```Student``` object, takes 3 arguments, name, branch, year.\n" +" \n" +" \"\"\"\n" " def __init__(self,name,branch,year):\n" " Person.__init__(self,name)\n" " self.branch = branch\n" " self.year = year\n" "\n" -" def getDetails(self):\n" -" return (self.name, self.branch, self.year)\n" +" def get_details(self):\n" +" \"Returns a string containing student's details.\"\n" +" return \"%s studies %s and is in %s year.\" % (self.name, self.branch, self.year)\n" "\n" "\n" "class Teacher(Person):\n" -" def __init__(self,name,papers):\n" -" Person.__init__(self,name)\n" +" \"\"\"\n" +" Returns a ```Teacher``` object, takes a list of strings (list of papers) as\n" +" argument.\n" +" \"\"\" \n" +" def __init__(self, name, papers):\n" +" Person.__init__(self, name)\n" " self.papers = papers\n" "\n" -" def getDetails(self):\n" -" return (self.name, self.papers)\n" +" def get_details(self):\n" +" return \"%s teaches %s\" % (self.name, ','.join(self.papers))\n" "\n" "\n" -"person1 = Person('Rahul')\n" -"student1 = Student('Kushal','CSE',2005)\n" -"teacher1 = Teacher('Prashad',['C','C++'])\n" +"person1 = Person('Sachin')\n" +"student1 = Student('Kushal', 'CSE', 2005)\n" +"teacher1 = Teacher('Prashad', ['C', 'C++'])\n" "\n" -"print person1.getDetails()\n" -"print student1.getDetails()\n" -"print teacher1.getDetails()\n" +"print person1.get_details()\n" +"print student1.get_details()\n" +"print teacher1.get_details()\n" "\n" "\n" "" @@ -241,12 +258,10 @@ msgstr "" #. Tag: screen #, no-c-format -msgid "\n" -"\n" -"[kdas@kdas code]$ ./student_teacher.py\n" -"Rahul\n" -"('Kushal', 'CSE', 2005)\n" -"('Prashad', ['C', 'C++'])\n" +msgid "$ ./student_teacher.py \n" +"Sachin\n" +"Kushal studies CSE and is in 2005 year.\n" +"Prashad teaches C,C++\n" "\n" "\n" "" @@ -254,7 +269,7 @@ msgstr "" #. Tag: para #, no-c-format -msgid "In this example you can see how we called the __init__ method of the class Person in both Studentą¦¾ and Teacher classes' __init__ method. We also reimplemented getDetails() method of Person class in both Student and Teacher class. So, when we are calling getDetails() method on the teacher1 object it returns based on the object itself (which is of teacher class) and when we call getDetails() on the student1 or person1 object it returns based on getDetails() method implemented in it's own class." +msgid "In this example you can see how we called the __init__ method of the class Person in both Student and Teacher classes' __init__ method. We also reimplemented get_details() method of Person class in both Student and Teacher class. So, when we are calling get_details() method on the teacher1 object it returns based on the object itself (which is of teacher class) and when we call get_details() on the student1 or person1 object it returns based on get_details() method implemented in it's own class." msgstr "" #. Tag: title @@ -267,11 +282,9 @@ msgstr "" msgid "One class can inherit more than one classes. It gets access to all methods and variables of the parent classes. The general syntax is:" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"class MyClass(Parentclass1, Parentclass2,...):\n" +msgid "class MyClass(Parentclass1, Parentclass2,...):\n" " def __init__(self):\n" " Parentclass1.__init__(self)\n" " Parentclass2.__init__(self)\n" @@ -291,11 +304,9 @@ msgstr "" msgid "As we already know how to create an object , now we are going to see how to delete an python object. We use del for this." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> s = \"I love you\"\n" +msgid ">>> s = \"I love you\"\n" ">>> del s\n" ">>> s\n" "Traceback (most recent call last):\n" diff --git a/pot/datastructure.pot b/pot/datastructure.pot index 0994856..b8c65c6 100644 --- a/pot/datastructure.pot +++ b/pot/datastructure.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -27,11 +27,9 @@ msgstr "" msgid "Lists" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = [23, 45, 1, -3434, 43624356, 234]\n" +msgid ">>> a = [23, 45, 1, -3434, 43624356, 234]\n" ">>> a.append(45)\n" ">>> a\n" "[23, 45, 1, -3434, 43624356, 234, 45]\n" @@ -44,11 +42,9 @@ msgstr "" msgid "At first we created a list a. Then to add 45 at the end of the list we call a.append(45) method. You can see that 45 added at the end of the list. Sometimes it may require to insert data at any place within the list, for that we have insert() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a.insert(0, 1) # 1 added at the 0th position of the list\n" +msgid ">>> a.insert(0, 1) # 1 added at the 0th position of the list\n" ">>> a\n" "[1, 23, 45, 1, -3434, 43624356, 234, 45]\n" ">>> a.insert(0, 111)\n" @@ -63,11 +59,9 @@ msgstr "" msgid "count(s) will return you number of times s is in the list. Here we are going to check how many times 45 is there in the list." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a.count(45)\n" +msgid ">>> a.count(45)\n" "2\n" "\n" "" @@ -78,11 +72,9 @@ msgstr "" msgid "If you want to any particular value from the list you have to use remove() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a.remove(234)\n" +msgid ">>> a.remove(234)\n" ">>> a\n" "[111, 1, 23, 45, 1, -3434, 43624356, 45]\n" "\n" @@ -94,11 +86,9 @@ msgstr "" msgid "Now to reverse the whole list" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a.reverse()\n" +msgid ">>> a.reverse()\n" ">>> a\n" "[45, 43624356, -3434, 1, 45, 23, 1, 111]\n" "\n" @@ -110,11 +100,9 @@ msgstr "" msgid "We can store anything in the list, so first we are going to add another list b in a , then we will learn how to add the values of b into a ." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> b = [45, 56, 90]\n" +msgid ">>> b = [45, 56, 90]\n" ">>> a.append(b)\n" ">>> a\n" "[45, 43624356, -3434, 1, 45, 23, 1, 111, [45, 56, 90]]\n" @@ -134,11 +122,9 @@ msgstr "" msgid "Above you can see how we used a.extend() method to extend the list. To sort any list we have sort() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a.sort()\n" +msgid ">>> a.sort()\n" ">>> a\n" "[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356, [45, 56, 90]]\n" "\n" @@ -150,11 +136,9 @@ msgstr "" msgid "You can also delete element at any particular position of the list using the del keyword." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> del a[-1]\n" +msgid ">>> del a[-1]\n" ">>> a\n" "[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356]\n" "\n" @@ -171,11 +155,9 @@ msgstr "" msgid "Stacks are often known as LIFO (Last In First Out) structure. It means the data will enter into it at the end , and the last data will come out first. The easiest example can be of couple of marbles in an one side closed pipe. So if you want to take the marbles out of it you have to do that from the end where you entered the last marble. To achieve the same in code" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a\n" +msgid ">>> a\n" "[1, 2, 3, 4, 5, 6]\n" ">>> a.pop()\n" "6\n" @@ -204,11 +186,9 @@ msgstr "" msgid "In our daily life we have to encounter queues many times, like in ticket counters or in library or in the billing section of any supermarket. Queue is the data structure where you can append more data at the end and take out data from the beginning. That is why it is known as FIFO (First In First Out)." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = [1, 2, 3, 4, 5]\n" +msgid ">>> a = [1, 2, 3, 4, 5]\n" ">>> a.append(1)\n" ">>> a\n" "[1, 2, 3, 4, 5, 1]\n" @@ -242,11 +222,9 @@ msgstr "" msgid "For example if we want to make a list out of the square values of another list, then" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = [1, 2, 3]\n" +msgid ">>> a = [1, 2, 3]\n" ">>> [x ** 2 for x in a]\n" "[1, 4, 9]\n" ">>> z = [x + 1 for x in [x ** 2 for x in a]]\n" @@ -272,11 +250,9 @@ msgstr "" msgid "Tuples are data separated by comma." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'\n" +msgid ">>> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'\n" ">>> a\n" "('Fedora', 'Debian', 'Kubuntu', 'Pardus')\n" ">>> a[1]\n" @@ -294,11 +270,9 @@ msgstr "" msgid "You can also unpack values of any tuple in to variables, like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> divmod(15,2)\n" +msgid ">>> divmod(15,2)\n" "(7, 1)\n" ">>> x, y = divmod(15,2)\n" ">>> x\n" @@ -314,11 +288,9 @@ msgstr "" msgid "Tuples are immutable, that means you can not del/add/edit any value inside the tuple. Here is another example" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = (1, 2, 3, 4)\n" +msgid ">>> a = (1, 2, 3, 4)\n" ">>> del a[0]\n" "Traceback (most recent call last):\n" " File \"<stdin>\", line 1, in <module>\n" @@ -337,11 +309,9 @@ msgstr "" msgid "To create a tuple which contains only one value you have to type a trailing comma." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = (123)\n" +msgid ">>> a = (123)\n" ">>> a\n" "123\n" ">>> type(a)\n" @@ -360,11 +330,9 @@ msgstr "" msgid "Using the buitin function type() you can know the data type of any variable. Remember the len() function we used to find the length of any sequence ?" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> type(len)\n" +msgid ">>> type(len)\n" "<type 'bulletin_function_or_method'>\n" "\n" "" @@ -380,11 +348,9 @@ msgstr "" msgid "Sets are another type of data structure with no duplicate items. We can also mathematical set operations on sets." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = set('abcthabcjwethddda')\n" +msgid ">>> a = set('abcthabcjwethddda')\n" ">>> a\n" "set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 't', 'w'])\n" "\n" @@ -396,11 +362,9 @@ msgstr "" msgid "And some examples of the set operations" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = set('abracadabra')\n" +msgid ">>> a = set('abracadabra')\n" ">>> b = set('alacazam')\n" ">>> a # unique letters in a\n" "set(['a', 'r', 'b', 'c', 'd'])\n" @@ -421,11 +385,9 @@ msgstr "" msgid "To add or pop values from a set" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a\n" +msgid ">>> a\n" "set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 't', 'w'])\n" ">>> a.add('p')\n" ">>> a\n" @@ -444,11 +406,9 @@ msgstr "" msgid "Dictionaries are unordered set of key: value pairs where keys are unique. We declare dictionaries using {} braces. We use dictionaries to store data for any particular key and then retrieve them." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}\n" +msgid ">>> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}\n" ">>> data\n" "{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian'}\n" ">>> data['kart_']\n" @@ -462,11 +422,9 @@ msgstr "" msgid "We can add more data to it by simply" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> data['parthan'] = 'Ubuntu'\n" +msgid ">>> data['parthan'] = 'Ubuntu'\n" ">>> data\n" "{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}\n" "\n" @@ -478,11 +436,9 @@ msgstr "" msgid "To delete any particular key:value pair" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> del data['kushal']\n" +msgid ">>> del data['kushal']\n" ">>> data\n" "{'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'\n" "\n" @@ -491,16 +447,12 @@ msgstr "" #. Tag: para #, no-c-format -msgid "To check if any key is there in the dictionary or not you can use has_key() or in keyword." +msgid "To check if any key is there in the dictionary or not you can use in keyword." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> data.has_key('Soumya')\n" -"False\n" -">>> 'Soumya' in data\n" +msgid ">>> 'Soumya' in data\n" "False\n" "\n" "" @@ -516,11 +468,9 @@ msgstr "" msgid "dict() can create dictionaries from tuples of key,value pair." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))\n" +msgid ">>> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))\n" "{'Indian': 'Delhi', 'Bangladesh': 'Dhaka'}\n" "\n" "" @@ -531,11 +481,9 @@ msgstr "" msgid "If you want to loop through a dict use iteritems() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> data\n" +msgid ">>> data\n" "{'Kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}\n" ">>> for x, y in data.iteritems():\n" "... print \"%s uses %s\" % (x, y)\n" @@ -550,14 +498,52 @@ msgstr "" #. Tag: para #, no-c-format -msgid "If you want to loop through a list (or any sequence) and get iteration number at the same time you have to use enumerate()." +msgid "Many times it happens that we want to add more data to a value in a dictionary and if the key does not exists then we add some default value. You can do this efficiently using dict.setdefault(key, default)." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" +">>> data = {}\n" +">>> data.setdefault('names', []).append('Ruby')\n" +">>> data\n" +"{'names': ['Ruby']}\n" +">>> data.setdefault('names', []).append('Python')\n" +">>> data\n" +"{'names': ['Ruby', 'Python']}\n" +">>> data.setdefault('names', []).append('C')\n" +">>> data\n" +"{'names': ['Ruby', 'Python', 'C']}\n" "\n" -">>> for i, j in enumerate(['a', 'b', 'c']):\n" +"" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "When we try to get value for a key which does not exists we get KeyError. We can use dict.get(key, default) to get a default value when they key does not exists before." +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +">>> data['foo']\n" +"Traceback (most recent call last):\n" +" File \"<stdin>\", line 1, in <module>\n" +"KeyError: 'foo'\n" +">>> data.get('foo', 0)\n" +"0\n" +"\n" +"" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "If you want to loop through a list (or any sequence) and get iteration number at the same time you have to use enumerate()." +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid ">>> for i, j in enumerate(['a', 'b', 'c']):\n" "... print i, j\n" "...\n" "0 a\n" @@ -572,11 +558,9 @@ msgstr "" msgid "You may also need to iterate through two sequences same time, for that use zip() function." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = ['Pradeepto', 'Kushal']\n" +msgid ">>> a = ['Pradeepto', 'Kushal']\n" ">>> b = ['OpenSUSE', 'Fedora']\n" ">>> for x, y in zip(a, b):\n" "... print \"%s uses %s\" % (x, y)\n" @@ -597,11 +581,9 @@ msgstr "" msgid "In this example , you have to take number of students as input , then ask marks for three subjects as 'Physics', 'Maths', 'History', if the total number for any student is less 120 then print he failed, or else say passed." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "n = int(raw_input(\"Enter the number of students:\"))\n" "data = {} # here we will store the data\n" "languages = ('Physics', 'Maths', 'History') #all languages\n" @@ -627,24 +609,22 @@ msgstr "" msgid "The output" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./students.py\n" +msgid "[kd@kdlappy book]$ ./students.py\n" "Enter the number of students:2\n" "Enter the name of the student 1: Babai\n" "Enter marks of Physics: 12\n" "Enter marks of Maths: 45\n" "Enter marks of History: 40\n" -"Enter the name of the student 2: Ria\n" -"Enter marks of Physics: 89\n" +"Enter the name of the student 2: Tesla\n" +"Enter marks of Physics: 99\n" "Enter marks of Maths: 98\n" -"Enter marks of History: 40\n" +"Enter marks of History: 99\n" "Babai 's total marks 97\n" "Babai failed :(\n" -"Ria 's total marks 227\n" -"Ria passed :)\n" +"Tesla 's total marks 296\n" +"Tesla passed :)\n" "\n" "" msgstr "" @@ -659,11 +639,9 @@ msgstr "" msgid "In this example we will multiply two matrix's. First we will take input the number of rows/columns in the matrix (here we assume we are using n x n matrix). Then values of the matrix's." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "n = int(raw_input(\"Enter the value of n: \"))\n" "print \"Enter values for the Matrix A\"\n" "a = []\n" @@ -687,11 +665,9 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./matrixmul.py\n" +msgid "[kd@kdlappy book]$ ./matrixmul.py\n" "Enter the value of n: 3\n" "Enter values for the Matrix A\n" "1 2 3\n" diff --git a/pot/file.pot b/pot/file.pot index c9fa0d3..cfb78df 100644 --- a/pot/file.pot +++ b/pot/file.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -52,14 +52,11 @@ msgstr "" msgid "The default mode is read only, ie if you do not provide any mode it will open the file as read only. Let us open a file" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"love.txt\")\n" +msgid ">>> f = open(\"love.txt\")\n" ">>> f\n" "<open file 'love.txt', mode 'r' at 0xb7f2d968>\n" -"\n" "" msgstr "" @@ -73,16 +70,12 @@ msgstr "" msgid "After opening a file one should always close the opened file. We use method close() for this." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"love.txt\")\n" +msgid ">>> f = open(\"love.txt\")\n" ">>> f\n" "<open file 'love.txt', mode 'r' at 0xb7f2d968>\n" ">>> f.close()\n" -"\n" -"\n" "" msgstr "" @@ -121,17 +114,14 @@ msgstr "" msgid "To read the whole file at once use the read() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"sample.txt\")\n" +msgid ">>> f = open(\"sample.txt\")\n" ">>> f.read()\n" "'I love Python\n" "Pradeepto loves KDE\n" "Sankarshan loves Openoffice\n" "'\n" -"\n" "" msgstr "" @@ -140,18 +130,15 @@ msgstr "" msgid "If you call read() again it will return empty string as it already read the whole file. readline() can help you to read one line each time from the file." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"sample.txt\")\n" +msgid ">>> f = open(\"sample.txt\")\n" ">>> f.readline()\n" "'I love Python\n" "'\n" ">>> f.readline()\n" "'Pradeepto loves KDE\n" "'\n" -"\n" "" msgstr "" @@ -160,17 +147,14 @@ msgstr "" msgid "To read all the all the lines in a list we use readlines() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"sample.txt\")\n" +msgid ">>> f = open(\"sample.txt\")\n" ">>> f.readlines()\n" "['I love Python\n" "', 'Pradeepto loves KDE\n" "', 'Sankarshan loves Openoffice\n" "']\n" -"\n" "" msgstr "" @@ -179,18 +163,15 @@ msgstr "" msgid "You can even loop through the lines in a file object." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"sample.txt\")\n" +msgid ">>> f = open(\"sample.txt\")\n" ">>> for x in f:\n" "... print x,\n" "...\n" "I love Python\n" "Pradeepto loves KDE\n" "Sankarshan loves Openoffice\n" -"\n" "" msgstr "" @@ -199,16 +180,13 @@ msgstr "" msgid "Let us write a program which will take the file name as the input from the user and show the content of the file in the console." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "name = raw_input(\"Enter the file name: \")\n" "f = open(name)\n" "print f.read()\n" "f.close()\n" -"\n" "" msgstr "" @@ -224,14 +202,11 @@ msgstr "" #. Tag: screen #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./showfile.py\n" +msgid "$ ./showfile.py\n" "Enter the filename: sample.txt\n" "I love Python\n" "Pradeepto loves KDE\n" "Sankarshan loves Openoffice\n" -"\n" "" msgstr "" @@ -245,20 +220,17 @@ msgstr "" msgid "Let us open a file then we will write some random text into it by using the write() method." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open(\"ircnicks.txt\", 'w')\n" +msgid ">>> f = open(\"ircnicks.txt\", 'w')\n" ">>> f.write('powerpork\n" "')\n" ">>> f.write('indrag\n" "')\n" ">>> f.write('mishti\n" "')\n" -">>> f.write('sm|CPU')\n" +">>> f.write('sankarshan')\n" ">>> f.close()\n" -"\n" "" msgstr "" @@ -267,18 +239,15 @@ msgstr "" msgid "Now read the file we just created" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open('ircnicks.txt')\n" +msgid ">>> f = open('ircnicks.txt')\n" ">>> s = f.read()\n" ">>> print s\n" "powerpork\n" "indrag\n" "mishti\n" -"sm|CPU\n" -"\n" +"sankarshan\n" "" msgstr "" @@ -289,14 +258,12 @@ msgstr "" #. Tag: para #, no-c-format -msgid "In this example we will copy a given file to another file." +msgid "In this example we will copy a given text file to another file." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "import sys\n" "if len(sys.argv) < 3:\n" " print \"Wrong parameter\"\n" @@ -308,10 +275,14 @@ msgid "\n" "f2 = open(sys.argv[2], 'w')\n" "f2.write(s)\n" "f2.close()\n" -"\n" "" msgstr "" +#. Tag: para +#, no-c-format +msgid "This way of reading file is not always a good idea, a file can be very large to read and fit in the memory. It is always better to read a known size of the file and wirte that to the new file." +msgstr "" + #. Tag: para #, no-c-format msgid "You can see we used a new module here sys. sys.argv contains all command line parameters. Remember cp command in shell, after cp we type first the file to be copied and then the new file name." @@ -322,31 +293,25 @@ msgstr "" msgid "The first value in sys.argv is the name of the command itself." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "import sys\n" "print \"First value\", sys.argv[0]\n" "print \"All values\"\n" "for i, x in enumerate(sys.argv):\n" " print i, x\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./argvtest.py Hi there\n" +msgid "$ ./argvtest.py Hi there\n" "First value ./argvtest.py\n" "All values\n" "0 ./argvtest.py\n" "1 Hi\n" "2 there\n" -"\n" "" msgstr "" @@ -375,14 +340,12 @@ msgstr "" msgid "Let us see one example" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> f = open('tempfile', 'w')\n" +msgid ">>> f = open('/tmp/tempfile', 'w')\n" ">>> f.write('0123456789abcdef')\n" ">>> f.close()\n" -">>> f = open('tempfile')\n" +">>> f = open('/tmp/tempfile')\n" ">>> f.tell() #tell us the offset position\n" "0L\n" ">>> f.seek(5) # Goto 5th byte\n" @@ -393,7 +356,6 @@ msgid "\n" ">>> f.seek(-3, 2) # goto 3rd byte from the end\n" ">>> f.read() #Read till the end of the file\n" "'def'\n" -"\n" "" msgstr "" @@ -404,6 +366,67 @@ msgstr "" #. Tag: para #, no-c-format -msgid "Let us try to write an application which will count the spaces , tabs, and new lines in any given file." +msgid "Let us try to write an application which will count the spaces , tabs, and lines in any given file." +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"#!/usr/bin/env python\n" +"\n" +"import os\n" +"import sys\n" +"\n" +"\n" +"def parse_file(path):\n" +" \"\"\"\n" +" Parses the text file in the given path and returns space, tab & new line\n" +" details.\n" +"\n" +" :arg path: Path of the text file to parse\n" +"\n" +" :return: A tuple with count of spacaes, tabs and lines. \n" +" \"\"\"\n" +" fd = open(path)\n" +" i = 0\n" +" spaces = 0\n" +" tabs = 0\n" +" for i,line in enumerate(fd):\n" +" spaces += line.count(' ')\n" +" tabs += line.count('\\t')\n" +" #Now close the open file\n" +" fd.close()\n" +"\n" +" #Return the result as a tuple\n" +" return spaces, tabs, i + 1\n" +"\n" +"def main(path):\n" +" \"\"\"\n" +" Function which prints counts of spaces, tabs and lines in a file.\n" +"\n" +" :arg path: Path of the text file to parse\n" +" :return: True if the file exits or False.\n" +" \"\"\"\n" +" if os.path.exists(path):\n" +" spaces, tabs, lines = parse_file(path)\n" +" print \"Spaces %d. tabs %d. lines %d\" % (spaces, tabs, lines)\n" +" return True\n" +" else:\n" +" return False\n" +"\n" +"\n" +"if __name__ == '__main__':\n" +" if len(sys.argv) > 1:\n" +" main(sys.argv[1])\n" +" else:\n" +" sys.exit(-1)\n" +" sys.exit(0)\n" +"\n" +"" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "You can see that we have two functions in the program , main and parse_file where the second one actually parses the file and returns the result and we print the result in main function. By splitting up the code in smaller units (functions) helps us to organize the codebase and also it will be easier to write test cases for the functions." msgstr "" diff --git a/pot/functions.pot b/pot/functions.pot index 337ac76..0d18fb1 100644 --- a/pot/functions.pot +++ b/pot/functions.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -32,14 +32,11 @@ msgstr "" msgid "We use def keyword to define a function. general syntax is like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"def functionname(params):\n" +msgid "def functionname(params):\n" " statement1\n" " statement2\n" -"\n" "" msgstr "" @@ -48,13 +45,10 @@ msgstr "" msgid "Let us write a function which will take two integers as input and then return the sum." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> def sum(a, b):\n" +msgid ">>> def sum(a, b):\n" "... return a + b\n" -"\n" "" msgstr "" @@ -63,14 +57,11 @@ msgstr "" msgid "In the second line with the return keyword, we are sending back the value of a + b to the caller. You must call it like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> res = sum(234234, 34453546464)\n" +msgid ">>> res = sum(234234, 34453546464)\n" ">>> res\n" "34453780698L\n" -"\n" "" msgstr "" @@ -79,11 +70,9 @@ msgstr "" msgid "Remember the palindrome program we wrote in the last chapter. Let us write a function which will check if a given string is palindrome or not, then return True or False." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "def palindrome(s):\n" " z = s\n" " z = [x for x in z]\n" @@ -97,7 +86,6 @@ msgid "\n" " print \"Yay a palindrome\"\n" "else:\n" " print \"Oh no, not a palindrome\"\n" -"\n" "" msgstr "" @@ -116,10 +104,9 @@ msgstr "" msgid "To understand local and global variables we will go through two examples." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" "#!/usr/bin/env python\n" "def change(b):\n" " a = 90\n" @@ -129,7 +116,6 @@ msgid "\n" "print \"inside change function\",\n" "change(a)\n" "print \"After the function call \", a\n" -"\n" "" msgstr "" @@ -140,13 +126,10 @@ msgstr "" #. Tag: screen #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./local.py\n" +msgid "$ ./local.py\n" "Before the function call 9\n" "inside change function 90\n" "After the function call 9\n" -"\n" "" msgstr "" @@ -155,11 +138,9 @@ msgstr "" msgid "First we are assigning 9 to a, then calling change function, inside of that we are assigning 90 to a and printing a. After the function call we are again printing the value of a. When we are writing a = 90 inside the function, it is actually creating a new variable called a, which is only available inside the function and will be destroyed after the function finished. So though the name is same for the variable a but they are different in and out side of the function." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "def chvariable ange(b):\n" " global a\n" " a = 90\n" @@ -169,7 +150,6 @@ msgid "\n" "print \"inside change function\",\n" "change(a)\n" "print \"After the function call \", a\n" -"\n" "" msgstr "" @@ -188,11 +168,9 @@ msgstr "" msgid "In a function variables may have default argument values, that means if we don't give any value for that particular variable it will assigned automatically." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> def test(a , b = -99):\n" +msgid ">>> def test(a , b = -99):\n" "... if a > b:\n" "... return True\n" "... else:\n" @@ -206,15 +184,12 @@ msgstr "" msgid "In the above example we have written b = -99 in the function parameter list. That means of no value for b is given then b's value is -99. This is a very simple example of default arguments. You can test the code by" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> test(12, 23)\n" +msgid ">>> test(12, 23)\n" "False\n" ">>> test(12)\n" "True\n" -"\n" "" msgstr "" @@ -233,11 +208,9 @@ msgstr "" msgid "Also remember that default value is evaluated only once, so if you have any mutable object like list it will make a difference. See the next example" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> def f(a, data=[]):\n" +msgid ">>> def f(a, data=[]):\n" "... data.append(a)\n" "... return data\n" "...\n" @@ -247,7 +220,6 @@ msgid "\n" "[1, 2]\n" ">>> print f(3)\n" "[1, 2, 3]\n" -"\n" "" msgstr "" @@ -256,11 +228,9 @@ msgstr "" msgid "Keyword arguments" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> def func(a, b=5, c=10):\n" +msgid ">>> def func(a, b=5, c=10):\n" "... print 'a is', a, 'and b is', b, 'and c is', c\n" "...\n" ">>> func(12, 24)\n" @@ -269,7 +239,6 @@ msgid "\n" "a is 12 and b is 5 and c is 24\n" ">>> func(b=12, c = 24, a = -1)\n" "a is -1 and b is 12 and c is 24\n" -"\n" "" msgstr "" @@ -278,16 +247,56 @@ msgstr "" msgid "In the above example you can see we are calling the function with variable names, like func(12, c = 24), by that we are assigning 24 to c and b is getting its default value. Also remember that you can not have without keyword based argument after a keyword based argument. like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> def func(a, b=13, v):\n" +msgid ">>> def func(a, b=13, v):\n" "... print a, b, v\n" "...\n" " File \"<stdin>\", line 1\n" "SyntaxError: non-default argument follows default argument\n" +"" +msgstr "" + +#. Tag: title +#, no-c-format +msgid "Docstrings" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "In Python we use docstrings to explain how to use the code, it will be useful in interactive mode and to create auto-documentation. Below we see an example of the docstring for a function called longest_side." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "text" +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"#!/usr/bin/env python\n" +"import math\n" +"\n" +"def longest_side(a, b):\n" +" \"\"\"\n" +" Function to find the length of the longest side of a right triangle.\n" +"\n" +" :arg a: Side a of the triangle\n" +" :arg b: Side b of the triangle\n" +"\n" +" :return: Length of the longest side c as float\n" +" \"\"\"\n" +" return math.sqrt(a*a + b*b)\n" +"\n" +"if __name__ == '__main__':\n" +" print longest_side(4, 5)\n" "\n" "" msgstr "" +#. Tag: para +#, no-c-format +msgid "We will learn more on docstrings in reStructuredText chapter." +msgstr "" + diff --git a/pot/ifelse.pot b/pot/ifelse.pot index e92b6ec..eb53ae3 100644 --- a/pot/ifelse.pot +++ b/pot/ifelse.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -32,13 +32,10 @@ msgstr "" msgid "The syntax looks like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"if expression:\n" +msgid "if expression:\n" " do this\n" -"\n" "" msgstr "" @@ -47,15 +44,12 @@ msgstr "" msgid "If the value of expression is true (anything other than zero), do the what is written below under indentation. Please remember to give proper indentation, all the lines indented will be evaluated on the True value of the expression. One simple example is to take some number as input and check if the number is less than 100 or not." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "number = int(raw_input(\"Enter a number: \"))\n" "if number < 100:\n" " print \"The number is less than 100\"\n" -"\n" "" msgstr "" @@ -64,14 +58,11 @@ msgstr "" msgid "Then we run it" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./number100.py\n" +msgid "$ ./number100.py\n" "Enter a number: 12\n" "The number is less than 100\n" -"\n" "" msgstr "" @@ -85,17 +76,14 @@ msgstr "" msgid "Now in the above example we want to print \"Greater than\" if the number is greater than 100. For that we have to use the else statement. This works when the ifstatement is not fulfilled." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "number = int(raw_input(\"Enter a number: \"))\n" "if number < 100:\n" " print \"The number is less than 100\"\n" "else:\n" " print \"The number is greater than 100\"\n" -"\n" "" msgstr "" @@ -104,14 +92,11 @@ msgstr "" msgid "The output" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -" \n" -"[kd@kdlappy book]$ ./number100.py\n" +msgid "$ ./number100.py\n" "Enter a number: 345\n" "The number is greater than 100\n" -"\n" "" msgstr "" @@ -120,11 +105,9 @@ msgstr "" msgid "Another very basic example" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> x = int(raw_input(\"Please enter an integer: \"))\n" +msgid ">>> x = int(raw_input(\"Please enter an integer: \"))\n" ">>> if x < 0:\n" "... x = 0\n" "... print 'Negative changed to zero'\n" @@ -134,7 +117,37 @@ msgid "\n" "... print 'Single'\n" "... else:\n" "... print 'More'\n" -"\n" +"" +msgstr "" + +#. Tag: title +#, no-c-format +msgid "Truth value testing" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "The elegant way to test Truth values is like" +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"if x:\n" +" pass\n" +" " +msgstr "" + +#. Tag: title +#, no-c-format +msgid "Don't do this" +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"if x == True:\n" +" pass\n" "" msgstr "" diff --git a/pot/installation.pot b/pot/installation.pot index efb72b6..8f933a6 100644 --- a/pot/installation.pot +++ b/pot/installation.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" diff --git a/pot/looping.pot b/pot/looping.pot index b02b051..c5db2f7 100644 --- a/pot/looping.pot +++ b/pot/looping.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -32,14 +32,11 @@ msgstr "" msgid "The syntax for while statement is like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"while condition:\n" +msgid "while condition:\n" " statement1\n" " statement2\n" -"\n" "" msgstr "" @@ -48,11 +45,9 @@ msgstr "" msgid "The code we want to reuse must be indented properly under the while statement. They will be executed if the condition is true. Again like in if-else statement any non zero value is true. Let us write a simple code to print numbers 0 to 10" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> n = 0\n" +msgid ">>> n = 0\n" ">>> while n < 11:\n" "... print n\n" "... n += 1\n" @@ -68,7 +63,6 @@ msgid "\n" "8\n" "9\n" "10\n" -"\n" "" msgstr "" @@ -87,16 +81,13 @@ msgstr "" msgid "Let us try to solve Fibonacci series. In this series we get the next number by adding the previous two numbers. So the series looks like 1,1,2,3,5,8,13 ......." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "a, b = 0, 1\n" "while b < 100:\n" " print b\n" " a, b = b, a + b\n" -"\n" "" msgstr "" @@ -105,11 +96,10 @@ msgstr "" msgid "The output" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" -"[kd@kdlappy book]$ ./fibonacci1.py\n" +"$ ./fibonacci1.py\n" "1\n" "1\n" "2\n" @@ -121,7 +111,6 @@ msgid "\n" "34\n" "55\n" "89\n" -"\n" "" msgstr "" @@ -135,26 +124,21 @@ msgstr "" msgid "If you put a trailing comma in the print statement , then it will print in the same line" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" "#!/usr/bin/env python\n" "a, b = 0, 1\n" "while b < 100:\n" " print b,\n" " a, b = b, a + b\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./fibonacci2.py\n" +msgid "$ ./fibonacci2.py\n" "1 1 2 3 5 8 13 21 34 55 89\n" -"\n" "" msgstr "" @@ -168,11 +152,9 @@ msgstr "" msgid "Let us write a program to evaluate the power series. The series looks like e**x =1+x+x**2/2! +x**3/3! +....+ x**n/n! where 0 < x < 1" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "x = float(raw_input(\"Enter the value of x: \"))\n" "n = term = num = 1\n" "sum = 1.0\n" @@ -183,24 +165,20 @@ msgid "\n" " if term < 0.0001:\n" " break\n" "print \"No of Times= %d and Sum= %f\" % (n, sum)\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"kd@kdlappy book]$ ./powerseries.py\n" +msgid "$ ./powerseries.py\n" "Enter the value of x: 0\n" "No of Times= 2 and Sum= 1.000000\n" -"[kd@kdlappy book]$ ./powerseries.py\n" +"$ ./powerseries.py\n" "Enter the value of x: 0.1\n" "No of Times= 5 and Sum= 1.105171\n" -"[kd@kdlappy book]$ ./powerseries.py\n" +"$ ./powerseries.py\n" "Enter the value of x: 0.5\n" -"No of Times= 7 and Sum= 1.648720\n" -"" +"No of Times= 7 and Sum= 1.648720" msgstr "" #. Tag: para @@ -208,13 +186,10 @@ msgstr "" msgid "In this program we introduced a new keyword called break. What break does is stop the innermost loop. In this example we are using break under the if statement" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"if term < 0.0001:\n" +msgid "if term < 0.0001:\n" " break\n" -"\n" "" msgstr "" @@ -233,11 +208,9 @@ msgstr "" msgid "In this example we are going to print the multiplication table up to 10." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "i = 1\n" "print \"-\" * 50\n" "while i < 11:\n" @@ -248,15 +221,12 @@ msgid "\n" " print \"\"\n" " i += 1\n" "print \"-\" * 50\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./multiplication.py\n" +msgid "$ ./multiplication.py\n" "--------------------------------------------------\n" " 1 2 3 4 5 6 7 8 9 10\n" " 2 4 6 8 10 12 14 16 18 20\n" @@ -269,7 +239,6 @@ msgid "\n" " 9 18 27 36 45 54 63 72 81 90\n" " 10 20 30 40 50 60 70 80 90 100\n" "--------------------------------------------------\n" -"\n" "" msgstr "" @@ -278,12 +247,9 @@ msgstr "" msgid "Here we used one while loop inside another loop, this is known as nested looping. You can also see one interesting statement here" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"print \"-\" * 50\n" -"\n" +msgid "print \"-\" * 50\n" "" msgstr "" @@ -292,11 +258,9 @@ msgstr "" msgid "In a print statement if we multiply the string with an integer n , the string will be printed nmany times. Some examples" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> print \"*\" * 10\n" +msgid ">>> print \"*\" * 10\n" "**********\n" ">>> print \"#\" * 20\n" "####################\n" @@ -304,7 +268,6 @@ msgid "\n" "----------------------------------------\n" ">>> print \"-\" * 40\n" "----------------------------------------\n" -"\n" "" msgstr "" @@ -323,33 +286,27 @@ msgstr "" msgid "Design 1" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "row = int(raw_input(\"Enter the number of rows: \"))\n" "n = row\n" "while n >= 0:\n" " x = \"*\" * n\n" " print x\n" " n -= 1\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./design1.py\n" +msgid "$ ./design1.py\n" "Enter the number of rows: 5\n" "*****\n" "****\n" "***\n" "**\n" "*\n" -"\n" "" msgstr "" @@ -358,32 +315,26 @@ msgstr "" msgid "Design 2" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "n = int(raw_input(\"Enter the number of rows: \"))\n" "i = 1\n" "while i <= n:\n" " print \"*\" * i\n" " i += 1\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./design2.py\n" +msgid "$ ./design2.py\n" "Enter the number of rows: 5\n" "*\n" "**\n" "***\n" "****\n" "*****\n" -"\n" "" msgstr "" @@ -392,11 +343,9 @@ msgstr "" msgid "Design 3" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "row = int(raw_input(\"Enter the number of rows: \"))\n" "n = row\n" "while n >= 0:\n" @@ -404,22 +353,18 @@ msgid "\n" " y = \" \" * (row - n)\n" " print y + x\n" " n -= 1\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./design3.py\n" +msgid "$ ./design3.py\n" "Enter the number of rows: 5\n" "*****\n" " ****\n" " ***\n" " **\n" " *\n" -"\n" "" msgstr "" @@ -433,14 +378,11 @@ msgstr "" msgid "We are going to learn a data structure called list before we go ahead to learn more on looping. Lists an be written as a list of comma-separated values (items) between square brackets." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = [ 1 , 342, 2233423, 'India', 'Fedora']\n" +msgid ">>> a = [ 1 , 342, 2233423, 'India', 'Fedora']\n" ">>> a\n" "[1, 342, 2233423, 'India', 'Fedora']\n" -"\n" "" msgstr "" @@ -449,15 +391,12 @@ msgstr "" msgid "Lists can keep any other data inside it. It works as a sequence too, that means" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a[0]\n" +msgid ">>> a[0]\n" "1\n" ">>> a[4]\n" "'Fedora'\n" -"\n" "" msgstr "" @@ -466,11 +405,9 @@ msgstr "" msgid "You can even slice it into different pieces, examples are given below" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a[4]\n" +msgid ">>> a[4]\n" "'Fedora'\n" ">>> a[-1]\n" "'Fedora'\n" @@ -483,8 +420,7 @@ msgid "\n" ">>> a[:-2]\n" "[1, 342, 2233423]\n" ">>> a[0::2]\n" -"[1, 2233423, 'Fedora']\n" -"" +"[1, 2233423, 'Fedora']" msgstr "" #. Tag: para @@ -497,16 +433,13 @@ msgstr "" msgid "To check if any value exists within the list or not you can do" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = ['Fedora', 'is', 'cool']\n" +msgid ">>> a = ['Fedora', 'is', 'cool']\n" ">>> 'cool' in a\n" "True\n" ">>> 'Linux' in a\n" "False\n" -"\n" "" msgstr "" @@ -515,16 +448,28 @@ msgstr "" msgid "That means we can use the above statement as if clause expression. The built-in function len() can tell the length of a list." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> len(a)\n" +msgid ">>> len(a)\n" "3\n" -"\n" "" msgstr "" +#. Tag: para +#, no-c-format +msgid "If you want to test if the list is empty or not, do it like this" +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"if list_name: #This means the list is not empty\n" +" pass\n" +"else: #This means the list is empty\n" +" pass\n" +" " +msgstr "" + #. Tag: title #, no-c-format msgid "For loop" @@ -535,16 +480,13 @@ msgstr "" msgid "There is another to loop by using for statement. In python the for statement is different from the way it works in C. Here for statement iterates over the items of any sequence (a list or a string). Example given below" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a = ['Fedora', 'is', 'powerfull']\n" +msgid ">>> a = ['Fedora', 'is', 'powerfull']\n" ">>> for x in a:\n" "... print x,\n" "...\n" "Fedora is powerfull\n" -"\n" "" msgstr "" @@ -553,10 +495,9 @@ msgstr "" msgid "We can also do things like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -">>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" +msgid ">>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" ">>> for x in a[::2]:\n" "... print x\n" "...\n" @@ -578,11 +519,9 @@ msgstr "" msgid "range() is a buitin function. From the help document" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"range(...)\n" +msgid "range(...)\n" " range([start,] stop[, step]) -> list of integers\n" " Return a list containing an arithmetic progression of integers.\n" " range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n" @@ -598,11 +537,9 @@ msgstr "" msgid "Now if you want to see this help message on your system type help(range) in the python interpreter. help(s) will return help message on the object s. Examples of range function" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> range(1,5)\n" +msgid ">>> range(1,5)\n" "[1, 2, 3, 4]\n" ">>> range(1,15,3)\n" "[1, 4, 7, 10, 13]\n" @@ -622,11 +559,9 @@ msgstr "" msgid "Just like break we have another statement, continue, which skips the execution of the code after itself and goes back to the start of the loop. That means it will help you to skip a part of the loop. In the below example we will ask the user to input an integer, if the input is negative then we will ask again, if positive then we will square the number. To get out of the infinite loop user must input 0." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "while True:\n" " n = int(raw_input(\"Please enter an Integer: \"))\n" " if n < 0:\n" @@ -635,14 +570,12 @@ msgid "\n" " break\n" " print \"Square is \", n ** 2\n" "print \"Goodbye\"\n" -"\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"[kd@kdlappy book]$ ./continue.py\n" +msgid "$ ./continue.py\n" "Please enter an Integer: 34\n" "Square is 1156\n" "Please enter an Integer: 4\n" @@ -663,11 +596,9 @@ msgstr "" msgid "We can have an optional else statement after any loop. It will be executed after the loop unless a break statement stopped the loop." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> for i in range(0,5):\n" +msgid ">>> for i in range(0,5):\n" "... print i\n" "... else:\n" "... print \"Bye bye\"\n" @@ -678,7 +609,6 @@ msgid "\n" "3\n" "4\n" "Bye bye\n" -"\n" "" msgstr "" @@ -697,11 +627,9 @@ msgstr "" msgid "This is a very simple game of sticks. There are 21 sticks, first the user picks number of sticks between 1-4, then the computer picks sticks(1-4). Who ever will pick the last stick will loose. Can you find out the case when the user will win ?" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "\n" "sticks = 21\n" "\n" @@ -721,8 +649,6 @@ msgid "\n" "\n" "\"\n" " sticks -= 5\n" -"\n" -"\n" "" msgstr "" diff --git a/pot/modules.pot b/pot/modules.pot index ab1a2c4..37b1c2a 100644 --- a/pot/modules.pot +++ b/pot/modules.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -39,22 +39,45 @@ msgstr "" #. Tag: para #, no-c-format -msgid "Now we are going to see how modules work. Create a file called greetings.py. Content of the file is given bellow." +msgid "Now we are going to see how modules work. Create a file called bars.py. Content of the file is given bellow." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" +"\"\"\"\n" +"Bars Module\n" +"============\n" +"\n" +"This is an example module with provide different ways to print bars.\n" "\n" -"#Bars module\n" +"\"\"\"\n" "\n" "def starbar(num):\n" +" \"\"\"\n" +" Prints a bar with *\n" +"\n" +" :arg num: Length of the bar\n" +"\n" +" \"\"\"\n" " print '*' * num\n" "\n" "def hashbar(num):\n" +" \"\"\"\n" +" Prints a bar with #\n" +"\n" +" :arg num: Length of the bar\n" +"\n" +" \"\"\"\n" " print '#' * num\n" "\n" "def simplebar(num):\n" +" \"\"\"\n" +" Prints a bar with -\n" +"\n" +" :arg num: Length of the bar\n" +" \n" +" \"\"\"\n" " print '-' * num\n" "\n" "\n" @@ -66,10 +89,9 @@ msgstr "" msgid "Now we are going to start the python interpreter and import our module." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> import bars\n" ">>>\n" "\n" @@ -81,10 +103,9 @@ msgstr "" msgid "This will import the module bars. We have to use the module name to access functions inside the module." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> bars.hashbar(10)\n" "##########\n" ">>> bars.simplebar(10)\n" @@ -105,10 +126,9 @@ msgstr "" msgid "There are different ways to import modules. We already saw one way to do this. You can even import selected functions from modules. To do so:" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> from bars import simplebar, starbar\n" ">>> simplebar(20)\n" "--------------------\n" @@ -116,22 +136,6 @@ msgid "\n" "" msgstr "" -#. Tag: para -#, no-c-format -msgid "Or you can import all functions or variables from a module directly into the current namespace by using *" -msgstr "" - -#. Tag: screen -#, no-c-format -msgid "\n" -"\n" -">>> from bars import *\n" -">>> hashbar(20)\n" -"####################\n" -"\n" -"" -msgstr "" - #. Tag: title #, no-c-format msgid "Default modules" @@ -142,10 +146,9 @@ msgstr "" msgid "Now your Python installation comes with different modules installed, you can use them as required and install new modules for any other special purposes. In the following few examples we are going to see many examples on the same." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> help()\n" "\n" "Welcome to Python 2.6! This is the online help utility.\n" @@ -175,18 +178,44 @@ msgstr "" #. Tag: title #, no-c-format -msgid "Module os" +msgid "Submodules" msgstr "" #. Tag: para #, no-c-format -msgid "os module provides operating system dependent functionality. You can import it using the following import statement." +msgid "We can many submodules inside a module. A directory with a __init__.py can also be used a module and all .py files inside it become submodules." msgstr "" #. Tag: screen #, no-c-format msgid "\n" +"$ tree mymodule\n" +"mymodule\n" +"|-- bars.py\n" +"|-- __init__.py\n" +"`-- utils.py\n" "\n" +"" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "In this example mymodule is the module name and bars and utils are two submodules in it." +msgstr "" + +#. Tag: title +#, no-c-format +msgid "Module os" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "os module provides operating system dependent functionality. You can import it using the following import statement." +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" ">>> import os\n" "\n" "\n" @@ -198,7 +227,7 @@ msgstr "" msgid "getuid() function returns the current process's effective user's id." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" "\n" @@ -214,7 +243,7 @@ msgstr "" msgid "getpid() returns the current process's id. getppid() returns the parent process's id." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" "\n" @@ -233,7 +262,7 @@ msgstr "" msgid "uname() returns different information identifying the operating system, in Linux it returns details you can get from the uname command. The returned object is a tuple, (sysname, nodename, release, version, machine)" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" "\n" @@ -249,11 +278,11 @@ msgstr "" msgid "getcwd()returns the current working directory. chdir(path) changes the current working directory to path. In the example we first see the current directory which is my home directory and change the current directory to /tmp and then again checking the current directory." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" ">>> os.getcwd()\n" -"'/home/kdas'\n" +"'/home/kushal'\n" ">>> os.chdir('/tmp')\n" ">>> os.getcwd()\n" "'/tmp'\n" diff --git a/pot/operatorsexpressions.pot b/pot/operatorsexpressions.pot index 71902e6..ae4a549 100644 --- a/pot/operatorsexpressions.pot +++ b/pot/operatorsexpressions.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -32,10 +32,9 @@ msgstr "" msgid "Operators are the symbols which tells the python interpreter to do some mathematical or logical operation. Few basic examples of mathematical operators are given below:" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> 2 + 3\n" "5\n" ">>> 23 - 3\n" @@ -51,10 +50,9 @@ msgstr "" msgid "To get floating result you need to the division using any of operand as floating number. To do modulo operation use % operator" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> 14 % 3\n" "2\n" "\n" @@ -71,10 +69,9 @@ msgstr "" msgid "The code" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "days = int(raw_input(\"Enter days: \"))\n" "months = days / 30\n" @@ -89,11 +86,10 @@ msgstr "" msgid "The output" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./integer.py\n" +msgid " \n" +"$ ./integer.py\n" "Enter days: 265\n" "Months = 8 Days = 25\n" "\n" @@ -105,10 +101,9 @@ msgstr "" msgid "In the first line I am taking the input of days, then getting the months and days and at last printing them. You can do it in a easy way" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "days = int(raw_input(\"Enter days: \"))\n" "print \"Months = %d Days = %d\" % (divmod(days, 30))\n" @@ -206,10 +201,9 @@ msgstr "" msgid "Some examples" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> 1 < 2\n" "True\n" ">>> 3 > 34\n" @@ -227,10 +221,9 @@ msgstr "" msgid "// operator gives the floor division result" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> 4.0 // 3\n" "1.0\n" ">>> 4.0 / 3\n" @@ -249,10 +242,9 @@ msgstr "" msgid "To do logical AND , OR we use and , or keywords. x and y returns False if x is False else it returns evaluation of y. If x is True, it returns True." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> 1 and 4\n" "4\n" ">>> 1 or 4\n" @@ -275,10 +267,9 @@ msgstr "" msgid "x op = expression is the syntax for shorthand operators. It will be evaluated like x = x op expression , Few examples are" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" ">>> a = 12\n" ">>> a += 13\n" ">>> a\n" @@ -298,10 +289,9 @@ msgstr "" msgid "shorthand.py example" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "N = 100\n" "a = 2\n" @@ -312,11 +302,10 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./shorthand.py\n" +msgid " \n" +"$ ./shorthand.py\n" "2\n" "4\n" "16\n" @@ -334,10 +323,9 @@ msgstr "" msgid "Generally while writing expressions we put spaces before and after every operator so that the code becomes clearer to read, like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "a = 234 * (45 - 56.0 / 34)\n" "\n" "" @@ -348,10 +336,9 @@ msgstr "" msgid "One example code used to show expressions" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "a = 9\n" "b = 12\n" @@ -366,11 +353,10 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./evaluationexp.py\n" +msgid " \n" +"$ ./evaluationexp.py\n" "X = 10\n" "Y = 7\n" "Z = 4\n" @@ -383,10 +369,9 @@ msgstr "" msgid "At first x is being calculated. The steps are like this" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "9 - 12 / 3 + 3 * 2 -1\n" "9 - 4 + 3 * 2 - 1\n" "9 - 4 + 6 - 1\n" @@ -412,10 +397,9 @@ msgstr "" msgid "We have to do the type conversions manually. Like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "float(string) -> float value\n" "int(string) -> integer value\n" "str(integer) or str(float) -> string representation \n" @@ -436,10 +420,9 @@ msgstr "" msgid "This is a program to evaluate 1/x+1/(x+1)+1/(x+2)+ ... +1/n series upto n, in our case x = 1 and n =10" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "sum = 0.0\n" "for i in range(1, 11):\n" @@ -449,11 +432,10 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./evaluateequ.py\n" +msgid " \n" +"$ ./evaluateequ.py\n" " 1 1.0000\n" " 2 1.5000\n" " 3 1.8333\n" @@ -483,10 +465,9 @@ msgstr "" msgid "This is a program to evaluate the quadratic equation" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "import math\n" "a = int(raw_input(\"Enter value of a: \"))\n" @@ -514,10 +495,9 @@ msgstr "" msgid "In this example we are going to calculate the salary of a camera salesman. His basic salary is 1500, for every camera he will sell he will get 200 and the commission on the month's sale is 2 %. The input will be number of cameras sold and total price of the cameras." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" +msgid " \n" "#!/usr/bin/env python\n" "basic_salary = 1500\n" "bonus_rate = 200\n" @@ -534,11 +514,10 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./salesmansalary.py\n" +msgid " \n" +"$ ./salesmansalary.py\n" "Enter the number of inputs sold: 5\n" "Enter the total prices: 20450\n" "Bonus = 1000.00\n" diff --git a/pot/strings.pot b/pot/strings.pot index 6d3122c..f89b176 100644 --- a/pot/strings.pot +++ b/pot/strings.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -25,7 +25,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"I am Indian\"\n" ">>> s\n" "'I am Indian'\n" @@ -54,7 +53,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"\"\" This is a\n" "... multiline string, so you can\n" "... write many lines\"\"\"\n" @@ -79,7 +77,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"kushal das\"\n" ">>> s.title()\n" "'Kushal Das' \n" @@ -95,7 +92,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> z = s.upper()\n" ">>> z\n" "'KUSHAL DAS'\n" @@ -113,7 +109,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"I am A pRoGraMMer\"\n" ">> s.swapcase()\n" "'i AM a PrOgRAmmER'\n" @@ -129,7 +124,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"jdwb 2323bjb\"\n" ">>> s.isalnum()\n" "False\n" @@ -148,7 +142,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"SankarshanSir\"\n" ">>> s.isalpha()\n" "True\n" @@ -167,7 +160,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"1234\"\n" ">>> s.isdigit() #To check if all the characters are digits or not\n" "True\n" @@ -192,7 +184,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"We all love Python\"\n" ">>> s.split(\" \")\n" "['We', 'all', 'love', 'Python']\n" @@ -211,7 +202,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> \"-\".join(\"GNU/Linux is great\".split(\" \"))\n" "'GNU/Linux-is-great'\n" "\n" @@ -225,7 +215,7 @@ msgstr "" #. Tag: title #, no-c-format -msgid "String the strings" +msgid "Strip the strings" msgstr "" #. Tag: para @@ -236,7 +226,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \" abc\n" " \"\n" ">>> s.strip()\n" @@ -253,7 +242,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s = \"www.foss.in\"\n" ">>> s.lstrip(\"cwsd.\")\n" "'foss.in'\n" @@ -276,7 +264,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> s.find(\"for\")\n" "7\n" ">>> s.find(\"fora\")\n" @@ -307,7 +294,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" "#!/usr/bin/env python\n" "s = raw_input(\"Please enter a string: \")\n" "z = [x for x in s]\n" @@ -328,7 +314,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" "[kd@kdlappy book]$ ./palindrome.py\n" "Please enter a string: madam1\n" "The string is not a palindrome\n" @@ -352,7 +337,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" "#!/usr/bin/env python\n" "s = raw_input(\"Enter a line: \")\n" "print \"The number of words in the line are %d\" % (len(s.split(\" \")))\n" @@ -363,7 +347,6 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" "[kd@kdlappy book]$ ./countwords.py\n" "Enter a line: Sayamindu is a great programmer\n" "The number of words in the line are 5 \n" diff --git a/pot/thebeginning.pot b/pot/thebeginning.pot index ba77e30..8d76e82 100644 --- a/pot/thebeginning.pot +++ b/pot/thebeginning.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -133,6 +133,51 @@ msgstr "" msgid "You can even get into this indentation errors if you mix up tabs and spaces. Like if you use spaces and only use spaces for indentation, don't use tabs in that case. For you it may look same, but the code will give you error if you try to run it." msgstr "" +#. Tag: para +#, no-c-format +msgid "So we can have few basic rules ready for spaces and indentation." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Use 4 spaces for indentation." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Never mix tab and spaces." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "One blank line between functions." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Two blank lines between classes." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "There are more places where you should be following same type of rules of whitespace, they are like" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Add a space after \",\" in dicts, lists, typles, and argument lists and after \":\" in dicts." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Spaces around assignments and comparisons (except in argument list)" +msgstr "" + +#. Tag: para +#, no-c-format +msgid "No spaces just inside parentheses." +msgstr "" + #. Tag: title #, no-c-format msgid "Comments" @@ -146,12 +191,24 @@ msgstr "" #. Tag: screen #, no-c-format msgid "\n" -"\n" ">>> #this is a comment\n" ">>> #the next line will add two numbers\n" ">>> a = 12 + 34\n" ">>> print c #this is a comment too :)\n" -"" +" " +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Comments are mainly for the people will develop or maintain the codebase, so it means if you have some complex code somewhere you should write enough comments inside so that anyone else can understand the code by reading the comments. You can also use some standard comments like" +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +"#FIXME -- fix these code later\n" +"#TODO -- in future you have to do this\n" +" " msgstr "" #. Tag: title @@ -164,14 +221,12 @@ msgstr "" msgid "Modules are python files which contain different function definitions , variables which we can reuse, it should always end with a .py extension.. Python itself is having a vast module library with the default installation. We are going to use some of them. To use a module you have to import it first." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> import math\n" ">>> print math.e\n" "2.71828182846\n" -"\n" "" msgstr "" diff --git a/pot/variablesanddatatypes.pot b/pot/variablesanddatatypes.pot index 335346e..9066f1a 100644 --- a/pot/variablesanddatatypes.pot +++ b/pot/variablesanddatatypes.pot @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: 0\n" -"POT-Creation-Date: 2011-11-05T11:20:40\n" -"PO-Revision-Date: 2011-11-05T11:20:40\n" +"POT-Creation-Date: 2012-08-13T13:28:38\n" +"PO-Revision-Date: 2012-08-13T13:28:38\n" "Last-Translator: Automatically generated\n" "Language-Team: None\n" "MIME-Version: 1.0\n" @@ -32,17 +32,16 @@ msgstr "" msgid "Python codes can be divided into identifiers. Identifiers (also referred to as names) are described by the following lexical definitions:" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" "identifier ::= (letter|\"_\") (letter | digit | \"_\")* \n" "letter ::= lowercase | uppercase \n" "lowercase ::= \"a\"...\"z\" \n" "uppercase ::= \"A\"...\"Z\" \n" "digit ::= \"0\"...\"9\"\n" "\n" -"" +" " msgstr "" #. Tag: para @@ -50,10 +49,9 @@ msgstr "" msgid "This means _abcd is a valid identifier where as 1sd is not. The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here:" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" "and del from not while \n" "as elif global or with \n" "assert else if pass yield \n" @@ -62,7 +60,7 @@ msgid "\n" "continue finally is return \n" "def for lambda try\n" "\n" -"" +" " msgstr "" #. Tag: para @@ -70,16 +68,15 @@ msgstr "" msgid "In Python we don't specify what kind of data we are going to put in a variable. So you can directly write abc = 1 and abc will become an integer datatype. If you write abc = 1.0 abc will become of floating type. Here is a small program to add two given numbers" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> a = 13 \n" ">>> b = 23\n" ">>> a + b \n" "36\n" "\n" -"" +" " msgstr "" #. Tag: para @@ -87,10 +84,9 @@ msgstr "" msgid "From the above example you can understand that to declare a variable in python , what you need is just to type the name and the value. Python can also manipulate strings They can be enclosed in single quotes or double quotes like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" ">>> 'India'\n" "'India' \n" ">>> 'India\\'s best' \n" @@ -98,7 +94,7 @@ msgid "\n" ">>> \"Hello World!\" \n" "'Hello World!'\n" "\n" -"" +" " msgstr "" #. Tag: title @@ -111,10 +107,9 @@ msgstr "" msgid "Generally the real life python codes do not need to read input from the keyboard. In python we use raw_input function to do input. raw_input(\"String to show\") , this will return a string as output. Let us write a program to read a number from the keyboard and check if it is less than 100 or not. Name of the program is testhundred.py" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" "#!/usr/bin/env python \n" "number = int(raw_input(\"Enter an integer: \"))\n" "if number < 100: \n" @@ -130,14 +125,13 @@ msgstr "" msgid "The output" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format msgid "\n" -"\n" -"[kd@kdlappy book]$ ./testhundred.py \n" +"$ ./testhundred.py \n" "Enter an integer: 13 \n" "Your number is smaller than 100 \n" -"[kd@kdlappy book]$ ./testhundred.py \n" +"$ ./testhundred.py \n" "Enter an integer: 123 \n" "Your number is greater than 100\n" "\n" @@ -149,11 +143,9 @@ msgstr "" msgid "In the next program we are going to calculate investments." msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python \n" +msgid "#!/usr/bin/env python \n" "amount = float(raw_input(\"Enter amount: \")) \n" "inrate = float(raw_input(\"Enter Interest rate: \")) \n" "period = int(raw_input(\"Enter period: \")) \n" @@ -168,11 +160,9 @@ msgid "\n" "" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./investment.py\n" +msgid "$ ./investment.py\n" "Enter amount: 10000\n" "Enter Interest rate: 0.14\n" "Enter period: 5\n" @@ -202,7 +192,7 @@ msgstr "" #. Tag: para #, no-c-format -msgid "In the next program we will do an average of N numbers." +msgid "In the next program we will do an average of N numbers. LoopCreating a loop in Python" msgstr "" #. Tag: programlisting @@ -224,7 +214,7 @@ msgstr "" #. Tag: screen #, no-c-format -msgid "[kd@kdlappy book]$ ./averagen.py\n" +msgid "$ ./averagen.py\n" "1\n" "2.3\n" "4.67\n" @@ -251,11 +241,9 @@ msgstr "" msgid "In this program we will convert the given temperature to Celsius from Fahrenheit by using the formula C=(F-32)/1.8" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -"#!/usr/bin/env python\n" +msgid "#!/usr/bin/env python\n" "fahrenhite = 0.0\n" "print \"Fahrenheit Celsius\"\n" "while fahrenheit <= 250:\n" @@ -268,9 +256,7 @@ msgstr "" #. Tag: screen #, no-c-format -msgid "\n" -"\n" -"[kd@kdlappy book]$ ./temperature.py\n" +msgid "[kd@kdlappy book]$ ./temperature.py\n" "Fahrenheit Celsius\n" " 0.0 -17.78\n" " 25.0 -3.89\n" @@ -297,17 +283,15 @@ msgstr "" msgid "You can even assign values to multiple variables in a single line, like" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a , b = 45, 54\n" +msgid ">>> a , b = 45, 54\n" ">>> a\n" "45\n" ">>> b\n" "54\n" "\n" -"" +" " msgstr "" #. Tag: para @@ -315,16 +299,39 @@ msgstr "" msgid "Using this swapping two numbers becomes very easy" msgstr "" -#. Tag: screen +#. Tag: programlisting #, no-c-format -msgid "\n" -"\n" -">>> a, b = b , a\n" +msgid ">>> a, b = b , a\n" ">>> a\n" "54\n" ">>> b\n" "45\n" "\n" -"" +" " +msgstr "" + +#. Tag: para +#, no-c-format +msgid "To understand how this works, you will have to learn about a data type called tuple. We use comma to create tuple. In the right hand side we create the tuple (we call this as tuple packing) and in the left hand side we do tuple unpacking into a new tuple." +msgstr "" + +#. Tag: para +#, no-c-format +msgid "Below we have another example of tuple unpacking." +msgstr "" + +#. Tag: programlisting +#, no-c-format +msgid "\n" +">>> data = (\"Kushal Das\", \"India\", \"Python\")\n" +">>> name, country, language = data\n" +">>> name\n" +"'Kushal Das'\n" +">>> country\n" +"'India'\n" +">>> language\n" +"'Python'\n" +"\n" +" " msgstr ""