Created
April 10, 2012 23:52
-
-
Save nitsas/2355754 to your computer and use it in GitHub Desktop.
A simple Python program. You give it a filename and a word and it checks if the word is in the file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Γλώσσα: Python που είναι εύκολη και δυνατή ;) | |
# από εδώ την κατεβάζεις: http://www.python.org/ftp/python/3.2.2/python-3.2.2.msi | |
# Τρόπος χρήσης (από γραμμή εντολών): | |
# python search_for_word.py filename word | |
# Όποια γραμμή ξεκινάει με δίεση είναι σχόλια, δεν κάνει τίποτα. | |
# αυτό το βάζουμε πάντα | |
import sys | |
# πάρε το όνομα αρχείου και την λέξη απ' τη γραμμή εντολών | |
# και βάλτα στις μεταβλητές filename και word | |
filename = sys.argv[1] | |
word = sys.argv[2] | |
# άνοιξε το αρχείο (για ανάγνωση), διάβασε τα περιεχόμενά του | |
# και βάλτα στη μεταβλητή text | |
with open(filename, "r") as file: | |
text = file.read() | |
# το αρχείο κλείνει μόνο του | |
# τσέκαρε αν η λέξη είναι μέσα στο text | |
if word in text: | |
print("Yes!") | |
else: | |
print("Nope") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment