Skip to content

Commit

Permalink
Update 2013-09-30-Jonathan-Python-Names-Code.md
Browse files Browse the repository at this point in the history
Added content.
  • Loading branch information
jpulliza committed Sep 30, 2013
1 parent 4ab531b commit 4737fd3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions _posts/jpulliza/2013-09-30-Jonathan-Python-Names-Code.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ 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)




Expand Down

0 comments on commit 4737fd3

Please sign in to comment.