Skip to content

Commit

Permalink
a lot changes now I can not track :(
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed May 7, 2013
1 parent 34c3d7e commit b0f7017
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 102 deletions.
3 changes: 2 additions & 1 deletion .tx/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[main]
host = https://www.transifex.net
host = https://www.transifex.com
lang_map = aln:aln-AL, ar:ar-SA, as:as-IN, bal:bal-PK, bg:bg-BG, bn:bn-BD, bn_IN:bn-IN, bs:bs-BA, ca:ca-ES, cs:cs-CZ, da:da-DK, de_CH:de-CH, de:de-DE, el:el-GR, en_GB:en-GB, es:es-ES, et:et-EE, fa:fa-IR, fi:fi-FI, fr:fr-FR, gu:gu-IN, he:he-IL, hi:hi-IN, hr:hr-HR, hu:hu-HU, id:id-ID, is:is-IS, it:it-IT, ja:ja-JP, kn:kn-IN, ko:ko-KR, lt:lt-LT, lv:lv-LV, mai:mai-IN, ml:ml-IN, mr:mr-IN, ms:ms-MY, nb:nb-NO, nds:nds-DE, nl:nl-NL, nn:nn-NO, or:or-IN, pa:pa-IN, pl:pl-PL, pt_BR:pt-BR, pt:pt-PT, ro:ro-RO, ru:ru-RU, si:si-LK, sk:sk-SK, sl:sl-SI, sq:sq-AL, sr:sr-RS, sr@latin:sr-Latn-RS, sv:sv-SE, ta:ta-IN, te:te-IN, tr:tr-TR, uk:uk-UA, ur:ur-PK, vi:vi-VN, zh_CN:zh-CN, zh_HK:zh-HK, zh_TW:zh-TW
type = PO

[pym.acknowledgment]
file_filter = <lang>/acknowledgment.po
Expand Down
3 changes: 1 addition & 2 deletions en-US/classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<chapter id="pythonforyouandme-classes">
<title>Class</title>
<para>
What is a <emphasis>class</emphasis>? In our daily life, we come across many objects which are similar kind or in words which are basically same. For example we can think about a car. There are different brands , color, look, style, parts, but basically they all are cars. All them of are made by different companies but with similar kind of components.
</para>
<para>
We can say all of them are different instances of the <emphasis>class</emphasis> car. They all belongs to the car class. Every instance is known as an <emphasis>object</emphasis> in computer world. A <emphasis>class</emphasis> can contain variables or methods to access those variables.In Python everything is an <emphasis>object</emphasis>. Even if you create an integer, that is an object of the <emphasis>Integer class</emphasis>. In C++ this is different.

</para>
<section id="pythonforyouandme-Classes-firstclass">
<title>Your first class</title>
Expand Down
15 changes: 15 additions & 0 deletions en-US/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ True]]>
>>> print f(3)
[1, 2, 3]]]>
</programlisting>
<para>
To avoid this you can write more idiomatic Python, like the following
</para>
<programlisting language="Python"><![CDATA[>>> def f(a, data=None):
if data is None:
data = []
data.append(a)
return data
>>> print f(1)
[1]
>>> print f(2)
[2]]]>
</programlisting>
</section>

<section id="pythonforyouandme-Functions-keyword">
Expand All @@ -159,6 +173,7 @@ SyntaxError: non-default argument follows default argument]]>
</section>
<section id="pythonforyouandme-Functions-doctstrings">
<title>Docstrings</title>
<indexterm><primary>Docstrings</primary><secondary>Docstrings in Python</secondary></indexterm>
<para>
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 <emphasis>longest_side</emphasis>.
</para>
Expand Down
1 change: 1 addition & 0 deletions en-US/looping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Enter the number of rows: 5

