convert php script to python
I try to convert a PHP script to Python
$texte = file_get_contents("../test/detail-20110503_10");
preg_match_all("#Acct-Status-Type(.*)Timestamp#Ums", $texte, $blocs);
$nbBlocks = count($blocs[0]);
for ($i = 0; $i < $nbBlocks; $i++)
{
preg_match('#Acme-Session-Egress-Realm = "(.*)\"#i', $blocs[0][$i], $Session_Egress开发者_StackOverflow_Realm);
if ($Session_Egress_Realm[1] == "Ext-9C" OR $Session_Egress_Realm[1] == "Ext-OBS")
{
echo "cool";
}
}
But the file "detail-20110503_10" is very fat (+100Mo) so I have this error when I try to read it. IOError: [errno 12] Not enough space
mon_fichier = open("D:/CDR SBC/test/detail-20110503_10", "r")
contenu = mon_fichier.read()
print(contenu)
Please someone could help me to convert the PHP script to python?
you can read certain length of content by passing a param to read()
function, like read(100)
or you can use readline()
to get a single line at a time
精彩评论