gpt4 book ai didi

python - 将 Perl For 循环转换为 Python

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:19 25 4
gpt4 key购买 nike

这就是我正在尝试转换为 python 的内容

这是我有点迷路的地方

    foreach (@files) {
if ($_ =~ /_histogram/) { next; } #Exclude all the histogram files

for($row = 0, $mytype = 500; $row < $filearray_count; $row++) {
if ($_ eq $filearray[$row][0]) {
$mytype = $filearray[$row][1];
print "$row, $mytype, $_ \n";
break;
}}


$myfile = $mydir.$_;

if ($mytype > 0) {
open($in, "<", ($myfile)) or die "Can't open source file $myfile: $!";

if ($mytype >= 500) { $mytype += ++$new_attribute; }
#print "$row, $mytype, $_ \n";
this while loop is confusing. Is it setting $Instring equal to $in?
while ($inString = <$in>) {
$inString =~ s/^\s*(.*)\s*$/$1/;
if ($inString =~ /Feature File Version:/) { next; }
if ($mytype eq 11 && $inString !~ /Subject:/) { next; }

if ($mytype eq 11 && $inString =~ /Subject:/) {

my($f1, $f2, $f3) = $inString =~ m/(.*\t)(.*\t)(.*)/;
#print $out $inString, "\n";
$f3 =~ s/(\\\d{3})/\^/g;
print $out $mytype, "\t", $f1, $f2, $f3, "\n";

foreach ($f3) {
push @f4, split(/(Subject:|In-Reply-To:|Reply-To:|To:|From:|Bcc:|Cc:|Host:|Date:|Distribution:)/i);
}

#print $out $mytype, "\t", $f1, "\t", "scalar=", $#f4+1, "\n";
$count = 0;
while ($count < $#f4) {

$f4[$count+2] =~ s/\^/ /g;
push @f5, substr(join('', $f4[$count+1], $f4[$count+2]), 0, 50);;
$count = $count + 2;

这部分很容易理解

                    print $out $mytype, "\t", $f1, $_, "\t", $f3, "\n" for @f5;
undef @f4;
undef @f5;

next;
}

不确定这里的替换。 $inString =~ s/(\\d{3})/\^/g; 打印 $out $mytype, "\t", $inString, "\n";

            }

}

};

最佳答案

看起来可以这样做:

my_type = 500
for row, value in filearray:
if row == member:
my_type = value
print row, my_type
break

关于python - 将 Perl For 循环转换为 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11138297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com