-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from silshack/gh-pages
Update Repository
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
layout: post | ||
author: mbaxter | ||
category: post | ||
--- | ||
Here is the screenshot of my terminal window after finishing Exercise Two: | ||
![Ubuntu Screenshot](https://lh4.googleusercontent.com/-tEca61KR_-Y/UkmAn-UgcqI/AAAAAAAAAV0/CcMleZaBLfw/w607-h322-no/Screen+Shot+2013-09-30+at+9.21.54+AM.png "Ubuntu Screenshot") | ||
|
||
A little shoutout to Grant for helping me, with great patience, on that exercise! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
layout: post | ||
author: jpulliza | ||
categories: post | ||
title: Jonathan's Python Names Code | ||
--- | ||
|
||
```python | ||
def add_names(list_of_names, file): | ||
""" | ||
Opens and adds a list of names to the end of a file, each on its own line | ||
""" | ||
# We open a file in 'a' mode, for appending to it. | ||
names_file = open(file, 'a') | ||
|
||
# For each line in the list, we print that to the file. | ||
# This assumes one file per line. | ||
for name in list_of_names: | ||
print >> names_file, name | ||
|
||
# Close the file so the changes are visible. | ||
print file + ' written successfully' | ||
names_file.close() | ||
|
||
|
||
# Exercise: make new_names customizible: | ||
new_names = input('Enter a list of names:') | ||
|
||
# Exercise: make the file name used here customizible: | ||
|
||
file = input('Enter a file name:') | ||
|
||
add_names(new_names, file) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
``` |