From c69c33a07ae52af1264ffb001437bf8e014bd647 Mon Sep 17 00:00:00 2001 From: localadmin Date: Mon, 10 Sep 2018 16:47:12 -0500 Subject: [PATCH] rrr --- lab-01/file_ops.py | 33 ++++++++++++++++++++++++++------- lab-01/list-operations.py | 25 ++++++++++++++++++------- lab-02/Ex0910b.py | 17 +++++++++++++++++ lab-02/exercise0910.py | 18 ++++++++++++++++++ lab-02/func-03.py | 7 +++++++ lab-02/functions-args.py | 7 ++++++- lab-06/E0910b.py | 22 ++++++++++++++++++++++ 7 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 lab-02/Ex0910b.py create mode 100644 lab-02/exercise0910.py create mode 100644 lab-02/func-03.py create mode 100644 lab-06/E0910b.py diff --git a/lab-01/file_ops.py b/lab-01/file_ops.py index 37c371c..0611731 100644 --- a/lab-01/file_ops.py +++ b/lab-01/file_ops.py @@ -1,18 +1,37 @@ #!/usr/bin/python - # Open the license file, read the content into the buffer # then close the file descriptor -f = open('conditions.py') -lines10 = f.read(10) -#alllines = f.read() -print (lines10) -f.close() +# f = open('conditions.py') +# lines10 = f.read(10) +# # #alllines = f.read() +# print (lines10) +# f.close() # Open the license file, read the content as "lines" into the # buffer and close it. f = open('conditions.py') file_content = f.readlines() -f.close() \ No newline at end of file +print file_content +f.close() + +for line in file_content: + #print line.split() + if len(line) !=0: + line_list = line.split() + if len(line_list) !=0: + if line_list[0] == 'print': + print line_list + +# READ 15-20 +# f = open('conditions.py') +# f.seek(15) +# line15 = f.read(5) + +# TRYING READ VS READLINES +# f = open('conditions.py') +# file_content = f.read() +# print file_content +# f.close() \ No newline at end of file diff --git a/lab-01/list-operations.py b/lab-01/list-operations.py index 2b52b84..ea04771 100644 --- a/lab-01/list-operations.py +++ b/lab-01/list-operations.py @@ -5,12 +5,23 @@ new_list = [] -for l in mylist: - #print l * 100 - new_list.append(l + 100) +for list_item in mylist: + new_item = list_item * 100 + #add_more = new_item +50 + new_list.append(new_item) + #new_list.append(add_more) + # print new_list + # print max(new_list) + # print min(new_list) + # print sum(new_list) -print new_list -print max(new_list) -print min(new_list) -print sum(new_list) +# for l in mylist: +# #print l * 100 +# new_list.append(l + 100) +# 2-10, put in a list +this_list = [] +for item in (range (2,10)): + #add10 = item + 10 + this_list.append(item) +print this_list \ No newline at end of file diff --git a/lab-02/Ex0910b.py b/lab-02/Ex0910b.py new file mode 100644 index 0000000..4ddbaa4 --- /dev/null +++ b/lab-02/Ex0910b.py @@ -0,0 +1,17 @@ +import multiprocessing + +import os + +def myfunction(): + print multiprocessing.cpu_count() + #print os.cpu_count +#kernel name + print os.uname()[0] +# load average + print os.getloadavg +#uptime + print os.system("uptime") + #disk usage + print os.system("df -h") + +print myfunction() \ No newline at end of file diff --git a/lab-02/exercise0910.py b/lab-02/exercise0910.py new file mode 100644 index 0000000..9b21102 --- /dev/null +++ b/lab-02/exercise0910.py @@ -0,0 +1,18 @@ +def myfunction(filename, num_lines): + #return error if the filename is less than 4 - length + if len(filename) > 4: +#copies arg2 number of lines of arg1 into home dir + f = open(filename) + f2 = f.read(filename) + home_dir_file = [] + home_dir_file = f2.split("\n") + print home_dir_file + #to slice to number of line - use colon + #n = int(num_lines) + print_this = home_dir_file[:num_lines] + for each in print_this: + print each + +# ~/devopstraining/ansible/ +myfunction("/Users/localadmin/devopstraining/ansible/mylogfile.log", 3) +print "error" diff --git a/lab-02/func-03.py b/lab-02/func-03.py new file mode 100644 index 0000000..0c53430 --- /dev/null +++ b/lab-02/func-03.py @@ -0,0 +1,7 @@ +def myfunction(arg1, arg2): +#multiply + answer = arg1 * arg2 +#return arg1 * arg2 +#print + print answer +myfunction(1,2) \ No newline at end of file diff --git a/lab-02/functions-args.py b/lab-02/functions-args.py index 497c21b..5108a21 100644 --- a/lab-02/functions-args.py +++ b/lab-02/functions-args.py @@ -2,6 +2,9 @@ def myfunction(arg1, arg2,arg3): print "My Very first python function with Arguments" print "{},{},{}".format(arg1, arg2, arg3) + sum = arg1 + arg2 + arg3 + + #return sum if arg3 == "chicago": second_func(arg1,arg2) @@ -21,4 +24,6 @@ def third_func(arg1): if __name__ == "__main__": - myfunction("hello","world","chicago") \ No newline at end of file + # myfunction(1,2,3) + myreturn = myfunction(1,2,3) + print my_return diff --git a/lab-06/E0910b.py b/lab-06/E0910b.py new file mode 100644 index 0000000..97854a4 --- /dev/null +++ b/lab-06/E0910b.py @@ -0,0 +1,22 @@ +import requests + +def count_yelp(text): + all_words = text.split() + yelp_count = all_words.count('Yelp') + return yelp_count + +def replace_yelp(text): + return text.replace('yelp','google') + +r = requests.get('http://wwww.yelp.com') +if r.status_code == 200: + # print r.content + print count_yelp(r.text) + #print replace_yelp(r.text) + +# Assignment + +# Load the yelp page and replace all occurance of yelp to google + +# Load the file from http://censusdata.ire.org/36/all_050_in_36.P2.csv and find +# the max P002001