将perl转换为python3

ehxuflar  于 2022-11-15  发布在  Perl
关注(0)|答案(2)|浏览(194)

我正在尝试重新创建一个perl代码到python3代码。我没有足够的python专业知识来做这件事。提前感谢。
我试着(在Python中)分割()和其他东西,但我没有得到任何地方。

use strict;
use warnings;

open(FILE,"file.name.txt") or die;
while(<FILE>){
    chomp;
    my $name = $_;
    $name =~ s/\.Q20L20\.fq\.gz//;
    open(OUT,">$name.sh") or die;
    print OUT "#!/bin/bash\n";
    print OUT "tophat2 -output -input $name.Q20L20.fq.gz";
    print $name;
    close OUT;
 }
 close FILE;

perl脚本运行良好,但我无法将其转换为Python

nwlqm0z1

nwlqm0z11#

下面是Python 3中的一个例子:

import os
import re

with open( "file.name.txt") as fp:
    for line in fp:
        name = line.rstrip()
        name = re.sub(r'\.Q20L20\.fq\.gz', '', name)
        with open(name + '.sh', 'w') as fpw:
            fpw.write("#!/bin/bash" + os.linesep)
            fpw.write("tophat2 -output -input {}.Q20L20.fq.gz".format(name));
        print(name)
1bqhqjot

1bqhqjot2#

我专门为此构建了一个Perl到Python代码语言转换器,您可以在这里查看它:)https://codelanguageconverter.com/convert-python-to-perl

相关问题