I am trying to write on a volume of E drive. But in that file I also want to add some random text like just "random text". How can I do that?
Here is the code:
import os.path
textFile=os.system("vol E: > file.txt")
I am trying to write on a volume of E drive. But in that file I also want to add some random text like just "random text". How can I do that?
Here is the code:
import os.path
textFile=os.system("vol E: > file.txt")
要生成随机文本,您可以导入random模块,然后制作随机单词或字符的列表,然后将它们加在一起
import random
import os
words = ['dog', 'pizza', 'pasta', 'Giovanni', 'lasagne', 'salame', 'pecorino'] # make a list of words or characters
minimum_words = 3
maximum_words = 10
random_text = ''
for i in range(random.randint(minimum_words, maximum_words)): # uses as range a random integer number between 3 and 10
random_text += random.choice(words) + ' ' # choose a random word from the list
os.system(f"vol E: {random_text} > file.txt") # use f strings
希望这能解决你的问题,晚安