46 |
47 |
--------------------------------------------------------------------------------
/problem_solving.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | اضافه خواهد شد
4 |
5 | test
6 |
--------------------------------------------------------------------------------
/programs/abc.txt:
--------------------------------------------------------------------------------
1 | Imagine non-English language here
--------------------------------------------------------------------------------
/programs/backup_ver1.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 |
4 | # 1. The files and directories to be backed up are
5 | # specified in a list.
6 | # Example on Windows:
7 | # source = ['"C:\\My Documents"', 'C:\\Code']
8 | # Example on Mac OS X and Linux:
9 | source = ['/Users/swa/notes']
10 | # Notice we had to use double quotes inside the string
11 | # for names with spaces in it.
12 |
13 | # 2. The backup must be stored in a
14 | # main backup directory
15 | # Example on Windows:
16 | # target_dir = 'E:\\Backup'
17 | # Example on Mac OS X and Linux:
18 | target_dir = '/Users/swa/backup'
19 | # Remember to change this to which folder you will be using
20 |
21 | # 3. The files are backed up into a zip file.
22 | # 4. The name of the zip archive is the current date and time
23 | target = target_dir + os.sep + \
24 | time.strftime('%Y%m%d%H%M%S') + '.zip'
25 |
26 | # Create target directory if it is not present
27 | if not os.path.exists(target_dir):
28 | os.mkdir(target_dir) # make directory
29 |
30 | # 5. We use the zip command to put the files in a zip archive
31 | zip_command = 'zip -r {0} {1}'.format(target,
32 | ' '.join(source))
33 |
34 | # Run the backup
35 | print('Zip command is:')
36 | print(zip_command)
37 | print('Running:')
38 | if os.system(zip_command) == 0:
39 | print('Successful backup to', target)
40 | else:
41 | print('Backup FAILED')
42 |
--------------------------------------------------------------------------------
/programs/backup_ver1.txt:
--------------------------------------------------------------------------------
1 | $ python backup_ver1.py
2 | Zip command is:
3 | zip -r /Users/swa/backup/20140328084844.zip /Users/swa/notes
4 | Running:
5 | adding: Users/swa/notes/ (stored 0%)
6 | adding: Users/swa/notes/blah1.txt (stored 0%)
7 | adding: Users/swa/notes/blah2.txt (stored 0%)
8 | adding: Users/swa/notes/blah3.txt (stored 0%)
9 | Successful backup to /Users/swa/backup/20140328084844.zip
10 |
--------------------------------------------------------------------------------
/programs/backup_ver2.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 |
4 | # 1. The files and directories to be backed up are
5 | # specified in a list.
6 | # Example on Windows:
7 | # source = ['"C:\\My Documents"', 'C:\\Code']
8 | # Example on Mac OS X and Linux:
9 | source = ['/Users/swa/notes']
10 | # Notice we had to use double quotes inside the string
11 | # for names with spaces in it.
12 |
13 | # 2. The backup must be stored in a
14 | # main backup directory
15 | # Example on Windows:
16 | # target_dir = 'E:\\Backup'
17 | # Example on Mac OS X and Linux:
18 | target_dir = '/Users/swa/backup'
19 | # Remember to change this to which folder you will be using
20 |
21 | # Create target directory if it is not present
22 | if not os.path.exists(target_dir):
23 | os.mkdir(target_dir) # make directory
24 |
25 | # 3. The files are backed up into a zip file.
26 | # 4. The current day is the name of the subdirectory
27 | # in the main directory.
28 | today = target_dir + os.sep + time.strftime('%Y%m%d')
29 | # The current time is the name of the zip archive.
30 | now = time.strftime('%H%M%S')
31 |
32 | # The name of the zip file
33 | target = today + os.sep + now + '.zip'
34 |
35 | # Create the subdirectory if it isn't already there
36 | if not os.path.exists(today):
37 | os.mkdir(today)
38 | print('Successfully created directory', today)
39 |
40 | # 5. We use the zip command to put the files in a zip archive
41 | zip_command = 'zip -r {0} {1}'.format(target,
42 | ' '.join(source))
43 |
44 | # Run the backup
45 | print('Zip command is:')
46 | print(zip_command)
47 | print('Running:')
48 | if os.system(zip_command) == 0:
49 | print('Successful backup to', target)
50 | else:
51 | print('Backup FAILED')
52 |
--------------------------------------------------------------------------------
/programs/backup_ver2.txt:
--------------------------------------------------------------------------------
1 | $ python backup_ver2.py
2 | Successfully created directory /Users/swa/backup/20140329
3 | Zip command is:
4 | zip -r /Users/swa/backup/20140329/073201.zip /Users/swa/notes
5 | Running:
6 | adding: Users/swa/notes/ (stored 0%)
7 | adding: Users/swa/notes/blah1.txt (stored 0%)
8 | adding: Users/swa/notes/blah2.txt (stored 0%)
9 | adding: Users/swa/notes/blah3.txt (stored 0%)
10 | Successful backup to /Users/swa/backup/20140329/073201.zip
11 |
--------------------------------------------------------------------------------
/programs/backup_ver3.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 |
4 | # 1. The files and directories to be backed up are
5 | # specified in a list.
6 | # Example on Windows:
7 | # source = ['"C:\\My Documents"', 'C:\\Code']
8 | # Example on Mac OS X and Linux:
9 | source = ['/Users/swa/notes']
10 | # Notice we had to use double quotes inside the string
11 | # for names with spaces in it.
12 |
13 | # 2. The backup must be stored in a
14 | # main backup directory
15 | # Example on Windows:
16 | # target_dir = 'E:\\Backup'
17 | # Example on Mac OS X and Linux:
18 | target_dir = '/Users/swa/backup'
19 | # Remember to change this to which folder you will be using
20 |
21 | # Create target directory if it is not present
22 | if not os.path.exists(target_dir):
23 | os.mkdir(target_dir) # make directory
24 |
25 | # 3. The files are backed up into a zip file.
26 | # 4. The current day is the name of the subdirectory
27 | # in the main directory.
28 | today = target_dir + os.sep + time.strftime('%Y%m%d')
29 | # The current time is the name of the zip archive.
30 | now = time.strftime('%H%M%S')
31 |
32 | # Take a comment from the user to
33 | # create the name of the zip file
34 | comment = input('Enter a comment --> ')
35 | # Check if a comment was entered
36 | if len(comment) == 0:
37 | target = today + os.sep + now + '.zip'
38 | else:
39 | target = today + os.sep + now + '_' +
40 | comment.replace(' ', '_') + '.zip'
41 |
42 | # Create the subdirectory if it isn't already there
43 | if not os.path.exists(today):
44 | os.mkdir(today)
45 | print('Successfully created directory', today)
46 |
47 | # 5. We use the zip command to put the files in a zip archive
48 | zip_command = "zip -r {0} {1}".format(target,
49 | ' '.join(source))
50 |
51 | # Run the backup
52 | print('Zip command is:')
53 | print(zip_command)
54 | print('Running:')
55 | if os.system(zip_command) == 0:
56 | print('Successful backup to', target)
57 | else:
58 | print('Backup FAILED')
59 |
--------------------------------------------------------------------------------
/programs/backup_ver3.txt:
--------------------------------------------------------------------------------
1 | $ python backup_ver3.py
2 | File "backup_ver3.py", line 39
3 | target = today + os.sep + now + '_' +
4 | ^
5 | SyntaxError: invalid syntax
6 |
--------------------------------------------------------------------------------
/programs/backup_ver4.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 |
4 | # 1. The files and directories to be backed up are
5 | # specified in a list.
6 | # Example on Windows:
7 | # source = ['"C:\\My Documents"', 'C:\\Code']
8 | # Example on Mac OS X and Linux:
9 | source = ['/Users/swa/notes']
10 | # Notice we had to use double quotes inside the string
11 | # for names with spaces in it.
12 |
13 | # 2. The backup must be stored in a
14 | # main backup directory
15 | # Example on Windows:
16 | # target_dir = 'E:\\Backup'
17 | # Example on Mac OS X and Linux:
18 | target_dir = '/Users/swa/backup'
19 | # Remember to change this to which folder you will be using
20 |
21 | # Create target directory if it is not present
22 | if not os.path.exists(target_dir):
23 | os.mkdir(target_dir) # make directory
24 |
25 | # 3. The files are backed up into a zip file.
26 | # 4. The current day is the name of the subdirectory
27 | # in the main directory.
28 | today = target_dir + os.sep + time.strftime('%Y%m%d')
29 | # The current time is the name of the zip archive.
30 | now = time.strftime('%H%M%S')
31 |
32 | # Take a comment from the user to
33 | # create the name of the zip file
34 | comment = input('Enter a comment --> ')
35 | # Check if a comment was entered
36 | if len(comment) == 0:
37 | target = today + os.sep + now + '.zip'
38 | else:
39 | target = today + os.sep + now + '_' + \
40 | comment.replace(' ', '_') + '.zip'
41 |
42 | # Create the subdirectory if it isn't already there
43 | if not os.path.exists(today):
44 | os.mkdir(today)
45 | print('Successfully created directory', today)
46 |
47 | # 5. We use the zip command to put the files in a zip archive
48 | zip_command = 'zip -r {0} {1}'.format(target,
49 | ' '.join(source))
50 |
51 | # Run the backup
52 | print('Zip command is:')
53 | print(zip_command)
54 | print('Running:')
55 | if os.system(zip_command) == 0:
56 | print('Successful backup to', target)
57 | else:
58 | print('Backup FAILED')
59 |
--------------------------------------------------------------------------------
/programs/backup_ver4.txt:
--------------------------------------------------------------------------------
1 | $ python backup_ver4.py
2 | Enter a comment --> added new examples
3 | Zip command is:
4 | zip -r /Users/swa/backup/20140329/074122_added_new_examples.zip /Users/swa/notes
5 | Running:
6 | adding: Users/swa/notes/ (stored 0%)
7 | adding: Users/swa/notes/blah1.txt (stored 0%)
8 | adding: Users/swa/notes/blah2.txt (stored 0%)
9 | adding: Users/swa/notes/blah3.txt (stored 0%)
10 | Successful backup to /Users/swa/backup/20140329/074122_added_new_examples.zip
11 |
--------------------------------------------------------------------------------
/programs/break.py:
--------------------------------------------------------------------------------
1 | while True:
2 | s = input('Enter something : ')
3 | if s == 'quit':
4 | break
5 | print('Length of the string is', len(s))
6 | print('Done')
7 |
--------------------------------------------------------------------------------
/programs/break.txt:
--------------------------------------------------------------------------------
1 | $ python break.py
2 | Enter something : Programming is fun
3 | Length of the string is 18
4 | Enter something : When the work is done
5 | Length of the string is 21
6 | Enter something : if you wanna make your work also fun:
7 | Length of the string is 37
8 | Enter something : use Python!
9 | Length of the string is 11
10 | Enter something : quit
11 | Done
12 |
--------------------------------------------------------------------------------
/programs/continue.py:
--------------------------------------------------------------------------------
1 | while True:
2 | s = input('Enter something : ')
3 | if s == 'quit':
4 | break
5 | if len(s) < 3:
6 | print('Too small')
7 | continue
8 | print('Input is of sufficient length')
9 | # Do other kinds of processing here...
10 |
--------------------------------------------------------------------------------
/programs/continue.txt:
--------------------------------------------------------------------------------
1 | $ python continue.py
2 | Enter something : a
3 | Too small
4 | Enter something : 12
5 | Too small
6 | Enter something : abc
7 | Input is of sufficient length
8 | Enter something : quit
9 |
--------------------------------------------------------------------------------
/programs/ds_reference.py:
--------------------------------------------------------------------------------
1 | print('Simple Assignment')
2 | shoplist = ['apple', 'mango', 'carrot', 'banana']
3 | # mylist is just another name pointing to the same object!
4 | mylist = shoplist
5 |
6 | # I purchased the first item, so I remove it from the list
7 | del shoplist[0]
8 |
9 | print('shoplist is', shoplist)
10 | print('mylist is', mylist)
11 | # Notice that both shoplist and mylist both print
12 | # the same list without the 'apple' confirming that
13 | # they point to the same object
14 |
15 | print('Copy by making a full slice')
16 | # Make a copy by doing a full slice
17 | mylist = shoplist[:]
18 | # Remove first item
19 | del mylist[0]
20 |
21 | print('shoplist is', shoplist)
22 | print('mylist is', mylist)
23 | # Notice that now the two lists are different
24 |
--------------------------------------------------------------------------------
/programs/ds_reference.txt:
--------------------------------------------------------------------------------
1 | $ python ds_reference.py
2 | Simple Assignment
3 | shoplist is ['mango', 'carrot', 'banana']
4 | mylist is ['mango', 'carrot', 'banana']
5 | Copy by making a full slice
6 | shoplist is ['mango', 'carrot', 'banana']
7 | mylist is ['carrot', 'banana']
8 |
--------------------------------------------------------------------------------
/programs/ds_seq.py:
--------------------------------------------------------------------------------
1 | shoplist = ['apple', 'mango', 'carrot', 'banana']
2 | name = 'swaroop'
3 |
4 | # Indexing or 'Subscription' operation #
5 | print('Item 0 is', shoplist[0])
6 | print('Item 1 is', shoplist[1])
7 | print('Item 2 is', shoplist[2])
8 | print('Item 3 is', shoplist[3])
9 | print('Item -1 is', shoplist[-1])
10 | print('Item -2 is', shoplist[-2])
11 | print('Character 0 is', name[0])
12 |
13 | # Slicing on a list #
14 | print('Item 1 to 3 is', shoplist[1:3])
15 | print('Item 2 to end is', shoplist[2:])
16 | print('Item 1 to -1 is', shoplist[1:-1])
17 | print('Item start to end is', shoplist[:])
18 |
19 | # Slicing on a string #
20 | print('characters 1 to 3 is', name[1:3])
21 | print('characters 2 to end is', name[2:])
22 | print('characters 1 to -1 is', name[1:-1])
23 | print('characters start to end is', name[:])
24 |
--------------------------------------------------------------------------------
/programs/ds_seq.txt:
--------------------------------------------------------------------------------
1 | $ python ds_seq.py
2 | Item 0 is apple
3 | Item 1 is mango
4 | Item 2 is carrot
5 | Item 3 is banana
6 | Item -1 is banana
7 | Item -2 is carrot
8 | Character 0 is s
9 | Item 1 to 3 is ['mango', 'carrot']
10 | Item 2 to end is ['carrot', 'banana']
11 | Item 1 to -1 is ['mango', 'carrot']
12 | Item start to end is ['apple', 'mango', 'carrot', 'banana']
13 | characters 1 to 3 is wa
14 | characters 2 to end is aroop
15 | characters 1 to -1 is waroo
16 | characters start to end is swaroop
17 |
--------------------------------------------------------------------------------
/programs/ds_str_methods.py:
--------------------------------------------------------------------------------
1 | # This is a string object
2 | name = 'Swaroop'
3 |
4 | if name.startswith('Swa'):
5 | print('Yes, the string starts with "Swa"')
6 |
7 | if 'a' in name:
8 | print('Yes, it contains the string "a"')
9 |
10 | if name.find('war') != -1:
11 | print('Yes, it contains the string "war"')
12 |
13 | delimiter = '_*_'
14 | mylist = ['Brazil', 'Russia', 'India', 'China']
15 | print(delimiter.join(mylist))
16 |
--------------------------------------------------------------------------------
/programs/ds_str_methods.txt:
--------------------------------------------------------------------------------
1 | $ python ds_str_methods.py
2 | Yes, the string starts with "Swa"
3 | Yes, it contains the string "a"
4 | Yes, it contains the string "war"
5 | Brazil_*_Russia_*_India_*_China
6 |
--------------------------------------------------------------------------------
/programs/ds_using_dict.py:
--------------------------------------------------------------------------------
1 | # 'ab' is short for 'a'ddress'b'ook
2 |
3 | ab = {
4 | 'Swaroop': 'swaroop@swaroopch.com',
5 | 'Larry': 'larry@wall.org',
6 | 'Matsumoto': 'matz@ruby-lang.org',
7 | 'Spammer': 'spammer@hotmail.com'
8 | }
9 |
10 | print("Swaroop's address is", ab['Swaroop'])
11 |
12 | # Deleting a key-value pair
13 | del ab['Spammer']
14 |
15 | print('\nThere are {} contacts in the address-book\n'.format(len(ab)))
16 |
17 | for name, address in ab.items():
18 | print('Contact {} at {}'.format(name, address))
19 |
20 | # Adding a key-value pair
21 | ab['Guido'] = 'guido@python.org'
22 |
23 | if 'Guido' in ab:
24 | print("\nGuido's address is", ab['Guido'])
25 |
--------------------------------------------------------------------------------
/programs/ds_using_dict.txt:
--------------------------------------------------------------------------------
1 | $ python ds_using_dict.py
2 | Swaroop's address is swaroop@swaroopch.com
3 |
4 | There are 3 contacts in the address-book
5 |
6 | Contact Swaroop at swaroop@swaroopch.com
7 | Contact Matsumoto at matz@ruby-lang.org
8 | Contact Larry at larry@wall.org
9 |
10 | Guido's address is guido@python.org
11 |
--------------------------------------------------------------------------------
/programs/ds_using_list.py:
--------------------------------------------------------------------------------
1 | # This is my shopping list
2 | shoplist = ['apple', 'mango', 'carrot', 'banana']
3 |
4 | print('I have', len(shoplist), 'items to purchase.')
5 |
6 | print('These items are:', end=' ')
7 | for item in shoplist:
8 | print(item, end=' ')
9 |
10 | print('\nI also have to buy rice.')
11 | shoplist.append('rice')
12 | print('My shopping list is now', shoplist)
13 |
14 | print('I will sort my list now')
15 | shoplist.sort()
16 | print('Sorted shopping list is', shoplist)
17 |
18 | print('The first item I will buy is', shoplist[0])
19 | olditem = shoplist[0]
20 | del shoplist[0]
21 | print('I bought the', olditem)
22 | print('My shopping list is now', shoplist)
23 |
--------------------------------------------------------------------------------
/programs/ds_using_list.txt:
--------------------------------------------------------------------------------
1 | $ python ds_using_list.py
2 | I have 4 items to purchase.
3 | These items are: apple mango carrot banana
4 | I also have to buy rice.
5 | My shopping list is now ['apple', 'mango', 'carrot', 'banana', 'rice']
6 | I will sort my list now
7 | Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice']
8 | The first item I will buy is apple
9 | I bought the apple
10 | My shopping list is now ['banana', 'carrot', 'mango', 'rice']
11 |
--------------------------------------------------------------------------------
/programs/ds_using_tuple.py:
--------------------------------------------------------------------------------
1 | # I would recommend always using parentheses
2 | # to indicate start and end of tuple
3 | # even though parentheses are optional.
4 | # Explicit is better than implicit.
5 | zoo = ('python', 'elephant', 'penguin')
6 | print('Number of animals in the zoo is', len(zoo))
7 |
8 | new_zoo = 'monkey', 'camel', zoo
9 | print('Number of cages in the new zoo is', len(new_zoo))
10 | print('All animals in new zoo are', new_zoo)
11 | print('Animals brought from old zoo are', new_zoo[2])
12 | print('Last animal brought from old zoo is', new_zoo[2][2])
13 | print('Number of animals in the new zoo is',
14 | len(new_zoo)-1+len(new_zoo[2]))
15 |
--------------------------------------------------------------------------------
/programs/ds_using_tuple.txt:
--------------------------------------------------------------------------------
1 | $ python ds_using_tuple.py
2 | Number of animals in the zoo is 3
3 | Number of cages in the new zoo is 3
4 | All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin'))
5 | Animals brought from old zoo are ('python', 'elephant', 'penguin')
6 | Last animal brought from old zoo is penguin
7 | Number of animals in the new zoo is 5
8 |
--------------------------------------------------------------------------------
/programs/exceptions_finally.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import time
3 |
4 | f = None
5 | try:
6 | f = open("poem.txt")
7 | # Our usual file-reading idiom
8 | while True:
9 | line = f.readline()
10 | if len(line) == 0:
11 | break
12 | print(line, end='')
13 | sys.stdout.flush()
14 | print("Press ctrl+c now")
15 | # To make sure it runs for a while
16 | time.sleep(2)
17 | except IOError:
18 | print("Could not find file poem.txt")
19 | except KeyboardInterrupt:
20 | print("!! You cancelled the reading from the file.")
21 | finally:
22 | if f:
23 | f.close()
24 | print("(Cleaning up: Closed the file)")
25 |
--------------------------------------------------------------------------------
/programs/exceptions_finally.txt:
--------------------------------------------------------------------------------
1 | $ python exceptions_finally.py
2 | Programming is fun
3 | Press ctrl+c now
4 | ^C!! You cancelled the reading from the file.
5 | (Cleaning up: Closed the file)
6 |
--------------------------------------------------------------------------------
/programs/exceptions_handle.py:
--------------------------------------------------------------------------------
1 | try:
2 | text = input('Enter something --> ')
3 | except EOFError:
4 | print('Why did you do an EOF on me?')
5 | except KeyboardInterrupt:
6 | print('You cancelled the operation.')
7 | else:
8 | print('You entered {}'.format(text))
9 |
--------------------------------------------------------------------------------
/programs/exceptions_handle.txt:
--------------------------------------------------------------------------------
1 | # Press ctrl + d
2 | $ python exceptions_handle.py
3 | Enter something --> Why did you do an EOF on me?
4 |
5 | # Press ctrl + c
6 | $ python exceptions_handle.py
7 | Enter something --> ^CYou cancelled the operation.
8 |
9 | $ python exceptions_handle.py
10 | Enter something --> No exceptions
11 | You entered No exceptions
12 |
--------------------------------------------------------------------------------
/programs/exceptions_raise.py:
--------------------------------------------------------------------------------
1 | class ShortInputException(Exception):
2 | '''A user-defined exception class.'''
3 | def __init__(self, length, atleast):
4 | Exception.__init__(self)
5 | self.length = length
6 | self.atleast = atleast
7 |
8 | try:
9 | text = input('Enter something --> ')
10 | if len(text) < 3:
11 | raise ShortInputException(len(text), 3)
12 | # Other work can continue as usual here
13 | except EOFError:
14 | print('Why did you do an EOF on me?')
15 | except ShortInputException as ex:
16 | print(('ShortInputException: The input was ' +
17 | '{0} long, expected at least {1}')
18 | .format(ex.length, ex.atleast))
19 | else:
20 | print('No exception was raised.')
21 |
--------------------------------------------------------------------------------
/programs/exceptions_raise.txt:
--------------------------------------------------------------------------------
1 | $ python exceptions_raise.py
2 | Enter something --> a
3 | ShortInputException: The input was 1 long, expected at least 3
4 |
5 | $ python exceptions_raise.py
6 | Enter something --> abc
7 | No exception was raised.
8 |
--------------------------------------------------------------------------------
/programs/exceptions_using_with.py:
--------------------------------------------------------------------------------
1 | with open("poem.txt") as f:
2 | for line in f:
3 | print(line, end='')
4 |
--------------------------------------------------------------------------------
/programs/for.py:
--------------------------------------------------------------------------------
1 | for i in range(1, 5):
2 | print(i)
3 | else:
4 | print('The for loop is over')
5 |
--------------------------------------------------------------------------------
/programs/for.txt:
--------------------------------------------------------------------------------
1 | $ python for.py
2 | 1
3 | 2
4 | 3
5 | 4
6 | The for loop is over
7 |
--------------------------------------------------------------------------------
/programs/function1.py:
--------------------------------------------------------------------------------
1 | def say_hello():
2 | # block belonging to the function
3 | print('hello world')
4 | # End of function
5 |
6 | say_hello() # call the function
7 | say_hello() # call the function again
8 |
--------------------------------------------------------------------------------
/programs/function1.txt:
--------------------------------------------------------------------------------
1 | $ python function1.py
2 | hello world
3 | hello world
4 |
--------------------------------------------------------------------------------
/programs/function_default.py:
--------------------------------------------------------------------------------
1 | def say(message, times=1):
2 | print(message * times)
3 |
4 | say('Hello')
5 | say('World', 5)
6 |
--------------------------------------------------------------------------------
/programs/function_default.txt:
--------------------------------------------------------------------------------
1 | $ python function_default.py
2 | Hello
3 | WorldWorldWorldWorldWorld
4 |
--------------------------------------------------------------------------------
/programs/function_docstring.py:
--------------------------------------------------------------------------------
1 | def print_max(x, y):
2 | '''Prints the maximum of two numbers.
3 |
4 | The two values must be integers.'''
5 | # convert to integers, if possible
6 | x = int(x)
7 | y = int(y)
8 |
9 | if x > y:
10 | print(x, 'is maximum')
11 | else:
12 | print(y, 'is maximum')
13 |
14 | print_max(3, 5)
15 | print(print_max.__doc__)
16 |
--------------------------------------------------------------------------------
/programs/function_docstring.txt:
--------------------------------------------------------------------------------
1 | $ python function_docstring.py
2 | 5 is maximum
3 | Prints the maximum of two numbers.
4 |
5 | The two values must be integers.
6 |
--------------------------------------------------------------------------------
/programs/function_global.py:
--------------------------------------------------------------------------------
1 | x = 50
2 |
3 |
4 | def func():
5 | global x
6 |
7 | print('x is', x)
8 | x = 2
9 | print('Changed global x to', x)
10 |
11 |
12 | func()
13 | print('Value of x is', x)
14 |
--------------------------------------------------------------------------------
/programs/function_global.txt:
--------------------------------------------------------------------------------
1 | $ python function_global.py
2 | x is 50
3 | Changed global x to 2
4 | Value of x is 2
5 |
--------------------------------------------------------------------------------
/programs/function_keyword.py:
--------------------------------------------------------------------------------
1 | def func(a, b=5, c=10):
2 | print('a is', a, 'and b is', b, 'and c is', c)
3 |
4 | func(3, 7)
5 | func(25, c=24)
6 | func(c=50, a=100)
7 |
--------------------------------------------------------------------------------
/programs/function_keyword.txt:
--------------------------------------------------------------------------------
1 | $ python function_keyword.py
2 | a is 3 and b is 7 and c is 10
3 | a is 25 and b is 5 and c is 24
4 | a is 100 and b is 5 and c is 50
5 |
--------------------------------------------------------------------------------
/programs/function_local.py:
--------------------------------------------------------------------------------
1 | x = 50
2 |
3 |
4 | def func(x):
5 | print('x is', x)
6 | x = 2
7 | print('Changed local x to', x)
8 |
9 |
10 | func(x)
11 | print('x is still', x)
12 |
--------------------------------------------------------------------------------
/programs/function_local.txt:
--------------------------------------------------------------------------------
1 | $ python function_local.py
2 | x is 50
3 | Changed local x to 2
4 | x is still 50
5 |
--------------------------------------------------------------------------------
/programs/function_param.py:
--------------------------------------------------------------------------------
1 | def print_max(a, b):
2 | if a > b:
3 | print(a, 'is maximum')
4 | elif a == b:
5 | print(a, 'is equal to', b)
6 | else:
7 | print(b, 'is maximum')
8 |
9 | # directly pass literal values
10 | print_max(3, 4)
11 |
12 | x = 5
13 | y = 7
14 |
15 | # pass variables as arguments
16 | print_max(x, y)
17 |
--------------------------------------------------------------------------------
/programs/function_param.txt:
--------------------------------------------------------------------------------
1 | $ python function_param.py
2 | 4 is maximum
3 | 7 is maximum
4 |
--------------------------------------------------------------------------------
/programs/function_return.py:
--------------------------------------------------------------------------------
1 | def maximum(x, y):
2 | if x > y:
3 | return x
4 | elif x == y:
5 | return 'The numbers are equal'
6 | else:
7 | return y
8 |
9 | print(maximum(2, 3))
10 |
--------------------------------------------------------------------------------
/programs/function_return.txt:
--------------------------------------------------------------------------------
1 | $ python function_return.py
2 | 3
3 |
--------------------------------------------------------------------------------
/programs/function_varargs.py:
--------------------------------------------------------------------------------
1 | def total(a=5, *numbers, **phonebook):
2 | print('a', a)
3 |
4 | #iterate through all the items in tuple
5 | for single_item in numbers:
6 | print('single_item', single_item)
7 |
8 | #iterate through all the items in dictionary
9 | for first_part, second_part in phonebook.items():
10 | print(first_part,second_part)
11 |
12 | print(total(10,1,2,3,Jack=1123,John=2231,Inge=1560))
13 |
--------------------------------------------------------------------------------
/programs/function_varargs.txt:
--------------------------------------------------------------------------------
1 | $ python function_varargs.py
2 | a 10
3 | single_item 1
4 | single_item 2
5 | single_item 3
6 | Inge 1560
7 | John 2231
8 | Jack 1123
9 | None
10 |
--------------------------------------------------------------------------------
/programs/if.py:
--------------------------------------------------------------------------------
1 | number = 23
2 | guess = int(input('Enter an integer : '))
3 |
4 | if guess == number:
5 | # New block starts here
6 | print('Congratulations, you guessed it.')
7 | print('(but you do not win any prizes!)')
8 | # New block ends here
9 | elif guess < number:
10 | # Another block
11 | print('No, it is a little higher than that')
12 | # You can do whatever you want in a block ...
13 | else:
14 | print('No, it is a little lower than that')
15 | # you must have guessed > number to reach here
16 |
17 | print('Done')
18 | # This last statement is always executed,
19 | # after the if statement is executed.
20 |
--------------------------------------------------------------------------------
/programs/if.txt:
--------------------------------------------------------------------------------
1 | $ python if.py
2 | Enter an integer : 50
3 | No, it is a little lower than that
4 | Done
5 |
6 | $ python if.py
7 | Enter an integer : 22
8 | No, it is a little higher than that
9 | Done
10 |
11 | $ python if.py
12 | Enter an integer : 23
13 | Congratulations, you guessed it.
14 | (but you do not win any prizes!)
15 | Done
16 |
--------------------------------------------------------------------------------
/programs/io_input.py:
--------------------------------------------------------------------------------
1 | def reverse(text):
2 | return text[::-1]
3 |
4 |
5 | def is_palindrome(text):
6 | return text == reverse(text)
7 |
8 |
9 | something = input("Enter text: ")
10 | if is_palindrome(something):
11 | print("Yes, it is a palindrome")
12 | else:
13 | print("No, it is not a palindrome")
14 |
--------------------------------------------------------------------------------
/programs/io_input.txt:
--------------------------------------------------------------------------------
1 | $ python3 io_input.py
2 | Enter text: sir
3 | No, it is not a palindrome
4 |
5 | $ python3 io_input.py
6 | Enter text: madam
7 | Yes, it is a palindrome
8 |
9 | $ python3 io_input.py
10 | Enter text: racecar
11 | Yes, it is a palindrome
12 |
--------------------------------------------------------------------------------
/programs/io_pickle.py:
--------------------------------------------------------------------------------
1 | import pickle
2 |
3 | # The name of the file where we will store the object
4 | shoplistfile = 'shoplist.data'
5 | # The list of things to buy
6 | shoplist = ['apple', 'mango', 'carrot']
7 |
8 | # Write to the file
9 | f = open(shoplistfile, 'wb')
10 | # Dump the object to a file
11 | pickle.dump(shoplist, f)
12 | f.close()
13 |
14 | # Destroy the shoplist variable
15 | del shoplist
16 |
17 | # Read back from the storage
18 | f = open(shoplistfile, 'rb')
19 | # Load the object from the file
20 | storedlist = pickle.load(f)
21 | print(storedlist)
22 |
--------------------------------------------------------------------------------
/programs/io_pickle.txt:
--------------------------------------------------------------------------------
1 | $ python io_pickle.py
2 | ['apple', 'mango', 'carrot']
3 |
--------------------------------------------------------------------------------
/programs/io_unicode.py:
--------------------------------------------------------------------------------
1 | # encoding=utf-8
2 | import io
3 |
4 | f = io.open("abc.txt", "wt", encoding="utf-8")
5 | f.write(u"Imagine non-English language here")
6 | f.close()
7 |
8 | text = io.open("abc.txt", encoding="utf-8").read()
9 | print(text)
10 |
--------------------------------------------------------------------------------
/programs/io_using_file.py:
--------------------------------------------------------------------------------
1 | poem = '''\
2 | Programming is fun
3 | When the work is done
4 | if you wanna make your work also fun:
5 | use Python!
6 | '''
7 |
8 | # Open for 'w'riting
9 | f = open('poem.txt', 'w')
10 | # Write text to file
11 | f.write(poem)
12 | # Close the file
13 | f.close()
14 |
15 | # If no mode is specified,
16 | # 'r'ead mode is assumed by default
17 | f = open('poem.txt')
18 | while True:
19 | line = f.readline()
20 | # Zero length indicates EOF
21 | if len(line) == 0:
22 | break
23 | # The `line` already has a newline
24 | # at the end of each line
25 | # since it is reading from a file.
26 | print(line, end='')
27 | # close the file
28 | f.close()
29 |
--------------------------------------------------------------------------------
/programs/io_using_file.txt:
--------------------------------------------------------------------------------
1 | $ python3 io_using_file.py
2 | Programming is fun
3 | When the work is done
4 | if you wanna make your work also fun:
5 | use Python!
6 |
--------------------------------------------------------------------------------
/programs/module_using_name.py:
--------------------------------------------------------------------------------
1 | if __name__ == '__main__':
2 | print('This program is being run by itself')
3 | else:
4 | print('I am being imported from another module')
5 |
--------------------------------------------------------------------------------
/programs/module_using_name.txt:
--------------------------------------------------------------------------------
1 | $ python module_using_name.py
2 | This program is being run by itself
3 |
4 | $ python
5 | >>> import module_using_name
6 | I am being imported from another module
7 | >>>
8 |
--------------------------------------------------------------------------------
/programs/module_using_sys.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | print('The command line arguments are:')
4 | for i in sys.argv:
5 | print(i)
6 |
7 | print('\n\nThe PYTHONPATH is', sys.path, '\n')
8 |
--------------------------------------------------------------------------------
/programs/module_using_sys.txt:
--------------------------------------------------------------------------------
1 | $ python module_using_sys.py we are arguments
2 | The command line arguments are:
3 | module_using_sys.py
4 | we
5 | are
6 | arguments
7 |
8 |
9 | The PYTHONPATH is ['/tmp/py',
10 | # many entries here, not shown here
11 | '/Library/Python/2.7/site-packages',
12 | '/usr/local/lib/python2.7/site-packages']
13 |
--------------------------------------------------------------------------------
/programs/more_decorator.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | from functools import wraps
3 | import logging
4 | logging.basicConfig()
5 | log = logging.getLogger("retry")
6 |
7 |
8 | def retry(f):
9 | @wraps(f)
10 | def wrapped_f(*args, **kwargs):
11 | MAX_ATTEMPTS = 5
12 | for attempt in range(1, MAX_ATTEMPTS + 1):
13 | try:
14 | return f(*args, **kwargs)
15 | except:
16 | log.exception("Attempt %s/%s failed : %s",
17 | attempt,
18 | MAX_ATTEMPTS,
19 | (args, kwargs))
20 | sleep(10 * attempt)
21 | log.critical("All %s attempts failed : %s",
22 | MAX_ATTEMPTS,
23 | (args, kwargs))
24 | return wrapped_f
25 |
26 |
27 | counter = 0
28 |
29 |
30 | @retry
31 | def save_to_database(arg):
32 | print("Write to a database or make a network call or etc.")
33 | print("This will be automatically retried if exception is thrown.")
34 | global counter
35 | counter += 1
36 | # This will throw an exception in the first call
37 | # And will work fine in the second call (i.e. a retry)
38 | if counter < 2:
39 | raise ValueError(arg)
40 |
41 |
42 | if __name__ == '__main__':
43 | save_to_database("Some bad value")
44 |
--------------------------------------------------------------------------------
/programs/more_decorator.txt:
--------------------------------------------------------------------------------
1 | $ python more_decorator.py
2 | Write to a database or make a network call or etc.
3 | This will be automatically retried if exception is thrown.
4 | ERROR:retry:Attempt 1/5 failed : (('Some bad value',), {})
5 | Traceback (most recent call last):
6 | File "more_decorator.py", line 14, in wrapped_f
7 | return f(*args, **kwargs)
8 | File "more_decorator.py", line 39, in save_to_database
9 | raise ValueError(arg)
10 | ValueError: Some bad value
11 | Write to a database or make a network call or etc.
12 | This will be automatically retried if exception is thrown.
13 |
--------------------------------------------------------------------------------
/programs/more_lambda.py:
--------------------------------------------------------------------------------
1 | points = [{'x': 2, 'y': 3},
2 | {'x': 4, 'y': 1}]
3 | points.sort(key=lambda i: i['y'])
4 | print(points)
5 |
--------------------------------------------------------------------------------
/programs/more_lambda.txt:
--------------------------------------------------------------------------------
1 | $ python more_lambda.py
2 | [{'y': 1, 'x': 4}, {'y': 3, 'x': 2}]
3 |
--------------------------------------------------------------------------------
/programs/more_list_comprehension.py:
--------------------------------------------------------------------------------
1 | listone = [2, 3, 4]
2 | listtwo = [2*i for i in listone if i > 2]
3 | print(listtwo)
4 |
--------------------------------------------------------------------------------
/programs/more_list_comprehension.txt:
--------------------------------------------------------------------------------
1 | $ python more_list_comprehension.py
2 | [6, 8]
3 |
--------------------------------------------------------------------------------
/programs/mymodule.py:
--------------------------------------------------------------------------------
1 | def say_hi():
2 | print('Hi, this is mymodule speaking.')
3 |
4 | __version__ = '0.1'
5 |
--------------------------------------------------------------------------------
/programs/mymodule_demo.py:
--------------------------------------------------------------------------------
1 | import mymodule
2 |
3 | mymodule.say_hi()
4 | print('Version', mymodule.__version__)
5 |
--------------------------------------------------------------------------------
/programs/mymodule_demo.txt:
--------------------------------------------------------------------------------
1 | $ python mymodule_demo.py
2 | Hi, this is mymodule speaking.
3 | Version 0.1
4 |
--------------------------------------------------------------------------------
/programs/mymodule_demo2.py:
--------------------------------------------------------------------------------
1 | from mymodule import say_hi, __version__
2 |
3 | say_hi()
4 | print('Version', __version__)
5 |
--------------------------------------------------------------------------------
/programs/oop_init.py:
--------------------------------------------------------------------------------
1 | class Person:
2 | def __init__(self, name):
3 | self.name = name
4 |
5 | def say_hi(self):
6 | print('Hello, my name is', self.name)
7 |
8 | p = Person('Swaroop')
9 | p.say_hi()
10 | # The previous 2 lines can also be written as
11 | # Person('Swaroop').say_hi()
12 |
--------------------------------------------------------------------------------
/programs/oop_init.txt:
--------------------------------------------------------------------------------
1 | $ python oop_init.py
2 | Hello, my name is Swaroop
3 |
--------------------------------------------------------------------------------
/programs/oop_method.py:
--------------------------------------------------------------------------------
1 | class Person:
2 | def say_hi(self):
3 | print('Hello, how are you?')
4 |
5 | p = Person()
6 | p.say_hi()
7 | # The previous 2 lines can also be written as
8 | # Person().say_hi()
9 |
--------------------------------------------------------------------------------
/programs/oop_method.txt:
--------------------------------------------------------------------------------
1 | $ python oop_method.py
2 | Hello, how are you?
3 |
--------------------------------------------------------------------------------
/programs/oop_objvar.py:
--------------------------------------------------------------------------------
1 | class Robot:
2 | """Represents a robot, with a name."""
3 |
4 | # A class variable, counting the number of robots
5 | population = 0
6 |
7 | def __init__(self, name):
8 | """Initializes the data."""
9 | self.name = name
10 | print("(Initializing {})".format(self.name))
11 |
12 | # When this person is created, the robot
13 | # adds to the population
14 | Robot.population += 1
15 |
16 | def die(self):
17 | """I am dying."""
18 | print("{} is being destroyed!".format(self.name))
19 |
20 | Robot.population -= 1
21 |
22 | if Robot.population == 0:
23 | print("{} was the last one.".format(self.name))
24 | else:
25 | print("There are still {:d} robots working.".format(
26 | Robot.population))
27 |
28 | def say_hi(self):
29 | """Greeting by the robot.
30 |
31 | Yeah, they can do that."""
32 | print("Greetings, my masters call me {}.".format(self.name))
33 |
34 | @classmethod
35 | def how_many(cls):
36 | """Prints the current population."""
37 | print("We have {:d} robots.".format(cls.population))
38 |
39 |
40 | droid1 = Robot("R2-D2")
41 | droid1.say_hi()
42 | Robot.how_many()
43 |
44 | droid2 = Robot("C-3PO")
45 | droid2.say_hi()
46 | Robot.how_many()
47 |
48 | print("\nRobots can do some work here.\n")
49 |
50 | print("Robots have finished their work. So let's destroy them.")
51 | droid1.die()
52 | droid2.die()
53 |
54 | Robot.how_many()
55 |
--------------------------------------------------------------------------------
/programs/oop_objvar.txt:
--------------------------------------------------------------------------------
1 | $ python oop_objvar.py
2 | (Initializing R2-D2)
3 | Greetings, my masters call me R2-D2.
4 | We have 1 robots.
5 | (Initializing C-3PO)
6 | Greetings, my masters call me C-3PO.
7 | We have 2 robots.
8 |
9 | Robots can do some work here.
10 |
11 | Robots have finished their work. So let's destroy them.
12 | R2-D2 is being destroyed!
13 | There are still 1 robots working.
14 | C-3PO is being destroyed!
15 | C-3PO was the last one.
16 | We have 0 robots.
17 |
--------------------------------------------------------------------------------
/programs/oop_simplestclass.py:
--------------------------------------------------------------------------------
1 | class Person:
2 | pass # An empty block
3 |
4 | p = Person()
5 | print(p)
6 |
--------------------------------------------------------------------------------
/programs/oop_simplestclass.txt:
--------------------------------------------------------------------------------
1 | $ python oop_simplestclass.py
2 | <__main__.Person instance at 0x10171f518>
3 |
--------------------------------------------------------------------------------
/programs/oop_subclass.py:
--------------------------------------------------------------------------------
1 | class SchoolMember:
2 | '''Represents any school member.'''
3 | def __init__(self, name, age):
4 | self.name = name
5 | self.age = age
6 | print('(Initialized SchoolMember: {})'.format(self.name))
7 |
8 | def tell(self):
9 | '''Tell my details.'''
10 | print('Name:"{}" Age:"{}"'.format(self.name, self.age), end=" ")
11 |
12 |
13 | class Teacher(SchoolMember):
14 | '''Represents a teacher.'''
15 | def __init__(self, name, age, salary):
16 | SchoolMember.__init__(self, name, age)
17 | self.salary = salary
18 | print('(Initialized Teacher: {})'.format(self.name))
19 |
20 | def tell(self):
21 | SchoolMember.tell(self)
22 | print('Salary: "{:d}"'.format(self.salary))
23 |
24 |
25 | class Student(SchoolMember):
26 | '''Represents a student.'''
27 | def __init__(self, name, age, marks):
28 | SchoolMember.__init__(self, name, age)
29 | self.marks = marks
30 | print('(Initialized Student: {})'.format(self.name))
31 |
32 | def tell(self):
33 | SchoolMember.tell(self)
34 | print('Marks: "{:d}"'.format(self.marks))
35 |
36 | t = Teacher('Mrs. Shrividya', 40, 30000)
37 | s = Student('Swaroop', 25, 75)
38 |
39 | # prints a blank line
40 | print()
41 |
42 | members = [t, s]
43 | for member in members:
44 | # Works for both Teachers and Students
45 | member.tell()
46 |
--------------------------------------------------------------------------------
/programs/oop_subclass.txt:
--------------------------------------------------------------------------------
1 | $ python oop_subclass.py
2 | (Initialized SchoolMember: Mrs. Shrividya)
3 | (Initialized Teacher: Mrs. Shrividya)
4 | (Initialized SchoolMember: Swaroop)
5 | (Initialized Student: Swaroop)
6 |
7 | Name:"Mrs. Shrividya" Age:"40" Salary: "30000"
8 | Name:"Swaroop" Age:"25" Marks: "75"
9 |
--------------------------------------------------------------------------------
/programs/poem.txt:
--------------------------------------------------------------------------------
1 | Programming is fun
2 | When the work is done
3 | if you wanna make your work also fun:
4 | use Python!
5 |
--------------------------------------------------------------------------------
/programs/shoplist.data:
--------------------------------------------------------------------------------
1 | (lp0
2 | S'apple'
3 | p1
4 | aS'mango'
5 | p2
6 | aS'carrot'
7 | p3
8 | a.
--------------------------------------------------------------------------------
/programs/stdlib_logging.py:
--------------------------------------------------------------------------------
1 | import os
2 | import platform
3 | import logging
4 |
5 | if platform.platform().startswith('Windows'):
6 | logging_file = os.path.join(os.getenv('HOMEDRIVE'),
7 | os.getenv('HOMEPATH'),
8 | 'test.log')
9 | else:
10 | logging_file = os.path.join(os.getenv('HOME'),
11 | 'test.log')
12 |
13 | print("Logging to", logging_file)
14 |
15 | logging.basicConfig(
16 | level=logging.DEBUG,
17 | format='%(asctime)s : %(levelname)s : %(message)s',
18 | filename=logging_file,
19 | filemode='w',
20 | )
21 |
22 | logging.debug("Start of the program")
23 | logging.info("Doing something")
24 | logging.warning("Dying now")
25 |
--------------------------------------------------------------------------------
/programs/stdlib_logging.txt:
--------------------------------------------------------------------------------
1 | $ python stdlib_logging.py
2 | Logging to /Users/swa/test.log
3 |
4 | $ cat /Users/swa/test.log
5 | 2014-03-29 09:27:36,660 : DEBUG : Start of the program
6 | 2014-03-29 09:27:36,660 : INFO : Doing something
7 | 2014-03-29 09:27:36,660 : WARNING : Dying now
8 |
--------------------------------------------------------------------------------
/programs/while.py:
--------------------------------------------------------------------------------
1 | number = 23
2 | running = True
3 |
4 | while running:
5 | guess = int(input('Enter an integer : '))
6 |
7 | if guess == number:
8 | print('Congratulations, you guessed it.')
9 | # this causes the while loop to stop
10 | running = False
11 | elif guess < number:
12 | print('No, it is a little higher than that.')
13 | else:
14 | print('No, it is a little lower than that.')
15 | else:
16 | print('The while loop is over.')
17 | # Do anything else you want to do here
18 |
19 | print('Done')
20 |
--------------------------------------------------------------------------------
/programs/while.txt:
--------------------------------------------------------------------------------
1 | $ python while.py
2 | Enter an integer : 50
3 | No, it is a little lower than that.
4 | Enter an integer : 22
5 | No, it is a little higher than that.
6 | Enter an integer : 23
7 | Congratulations, you guessed it.
8 | The while loop is over.
9 | Done
10 |
--------------------------------------------------------------------------------
/revision_history.md:
--------------------------------------------------------------------------------
1 | {#history-lesson}
2 |
3 |
4 | # تاریخچه پیشرفت
5 |
6 | برای بار اول برای نرمافزار نصاب از پایتون استفاده کردم و اسمش را 'Diamond' گذاشتم. برای ساده سازی مراحل نصب، مجبور شدم بین زبان پریل و پایتون یکی را برای کتابخانهی کیوت انتخاب کنم. یک چرخی در اینترنت زدم و [مقالهی اریک اس. ریموند](http://www.python.org/about/success/esr/) را در اینترنت پیدا کردم. یک فرد مشهور و هکر بزرگوار، جاییکه که او میگفت چگونه زبان برنامهنویسی پایتون به زبان برنامهنویسی مورد علاقهاش تبدیل شده بود. همچنین فهمیدم که اتصال پایکیوت خیلی بیشتر از پریل-کیوت است به قول خودمون گفتنی با هم جوراند. این طور شد که فهمیدم پایتون همان زبان برنامهنویسی است، که من به دنبالاش بودم.
7 |
8 | بعد از این موضوع شروع کردم به جستجو برای یک کتاب برای یادگیری پایتون ولی نتوانستم همچین کتابی را پیدا کنم. کتابی که از O'Reilly پیدا کردم، ایا خیلی گرون بود، یا خیلی بیشتر از کتاب راهنما سنگین بود. بنابراین روی همان اموزشهای خود پایتون ایستادم. ولی این اسناد خیلی کوتاه و ساده بودند. این راهنماهامن را با کلیات پایتون اشنا کردند. اما اصلا برای مبتدیان مناسب نبود.
9 |
10 | بعد از شش ماه سرکله زدن با پایتون بالاخره پایتون را نصب کردم. همچنین اخرین نسخهی لینوکس ردهت 9.0 را هم نصب کردم. من با KWord خیلی سرکله میزدم و از این موضوع خیلی خوشحال بودم. ناگهان با یک جرقه تصمیم گرفتم یک چیزی دربارهی پایتون بنویسم و شروع به نوشتن چند صفحه کردم و اندک اندک به ۳۰ صفحه تبدیل شد. سپس این موضوع برایم جدی شد، که این صفحهها را تبدیل به یک کتاب بکنم.
11 |
12 | پس از نوشتنها و رونوشتنها بلاخره به ان مرحلهی رسیدم، که بتوانم این نوشتهها را به عنوان یک کتاب راهنما برای زبان برنامهنویسی پایتون استفاده کنم.این کتاب، به عنوان سهمی از خودم، در انجمن متنباز است.
13 |
14 | این کتاب به عنوان یک پیش نویس برای یادگیری پایتون بود و هنوز هم من همان دید را در حال حاضر دارم. با اینکه خیلی برای این کتاب زحمت کشیدم و سعی کردم که تا این کتاب مورد قبول دیگران باشد.
15 |
16 | روح واقعی منبع باز، من خیلی پیشنهادهای زیادی از سازندهها گرفتم از نظرات انتقادی
17 | ( [بازخوردها](./README.md#who-reads-bop) ) از خوانندههای مشتاق که به من کمک کردن تا این کتاب را بهبود ببخشم.
18 |
19 |
20 | ## وضیعت کتاب
21 |
22 | کتاب نیاز به کمک خوانندههای خود دارد, مانند شما، تا اینکه قسمتهای که درست نیست یا اینکه اصلا اشتباه است به ان اشاره کنید. لطفا [نام نویسندهی اصلی را بنویسید.]({{ book.contactUrl }}) . یا همان طور که اشاره شده در [مترجمین](./translations.md#translations) نظرها و پیشنهادات خود را بگوید.
23 |
24 |
25 | # تاریخچه
26 |
27 | - 4.0
28 |
29 | - ۱۹ ژانویه ۲۰۱۶
30 |
31 | - .دوباره برگشت به پایتون نسخهی ۳
32 |
33 | - برگشت به مارکداون و استفاده از [گیتبوک](https://www.gitbook.com) و [Spacemacs](http://spacemacs.org).
34 |
35 | - 3.0
36 |
37 | - ۳۱ مارس ۲۰۱۴
38 |
39 | - بازنویسی شد برای پایتون نسخهی ۲
40 | [اسکیداک](http://asciidoctor.org/docs/what-is-asciidoc/) و [adoc-mode](https://github.com/sensorflo/adoc-mode/wiki).
41 |
42 | - 2.1
43 |
44 | - ۰۳ اگوست ۲۰۱۳
45 |
46 | - برای مارکداون بازنویسی شد و [Jason Blevins' Markdown Mode](http://jblevins.org/projects/markdown-mode/).
47 |
48 |
49 | - 2.0
50 |
51 | - ۲۰ اکتبر ۲۰۱۲
52 |
53 | - با [ فرمت Pandoc](http://johnmacfarlane.net/pandoc/README.html) بازنویسی شد. از همسرم خودم تشکر میکنم که بیشتر بازنویسی تبدیل به MediaWiki انجام داد
54 |
55 | - ساده سازی متنی، حذف کردن قسمتهای اضافی، مانند: `غیر محلیها` و metaclasses.
56 |
57 |
58 | - 1.90
59 |
60 | - ۰۴ سپتامر ۲۰۰۸ و هنوز ادامه دارد.
61 |
62 | - بازتولد دوباره بعد ۳.۵ سال.
63 |
64 | - برای پایتون نسخهی ۳ بازنویسی شد.
65 |
66 | - بااستفاده از http://www.mediawiki.org[مدیاویکی] (دوباره) بازنویسی شد.
67 |
68 |
69 |
70 |
71 | - 1.20
72 |
73 | - ۱۳ ژانویه ۲۰۰۵
74 |
75 | - به طور کامل بازنویسی شد با استفاده از [کوئنتا+](https://en.wikipedia.org/wiki/Quanta_Plus) روی [فدورا](http://fedoraproject.org/) ۳ هستهی همراه با تعداد زیادی از رفع مشکل و بهروزرسانی. مثالهای جدید. تمام تظیمات DocBook از صفر بازنویسی کردم.
76 |
77 |
78 |
79 | - 1.15
80 |
81 | - ۲۸ مارس ۲۰۰۴
82 |
83 | - اعمال کمی تغییرات.
84 |
85 | - 1.12
86 |
87 | - ۱۶ مارس ۲۰۰۴
88 |
89 | - اعمال تغییرات مکمل.
90 |
91 |
92 | - 1.10
93 |
94 | - ۰۹ مارس ۲۰۰۴
95 |
96 | - رفع غلطهای املایی بیشتر، با تشکر از بسیاری از علاقهمندان و خوانندگان.
97 |
98 |
99 | - 1.00
100 |
101 | - ۰۸ مارس ۲۰۰۴
102 |
103 | - پس از بازیدهای بسیار، انتقادات و پیشنهادات بسیار، از خوانندگان، تغییرات قابل توجهی در درست کردن محتوا و غلط املایی دادم.
104 |
105 |
106 | - 0.99
107 |
108 | - ۲۲ فوریه ۲۰۰۴
109 |
110 | - اضافه شدن فصل جدید ماژولها همچنین اطلاعاتی دربارهی توابع، ارگومانها و متغیرها.
111 |
112 |
113 |
114 | - 0.98
115 |
116 | - ۱۶ فوریه ۲۰۰۴
117 |
118 | - نوشتن اسکریپت پایتون و طراحی سیاساس برای بهبودی خروجی اکساچتیامال, همچنین شامل crude-yet-functional lexical analyzer برای لیست کردن خودکار syntax برنامهها مانند ویم.
119 |
120 |
121 | - 0.97
122 |
123 | - ۱۳ فوریه ۲۰۰۴
124 |
125 | - یکی دیگر از یاداشتها که دوباره در داکبوک اکسامال بازنویسی شد. کتاب واقعا بهبود یافت. و درک کردن و فهمیدن کتاب اسانتر شد.
126 |
127 |
128 | - 0.93
129 |
130 | - ۲۵ ژانویه ۲۰۰۴
131 |
132 | - اضافه شدن بحث دربارهی IDLE و موارد دیگر برای ویندوز.
133 |
134 |
135 | - 0.92
136 |
137 | - ۰۵ ژانویه ۲۰۰۴
138 |
139 | - تغییردادن بعضی از مثالها.
140 |
141 |
142 | - 0.91
143 |
144 | - ۳۰ دسامبر ۲۰۰۳
145 |
146 | - تحصیح کردن غلط املایی.
147 |
148 |
149 | - 0.90
150 |
151 | - ۱۸ دسامبر ۲۰۰۳
152 |
153 | - اضافه شدن دو فصل دیگر با تغییر فرمت [اپن آفیس](https://en.wikipedia.org/wiki/OpenOffice) .
154 |
155 |
156 | - 0.60
157 |
158 | - ۲۱ نوامبر ۲۰۰۳
159 |
160 | - به طور کامل بازنویسی شده و گسترش یافته است.
161 |
162 |
163 | - 0.20
164 |
165 | - ۲۰ نوامبر ۲۰۰۳
166 |
167 | - تحصیح کردن بعضی از غلط املاییها و اشتباهات.
168 |
169 |
170 | - 0.15
171 |
172 | - ۲۰ نوامبر ۲۰۰۳
173 |
174 | - تبدیل به فرمت [داکبوک اکسامال](https://en.wikipedia.org/wiki/DocBook) به کمک XEmacs.
175 |
176 |
177 | - 0.10
178 |
179 | - ۱۴ نوامبر ۲۰۰۳
180 |
181 | - اولین پیشنویس و با استفاده از [KWord](https://en.wikipedia.org/wiki/Kword) نوشته شد.
182 |
--------------------------------------------------------------------------------
/translation_howto.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | {#translation-howto}
4 | # چگونه ترجمه کنیم
5 | ۱. منبع کامل کتاب قابل رویت باشد {{ book.sourceUrl }}.
6 |
7 | ۲. لطفا [fork the repository](https://help.github.com/articles/fork-a-repo) .
8 |
9 | ۳. منبع را در رایانهی خود داشته باشید. باید اطلاعاتی دربارهی گیت و چگونگی استفاده از [گیت](http://www.git-scm.com) را بدانید.
10 |
11 | ۴. خواندن [اسناد گیتبوک](https://help.gitbook.com) و [مارکداون](https://help.gitbook.com/format/markdown.html).
12 |
13 | ۵. شروع کردن به ویرایش فایلهای ".md" و یادگیری ان، برای ترجمه به زبان خود.
14 |
15 | ۶. [Sign up on GitBook.com](https://www.gitbook.com) ، کتاب را بنویسید و زیبای رندر کردن وبسایت را خواهید دید, با لینک برای دانلود پیدیاف ، ایپاب و غیره.
16 |
--------------------------------------------------------------------------------
/translations.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # مترجمین
4 |
5 | در اینجا ترجمههای زیادی از این کتاب با زبانهای مختلف وجود دارد، همچنین از افراد داوطلب خستگی ناپذیربرای ترجمه این کتاب سپاس گذاریم!
6 |
7 | اگر به ترجمهی این کتاب میخواهید کمک کنید، لطفا اول لیست زیرین داوطلبها و زبانها را ببینید و بعد تصمیم بگیرد که یا میخواهید ترجمه جدیدی را شروع یا کمک برای ترجمههای موجود برای پروژهها کنید.
8 |
9 | اگر شروع به ترجمه میخواهید کنید لطفا [چگونه ترجمه کنیم](./translation_howto.md#translation-howto) را بخوانید.
10 |
11 |
12 | ## عربی
13 |
14 | در اینجا لینکی برای نسخهی عربی موجود است. از اشراف علی خلاف برای ترجمه سپاس گذاریم, تمامی کتاب را میتوانید انلاین بخوانید با مراجعهی به این لینک
یا میتوانید با دانلود از این لینک [sourceforge.net](http://downloads.sourceforge.net/omlx/byteofpython_arabic.pdf?use_mirror=osdn) for more info see و از این کتاب لذت ببرید.
15 |
16 | ## اذربایجانی
17 |
18 |
19 | Jahangir Shabiyev داوطلب دیگری بوده برای ترجمهی این کتاب به اذربایجانی که ترجمه در حال ادامه است و برای مشاهده به لینک زیر مراجعه کنید
20 | https://www.gitbook.com/book/jahangir-sh/piton-sancmasi
21 |
22 |
23 |
24 |
25 | ## برزیلی پرتقالی
26 |
27 | در اینجا دو ترجمهی مختلف قاب دسترس است. در حال حاضر انان ترجمه قدیمی گم شده است و نیستش، و ترجمهی جدید هنوز به اتمام نرسیده است.
28 |
29 |
30 | Samuel Dias Neto (samuel.arataca@gmail.com)
31 |
32 | که اولین ترجمهی برزیلی پرتغالی را نوشته است (کههمان ترجمهی قدیمی است) که در ان زمان نسخهی کتاب پایتون ۲.۳.۵ بوده، که در مدت طولانی در دسترس نبود.
33 |
34 |
35 |
36 | [Rodrigo Amaral](http://rodrigoamaral.net) (rodrigoamaral@gmail.com)
37 |
38 |
39 |
40 | یک داوطلب دیگر که کتاب را به برزیلی پرتغالی ترجمه کر ده است (ترجمهی جدید). که هنوز در حال ترجمه برای کامل شدن است.
41 |
42 | ## کاتالان
43 |