Main.Lab6 History
Hide minor edits - Show changes to markup
Write a function called max(file_name) that returns the largest number stored in that file.
Write a function called max(file_name) that returns the largest number stored in that file. Here's an example.
Objectives: more practice with lists and files, command-line arguments
Replace in a file
Write a function replace(input_file, output_file, s, r) that replaces all occurrences of the string s in the input file with the string r, and writes the resulting file into the file called output_file.
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s r. To do so make use of the array sys.argv (note that you will need to import the sys module before using sys.argv). This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
List merging
Write a function merge(list1, list2) that receives two sorted lists as input and merges them. It should return the merged list.
Objectives: practice with files.
Reading a Fasta file
Fasta is a very common and simple file format for storing sequence data.
Here's a description of the format.
Write a function that reads a Fasta file that contains a single sequence. Your function called read_fasta(file_name) should return the header and sequence. Note that the sequence can span multiple lines; we assume the file does not contain Fasta comments. Here's an example.
Reading numbers from a file
Write a function called max(file_name) that returns the largest number stored in that file.
Write a function replace(input_file, output_file, s) that replaces all occurrences of the string s in the input file, and writes the resulting file into the file called output_file.
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s. To do so make use of the array sys.argv (note that you will need to import the sys module before using sys.argv). This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
Write a function replace(input_file, output_file, s, r) that replaces all occurrences of the string s in the input file with the string r, and writes the resulting file into the file called output_file.
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s r. To do so make use of the array sys.argv (note that you will need to import the sys module before using sys.argv). This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s. To do so make use of the array sys.argv. This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s. To do so make use of the array sys.argv (note that you will need to import the sys module before using sys.argv). This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
Objectives: more practice with lists and files
Objectives: more practice with lists and files, command-line arguments
Make your program runnable as a script from the command line as python replace_in_file.py input_file output_file s. To do so make use of the array sys.argv. This list contains the command-line arguments that were used in order to execute the script. The first element in the list is the file name in which the program resides, and the rest of the elements are the command-line arguments that were given by the user.
Write a function merge(list1, list2) that receives two sorted lists as input and merges. It should return the merged list.
Write a function merge(list1, list2) that receives two sorted lists as input and merges them. It should return the merged list.
Lab 6
Objectives: more practice with lists and files
Replace in a file
Write a function replace(input_file, output_file, s) that replaces all occurrences of the string s in the input file, and writes the resulting file into the file called output_file.
List merging
Write a function merge(list1, list2) that receives two sorted lists as input and merges. It should return the merged list.