<section id="pythonforyouandme-Looping-lists">
<title>Lists</title>
<indexterm><primary>List</primary><secondary>List datastructure</secondary></indexterm>
<para>
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.
</para>
Expand Down
67 changes: 42 additions & 25 deletions en-US/modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</para>
<section id="pythonforyouandme-Modules-introduction">
<title>Introduction</title>
<para>
<indexterm><primary>Module</primary><secondary>Python modules</secondary></indexterm>
<para>
Still now when ever we wrote code in the python interpreter, after we came out of it, the code was lost. But in when one writes a larger program, people breaks their codes into different files and reuse then as required. In python we do this by <emphasis>modules</emphasis>. Modules are nothing files with Python definitions and statements. The module name is same as the file name without the .py extension.
</para>
<para>
Expand Down Expand Up @@ -120,6 +121,11 @@ help> modules
<para>
The above example shows how to get the list of all installed modules in your system. I am not pasting them here as it is a big list in my system :)
</para>
<para>
You can also use <emphasis>help()</emphasis> function in the interpeter to find documentation about any module/classes. Say you want to know all available methods in strings, you can use the following method
</para>
<programlisting language="Python"><![CDATA[>>> help(str)]]>
</programlisting>
</section>
<section id="pythonforyouandme-Modules-submodules">
<title>Submodules</title>
Expand All @@ -135,51 +141,41 @@ mymodule
]]>
</screen>
<para>
In this example <emphasis>mymodule</emphasis> is the module name and <emphasis>bars</emphasis> and <emphasis>utils</emphasis> are two submodules in it.
In this example <emphasis>mymodule</emphasis> is the module name and <emphasis>bars</emphasis> and <emphasis>utils</emphasis> are two submodules in it. You can create an empty <emphasis>__init__.py</emphasis> using touch command.
</para>
<programlisting language="Python"><![CDATA[$ touch mymodule/__init__.py]]>
</programlisting>
</section>
<section id="pythonforyouandme-Modules-os">
<title>Module os</title>
<para>
os module provides operating system dependent functionality. You can import it using the following import statement.
</para>
<programlisting language="Python">
<![CDATA[>>> import os
]]>
<![CDATA[>>> import os]]>
</programlisting>
<para>
<emphasis>getuid()</emphasis> function returns the current process's effective user's id.
</para>
<programlisting language="Python">
<![CDATA[
>>> os.getuid()
500
]]>
<![CDATA[>>> os.getuid()
500]]>
</programlisting>
<para>
<emphasis>getpid()</emphasis> returns the current process's id. <emphasis>getppid()</emphasis> returns the parent process's id.
</para>
<programlisting language="Python">
<![CDATA[
>>> os.getpid()
<![CDATA[>>> os.getpid()
16150
>>> os.getppid()
14847
]]>
14847]]>
</programlisting>
<para>
<emphasis>uname()</emphasis> 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, <emphasis>(sysname, nodename, release, version, machine)</emphasis>
<emphasis>uname()</emphasis> returns different information identifying the operating system, in Linux it returns details you can get from the <emphasis>uname</emphasis> command. The returned object is a tuple, <emphasis>(sysname, nodename, release, version, machine)</emphasis>
</para>
<programlisting language="Python">
<![CDATA[
>>> os.uname()
('Linux', 'd80', '2.6.34.7-56.fc13.i686.PAE', '#1 SMP Wed Sep 15 03:27:15 UTC 2010', 'i686')
]]>
<![CDATA[>>> os.uname()
('Linux', 'd80', '2.6.34.7-56.fc13.i686.PAE', '#1 SMP Wed Sep 15 03:27:15 UTC 2010', 'i686')]]>
</programlisting>
<para>
<emphasis>getcwd()</emphasis>returns the current working directory. <emphasis>chdir(path)</emphasis> 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 <emphasis>/tmp</emphasis> and then again checking the current directory.
Expand All @@ -189,10 +185,31 @@ mymodule
'/home/kushal'
>>> os.chdir('/tmp')
>>> os.getcwd()
'/tmp'
]]>
'/tmp']]>
</programlisting>

<para>
So let us use another function provided by the os module and create our own function to list all files and directories in any given directory.
</para>
<programlisting language="Python">
<![CDATA[def view_dir(path='.'):
"""
This function prints all files and directories in the given directory.
:args path: Path to the directory, default is current directory
"""
names = os.listdir(path)
names.sort()
for name in names:
print name,]]>
</programlisting>
<programlisting language="Python">
<![CDATA[>>> view_dir('/')
.readahead bin boot dev etc home junk lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var]]>
</programlisting>


</section>

</chapter>

Loading

0 comments on commit b0f7017

Please sign in to comment.