如何解决可以在python中写入文件并开始不工作
我有问题。我有一个任务“按 ID 下载”
这是我以前下载文本(PDB文件)的程序
from urllib.request import urlopen
def download(inf):
url = xxxxxxxxxxx
response = urlopen(xxx)
text = response.read().decode('utf-8')
return data
new_download = download('154)
它工作得很好,但我必须创建的函数,不要写入以 num 开头的文件行
from urllib.request import urlopen #moduule for URL processing
with open('new_test','w') as a:
for sent in text: #for every line in sequences file
if line.startswith('num'):
line1.writeline(sent)
解决方法
您不是在迭代行,而是在迭代字符。改变
if ($request->hasFile('prodimg')){
$i = 1;
foreach ($product->productImage as $pr) {
Storage::disk('public')->exists('products/'.$product->id.'/'.$pr->path)?Storage::disk('public')->delete('products/'.$product->id.'/'.$pr->path):NULL;
$pr->delete();
};
foreach ($request->file('prodimg') as $prodimg) {
$dataimg['product_id'] = $product->id;
$dataimg['path'] = 'img_'.rand(1,999).time().'.'.$prodimg->getClientOriginalExtension();
$dataimg['position'] = $i++;
$dataimg['updated_at'] = Carbon::now();
$dataimg['created_at'] = Carbon::now();
$prodimg->storeAs('products/'.$product->id.'/',$dataimg['path']);
ProductImage::create($dataimg);
};
};
到
for line in data2:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。