Learn Python the Hard Way

From Hackerspace.gr
Revision as of 19:05, 29 June 2015 by Ebal (Talk | contribs)

Jump to: navigation, search
Learn python the hard way.jpg

external link
Starts Organizer
Mon 29 Jun 2015 18:00
Ends Event Owner
Mon 29 Jun 2015 20:00 User:Ebal
  • Κάθε Δευτέρα, 18:00-20:00
  • Συναντήσεις για εκμάθηση προγραμματισμού σε python.

Θα είναι υπό την μορφή study group, δηλαδή όλοι θα μαθαίνουμε παρέα και δεν θα υπάρχει κάποιος "δάσκαλος". Οι συναντήσεις είναι ανοιχτές σε όλες και όλους - αρκεί να φέρεις το laptop σου! Απευθύνονται σε ανθρώπους που θέλουν να ξεκινήσουν με python κι άρα θα είναι αρκετά εισαγωγικές. Η μοναδική δέσμευση είναι να τηρηθεί αυστηρά το ωράριο (δηλαδή εάν κάποιος ή κάποια αργήσει, να μην μας ζητήσει να γυρίσουμε πίσω για να καλύψουμε κάτι που έχουμε ήδη πει).

Έλα εγκαίρως/νωρίς αν θες να βρεις ελεύθερη θέση :)


  • Στις προηγούμενες συναντήσεις έχουμε καλύψει τις ασκήσεις 0 εως και 17


Η σελίδα της προηγούμενης συνάντησης (#04) με μερικές σημειώσεις:

https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_04



  • Every Monday at 18.00-20:00
  • python enthusiasts will try to learn programming "the hard way" !

The meetings will be in study group format, meaning that we will all learn together and there won't be a tutor. Meetings are open to everyone - just bring your laptop! They are for people that want to start learning python, so we will cover some introductory material. The only requirement is to be punctual (so if a person comes later than 18:00 please don't ask us to cover material that we have already gone through).

Come early if you want to ensure that you'll find a space to place your laptop :)


  • We have previously covered exercises 0 to 17 (including 17)


The page for the previous meeting (04) with some notes:

https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_04


This is Lesson 05

These events are based on peer2peer education





Exercise 16: Reading and Writing Files


#!/usr/bin/python2.7

# From python module sys, import section argv
from sys import argv

# Declare variables: script, filename from argv
# argv is going to take the command line arguments
script, filename = argv

# print something
print "We 're going to erase %r." % filename
print "If you don't want that, hit CTR-C (^C)."
print "If your do want that, hit RETURN."

# Get input from user/keyboard
# This is similar to press any key
raw_input("?")

print "Opening the file ... "
# Open filename with write operation and get the file descriptor into target
## target = open ( filename, 'w' )
## target = open ( filename, 'a' )
target = open ( filename, 'w+' )

# Truncate file, this means empty the file
## print "Truncating the file. Goodbye!"
## target.truncate()

print "Now I'm going to ask you for three lines."

# Ask from user input three lines
line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")

print "I'm going to write these to the file."

# Write them into the file descriptor
target.write ( line1 )
target.write ( "\n" )
target.write ( line2 )
target.write ( "\n" )
target.write ( line3 )
target.write ( "\n" )

string = "%r\n%r\n%r\n" % ( line1, line2, line3 )
target.write ( string )

print "And finally, we close it."
# Close the fd
target.close ()

## Study drills 2.
print ""
print ""
print ""
file = open ( filename ) 
print file.read() 
file.close()