'write a file after create some random strings [duplicate]
import random
class simulate_DNA:
def create_DNA(length):
sequence = ""
for i in range(length):
sequence = sequence + random.choice("ATGC")
return print(sequence)
def main():
length = 10
output_file = input("Enter output file path and name: ")
output_file = open(output_file, "w")
for i in range(10):
# simulate_DNA.create_DNA(length)
output_file.write(simulate_DNA.create_DNA(length))
output_file.readline()
output_file.close()
if __name__ == '__main__':
main()
I got this error after running the code above: TypeError: write() argument must be str, not None Would anyone please tell me how to fix this error? Thank you so much!
Solution 1:[1]
The print function returns None, and you're trying to return the result of the print function => So it's None
Replace this:
return print(sequence)
By:
return sequence
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PySoL |
