Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

...του ubuntu και έργων ΕΛ/ΛΑΚ (Έργα-Οδηγοί-Εργαλεία-Προτάσεις-Σχόλια)

Συντονιστής: Geochr

Κανόνες Δ. Συζήτησης
Ενημερώστε και την ελληνική κοινότητα του GNOME για σφάλματα που δεν αφορούν μόνο το Ubuntu.
https://www.gnome.gr/contribute/

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό Μάριος Ζηντίλης » 28 Μάιος 2009, 20:17

dimosfire το 11. Τα 12 και 13 τα έχει καβαντζώσει ο ατέρμον. Από 'κει και κάτω είναι διαθέσιμα. Μπορείτε να βλέπετε τη λίστα με τα κεφάλαια και αν τα έχει αναλάβει κάποιος, στο http://www.swaroopch.com/notes/User:Ubuntu-gr.org
Άβαταρ μέλους
Μάριος Ζηντίλης
punkTUX
punkTUX
 
Δημοσιεύσεις: 220
Εγγραφή: 25 Σεπ 2008, 11:16
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό atermon » 29 Μάιος 2009, 18:36

Ολοκληρώθηκε και το 12ο κεφάλαιο, επίλυση προβλημάτων
Από Δευτέρα θα ξεκινήσω με το 13ο, λόγω υποχρεώσεων.
<Οδηγίες προς νεοεισερχόμενους> | <Οδηγοί χρήσης>
DEBIAN "Sid" 32bit σε Sony VAIO VGN-FE11S
Intel T2400(1,83 GHz) │ 2GB DDR2 │ NVIDIA GeForce Go 7400 │Intel 3945ABG │Intel 82801G(ICH7 Family) │ TFT 15.4" WXGA
Άβαταρ μέλους
atermon
seniorTUX
seniorTUX
 
Δημοσιεύσεις: 711
Εγγραφή: 13 Μάιος 2008, 20:31
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό dimosfire » 30 Μάιος 2009, 12:10

