私信  •  关注

DontBe3Greedy

DontBe3Greedy 最近创建的主题
DontBe3Greedy 最近回复了
4 年前
回复了 DontBe3Greedy 创建的主题 » 在python中,在特定行后拆分文本文件
fp = open("random.txt")

data = []
temp = []

for i, line in enumerate(fp):
    if line.strip() == "END":
        new_file = open("file"+str(i)+".txt", "a+")
        for i in temp:
            new_file.write(i+"\n")
        temp = []
        new_file.close()
        continue
    temp.append(line.strip())

fp.close()
print(data)

这是一个,每次都创建一个新文件。文件名是file,是找到“END”行的索引。:)

<?php
$mysqli = new mysqli("database","my_user","my_password","my_db");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

// Obviously change this to match yours
$sql = "SELECT GROUP_CONCAT(CONCAT(username , '-',id) SEPARATOR ',') as grp FROM table";
$result =  $mysqli->query($sql);
$final_result = []
while($row = $result->fetch_assoc())
{
    array_push($final_result, $row['grp']);
}


$mysqli -> close();
?>