Υποβάλλω το πρώτο μισό του κεφαλαίου 11, για έλεγχο :
Κώδικας: Επιλογή όλων
Python en:Data Structures
Introduction
Data structures are basically just that - they are structures which can hold some data
together. In other words, they are used to store a collection of related data.
There are four built-in data structures in Python - list, tuple, dictionary and set. We will see
how to use each of them and how they make life easier for us.
List
A list is a data structure that holds an ordered collection of items i.e. you can store a
sequence of items in a list. This is easy to imagine if you can think of a shopping list where
you have a list of items to buy, except that you probably have each item on a separate line
in your shopping list whereas in Python you put commas in between them.
The list of items should be enclosed in square brackets so that Python understands that you
are specifying a list. Once you have created a list, you can add, remove or search for items
in the list. Since we can add and remove items, we say that a list is a mutable data type i.e.
this type can be altered.
Quick Introduction To Objects And Classes
Although I've been generally delaying the discussion of objects and classes till now, a little
explanation is needed right now so that you can understand lists better. We will explore this
topic in detail later in its own chapter.
A list is an example of usage of objects and classes. When we use a variable i and assign a
value to it, say integer 5 to it, you can think of it as creating an object (i.e. instance) i of
class (i.e. type) int. In fact, you can read help(int) to understand this better.
A class can also have methods i.e. functions defined for use with respect to that class only.
You can use these pieces of functionality only when you have an object of that class. For
example, Python provides an append method for the list class which allows you to add an
item to the end of the list. For example, mylist.append('an item') will add that string to
the list mylist. Note the use of dotted notation for accessing methods of the objects.
A class can also have fields which are nothing but variables defined for use with respect to
that class only. You can use these variables/names only when you have an object of that
class. Fields are also accessed by the dotted notation, for example, mylist.field.
Example:
#!/usr/bin/python
# Filename: using_list.py
# This is my shopping list
shoplist = ['apple', 'mango', 'carrot', 'banana']
print('I have', len(shoplist), 'items to purchase.')
print('These items are:', end=' ')
Python en:Data Structures 63
for item in shoplist:
print(item, end=' ')
print('\nI also have to buy rice.')
shoplist.append('rice')
print('My shopping list is now', shoplist)
print('I will sort my list now')
shoplist.sort()
print('Sorted shopping list is', shoplist)
print('The first item I will buy is', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('I bought the', olditem)
print('My shopping list is now', shoplist)
Output:
$ python using_list.py
I have 4 items to purchase.
These items are: apple mango carrot banana
I also have to buy rice.
My shopping list is now ['apple', 'mango', 'carrot', 'banana',
'rice']
I will sort my list now
Sorted shopping list is ['apple', 'banana', 'carrot', 'mango',
'rice']
The first item I will buy is apple
I bought the apple
My shopping list is now ['banana', 'carrot', 'mango', 'rice']
How It Works:
The variable shoplist is a shopping list for someone who is going to the market. In
shoplist, we only store strings of the names of the items to buy but you can add any kind
of object to a list including numbers and even other lists.
We have also used the for..in loop to iterate through the items of the list. By now, you
must have realised that a list is also a sequence. The speciality of sequences will be
discussed in a later section.
Notice the use of the end keyword argument to the print function to indicate that we
want to end the output with a space instead of the usual line break.
Next, we add an item to the list using the append method of the list object, as already
discussed before. Then, we check that the item has been indeed added to the list by
printing the contents of the list by simply passing the list to the print statement which
prints it neatly.
Then, we sort the list by using the sort method of the list. It is important to understand
that this method affects the list itself and does not return a modified list - this is different
from the way strings work. This is what we mean by saying that lists are mutable and that
Python en:Data Structures 64
strings are immutable.
Next, when we finish buying an item in the market, we want to remove it from the list. We
achieve this by using the del statement. Here, we mention which item of the list we want
to remove and the del statement removes it from the list for us. We specify that we want to
remove the first item from the list and hence we use del shoplist[0] (remember that
Python starts counting from 0).
If you want to know all the methods defined by the list object, see help(list) for details.
Tuple
Tuples are used to hold together multiple objects. Think of them as similar to lists, but
without the extensive functionality that the list class gives you. One major feature of tuples
is that they are immutable like strings i.e. you cannot modify tuples.
Tuples are defined by specifying items separated by commas within an optional pair of
parentheses.
Tuples are usually used in cases where a statement or a user-defined function can safely
assume that the collection of values i.e. the tuple of values used will not change.
Example:
#!/usr/bin/python
# Filename: using_tuple.py
zoo = ('python', 'elephant', 'penguin') # remember the parentheses are
optional
print('Number of animals in the zoo is', len(zoo))
new_zoo = ('monkey', 'camel', zoo)
print('Number of cages in the new zoo is', len(new_zoo))
print('All animals in new zoo are', new_zoo)
print('Animals brought from old zoo are', new_zoo[2])
print('Last animal brought from old zoo is', new_zoo[2][2])
print('Number of animals in the new zoo is',
len(new_zoo)-1+len(new_zoo[2]))
Output:
$ python using_tuple.py
Number of animals in the zoo is 3
Number of cages in the new zoo is 3
All animals in new zoo are ('monkey', 'camel', ('python',
'elephant', 'penguin'))
Animals brought from old zoo are ('python', 'elephant', 'penguin')
Last animal brought from old zoo is penguin
Number of animals in the new zoo is 5
How It Works:
The variable zoo refers to a tuple of items. We see that the len function can be used to get
the length of the tuple. This also indicates that a tuple is a sequence as well.
Python en:Data Structures 65
We are now shifting these animals to a new zoo since the old zoo is being closed. Therefore,
the new_zoo tuple contains some animals which are already there along with the animals
brought over from the old zoo. Back to reality, note that a tuple within a tuple does not lose
its identity.
We can access the items in the tuple by specifying the item's position within a pair of
square brackets just like we did for lists. This is called the indexing operator. We access the
third item in new_zoo by specifying new_zoo[2] and we access the third item within the
third item in the new_zoo tuple by specifying new_zoo[2][2]. This is pretty simple once
you've understood the idiom.
Parentheses
Although the parentheses is optional, I prefer always having them to make it obvious
that it is a tuple, especially because it avoids ambiguity. For example, print(1,2,3)
and print( (1,2,3) ) mean two different things - the former prints three numbers
whereas the latter prints a tuple (which contains three numbers).
Tuple with 0 or 1 items
An empty tuple is constructed by an empty pair of parentheses such as myempty = ().
However, a tuple with a single item is not so simple. You have to specify it using a
comma following the first (and only) item so that Python can differentiate between a
tuple and a pair of parentheses surrounding the object in an expression i.e. you have to
specify singleton = (2 , ) if you mean you want a tuple containing the item 2.
Note for Perl programmers
A list within a list does not lose its identity i.e. lists are not flattened as in Perl. The
same applies to a tuple within a tuple, or a tuple within a list, or a list within a tuple,
etc. As far as Python is concerned, they are just objects stored using another object,
that's all.
Dictionary
A dictionary is like an address-book where you can find the address or contact details of a
person by knowing only his/her name i.e. we associate keys (name) with values (details).
Note that the key must be unique just like you cannot find out the correct information if you
have two persons with the exact same name.
Note that you can use only immutable objects (like strings) for the keys of a dictionary but
you can use either immutable or mutable objects for the values of the dictionary. This
basically translates to say that you should use only simple objects for keys.
Pairs of keys and values are specified in a dictionary by using the notation d = {key1 :
value1, key2 : value2 }. Notice that the key-value pairs are separated by a colon and the
pairs are separated themselves by commas and all this is enclosed in a pair of curly braces.
Remember that key-value pairs in a dictionary are not ordered in any manner. If you want a
particular order, then you will have to sort them yourself before using it.
The dictionaries that you will be using are instances/objects of the dict class.
Example:
#!/usr/bin/python
# Filename: using_dict.py
Python en:Data Structures 66
# 'ab' is short for 'a'ddress'b'ook
ab = { 'Swaroop' : 'swaroop@swaroopch.com',
'Larry' : 'larry@wall.org',
'Matsumoto' : 'matz@ruby-lang.org',
'Spammer' : 'spammer@hotmail.com'
}
print("Swaroop's address is", ab['Swaroop'])
# Deleting a key-value pair
del ab['Spammer']
print('\nThere are {0} contacts in the address-book\n'.format(len(ab)))
for name, address in ab.items():
print('Contact {0} at {1}'.format(name, address))
# Adding a key-value pair
ab['Guido'] = 'guido@python.org'
if 'Guido' in ab: # OR ab.has_key('Guido')
print("\nGuido's address is", ab['Guido'])
Output:
$ python using_dict.py
Swaroop's address is swaroop@swaroopch.com
There are 3 contacts in the address-book
Contact Swaroop at swaroop@swaroopch.com
Contact Matsumoto at matz@ruby-lang.org
Contact Larry at larry@wall.org
Guido's address is guido@python.org
How It Works:
We create the dictionary ab using the notation already discussed. We then access key-value
pairs by specifying the key using the indexing operator as discussed in the context of lists
and tuples. Observe the simple syntax.
We can delete key-value pairs using our old friend - the del statement. We simply specify
the dictionary and the indexing operator for the key to be removed and pass it to the del
statement. There is no need to know the value corresponding to the key for this operation.
Next, we access each key-value pair of the dictionary using the items method of the
dictionary which returns a list of tuples where each tuple contains a pair of items - the key
followed by the value. We retrieve this pair and assign it to the variables name and address
correspondingly for each pair using the for..in loop and then print these values in the
Python en:Data Structures 67
for-block.
We can add new key-value pairs by simply using the indexing operator to access a key and
assign that value, as we have done for Guido in the above case.
We can check if a key-value pair exists using the in operator or even the has_key method
of the dict class. You can see the documentation for the complete list of methods of the
dict class using help(dict).
Keyword Arguments and Dictionaries
On a different note, if you have used keyword arguments in your functions, you have
already used dictionaries! Just think about it - the key-value pair is specified by you in
the parameter list of the function definition and when you access variables within your
function, it is just a key access of a dictionary (which is called the symbol table in
compiler design terminology).

Και η μετάφραση του:
Κώδικας: Επιλογή όλων
Δομές δεδομένων(Data structures)

Εισαγωγή
Οι δομές δεδομένων είναι αυτό που λέει το όνομά τους δηλ. είναι δομές που μπορούν να κρατήσουν μαζί μερικά δεδομένα. Με άλλα λόγια χρησιμοποιούνται για να αποθηκεύουν δεδομένα που έχουν σχέση μεταξύ τους. Υπάρχουν τέσσερις ενσωματωμένες δομές δεδομένων στη Python, οι λίστες, οι πλειάδες, τα λεξικά και τα σύνολα. Θα δούμε πως να τα χρησιμοποιούμε και πως μας κάνουν τη ζωή ευκολότερη.

Λίστα
Η λίστα είναι μια δομή δεδομένων που συγκρατεί μια διατεταγμένη συλλογή στοιχείων, δηλ. μπορείτε να αποθηκεύσετε μια ακολουθία(sequence) αντικειμένων στη λίστα. Αυτό είναι εύκολο να το φανταστείτε αν σκεφτείτε μια λίστα για αγορές, όπου έχετε μια λίστα με αντικείμενα που πρέπει να αγοράσετε, εκτός αυτού πιθανόν έχετε κάθε στοιχείο σε διαφορετική γραμμή στη λίστα αγορών σας, αντιθέτως στη Python τοποθετείτε κόμματα ανάμεσα στα στοιχεία.
Η λίστα των στοιχείων πρέπει να κλείνεται σε αγκύλες έτσι ώστε να καταλαβαίνει η Python ότι καθορίζετε μια λίστα. Αν έχετε δημιουργήσει μια λίστα μια φορά μπορείτε να προσθέσετε, να μετακινήσετε ή να ψάξετε για στοιχεία σ' αυτή τη λίστα. Από τη στιγμή που μπορούμε να προσθέσουμε και να μετακινήσουμε στοιχεία, λέμε ότι η λίστα είναι ένας μεταβλητός τύπος δεδομένων(mutable data type) δηλ. αυτός ο τύπος μπορεί να αλλαχθεί.

Γρήγορη εισαγωγή στα αντικείμενα(objects) και τις κλάσεις(classes)
Αν και έχουμε αναβάλει μέχρι τώρα τη συζήτηση για τα αντικείμενα και τις κλάσεις, μια μικρή επεξήγηση απαιτείται ακριβώς τώρα για να καταλάβετε καλύτερα τις λίστες. Θα εξερευνήσουμε αυτό το θέμα αργότερα σε δικό του κεφάλαιο.
Η λίστα είναι ένα παράδειγμα χρήσης αντικειμένων και κλάσεων. Όταν χρησιμοποιούμε τη μεταβλητή i και της ορίζουμε μια τιμή, ας πούμε τον ακέραιο αριθμό 5, αυτό μπορούμε να το σκεφτούμε σαν τη δημιουργία ενός αντικειμένου (δηλ. υπόστασης(instance)) i της κλάσης(δηλ. τύπου(type)) int. Στην πραγματικότητα μπορείτε να διαβάσετε τη βοήθεια(int) (help(int)) για να το καταλάβετε καλύτερα.
Mια τάξη μπορεί επίσης να έχει μεθόδους(methods) δηλ. συναρτήσεις, που ορίστηκαν για χρήση που έχει σχέση μόνο με αυτή την τάξη. Μπορείτε να χρησιμοποιήσετε αυτά τα μέρη λειτουργικότητας μόνο όταν έχετε ένα αντικείμενο σε αυτή την κλάση. Για παράδειγμα η Python παρέχει μια μέθοδο προσάρτησης για την τάξη της λίστας, που σας επιτρέπει να προσθέσετε ένα αντικείμενο στο τέλος της λίστας. Για παράδειγμα, το mylist.append('an item') θα προσθέσει αυτή τη συμβολοσειρά στο τέλος του mylist. Σημειώστε τη χρήση του συμβολισμού με τελείες για να εισαχθούν οι μέθοδοι των αντικειμένων.
Μια τάξη μπορεί επίσης να έχει πεδία(fields), που δεν είναι τίποτα άλλο παρά μεταβλητές που ορίστηκαν για χρήση που έχει σχέση μόνο με αυτή την τάξη. Μπορείτε να χρησιμοποιήσετε αυτές τις μεταβλητές/ονομασίες μόνο όταν έχετε ένα αντικείμενο αυτής της τάξης. Τα πεδία επίσης εισάγονται με συμβολισμό με τελείες, για παράδειγμα, mylist.field.

Παράδειγμα:
#!/usr/bin/python
# Filename: using_list.py
# Αυτή είναι η λίστα αγορών μου
shoplist = ['μήλο', 'μάνγκο', 'καρότο', 'μπανάνα']
print('Εχω', len(shoplist), 'στοιχεία να πληρώσω.')
print('Αυτά τα στοιχεία είναι:', end=' ')
print(item, end=' ')
print('\nΕπίσης πρέπει να αγοράσω ρύζι.')
shoplist.append('ρύζι')
print('Η λίστα αγορών μου τώρα είναι', shoplist)
print('Θα ταξινομήσω τη λίστα μου τώρα')
shoplist.sort()
print('Sorted shopping list is', shoplist)
print('Το πρώτο στοιχείο που θα αγοράσω είναι', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('Αγόρασα το', olditem)
print('Ηλίστα αγορών μου τώρα είναι', shoplist)

Έξοδος:
$ python using_list.py
Έχω 4 στοιχεία να πληρώσω.
Αυτά τα στοιχεία είναι: μήλο μάνγκο καρότο μπανάνα
Έπίσης πρέπει να πληρώσω το ρύζι.
Η λίστα αγορών μου τώρα είναι ['μήλο', 'μάνγκο', 'καρότο', 'μπανάνα',
'ρύζι']
Θα ταξινομήσω τη λίστα μου τώρα
Η ταξινομημένη λίστα αγορών είναι ['μήλο', 'μπανάνα', 'καρότο', 'μάνγκο',
'ρύζι']
Το πρώτο στοιχείο που θα αγοράσω είναι το μήλο
Αγόρασα το μήλο
Η λίστα αγορών μου τώρα είναι['μπανάνα', 'καρότο', 'μάνγκο', 'ρύζι' ]

Πως δουλεύει:
H μεταβλητή shoplist είναι μια λίστα αγορών για κάποιον που πηγαίνει στην αγορά. Στη shoplist αποθηκεύουμε συμβολοσειρές των ονομάτων των αντικειμένων που θα αγοράσουμε, αλλά δεν μπορείτε να προσθέσετε κανένα είδος αντικειμένου στη λίστα συμπεριλαμβανομένων αριθμών ή ακόμα και άλλες λίστες.
Επίσης έχουμε χρησιμοποιήσει το βρόχο for...in για να επανελέξουμε τα αντικείμενα της λίστας. Μέχρι τώρα, πρέπει να έχετε καταλάβει ότι η λίστα είναι επίσης μια ακολουθία. Η ιδιαιτερότητα των ακολουθιών θα συζητηθεί σε επόμενο κεφάλαιο. Παρατηρήστε πως χρησιμοποιούμε τη λέξη-κλειδί όρισμα end στη συνάρτηση print, για να δείξουμε ότι θέλουμε να τελειώσουμε (end) την έξοδο με ένα διάστημα(space) αντί της συνηθισμένης γραμμής διάλλειμα(break).Κατόπιν προσθέτουμε ένα στοιχείο στη λίστα χρησιμοποιώντας τη μέθοδο προσάρτησης(append method) της λίστας του αντικειμένου(list object), όπως ήδη συζητήσαμε. Τότε, παρατηρούμε ότι το στοιχείο έχει πραγματικά προστεθεί στη λίστα, τυπώνοντας τα περιεχόμενα της λίστας, απλά περνώντας τη λίστα στην εντολή print και απλά την τυπώνει.
Τότε, ταξινομούμε τη λίστα χρησιμοποιώντας τη μέθοδο ταξινόμησης(sort method) της λίστας. Είναι σημαντικό να καταλάβετε ότι αυτή η μέθοδος επηρεάζει την ίδια τη λίστα και δεν επιστρέφει μια τροποποιημένη λίστα, αυτή είναι η διαφορά από τον τρόπο που δουλεύουν οι συμβολοσειρές. Αυτό είναι που εννοούμε λέγοντας ότι οι λίστες είναι μεταβλητές(mutable) και οι συμβολοσειρές αμετάβλητες(immutable). Κατόπιν, όταν τελειώνουμε αγοράζοντας ένα στοιχείο στην αγορά, θέλουμε να το μετακινήσουμε από τη λίστα. Αυτό το επιτυγχάνουμε χρησιμοποιώντας την εντολή del. Εδώ αναφέρουμε ποιο στοιχείο της λίστας θέλουμε να μετακινήσουμε και η εντολή del το μετακινεί από τη λίστα για μας. Καθορίζουμε ότι θέλουμε να μετακινήσουμε το πρώτο αντικείμενο από τη λίστα και έτσι χρησιμοποιούμε την del shoplist[0] (θυμηθείτε ότι η Python αρχίζει να μετρά από το μηδέν).Εάν θέλετε να γνωρίσετε όλες τις μεθόδους που ορίζονται από τη λίστα αντικειμένου, κοιτάξτε το help(list) για λεπτομέρειες.

Πλειάδα
Οι πλειάδες χρησιμοποιούνται για να συγκρατήσουν μαζί πολλαπλά αντικείμενα. Σκεφτείτε τα σαν παρόμοια με τις λίστες, αλλά χωρίς την εκτεταμένη λειτουργικότητα που η κλάση της λίστας σας δίνει. Ένα κύριο χαρακτηριστικό των πλειάδων είναι ότι είναι αμετάβλητη όπως οι συμβολοσειρές δηλ. δεν μπορείτε να τροποποιήσετε πλειάδες.
Οι πλειάδες ορίζονται καθορίζοντας στοιχεία που διαχωρίζονται με κόμματα, μέσα σε ένα προαιρετικό ζευγάρι παρενθέσεων. Οι πλειάδες χρησιμοποιούνται, συνήθως, στις περιπτώσεις όπου μια εντολή ή μια συνάρτηση οριζόμενη από το χρήστη, μπορεί με ασφάλεια να θεωρήσει ότι η συλλογή των τιμών δηλ. η πλειάδα των τιμών που χρησιμοποιούνται δεν θα αλλάξει.

Παράδειγμα:
#!/usr/bin/python
# Filename: using_tuple.py
zoo = ('πύθωνας', 'ελέφαντας', 'πιγκουίνος') # θυμηθείτε οι παρενθέσεις είναι προαιρετικές
print('Ο αριθμός των ζώων στο ζωολογικό κήπο είναι', len(zoo))
new_zoo = ('μαϊμού', 'καμήλα', zoo)
print('Ο αριθμός των κλουβιών στο νέο ζωολογικό κήπο είναι', len(new_zoo))
print('Όλα τα ζώα στο νέο ζωολογικό κήπο είναι', new_zoo)
print('Όλα τα ζώα που έφεραν από τον παλιό ζωολογικό κήπο είναι', new_zoo[2])
print('Το τελευταίο ζώο που έφεραν από τον παλιό ζωολογικό κήπο είναι', new_zoo[2][2])
print('Ο αριθμός των ζώων που είναι στο νέο ζωολογικό κήπο',
len(new_zoo)-1+len(new_zoo[2]))

Έξοδος:
$ python using_tuple.py
Ο αριθμός των ζώων στο ζωολογικό κήπο είναι 3
Ο αριθμός των κλουβιών στο νέο ζωολογικό κήπο είναι 3
Όλα τα ζώα στο νέο ζωολογικό κήπο είναι ('μαϊμού', 'καμήλα', ('πύθωνας',
'ελέφαντας', 'πιγκουίνος'))
Τα ζώα που έφεραν από τον παλιό ζωολογικό κήπο είναι ('πύθωνας', 'ελέφαντας', 'πιγκουίνος')
Το τελευταίο ζώο που έφεραν από τον παλιό ζωολογικό κήπο είναι πιγκουίνος
Ο αριθμός των ζώων στο νέο ζωολογικό κήπο είναι 5

Πως δουλεύει:
Η μεταβλητή zoo αναφέρεται σε μια πλειάδα στοιχείων. Βλέπουμε ότι η συνάρτηση len μπορεί να χρησιμοποιηθεί για να πάρει το μήκος της πλειάδας. Αυτό επίσης δείχνει ότι η πλειάδα είναι και μια ακολουθία.
Τώρα μετακινούμε αυτά τα ζώα σε ένα νέο ζωολογικό κήπο επειδή ο παλιός κλείνει. Συνεπώς, η πλειάδα the new_zoo περιέχει κάποια ζώα που βρίσκονται ήδη μαζί με τα ζώα που έφεραν από τον παλιό ζωολογικό κήπο. Πίσω στην πραγματικότητα, σημειώστε ότι μια πλειάδα μέσα σε μια πλειάδα δεν χάνει την ταυτότητά της.
Μπορούμε να εισάγουμε τα στοιχεία μέσα στην πλειάδα, καθορίζοντας τη θέση του στοιχείου μέσα σε ένα ζευγάρι αγκύλες, ακριβώς όπως κάναμε για τις λίστες. Αυτό ονομάζεται τελεστής ευρετηρίασης(indexing operator). Eισάγουμε το τρίτο στοιχείο μέσα στο new_zoo καθορίζοντας new_zoo[2] και εισάγουμε το τρίτο στοιχείο μέσα στο τρίτο στοιχείο στην πλειάδα new_zoo καθορίζοντας new_zoo[2][2]. Aυτό είναι πολύ απλό άπαξ και έχετε καταλάβει το ιδίωμα.

Παρενθέσεις
Αν και οι παρενθέσεις είναι προαιρετικές, εγώ προτιμώ πάντα να τις έχω για να κάνω φανερό ότι αυτή είναι μια πλειάδα, ειδικά επειδή αποφεύγεις την ασάφεια. Για παράδειγμα, print(1,2,3) και print( (1,2,3) ) σημαίνουν δυο διαφορετικά πράγματα- το μεν τυπώνει τρεις αριθμούς, αντίθετα το δε τυπώνει μια πλειάδα(η οποία περιέχει τρεις αριθμούς).

Πλειάδα με 0 ή 1 στοιχεία
Μια άδεια πλειάδα δομείται από ένα άδειο ζευγάρι παρενθέσεων όπως myempty = (). Πάντως, μια πλειάδα με ένα μόνο στοιχείο δεν είναι δεν είναι τόσο απλή. Πρέπει να το καθορίσετε χρησιμοποιώντας ένα κόμμα ακολουθώντας το πρώτο και μοναδικό στοιχείο, έτσι ώστε η Python να μπορεί να διαφοροποιεί μια πλειάδα από ένα ζευγάρι παρενθέσεων που παρεμβάλλουν το αντικείμενο σε μια έκφραση δηλ. πρέπει να καθορίζετε singleton = (2, ), εάν εννοείτε ότι θέλετε μια πλειάδα που περιέχει το στοχείο 2.

Σημείωση για τους προγραμματιστές της Perl
Μια λίστα μέσα σε μια λίστα δεν χάνει την ταυτότητά της δηλ. οι λίστες δεν ισοπεδώνονται όπως στην Perl. Το ίδιο ισχύει για μια πλειάδα μέσα σε μια πλειάδα, ή για μια πλειάδα μέσα σε μια λίστα, ή για μια λίστα μέσα σε μια πλειάδα, κ.τ.λ. Σε ότι αφορά την Python, αυτά είναι μόνο αντικείμενα που αποθηκεύονται χρησιμοποιώντας ένα άλλο αντικείμενο, κι αυτό είναι όλο.

Λεξικό(Dictionary)
Ένα λεξικό είναι σαν ένα τηλεφωνικό κατάλογο όπου μπορείτε να βρείτε τη διεύθυνση ή να φέρετε σε επαφή λεπτομέρειες για ένα άτομο, γνωρίζοντας μόνο το όνομά του/της δηλ. συσχετίζουμε κλειδιά (ονομασία) με τιμές(λεπτομέρειες). Σημειώστε ότι μπορείτε να χρησιμοποιήσετε μόνο αμετάβλητα αντικείμενα (όπως συμβολοσειρές) για τα κλειδιά του λεξικού, αλλά μπορείτε να χρησιμοποιήσετε είτε αμετάβλητα είτε μεταβλητά αντικείμενα για τις τιμές του λεξικού. Αυτό κυρίως ερμηνεύει για να πει ότι πρέπει να χρησιμοποιείτε μόνο απλά αντικείμενα για κλειδιά.
Ζευγάρια κλειδιών και τιμών καθορίζονται στο λεξικό χρησιμοποιώντας το συμβολισμό d = {key1 : value1, key2 : value2 }. Παρατηρήστε ότι τα ζευγάρια κλειδί-τιμή διαχωρίζονται με διπλή τελεία και τα ζευγάρια διαχωρίζονται μεταξύ τους με κόμματα και όλα αυτά περικλείονται σε ένα ζευγάρι { }.
Θυμηθείτε ότι τα ζευγάρια κλειδί-τιμή σε ένα λεξικό δεν εντέλλονται με κανένα τρόπο. Αν θέλετε μια ειδική εντολή, τότε πρέπει να τα ταξινομήσετε από μόνοι σας πριν τα χρησιμοποιήσετε. Τα λεξικά που θα χρησιμοποιείτε είναι υποστάσεις/αντικείμενα της τάξης dict.

Παράδειγμα:
#!/usr/bin/python
# Filename: using_dict.py
# 'ab' is short for 'a'ddress'b'ook
ab = { 'Swaroop' : 'swaroop@swaroopch.com',
'Larry' : 'larry@wall.org',
'Matsumoto' : 'matz@ruby-lang.org',
'Spammer' : 'spammer@hotmail.com'
}
print("Swaroop's address is", ab['Swaroop'])
# Deleting a key-value pair
del ab['Spammer']
print('\nThere are {0} contacts in the address-book\n'.format(len(ab)))
for name, address in ab.items():
print('Contact {0} at {1}'.format(name, address))
# Adding a key-value pair
ab['Guido'] = 'guido@python.org'
if 'Guido' in ab: # OR ab.has_key('Guido')
print("\nGuido's address is", ab['Guido'])

Έξοδος:
$ python using_dict.py
Swaroop's address is swaroop@swaroopch.com
There are 3 contacts in the address-book
Contact Swaroop at swaroop@swaroopch.com
Contact Matsumoto at matz@ruby-lang.org
Contact Larry at larry@wall.org
Guido's address is guido@python.org

Πως δουλεύει:
Δημιουργούμε το λεξικό ab χρησιμοποιώντας το συμβολισμό που ήδη συζητήσαμε. Τότε εισάγουμε ζευγάρια κλειδί-τιμή καθορίζοντας το κλειδί,χρησιμοποιώντας τον τελεστή ευρετηρίασης(indexing operator) όπως συζητήθηκε στο απόσπασμα των λιστών και πλειάδων. Παρατηρήστε την απλή σύνταξη.
Μπορούμε να διαγράψουμε τα ζευγάρια κλειδί-τιμή χρησιμοποιώντας τον παλιό μας φίλο, την εντολή del. Eμείς απλά καθορίζουμε το λεξικό και ο τελεστής ευρετηρίασης για το κλειδί να μετακινηθεί και το περνάει στην εντολή del. Δεν είναι αναγκαίο να γνωρίζει την τιμή που αντιστοιχεί στο κλειδί για αυτή τη λειτουργία.
Έπειτα, εισάγουμε κάθε ζευγάρι κλειδί-τιμή του λεξικού χρησιμοποιώντας τη μέθοδο στοιχείων του λεξικού, η οποία επιστρέφει μια λίστα πλειάδων, όπου κάθε πλειάδα περιέχει ένα ζευγάρι στοιχείων- το κλειδί ακολουθείται από την τιμή. Ανακτούμε αυτό το ζευγάρι και το εκχωρούμε στις μεταβλητές name(ονομασία) και address(διεύθυνση), αντιστοίχως για κάθε ζευγάρι, χρησιμοποιώντας το βρόχο for...in και μετά τυπώνει αυτές τις τιμές στην πλοκάδα.
Μπορούμε να προσθέσουμε νέα ζευγάρια κλειδί-τιμή, απλά χρησιμοποιώντας τον τελεστή ευρετηρίασης, για να εισάγουμε ένα κλειδί και να εκχωρήσουμε τιμή, όπως έχουμε κάνει για το Guido στην ανωτέρω περίπτωση. Μπορούμε να ελέγξουμε εάν ένα ζευγάρι κλειδί-τιμή υπάρχει, χρησιμοποιώντας τον τελεστή in, ή ακόμα και τη μέθοδο has_key της τάξης dict. Μπορείτε να δείτε την τεκμηρίωση για ολόκληρη τη λίστα των μεθόδων της τάξης dict χρησιμοποιώντας τη help(dict).

Ορίσματα με λέξεις κλειδιά και λεξικά
Σε μια διαφορετική νότα, εάν έχετε χρησιμοποιήσει ορίσματα με λέξεις κλειδιά στις συναρτήσεις σας, τότε έχετε ήδη χρησιμοποιήσει λεξικά! Σκεφτείτε μόνο αυτό, το ζευγάρι κλειδί-τιμή καθορίζεται από εσάς στη λίστα της παραμέτρου του ορισμού της συνάρτησης και όταν εισάγετε μεταβλητές μέσα στη συνάρτησή σας, αυτό είναι είσοδος κλειδιού ενός λεξικού(που ονομάζεται συμβολοπίνακας στην ορολογία του σχεδιαστικού μεταγλωττιστή.


ubuntu 9.10 (AMD64),Innovator desktop, motherboard MSI K8N NEO4-F,cpu AMD ATHLON64 3500+ 2.20GHz,ram 1GHz, καρτα γραφ.GIGABYTE GEFORCE 6600 256MB,καρτα τηλεορ.κ radio FM PROLINK PIXELVIEW PLAYTV PRO/ΑΓΓΛΙΚΑ-ΚΑΛΑ/ΓΝΩΣΕΙΣ ΠΡΟΓΡ.-ΚΑΘΟΛΟΥ.
dimosfire
babeTUX
babeTUX
 
Δημοσιεύσεις: 141
Εγγραφή: 02 Φεβ 2009, 11:07
Τοποθεσία: ΠΑΤΡΑ
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό chrish » 30 Μάιος 2009, 16:15

Καλησπέρα...!!
Ξεκίνησα το κεφάλαιο 17 και ελπίζω μέχρι το βράδυ να το έχω τελιώσει και να ξεκινήσω το 18...πριν ξεκινήσω το 18 εννοείτε πως θα φέρω εδώ το 17
Linux: Λίγο ┃ Προγραμματισμός: Μέτριο ┃ Αγγλικά: Πολύ Καλά
Kubuntu 9.04
CPU: P4 3.2GHz ┃ RAM: 512MB/400Hz ┃ NVIDIA 7100GS 512MB AGP ┃ 2xIDE HDD 80GB ┃ PCTV USB2 pinnacle
Άβαταρ μέλους
chrish
babeTUX
babeTUX
 
Δημοσιεύσεις: 25
Εγγραφή: 16 Μάιος 2009, 07:48
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό dimosfire » 01 Ιουν 2009, 01:04

Καλησπέρα παιδιά, υποβάλω το δεύτερο μισό του κεφαλαίου 11 (δομές δεδομένων) και αναλαμβάνω και το 14 (είσοδος έξοδος).
Κώδικας: Επιλογή όλων
Sequences
Lists, tuples and strings are examples of sequences, but what are sequences and what is so
special about them?
The major features is that they have membership tests (i.e. the in and not in expressions)
and indexing operations. The indexing operation which allows us to fetch a particular item
in the sequence directly.
The three types of sequences mentioned above - lists, tuples and strings, also have a
slicing operation which allows us to retrieve a slice of the sequence i.e. a part of the
sequence.
Example:
#!/usr/bin/python
# Filename: seq.py
shoplist = ['apple', 'mango', 'carrot', 'banana']
name = 'swaroop'
# Indexing or 'Subscription' operation
print('Item 0 is', shoplist[0])
print('Item 1 is', shoplist[1])
print('Item 2 is', shoplist[2])
print('Item 3 is', shoplist[3])
print('Item -1 is', shoplist[-1])
print('Item -2 is', shoplist[-2])
print('Character 0 is', name[0])
# Slicing on a list
print('Item 1 to 3 is', shoplist[1:3])
print('Item 2 to end is', shoplist[2:])
print('Item 1 to -1 is', shoplist[1:-1])
print('Item start to end is', shoplist[:])
# Slicing on a string
print('characters 1 to 3 is', name[1:3])
print('characters 2 to end is', name[2:])
print('characters 1 to -1 is', name[1:-1])
print('characters start to end is', name[:])
Output:
$ python seq.py
Item 0 is apple
Item 1 is mango
Item 2 is carrot
Item 3 is banana
Item -1 is banana
Item -2 is carrot
Character 0 is s
Item 1 to 3 is ['mango', 'carrot']
Item 2 to end is ['carrot', 'banana']
Item 1 to -1 is ['mango', 'carrot']
Item start to end is ['apple', 'mango', 'carrot', 'banana']
characters 1 to 3 is wa
characters 2 to end is aroop
characters 1 to -1 is waroo
characters start to end is swaroop
How It Works:
First, we see how to use indexes to get individual items of a sequence. This is also referred
to as the subscription operation. Whenever you specify a number to a sequence within
square brackets as shown above, Python will fetch you the item corresponding to that
position in the sequence. Remember that Python starts counting numbers from 0. Hence,
shoplist[0] fetches the first item and shoplist[3] fetches the fourth item in the
shoplist sequence.
The index can also be a negative number, in which case, the position is calculated from the
end of the sequence. Therefore, shoplist[-1] refers to the last item in the sequence and
shoplist[-2] fetches the second last item in the sequence.
The slicing operation is used by specifying the name of the sequence followed by an
optional pair of numbers separated by a colon within square brackets. Note that this is very
similar to the indexing operation you have been using till now. Remember the numbers are
optional but the colon isn't.
The first number (before the colon) in the slicing operation refers to the position from
where the slice starts and the second number (after the colon) indicates where the slice will
stop at. If the first number is not specified, Python will start at the beginning of the
sequence. If the second number is left out, Python will stop at the end of the sequence.
Note that the slice returned starts at the start position and will end just before the end
position i.e. the start position is included but the end position is excluded from the
sequence slice.
Thus, shoplist[1:3] returns a slice of the sequence starting at position 1, includes
position 2 but stops at position 3 and therefore a slice of two items is returned. Similarly,
shoplist[:] returns a copy of the whole sequence.
You can also do slicing with negative positions. Negative numbers are used for positions
from the end of the sequence. For example, shoplist[:-1] will return a slice of the
sequence which excludes the last item of the sequence but contains everything else.
You can also provide a third argument for the slice, which is the step for the slicing (by
default, the step size is 1):
>>> shoplist = ['apple', 'mango', 'carrot', 'banana']
>>> shoplist[::1]
['apple', 'mango', 'carrot', 'banana']
>>> shoplist[::2]
['apple', 'carrot']
>>> shoplist[::3]
['apple', 'banana']
>>> shoplist[::-1]
['banana', 'carrot', 'mango', 'apple']
Notice that when the step is 2, we get the items with position 0, 2, ... When the step size is
3, we get the items with position 0, 3, etc.
Try various combinations of such slice specifications using the Python interpreter
interactively i.e. the prompt so that you can see the results immediately. The great thing
about sequences is that you can access tuples, lists and strings all in the same way!
Set
Sets are unordered collections of simple objects. These are used when the existence of an
object in a collection is more important than the order or how many times it occurs.
Using sets, you can test for membership, whether it is a subset of another set, find the
intersection between two sets, and so on.
>>> bri = set(['brazil', 'russia', 'india'])
>>> 'india' in bri
True
>>> 'usa' in bri
False
>>> bric = bri.copy()
>>> bric.add('china')
>>> bric.issuperset(bri)
True
>>> bri.remove('russia')
>>> bri & bric # OR bri.intersection(bric)
{'brazil', 'india'}
How It Works:
The example is pretty much self-explanatory because it involves basic set theory
mathematics taught in school.
References
When you create an object and assign it to a variable, the variable only refers to the object
and does not represent the object itself! That is, the variable name points to that part of
your computer's memory where the object is stored. This is called as binding of the name
to the object.
Generally, you don't need to be worried about this, but there is a subtle effect due to
references which you need to be aware of:
Example:
#!/usr/bin/python
# Filename: reference.py
print('Simple Assignment')
shoplist = ['apple', 'mango', 'carrot', 'banana']
mylist = shoplist # mylist is just another name pointing to the same
object!
del shoplist[0] # I purchased the first item, so I remove it from the
list
print('shoplist is', shoplist)
print('mylist is', mylist)
# notice that both shoplist and mylist both print the same list without
# the 'apple' confirming that they point to the same object
print('Copy by making a full slice')
mylist = shoplist[:] # make a copy by doing a full slice
del mylist[0] # remove first item
print('shoplist is', shoplist)
print('mylist is', mylist)
# notice that now the two lists are different
Output:
$ python reference.py
Simple Assignment
shoplist is ['mango', 'carrot', 'banana']
mylist is ['mango', 'carrot', 'banana']
Copy by making a full slice
shoplist is ['mango', 'carrot', 'banana']
mylist is ['carrot', 'banana']
How It Works:
Most of the explanation is available in the comments.
Remember that if you want to make a copy of a list or such kinds of sequences or complex
objects (not simple objects such as integers), then you have to use the slicing operation to
make a copy. If you just assign the variable name to another name, both of them will refer
to the same object and this could be trouble if you are not careful.
Note for Perl programmers
Remember that an assignment statement for lists does not create a copy. You have to
use slicing operation to make a copy of the sequence.
More About Strings
We have already discussed strings in detail earlier. What more can there be to know? Well,
did you know that strings are also objects and have methods which do everything from
checking part of a string to stripping spaces!
The strings that you use in program are all objects of the class str. Some useful methods of
this class are demonstrated in the next example. For a complete list of such methods, see
help(str).
Example:
#!/usr/bin/python
# Filename: str_methods.py
name = 'Swaroop' # This is a string object
if name.startswith('Swa'):
print('Yes, the string starts with "Swa"')
if 'a' in name:
print('Yes, it contains the string "a"')
if name.find('war') != -1:
print('Yes, it contains the string "war"')
delimiter = '_*_'
mylist = ['Brazil', 'Russia', 'India', 'China']
print(delimiter.join(mylist))
Output:
$ python str_methods.py
Yes, the string starts with "Swa"
Yes, it contains the string "a"
Yes, it contains the string "war"
Brazil_*_Russia_*_India_*_China
How It Works:
Here, we see a lot of the string methods in action. The startswith method is used to find
out whether the string starts with the given string. The in operator is used to check if a
given string is a part of the string.
The find method is used to do find the position of the given string in the string or returns
-1 if it is not successful to find the substring. The str class also has a neat method to join
the items of a sequence with the string acting as a delimiter between each item of the
sequence and returns a bigger string generated from this.
Summary
We have explored the various built-in data structures of Python in detail. These data
structures will be essential for writing programs of reasonable size.
Now that we have a lot of the basics of Python in place, we will next see how to design and
write a real-world Python program.

και η μετάφρασή του
Κώδικας: Επιλογή όλων
Ακολουθίες (Sequences)
Οι λίστες, οι πλειάδες και οι συμβολοσειρές είναι παραδείγματα ακολουθιών, αλλά τι είναι οι ακολουθίες και τι το ιδιαίτερο με αυτές;
Tα κυρίαρχα χαρακτηριστικά είναι ότι έχουν δοκιμές ένταξης (membership tests) (δηλ. τις εκφράσεις in και not in) και λειτουργίες ευρετηρίασης (indexing operations). H λειτουργία ευρετηρίασης μας επιτρέπει να κάνουμε μετάκληση ενός ιδιαίτερου στοιχείου στην ακολουθία απευθείας.
Οι τρεις τύποι ακολουθιών που αναφέρθηκαν παραπάνω, λίστες, πλειάδες και συμβολοσειρές έχουν επίσης μια λειτουργία τεμαχισμού (slicing operation), που μας επιτρέπει να ανακτούμε ένα μέρος (slice) της ακολουθίας.

Παράδειγμα:
#!/usr/bin/python
# Filename: seq.py

shoplist = ['apple', 'mango', 'carrot', 'banana']
name = 'swaroop'

# Indexing or 'Subscription' operation
print('Item 0 is', shoplist[0])
print('Item 1 is', shoplist[1])
print('Item 2 is', shoplist[2])
print('Item 3 is', shoplist[3])
print('Item -1 is', shoplist[-1])
print('Item -2 is', shoplist[-2])
print('Character 0 is', name[0])

# Slicing on a list
print('Item 1 to 3 is', shoplist[1:3])
print('Item 2 to end is', shoplist[2:])
print('Item 1 to -1 is', shoplist[1:-1])
print('Item start to end is', shoplist[:])

# Slicing on a string
print('characters 1 to 3 is', name[1:3])
print('characters 2 to end is', name[2:])
print('characters 1 to -1 is', name[1:-1])
print('characters start to end is', name[:]

Έξοδος:
$ python seq.py
Item 0 is apple
Item 1 is mango
Item 2 is carrot
Item 3 is banana
Item -1 is banana
Item -2 is carrot
Character 0 is s
Item 1 to 3 is ['mango', 'carrot']
Item 2 to end is ['carrot', 'banana']
Item 1 to -1 is ['mango', 'carrot']
Item start to end is ['apple', 'mango', 'carrot', 'banana']
characters 1 to 3 is wa
characters 2 to end is aroop
characters 1 to -1 is waroo
characters start to end is swaroop

Πως δουλεύει:
Αρχικά βλέπουμε πως να χρησιμοποιούμε ευρετήρια για να παίρνουμε μοναδικά στοιχεία της ακολουθίας. Αυτό αναφέρεται επίσης σαν δανειστική λειτουργία (subscription operation). Οποτεδήποτε καθορίζεις ένα νούμερο σε μια ακολουθία μέσα σε αγκύλες,όπως φαίνεται παραπάνω, η Python θα κάνει μετάκληση του στοιχείου που αντιστοιχεί σε αυτή τη θέση στην ακολουθία. Θυμηθείτε ότι η Python αρχει να μετράει τα νούμερα από το μηδέν. Για αυτό το λόγο η shoplist[0] κάνει μετάκληση του πρώτου στοιχείου και η shoplist[3] κάνει ματάκληση του τέταρτου στοιχείου στην ακολουθία shoplist.
Το ευρετήριο μπορεί να είναι ένας αρνητικός αριθμός, στην οποία περίπτωση, η θέση υπολογίζεται από το τέλος της ακολουθίας. Έτσι, η shoplist[-1] αναφέρεται στο τελευταίο στοιχείο στην ακολουθία και η shoplist[-2] κάνει μετάκληση του δεύτερου από το τέλος στοιχείου στην ακολουθία.
Η λειτουργία τεμαχισμού χρησιμοποιείται καθορίζοντας την ονομασία της ακολουθίας, ακολουθούμενη από ένα προαιρετικό ζευγάρι αριθμών, που διαχωρίζονται από διπλή τελεία μέσα σε αγκύλες. Σημειώστε ότι αυτό είναι παρόμοιο με τη λειτουργία ευρετηρίασης, που έχει χρησιμοποιηθεί μέχρι τώρα. Θυμηθείτε ότι τα νούμερα είναι προαιρετικά αλλά η διπλή τελεία δεν είναι.
Το πρώτο νούμερο (πριν από τη διπλή τελεία) στη λειτουργία τεμαχισμού αναφέρεται στη θέση από όπου το τμήμα (slice) αρχίζει και το δεύτερο νούμερο (μετά τη διπλή τελεία) δείχνει που θα σταματήσει το τμήμα. Εάν δεν καθορίζεται το πρώτο νούμερο, η Python θα αρχίσει στην αρχή της ακολουθίας. Εάν το δεύτερο νούμερο παραλήφθηκε, η Python θα σταματήσει στο τέλος της ακολουθίας. Σημειώστε ότι το τμήμα επέστρεψε starts στην αρχική θέση και θα τελειώσει ακριβώς πριν από τη θέση end, δηλ. η αρχική θέση περιλαμβάνεται αλλά η τελική θέση αποκλείεται από το τμήμα της ακολουθίας. Έτσι η shoplist[1:3] επιστρέφει ένα τμήμα της ακολουθίας αρχίζοντας στη θέση 1, περιλαμβάνει τη θέση 2, αλλά σταματάει στη θέση 3, συνεπώς, ένα τμήμα δύο αντικειμένων επιστρέφεται. Παρόμοια, η shoplist[:] επιστρέφει ένα αντίγραφο όλης της ακολουθίας.
Μπορείτε επίσης να κάνετε τεμαχισμό με αρνητικές θέσεις. Οι αρνητικοί αριθμοί χρησιμοποιούνται για θέσεις από το τέλος της ακολουθίας. Για παράδειγμα, η shoplist[:-1] θα επιστρέψει ένα τμήμα της ακολουθίας η οποία παραλείπει το τελευταίο στοιχείο της ακολουθίας, αλλά περιέχει κάθε άλλο. Μπορείτε επίσης να δώσετε ένα τρίτο όρισμα για το τμήμα, το οποίο είναι το βήμα (step) για τον τεμαχισμό (από προεπιλογή το μέγεθος βήματος είναι 1):
>>> shoplist = ['apple', 'mango', 'carrot', 'banana']
>>> shoplist[::1]
['apple', 'mango', 'carrot', 'banana']
>>> shoplist[::2]
['apple', 'carrot']
>>> shoplist[::3]
['apple', 'banana']
>>> shoplist[::-1]
['banana', 'carrot', 'mango', 'apple']
Παρατηρήστε ότι όταν το βήμα είναι 2, παίρνουμε τα στοιχεία με θέση 0, 2, ...Όταν το μέγεθος βήματος είναι 3, παίρνουμε τα στοιχεία με θέση 0, 3, κ.τ.λ.
Δοκιμάστε διάφορους συνδυασμούς από τέτοιους προσδιορισμούς τμημάτων, χρησιμοποιώντας το διερμηνευτή Python αλληλεπιδραστικά, δηλ. την προτροπή (prompt) έτσι ώστε να μπορείτε να δείτε τα αποτελέσματα αμέσως. Το σπουδαίο θέμα με τις ακολουθίες είναι ότι μπορείτε να εισάγετε πλειάδες, λίστες και συμβολοσειρές όλες με τον ίδιο τρόπο.


Σύνολο (Set)
Τα σύνολα είναι μη διατεταγμένες συλλογές απλών αντικεινένων. Αυτά χρησιμοποιούνται όταν η ύπαρξη ενός αντικειμένου σε μια συλλογή είναι πιο σπουδαία από την εντολή ή πόσες φορές αυτή συμβαίνει. Χρησιμοποιώντας τα σύνολα, μπορείτε να ελέγξετε για ένταξη (membership), εάν είναι ένα υποσύνολο (subset) ενός άλλου συνόλου, να βρείτε την τομή (intersection) ανάμεσα σε δύο σύνολα και ούτω καθεξής.

>>> bri = set(['brazil', 'russia', 'india'])
>>> 'india' in bri
True
>>> 'usa' in bri
False
>>> bric = bri.copy()
>>> bric.add('china')
>>> bric.issuperset(bri)
True
>>> bri.remove('russia')
>>> bri & bric # OR bri.intersection(bric)
{'brazil', 'india'}

Πως δουλεύει:
To παράδειγμα εξηγείται από μόνο του, διότι περιλαμβάνει βασική θεωρία μαθηματικών συνόλων που διδάσκεται στο σχολείο.


Παραπομπές (References)
Όταν δημιουργείτε ένα αντικείμενο και το εκχωρείτε σε μια μεταβλητή, μόνον η μεταβλητή παραπέμπει στο αντικείμενο και δεν αντιπροσωπεύει το αντικείμενο τον εαυτό του.H ονομασία της μεταβλητής δείχνει σε αυτό το σημείο της μνήμης του υπολογιστή, που αποθηκεύεται το αντικείμενο. Αυτό ονομάζεται συσχέτιση (binding) της ονομασίας με το αντικείμενο. Γενικά δεν πρέπει να ανησυχείτε για αυτό, αλλά υπάρχει μια λεπτή επίδραση εξαιτίας των παραπομπών την οποία πρέπει να αντιληφθείτε.

Παράδειγμα:
#!/usr/bin/python
# Filename: reference.py

print('Simple Assignment')
shoplist = ['apple', 'mango', 'carrot', 'banana']
mylist = shoplist # mylist είναι ακόμα μια ονομασία που δείχνει στο ίδιο αντικείμενο !

del shoplist[0] #Αγόρασα το πρώτο στοιχείο κι έτσι το μετακίνησα από τη λίστα

print('shoplist is', shoplist)
print('mylist is', mylist)
# παρατηρήστε ότι και τα δύο shoplist και mylist τυπώνουν την ίδια λίστα χωρίς
# το 'apple' επιβεβαιώνοντας ότι δείχνουν στο ίδιο αντικείμενο

print('Copy by making a full slice')
mylist = shoplist[:] # φτιάξε ένα αντίγραφο κάνοντας ένα πλήρες τμήμα
del mylist[0] # μετακίνησε το πρώτο στοιχείο

print('shoplist is', shoplist)
print('mylist is', mylist)
# παρατηρήστε ότι τώρα οι δύο λίστες είναι διαφορετικές

Έξοδος:
$ python reference.py
Simple Assignment
shoplist is ['mango', 'carrot', 'banana']
mylist is ['mango', 'carrot', 'banana']
Copy by making a full slice
shoplist is ['mango', 'carrot', 'banana']
mylist is ['carrot', 'banana']

Πως δουλεύει:
Το μεγαλύτερο μέρος της εξήγησης είναι διαθέσιμο στα σχόλια. Θυμηθείτε ότι εάν θέλετε να φτιάξετε ένα αντίγραφο μιας λίστας, ή τέτοιου είδους ακολουθίες, ή σύμπλοκα αντικείμενα (όχι απλά αντικείμενα όπως ακέραιους αριθμούς), τότε πρέπει να χρησιμοποιήσετε τη λειτουργία τεμαχισμού για να φτιάξετε αντίγραφο. Εάν εκχωρείτε την ονομασία της μεταβλητής σε μια άλλη ονομασία, τότε και οι δυο τους θα παραπέμπουν στο ίδιο αντικείμενο και αυτό θα μπορούσε να είναι πρόβλημα για σας, εάν δεν είστε προσεκτικοί.

Σημείωση για τους προγραμματιστές της Perl
Θυμηθείτε ότι μια εντολή εκχώρησης για λίστες δεν δημιουργεί αντίγραφο. Πρέπει να χρησιμοποιήσεις τη λειτουργία τεμαχισμού για να φτιάξεις αντίγραφο της ακολουθίας.


Περισσότερα για τις συμβολοσειρές
Έχουμε ήδη συζητήσει νωρίτερα για τις συμβολοσειρές (strings) λεπτομερώς. Όμως τι περισσότερο μπορούμε να μάθουμε; Λοιπόν, γνωρίζατε ότι οι συμβολοσειρές είναι επίσης αντικείμενα που κάνουν τα πάντα, από τον έλεγχο του τμήματος μιας συμβολοσειράς μέχρι απογύμνωση χώρων.
Οι συμβολοσειρές που χρησιμοποιείς στο πρόγραμμα είναι όλες αντικείμενα της κλάσης str. Μερικές χρήσιμες μεθόδοι της τάξης παρουσιάζονται στο επόμενο παράδειγμα. Για μια ολοκληρωμένη λίστα τέτοιων μεθόδων, κοιτάξτε τη help(str).

Παράδειγμα:
#!/usr/bin/python
# Filename: str_methods.py

name = 'Swaroop' # Αυτή είναι μια συμβολοσειρά αντικείμενο

if name.startswith('Swa'):
print('Yes, the string starts with "Swa"')

if 'a' in name:
print('Yes, it contains the string "a"')

if name.find('war') != -1:
print('Yes, it contains the string "war"')

delimiter = '_*_'
mylist = ['Brazil', 'Russia', 'India', 'China']
print(delimiter.join(mylist))

Έξοδος:
$ python str_methods.py
Yes, the string starts with "Swa"
Yes, it contains the string "a"
Yes, it contains the string "war"
Brazil_*_Russia_*_India_*_China

Πως δουλεύει:
Eδώ βλέπουμε πολλές μεθόδους της συμβολοσειράς σε ενέργεια. Η μέθοδος startswith χρησιμοποιείτε για να ανακαλύψουμε αν η συμβολοσειρά αρχίζει με τη δοθείσα συμβολοσειρά. Ο τελεστής in χρησιμοποιείται για να ελέγξει αν η δοθείσα συμβολοσειρά είναι μέρος της συμβολοσειράς. Η μέθοδος find χρησιμοποιείται για να ανακαλύψει τη θέση της δοθείσας συμβολοσειράς στη συμβολοσειρά ή επιστρέφει -1 εάν δεν επιτύχει την ανακάλυψη της υποσυμβολοσειράς (substring). Η κλάση str επίσης έχει μια καθαρή μέθοδο για να ενώνει (join) τα στοιχεία μιας ακολουθίας με τη συμβολοσειρά, ενεργώντας σαν διαχωριστικό (delimiter) ανάμεσα σε κάθε στοιχείο της ακολουθίας και επιστρέφει μια μεγαλύτερη συμβολοσειρά γεννημένη από αυτό.

Σύνοψη
Έχουμε διερευνήσει τις διάφορες ενσωματωμένες δομές δεδομένων της Python με λεπτομέρεια. Αυτές οι δομές δεδομένων θα είναι απαραίτητες για τη συγγραφή προγραμμάτων σε λογικό μέγεθος. Τώρα που έχουμε πολλά από τα βασικά της Python επίκαιρα, θα δούμε πως να σχεδιάζουμε και να γράφουμε ένα πρόγραμμα Python, στον πραγματικό κόσμο.




ubuntu 9.10 (AMD64),Innovator desktop, motherboard MSI K8N NEO4-F,cpu AMD ATHLON64 3500+ 2.20GHz,ram 1GHz, καρτα γραφ.GIGABYTE GEFORCE 6600 256MB,καρτα τηλεορ.κ radio FM PROLINK PIXELVIEW PLAYTV PRO/ΑΓΓΛΙΚΑ-ΚΑΛΑ/ΓΝΩΣΕΙΣ ΠΡΟΓΡ.-ΚΑΘΟΛΟΥ.
dimosfire
babeTUX
babeTUX
 
Δημοσιεύσεις: 141
Εγγραφή: 02 Φεβ 2009, 11:07
Τοποθεσία: ΠΑΤΡΑ
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό dimosfire » 03 Ιουν 2009, 18:52

Συνεχίζοντας τη μετάφραση υποβάλλω για έλεγχο το κεφάλαιο 14 και θα αναλάβω και το κεφάλαιο 15 (Εξαιρέσεις):

Κώδικας: Επιλογή όλων
Introduction

There will be situations where your program has to interact with the user. For example, you would want to take input from the user and then print some results back. We can achieve this using the input() and print() functions respectively.

For output, we can also use the various methods of the str (string) class. For example, you can use the rjust method to get a string which is right justified to a specified width. See help(str) for more details.

Another common type of input/output is dealing with files. The ability to create, read and write files is essential to many programs and we will explore this aspect in this chapter.
Input from user

#!/usr/bin/python
# user_input.py

def reverse(text):
return text[::-1]

def is_palindrome(text):
return text == reverse(text)

something = input('Enter text: ')
if (is_palindrome(something)):
print("Yes, it is a palindrome")
else:
print("No, it is not a palindrome")

Output:

$ python user_input.py
Enter text: sir
No, it is not a palindrome

$ python user_input.py
Enter text: madam
Yes, it is a palindrome

$ python user_input.py
Enter text: racecar
Yes, it is a palindrome

How It Works:

We use the slicing feature to reverse the text. We've already seen how we can make slices from sequences using the seq[a:b] code starting from position a to position b. We can also provide a third argument that determines the step by which the slicing is done. The default step is 1 because of which it returns a continuous part of the text. Giving a negative step, i.e., -1 will return the text in reverse.

The input() function takes a string as argument and displays it to the user. Then it waits for the user to type something and press the return key. Once the user has entered, the input() function will then return that text.

We take that text and reverse it. If the original text and reversed text are equal, then the text is a palindrome.

Homework exercise:

Checking whether a text is a palindrome should also ignore punctuation, spaces and case. For example, "Rise to vote, sir." is also a palindrome but our current program doesn't say it is. Can you improve the above program to recognize this palindrome?
Files

You can open and use files for reading or writing by creating an object of the file class and using its read, readline or write methods appropriately to read from or write to the file. The ability to read or write to the file depends on the mode you have specified for the file opening. Then finally, when you are finished with the file, you call the close method to tell Python that we are done using the file.

Example:

#!/usr/bin/python
# Filename: using_file.py

poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''

f = open('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file

f = open('poem.txt') # if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print(line, end='')
f.close() # close the file

Output:

$ python using_file.py
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!

How It Works:

First, open a file by using the built-in open function and specifying the name of the file and the mode in which we want to open the file. The mode can be a read mode ('r'), write mode ('w') or append mode ('a'). We can also by dealing with a text file ('t') or a binary file ('b'). There are actually many more modes available and help(open) will give you more details about them. By default, open() considers the file to be a 't'ext file and opens it in 'r'ead mode.

In our example, we first open the file in write text mode and use the write method of the file object to write to the file and then we finally close the file.

Next, we open the same file again for reading. We don't need to specify a mode because 'read text file' is the default mode. We read in each line of the file using the readline method in a loop. This method returns a complete line including the newline character at the end of the line. When an empty string is returned, it means that we have reached the end of the file and we 'break' out of the loop.

By deafult, the print() function prints the text as well as an automatic newline to the screen. We are suppressing the newline by specifying end='' because the line that is read from the file already ends with a newline character. Then, we finally close the file.

Now, check the contents of the poem.txt file to confirm that the program has indeed written and read from that file.
Pickle

Python provides a standard module called pickle using which you can store any Python object in a file and then get it back later. This is called storing the object persistently.

Example:

#!/usr/bin/python
# Filename: pickling.py

import pickle

# the name of the file where we will store the object
shoplistfile = 'shoplist.data'
# the list of things to buy
shoplist = ['apple', 'mango', 'carrot']

# Write to the file
f = open(shoplistfile, 'wb')
pickle.dump(shoplist, f) # dump the object to a file
f.close()

del shoplist # destroy the shoplist variable

# Read back from the storage
f = open(shoplistfile, 'rb')
storedlist = pickle.load(f) # load the object from the file
print(storedlist)

Output:

$ python pickling.py
['apple', 'mango', 'carrot']

How It Works:

To store an object in a file, we have to first open the file in 'w'rite 'b'inary mode and then call the dump function of the pickle module. This process is called pickling.

Next, we retrieve the object using the load function of the pickle module which returns the object. This process is called unpickling.
Summary

We have discussed various types of input/output and also file handling and using the pickle module.

Next, we will explore the concept of exceptions.

και η μετάφρασή του:
Κώδικας: Επιλογή όλων
ΕΙΣΟΔΟΣ-ΕΞΟΔΟΣ (Input-output)

Εισαγωγή
Θα υπάρξουν καταστάσεις όπου το πρόγραμμά σας πρέπει να αλλελεπιδράσει με το χρήστη. Για παράδειγμα, θα θέλετε να πάρετε είσοδο από το χρήστη και μετά να τυπώσετε πίσω μερικά αποτελέσματα. Μπορούμε να το επιτύχουμε χρησιμοποιώντας αντίστοιχα τις συναρτήσεις input() και print(). Για έξοδο μπορούμε να χρησιμοποιήσουμε τις διάφορες μεθόδους της κλάσης str (string). Για παράδειγμα μπορείτε να χρησιμοποιήσετε τη μέθοδο rjust για να πάρετε μια συμβολοσειρά, η οποία είναι δεξιά στοιχισμένη (right justified) σε ένα καθορισμένο εύρος. Κοιτάξτε τη help(str) για περισσότερες λεπτομέρειες. Ένας ακόμα συνηθισμένος τύπος εισόδου/εξόδου ασχολείται με τα αρχεία (files). Η ικανότητα να δημιουργείτε, διαβάζετε και να γράφετε αρχεία είναι βασική σε πολλά προγράμματα και θα εξερευνήσουμε αυτή την πτυχή σε αυτό το κεφάλαιο.

Είσοδος από το χρήστη
#!/usr/bin/python
# user_input.py

def reverse(text):
return text[::-1]

def is_palindrome(text):
return text == reverse(text)

something = input('Enter text: ')
if (is_palindrome(something)):
print("Yes, it is a palindrome")
else:
print("No, it is not a palindrome")

Έξοδος:
$ python user_input.py
Enter text: sir
No, it is not a palindrome

$ python user_input.py
Enter text: madam
Yes, it is a palindrome

$ python user_input.py
Enter text: racecar
Yes, it is a palindrome

Πως δουλεύει:
Χρησιμοποιούμε τον τεμαχισμό (κομμάτιασμα) για να αναστρέψουμε το κείμενο. Έχουμε ήδη δει πως μπορούμε να κάνουμε κομμάτια από ακολουθίες, χρησιμοποιώντας τον κώδικα seq[a:b], αρχίζοντας από τη θέση a μέχρι τη θέση b. Μπορούμε επίσης να δώσουμε ένα τρίτο όρισμα το οποίο προσδιορίζει το βήμα με το οποίο έγινε το κομμάτιασμα. Το προκαθορισμένο βήμα είναι το 1 εξαιτίας του οποίου επιστρέφει ένα συνεχές τμήμα του κειμένου. Δίνοντας ένα αρνητικό βήμα δηλ. -1, θα επιστρέψει το κείμενο ανάστροφα.
Η συνάρτηση input() παίρνει μια συμβολοσειρά σαν όρισμα και το παρουσιάζει στον χρήστη.Τότε περιμένει το χρήστη να τυπώσει κάτι και πιέζει το κλειδί επιστροφής (return key). Άπαξ και ο χρήστης έχει εισέλθει, η συνάρτηση input() τότε θα επιστρέψει αυτό το κείμενο. Παίρνουμε αυτό το κείμενο και το αναστρέφουμε. Εάν το αυθεντικό κείμενο και το ανεστραμμένο είναι ίσα, τότε το κείμενο είναι παλίνδρομο (palindrome).

Εργασία για το σπίτι:
Ελέγχοντας εάν ένα κείμενο είναι παλίνδρομο θα έπρεπε επίσης να αγνοεί τη στίξη, τα διαστήματα και τα κεφαλαία. Για παράδειγμα, το κείμενο "Rise to vote, sir" είναι παλίνδρομο, αλλά το τρέχον πρόγραμμά μας δεν το λέει. Μπορείτε να αναπτύξετε το ανωτέρο πρόγραμμα για να το αναγνωρίσει σαν παλίνδρομο;


Αρχεία (Files)
Μπορείτε να ανοίξετε και να χρησιμοποιήσετε αρχεία για διάβασμα ή γράψιμο, δημιουργώντας ένα αντικείμενο της τάξης file και χρησιμοποιώντας τις μεθόδους της, read, readline ή write κατάλληλα για να διαβάσει από ή να γράψει στο αρχείο. Η ικανότητα να διαβάζει ή να γράφει στο αρχείο εξαρτάται από τον τρόπο (mode) που έχετε καθορίσει για το άνοιγμα του αρχείου. Τότε τελικά, όταν τελειώσετε με το αρχείο, καλείτε τη μέθοδο close, να πει στην Python ότι είμαστε έτοιμοι με τη χρήση του αρχείου.

Παράδειγμα:
#!/usr/bin/python
# Filename: using_file.py

poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''

f = open('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file

f = open('poem.txt') # if no mode is specified, 'r'ead mode is assumed by default
while True:
line = f.readline()
if len(line) == 0: # Zero length indicates EOF
break
print(line, end='')
f.close() # close the file

Έξοδος:
$ python using_file.py
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!

Πως δουλεύει:
Αρχικά ανοίγετε ένα αρχείο χρησιμοποιώντας την ενσωματωμένη συνάρτηση open καθορίζοντας την ονομασία του αρχείου και τον τρόπο με τον οποίο θέλουμε να ανοίγει το αρχείο. Ο τύπος μπορεί να είναι με διάβασμα ('r') (read mode), με γράψιμο ('w') (write mode) ή με προσάρτηση ('a') (append mode). Μπορούμε επίσης συσχετίζοντας ένα αρχείο κειμένου ('t') (text file) ή ένα δυαδικό αρχείο ('b') (binary file). Στην πραγματικότητα υπάρχουν πάρα πολλοί τύποι διαθέσιμοι και η help(open) θα σας δώσει περισσότερες λεπτομέρειες γι αυτούς. Προκαθορισμένα η open() θεωρεί το αρχείο ως αρχείο κειμένου ('t'ext file) και το ανοίγει με τον τύπο 'r'ead.
Στο δικό μας παράδειγμα, αρχικά ανοίγουμε το αρχείο σε 'write text mode' και χρησιμοποιούμε τη μέθοδο write του αντικειμένου του αρχείου, για να γράψουμε στο αρχείο και τότε τελικά κλείνουμε (close) το αρχείο. Κατόπιν ανοίγουμε το ίδιο αρχείο πάλι για διάβασμα (reading). Δεν χρειάζεται να καθορίσουμε έναν τύπο, γιατί ο 'read text file' είναι ο προκαθορισμένος τύπος. Διαβάζουμε σε κάθε γραμμή του αρχείου χρησιμοποιώντας τη μέθοδο readline σε βρόχο. Αυτή η μέθοδος επιστρέφει μια ολοκληρωμένη γραμμή περιλαμβάνοντας το χαρακτήρα νέας γραμμής (newline character) στο τέλος της γραμμής. Όταν μια άδεια συμβολοσειρά επιστρέφεται, σημαίνει ότι έχουμε φθάσει στο τέλος του αρχείου και ξεφεύγουμε (break) από το βρόχο. Προκαθορισμένα η συνάρτηση print() τυπώνει το κείμενο καθώς και μια αυτόματη νέα γραμμή (newline) στην οθόνη. Καταστέλλουμε τη νέα γραμμή καθορίζοντας end='', διότι η γραμμή που διαβάζεται από το αρχείο ήδη τελειώνει με ένα χαρακτήρα νέας γραμμής. Τότε, τελικά κλείνουμε (close) το αρχείο.
Τώρα, ελέγξτε τα περιεχόμενα του poem.txt αρχείου, για να επιβεβαιώσετε ότι το πρόγραμμα έχει πραγματικά γραφτεί και διαβαστεί από αυτό το αρχείο.

Pickle
Η Python παρέχει ένα κύριο άρθρθωμα που ονομάζεται pickle και χρησιμοποιώντας το μπορείτε να αποθηκεύετε κάθε αντικείμενο της Python σε ένα αρχείο και αργότερα να το παίρνετε πίσω. Αυτό ονομάζεται αποθήκευση του αντικειμένου επίμονα (persistently).

Παράδειγμα:
#!/usr/bin/python
# Filename: pickling.py

import pickle

# the name of the file where we will store the object
shoplistfile = 'shoplist.data'
# the list of things to buy
shoplist = ['apple', 'mango', 'carrot']

# Write to the file
f = open(shoplistfile, 'wb')
pickle.dump(shoplist, f) # dump the object to a file
f.close()

del shoplist # destroy the shoplist variable

# Read back from the storage
f = open(shoplistfile, 'rb')
storedlist = pickle.load(f) # load the object from the file
print(storedlist)

Έξοδος:
$ python pickling.py
['apple', 'mango', 'carrot']

Πως δουλεύει:
Για να αποθηκεύσουμε ένα αντικείμενο σε ένα αρχείο, πρέπει αρχικά να ανοίξουμε (open) το αρχείο σε 'w'rite 'b'inary mode και μετά καλούμε τη συνάρτηση dump του αρθρώματος pickle. Αυτή η διαδικασία ονομάζεται pickling. Κατόπιν, ανακτούμε το αντικείμενο χρησιμοποιώντας τη συνάρτηση load του αρθρώματος pickle, η οποία επιστρέφει το αντικείμενο. Αυτή η διαδικασία ονομάζεται unpickling.

Σύνοψη
Έχουμε συζητήσει διάφορους τύπους εισόδου/εξόδου, καθώς επίσης διαχείριση αρχείου και χρήση του αρθρώματος pickle. Κατόπιν θα εξερευνήσουμε την έννοια των εξαιρέσεων (exceptions).

ubuntu 9.10 (AMD64),Innovator desktop, motherboard MSI K8N NEO4-F,cpu AMD ATHLON64 3500+ 2.20GHz,ram 1GHz, καρτα γραφ.GIGABYTE GEFORCE 6600 256MB,καρτα τηλεορ.κ radio FM PROLINK PIXELVIEW PLAYTV PRO/ΑΓΓΛΙΚΑ-ΚΑΛΑ/ΓΝΩΣΕΙΣ ΠΡΟΓΡ.-ΚΑΘΟΛΟΥ.
dimosfire
babeTUX
babeTUX
 
Δημοσιεύσεις: 141
Εγγραφή: 02 Φεβ 2009, 11:07
Τοποθεσία: ΠΑΤΡΑ
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό dimosfire » 04 Ιουν 2009, 17:46

Καλησπέρα παιδιά, υποβάλω το κεφάλαιο 15 για έλεγχο:
Κώδικας: Επιλογή όλων
Introduction

Exceptions occur when certain exceptional situations occur in your program. For example, what if you are going to read a file and the file does not exist? Or what if you accidentally deleted it when the program was running? Such situations are handled using exceptions.

Similarly, what if your program had some invalid statements? This is handled by Python which raises its hands and tells you there is an error.
Errors

Consider a simple print function call. What if we misspelt print as Print? Note the capitalization. In this case, Python raises a syntax error.

>>> Print('Hello World')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
Print('Hello World')
NameError: name 'Print' is not defined
>>> print('Hello World')
Hello World

Observe that a NameError is raised and also the location where the error was detected is printed. This is what an error handler for this error does.
Exceptions

We will try to read input from the user. Press ctrl-d and see what happens.

>>> s = input('Enter something --> ')
Enter something -->
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
s = input('Enter something --> ')
EOFError: EOF when reading a line

Python raises an error called EOFError which basically means it found an end of file symbol (which is represented by ctrl-d) when it did not expect to see it.
Handling Exceptions

We can handle exceptions using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block.

#!/usr/bin/python
# Filename: try_except.py

try:
text = input('Enter something --> ')
except EOFError:
print('Why did you do an EOF on me?')
except KeyboardInterrupt:
print('You cancelled the operation.')
else:
print('You entered {0}'.format(text))

Output:

$ python try_except.py
Enter something --> # Press ctrl-d
Why did you do an EOF on me?

$ python try_except.py
Enter something --> # Press ctrl-c
You cancelled the operation.

$ python try_except.py
Enter something --> no exceptions
You entered no exceptions

How It Works:

We put all the statements that might raise exceptions/errors inside the try block and then put handlers for the appropriate errors/exceptions in the except clause/block. The except clause can handle a single specified error or exception, or a parenthesized list of errors/exceptions. If no names of errors or exceptions are supplied, it will handle all errors and exceptions.

Note that there has to be at least one except clause associated with every try clause. Otherwise, what's the point of having a try block?

If any error or exception is not handled, then the default Python handler is called which just stops the execution of the program and prints an error message. We have already seen this in action above.

You can also have an else clause associated with a try..except block. The else clause is executed if no exception occurs.

In the next example, we will also see how to get the exception object so that we can retrieve additional information.
Raising Exceptions

You can raise exceptions using the raise statement by providing the name of the error/exception and the exception object that is to be thrown.

The error or exception that you can arise should be class which directly or indirectly must be a derived class of the Exception class.

#!/usr/bin/python
# Filename: raising.py

class ShortInputException(Exception):
'''A user-defined exception class.'''
def __init__(self, length, atleast):
Exception.__init__(self)
self.length = length
self.atleast = atleast

try:
text = input('Enter something --> ')
if len(text) < 3:
raise ShortInputException(len(text), 3)
# Other work can continue as usual here
except EOFError:
print('Why did you do an EOF on me?')
except ShortInputException as ex:
print('ShortInputException: The input was {0} long, expected at least {1}'\
.format(ex.length, ex.atleast))
else:
print('No exception was raised.')

Output:

$ python raising.py
Enter something --> a
ShortInputException: The input was 1 long, expected at least 3

$ python raising.py
Enter something --> abc
No exception was raised.

How It Works:

Here, we are creating our own exception type. This new exception type is called ShortInputException. It has two fields - length which is the length of the given input, and atleast which is the minimum length that the program was expecting.

In the except clause, we mention the class of error which will be stored as the variable name to hold the corresponding error/exception object. This is analogous to parameters and arguments in a function call. Within this particular except clause, we use the length and atleast fields of the exception object to print an appropriate message to the user.
Try .. Finally

Suppose you are reading a file in your program. How do you ensure that the file object is closed properly whether or not an exception was raised? This can be done using the finally block. Note that you can use an except clause along with a finally block for the same corresponding try block. You will have to embed one within another if you want to use both.

#!/usr/bin/python
# Filename: finally.py

import time

try:
f = open('poem.txt')
while True: # our usual file-reading idiom
line = f.readline()
if len(line) == 0:
break
print(line, end='')
time.sleep(2) # To make sure it runs for a while
except KeyboardInterrupt:
print('!! You cancelled the reading from the file.')
finally:
f.close()
print('(Cleaning up: Closed the file)')

Output:

$ python finally.py
Programming is fun
When the work is done
if you wanna make your work also fun:
!! You cancelled the reading from the file.
(Cleaning up: Closed the file)

How It Works:

We do the usual file-reading stuff, but we have arbitrarily introduced sleeping for 2 seconds after printing each line using the time.sleep function so that the program runs slowly (Python is very fast by nature). When the program is still running, press ctrl-c to interrupt/cancel the program.

Observe that the KeyboardInterrupt exception is thrown and the program quits. However, before the program exits, the finally clause is executed and the file object is always closed.
The with statement

Acquiring a resource in the try block and subsequently releasing the resource in the finally block is a common pattern. Hence, there is also a with statement that enables this to be done in a clean manner:

#!/usr/bin/python
# Filename: using_with.py

with open("poem.txt") as f:
for line in f:
print(line, end='')

How It Works:

The output should be same as the previous example. The difference here is that we are using the open function with the with statement - we leave the closing of the file to be done automatically by with open.

What happens behind the scenes is that there is a protocol used by the with statement. It fetches the object returned by the open statement, let's call it "thefile" in this case.

It always calls the thefile.__enter__ function before starting the block of code under it and always calls thefile.__exit__ after finishing the block of code.

So the code that we would have written in a finally block is should be taken care of automatically by the __exit__ method. This is what helps us to avoid having to use explicit try..finally statements repeatedly.

More discussion on this topic is beyond scope of this book, so please refer PEP 343 for comprehensive explanation.
Summary

We have discussed the usage of the try..except and try..finally statements. We have seen how to create our own exception types and how to raise exceptions as well.

Next, we will explore the Python Standard Library.

και η μετάφρασή του:
Κώδικας: Επιλογή όλων
Εξαιρέσεις (Exceptions)

Εισαγωγή
Οι εξαιρέσεις εμφανίζονται όταν ορισμένες εξαιρετικές καταστάσεις συμβαίνουν στο πρόγραμμά σας. Για παράδειγμα, τι συμβαίνει εάν πρόκειται να διαβάσετε ένα αρχείο και το αρχείο δεν υπάρχει; Ή τι συμβαίνει εάν ατυχώς το διαγράψατε όταν το πρόγραμμα έτρεχε; Τέτοιες καταστάσεις χειρίζονται χρησιμοποιώντας τις εξαιρέσεις. Παρομοίως, τι συμβαίνει εάν το πρόγραμμά σας είχε μερικές άκυρες εντολές; Αυτό το χειρίζεται η Python η οποία σηκώνει τα χέρια της και σας λέει ότι υπάρχει ένα σφάλμα.

Σφάλματα (Errors)
Σκεφτείτε μια απλή print κλήση συνάρτησης. Τι συμβαίνει αν γράψαμε ανορθόγραφα Print αντί για το σωστό print; Παρατηρήστε το κεφαλαίο P αντί για p. Σε αυτή την περίπτωση η Python αναδεικνύει (raises) ένα συντακτικό σφάλμα (syntax error).

>>> Print('Hello World')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
Print('Hello World')
NameError: name 'Print' is not defined
>>> print('Hello World')
Hello World
Παρατηρήστε ότι το NameError αναδυκνείεται καθώς επίσης τυπώνεται και η θέση που ανιχνεύεται το σφάλμα. Αυτό είναι που κάνει ο χειριστής σφάλματος (error handler) για αυτό το σφάλμα.

Εξαιρέσεις
Θα δοκιμάσουμε να διαβάσουμε είσοδο από το χρήστη. Πιέστε ctrl-d και κοιτάξτε τι συμβαίνει.
>>> s = input('Enter something --> ')
Enter something -->
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
s = input('Enter something --> ')
EOFError: EOF when reading a line
Η Python αναδυκνύει ένα σφάλμα, που ονομάζεται EOFError, που βασικά σημαίνει ότι βρήκε ένα σύμβολο end of file (που αντιπροσωπεύεται από το ctrl-d), όταν δεν περιμένει να το δει.

Χειρισμοί με τις εξαιρέσεις (Handling Exceptions)
Μπορούμε να χειριστούμε τις εξαιρέσεις χρησιμοποιώντας την εντολή try...except. Βασικά, τοποθετούμε όλες τις συνήθεις εντολές μέσα στην πλοκάδα try (try-block) και όλους τους χειριστές σφαλμάτων στην πλοκάδα except (except-block).

#!/usr/bin/python
# Filename: try_except.py
 
try:
text = input('Enter something --> ')
except EOFError:
print('Why did you do an EOF on me?')
except KeyboardInterrupt:
print('You cancelled the operation.')
else:
print('You entered {0}'.format(text))
Έξοδος:
$ python try_except.py
Enter something --> # Press ctrl-d
Why did you do an EOF on me?

$ python try_except.py
Enter something --> # Press ctrl-c
You cancelled the operation.

$ python try_except.py
Enter something --> no exceptions
You entered no exceptions
Πως δουλεύει:
Τοποθετούμε όλες τις εντολές, που ίσως αναδεικνύουν εξαιρέσεις/σφάλματα μέσα στην πλοκάδα try και μετά τοποθετούμε τους χειριστές για τα κατάλληλα σφάλματα/εξαιρέσεις στην πρόταση (clause)/πλοκάδα. Η πρόταση except μπορεί να χειριστεί ένα και μόνο καθορισμένο σφάλμα ή εξαίρεση, ή μια λίστα σφαλμάτων/εξαιρέσεων μέσα σε παρένθεση. Εάν δεν παρέχονται καθόλου ονομασίες σφαλμάτων ή εξαιρέσεων, τότε η πρόταση except θα χειριστεί όλες (all) τις εξαιρέσεις και τα σφάλματα.
Σημειώστε ότι πρέπει να υπάρχει τουλάχιστον μια πρόταση except συνδεδεμένη με κάθε πρόταση try. Διαφορετικά για ποιο λόγο να έχετε μια πλοκάδα try;
Εάν οποιοδήποτε σφάλμα ή εξαίρεση δεν χειρίζεται, τότε καλείται ο προκαθορισμένος χειριστής της Python, ο οποίος σταματάει την εκτέλεση του προγράμματος και τυπώνει ένα μήνυμα σφάλματος. Το έχουμε δει ήδη σε ενέργεια παραπάνω.
Μπορείτε επίσης να έχετε μια πρόταση else συνδεδεμένη με μια πλοκάδα try...except. H πρόταση else εκτελείται εάν δεν συμβαίνει καμμία εξαίρεση. Στο επόμενο παράδειγμα θα δούμε επίσης, πως να παίρνουμε το αντικείμενο της εξαίρεσης, έτσι ώστε να μπορούμε να ανακτούμε επιπρόσθετες πληροφορίες.

Ανάδειξη των εξαιρέσεων (Raising Exceptions)
Μπορείτε να αναδείξετε εξαιρέσεις χρησιμοποιώντας την εντολή raise, παρέχοντας την ονομασία του σφάλματος/εξαίρεσης και το αντικείμενο της εξαίρεσης είναι για να ρίχνεται (thrown). Το σφάλμα ή η εξαίρεση που μπορείτε να αναδείξετε, πρέπει να είναι τάξη, η οποία απευθείας ή έμμεσα πρέπει να είναι παράγωγη, της τάξης Exception.

class ShortInputException(Exception):
'''A user-defined exception class.'''
def __init__(self, length, atleast):
Exception.__init__(self)
self.length = length
self.atleast = atleast
 
try:
text = input('Enter something --> ')
if len(text) < 3:
raise ShortInputException(len(text), 3)
# Other work can continue as usual here
except EOFError:
print('Why did you do an EOF on me?')
except ShortInputException as ex:
print('ShortInputException: The input was {0} long, expected at least {1}'\
.format(ex.length, ex.atleast))
else:
print('No exception was raised.')
Έξοδος:
$ python raising.py
Enter something --> a
ShortInputException: The input was 1 long, expected at least 3

$ python raising.py
Enter something --> abc
No exception was raised.
Πως δουλεύει:
Εδώ δημιουργούμε το δικό μας τύπο εξαίρεσης. Αυτός ο νέος τύπος εξαίρεσης ονομάζεται ShortInputException. Έχει δύο πεδία το length, το οποίο είναι το μήκος της δοθείσας εισόδου και το atleast που είναι το ελάχιστο μήκος που το πρόγραμμα περίμενε. Στην πρόταση except, αναφέρουμε την τάξη του σφάλματος η οποία θα αποθηκεύεται σαν το όνομα μεταβλητής, για να συγκρατεί το αντίστοιχο αντικείμενο σφάλματος/εξαίρεσης. Αυτό είναι ανάλογο με τους παραμέτρους και τα ορίσματα σε μια κλήση συνάρτησης. Μέσα σε αυτή την ειδική πρόταση except, χρησιμοποιούμε τα πεδία length και atleast του αντικειμένου της εξαίρεσης, για να τυπώσουμε ένα κανονικό μήνυμα στο χρήστη.


Η εντολή try...finally
Υποθέστε ότι διαβάζετε ένα αρχείο στο πρόγραμμά σας. Πως επιβεβαιώνετε ότι το αντικείμενο του αρχείου έχει κλειστεί κανονικά,είτε η εξαίρεση αναδείχθηκε είτε όχι; Αυτό μπορεί να γίνει χρησιμοποιώντας την πλοκάδα finally. Σημειώστε ότι μπορείτε να χρησιμοποιήσετε μια πρόταση except μαζί με την πλοκάδα finally για την ίδια αντιστοιχούσα πλοκάδα try. Πρέπει να ενσωματώσετε τη μια μέσα στην άλλη, εάν θέλετε να χρησιμοποιήσετε και τις δύο.

#!/usr/bin/python
# Filename: finally.py
 
import time
 
try:
f = open('poem.txt')
while True: # our usual file-reading idiom
line = f.readline()
if len(line) == 0:
break
print(line, end='')
time.sleep(2) # To make sure it runs for a while
except KeyboardInterrupt:
print('!! You cancelled the reading from the file.')
finally:
f.close()
print('(Cleaning up: Closed the file)')

Έξοδος:
$ python finally.py
Programming is fun
When the work is done
if you wanna make your work also fun:
 !! You cancelled the reading from the file.
(Cleaning up: Closed the file)

Πως δουλεύει:
Κάνουμε το σύνηθες διάβασμα αρχείου (file-reading), αλλά αυθαίρετα έχουμε εισάγει “ύπνωση” για 2 δευτερόλεπτα, αφού τυπωθεί η κάθε γραμμή, χρησιμοποιώντας τη συνάρτηση time.sleep έτσι ώστε το πρόγραμμα να τρέχει αργά (η Python από τη φύση της τρέχει πολύ γρήγορα). Όταν το πρόγραμμα τρέχει ακόμα, πιέστε ctrl-c για να διακόψετε/ακυρώσετε το πρόγραμμα.
Παρατηρήστε ότι η εξαίρεση KeyboardInterrupt ρίχνεται και το πρόγραμμα εγκαταλείπεται. Πάντως, πριν το πρόγραμμα εγκαταλειφθεί, η πρόταση finally εκτελείται και το αντικείμενο του αρχείου πάντα κλείνεται.

Η εντολή with (The with statement)
Η απόκτηση ενός πόρου στην πλοκάδα try και ακολούθως η απελευθέρωση του πόρου στην πλοκάδα finally είναι μια συνηθισμένη σχηματομορφή. Γι αυτό το λόγο υπάρχει και η εντολή with, η οποία το κάνει ικανό να γίνει με καθαρό τρόπο:
#!/usr/bin/python
# Filename: using_with.py
 
with open("poem.txt") as f:
for line in f:
print(line, end='')
Πως δουλεύει:
Η έξοδος θα έπρεπε να είναι ίδια με το προηγούμενο παράδειγμα. Η διαφορά εδώ είναι ότι χρησιμοποιούμε τη συνάρτηση open με την εντολή with. Aφήνουμε το κλείσιμο του αρχείου να γίνει αυτόματα με το with open. Αυτό που συμβαίνει πίσω από τη σκηνή είναι ότι υπάρχει ένα πρωτόκολλο που χρησιμοποιείται με την εντολή with. Πιάνει το αντικείμενο που επέστρεψε με την εντολή open και ας το ονομάσουμε “ thefile” σε αυτή την περίπτωση. Πάντα καλεί τη συνάρτηση thefile.__enter__ πριν αρχίσει η πλοκάδα του κώδικα κάτω από αυτό, και πάντα καλεί το thefile.__exit__ , αφού τελειώσει η πλοκάδα του κώδικα. Έτσι ο κώδικας που θα είχαμε γράψει σε μια πλοκάδα finally θα έπρεπε να φροντίζεται αυτόματα από τη μέθοδο __exit__. Αυτό είναι που μας βοηθάει να αποφεύγουμε να χρησιμοποιούμε ρητές εντολές επανειλημμένως.
Περισσότερη συζήτηση για αυτό το θέμα είναι πέρα από το πεδίο αυτού του βιβλίου, έτσι παρακαλώ αναφερθείτε στο PEP343 για πλήρη επεξήγηση.

Σύνοψη
Έχουμε συζητήσει την χρήση των εντολών try...except και try...finally. Έχουμε δει πως να δημιουργούμε τους δικούς μας τύπους εξαιρέσεων και πως να αναδεικνύουμε, επίσης, εξαιρέσεις.
Κατόπιν θα εξερευνήσουμε την πρότυπη βιβλιοθήκη της Python (Python Standard Library).
ubuntu 9.10 (AMD64),Innovator desktop, motherboard MSI K8N NEO4-F,cpu AMD ATHLON64 3500+ 2.20GHz,ram 1GHz, καρτα γραφ.GIGABYTE GEFORCE 6600 256MB,καρτα τηλεορ.κ radio FM PROLINK PIXELVIEW PLAYTV PRO/ΑΓΓΛΙΚΑ-ΚΑΛΑ/ΓΝΩΣΕΙΣ ΠΡΟΓΡ.-ΚΑΘΟΛΟΥ.
dimosfire
babeTUX
babeTUX
 
Δημοσιεύσεις: 141
Εγγραφή: 02 Φεβ 2009, 11:07
Τοποθεσία: ΠΑΤΡΑ
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό dimosfire » 04 Ιουν 2009, 17:58

Θα συνεχίσω στο κεφάλαιο 16 (Πρότυπη βιβλιοθήκη) αν δεν θέλει να το αναλάβει κάποιος άλλος.
ubuntu 9.10 (AMD64),Innovator desktop, motherboard MSI K8N NEO4-F,cpu AMD ATHLON64 3500+ 2.20GHz,ram 1GHz, καρτα γραφ.GIGABYTE GEFORCE 6600 256MB,καρτα τηλεορ.κ radio FM PROLINK PIXELVIEW PLAYTV PRO/ΑΓΓΛΙΚΑ-ΚΑΛΑ/ΓΝΩΣΕΙΣ ΠΡΟΓΡ.-ΚΑΘΟΛΟΥ.
dimosfire
babeTUX
babeTUX
 
Δημοσιεύσεις: 141
Εγγραφή: 02 Φεβ 2009, 11:07
Τοποθεσία: ΠΑΤΡΑ
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό chrish » 05 Ιουν 2009, 00:24

Κατ' άρχην ζητώ συγγνώμη με την απουσία μου μου έτυχε κάτι σοβαρο και δεν μπόρεσα να ασχοληθώ σοβαρά με το θέμα..... έχω κάνει πολύ λίγο απο το κεφάλαιο 16 και το παραθέτω σαν ένα μικρο τμήμα, για τον dimosfire
Κώδικας: Επιλογή όλων
Python el : Περισσότερα

Εισαγωγή
Μέχρι τώρα έχουμε καλύψει την πλειοψηφία των διάφορων πτυχών της Python που θα χρησιμοποιήσετε. Σε αυτό το κεφάλαιο, θα καλύψουμε λίγο περισσότερες πτυχές που θα κάνουν τη γνώση σας στην Python ποίο σφαιρική.

Περνώντας tuples γύρω
Μήπως θα επιθυμούσατε να μπορούσατε να επιστρέψετε δύο διαφορετικές τιμές από μια λειτουργία; Μπορείτε. Το μόνο που πρέπει να κάνετε είναι χρήση μιας tuple.

>>> def get_error_details ():
... return (2, 'second error details')
...
>>> errnum, errstr = get_error_details()
>>> errnum
2
>>> errstr
'second error details'

Παρατηρήστε ότι η χρήση του a, b = <some expression> μεταφράζει το αποτέλεσμα της έκφρασης ως tuple με δύο τιμές.
Εάν θέλετε να μεταφράσετε τα αποτελέσματα όπως (a, < όλα τα άλλα >), κατόπιν χρειάζεστε ακριβώς στο αστέρι που ακριβώς όπως σας στις παραμέτρους λειτουργίας:

>>> a, *b = [1, 2, 3, 4]
>>> a
1
>>> b
[2, 3, 4]

Αυτό σημαίνει επίσης ότι ο γρηγορότερος τρόπος να ανταλλαχθούν δύο μεταβλητές στην Python είναι:

>>> a = 5; b = 8
>>> a, b = b, a
>>> a, b
(8, 5)

Ειδικές Μέθοδοι

Υπάρχουν ορισμένες μέθοδοι όπως το __init και __del__ μέθοδοι που έχουν πρόσθετη σημασία στις κατηγορίες.
Οι πρόσθετες μέθοδοι χρησιμοποιούνται για να μιμηθούν ορισμένες συμπεριφορές των ενσωματωμένων τύπων. Παραδείγματος χάριν, εάν θέλετε να χρησιμοποιήσετε τη λειτουργία ευρετηρίασης Χ [βασική] για την κατηγορία σας (ακριβώς όπως την χρησιμοποιήσατετε για τους καταλόγους και tuples), κατόπιν το μόνο που πρέπει να κάνετε είναι μέσο η μέθοδος __getitem () και η εργασία σας γίνεται. Εάν το σκεφτείτε, αυτό είναι αυτό που η Python κάνει για η ίδια την κατηγορία καταλόγων!
Μερικές χρήσιμες ειδικές μέθοδοι απαριθμούνται στον ακόλουθο πίνακα. Εάν θέλετε να ξέρετε για όλες τις ειδικές μεθόδους, δείτε το εγχειρίδιο (http://docs.python.org/dev/3.0/reference/datamodel. html#special-method-names).

Όνομα
Επεξήγηση
__init__(self, ...)
Αυτή η μέθοδος καλείται αμέσως πριν να επιστραφεί το πρόσφατα δημιουργημένο αντικείμενο για τη χρήση

Θέλει έλενγχο όμως γιατί δεν ξέρω τι σημαίνει tuple και δύο σημεία τα μετάφρασα επ' ακριβώς και δεν βγαίνει και το καλύτερο νόημα.... ένα σημείο είναι αυτό --> αυτό είναι αυτό που η Python κάνει για η ίδια την κατηγορία καταλόγων! και το άλλο σημείο είναι αυτό --> κατόπιν χρειάζεστε ακριβώς στο αστέρι που ακριβώς όπως σας στις παραμέτρους λειτουργίας
Linux: Λίγο ┃ Προγραμματισμός: Μέτριο ┃ Αγγλικά: Πολύ Καλά
Kubuntu 9.04
CPU: P4 3.2GHz ┃ RAM: 512MB/400Hz ┃ NVIDIA 7100GS 512MB AGP ┃ 2xIDE HDD 80GB ┃ PCTV USB2 pinnacle
Άβαταρ μέλους
chrish
babeTUX
babeTUX
 
Δημοσιεύσεις: 25
Εγγραφή: 16 Μάιος 2009, 07:48
Εκτύπωση

Re: Μαθήματα Python - Μετάφραση Διδασκόμενης Ύλης

Δημοσίευσηαπό medigeek » 05 Ιουν 2009, 01:56

Για τεχνολογικούς όρους στα ελληνικά:
http://inforterm.cs.aueb.gr/greek/search.php

(ο atermon το ανέφερε νομίζω) :)

tuple = πλειάδες (ό,τι και να είναι :P )
Κύπριος; Κόπιασε στο ubuntu-cy! ┃ Launchpad Debian Github
Οδηγός για νεοεισερχόμενους -- Αρχικές οδηγίες για αρχάριους χρήστες του Ubuntu

1 Γνώσεις Linux: Πολύ καλό ┃ Προγραμματισμού: Πολύ καλό ┃ Αγγλικών: Πολύ καλό
2 Ubuntu 12.10 quantal 3.5.0-21-generic 64bit (en_US.UTF-8, GNOME cinnamon2d), Ubuntu 3.5.0-19-generic, Windows 7
3 Intel Core2 Duo CPU E6550 2.33GHz ‖ RAM 5970 MiB ‖ MSI MS-7235
4 nVidia G73 [GeForce 7300 GT] [10de:0393] {nvidia}
5 eth0: Realtek RTL-8110SC/8169SC Gigabit Ethernet [10ec:8167] (rev 10)
Άβαταρ μέλους
medigeek
Freedom
Freedom
 
Δημοσιεύσεις: 5023
Εγγραφή: 24 Μάιος 2008, 14:49
Τοποθεσία: Σερβία/Κύπρος
Launchpad: medigeek
IRC: savvas
Εκτύπωση

ΠροηγούμενηΕπόμενο

Επιστροφή στο Μεταφράσεις Λογισμικού