Gemini 可以直接生成各种类型的文件以及zip压缩包了

2026-04-29 08:172阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐
问题描述:

如题,
看代码是直接在后台沙盒执行 Python 代码生成的文件。

代码

import os
import zipfile
from weasyprint import HTML

Create a directory for the files

dir_name = “random_files”
os.makedirs(dir_name, exist_ok=True)

1. TXT File

txt_content = “这是一个随机生成的文本文件内容。\n包含一些基本的文字描述。”
txt_path = os.path.join(dir_name, “sample.txt”)
with open(txt_path, “w”, encoding=“utf-8”) as f:
f.write(txt_content)

2. Markdown File

md_content = “# 随机 Markdown 文件\n\n## 章节 1\n这是 Markdown 格式的演示内容。\n- 列表项 A\n- 列表项 B”
md_path = os.path.join(dir_name, “sample.md”)
with open(md_path, “w”, encoding=“utf-8”) as f:
f.write(md_content)

3. CSV File

csv_content = “ID,Name,Value\n1,Alpha,100\n2,Beta,200\n3,Gamma,300”
csv_path = os.path.join(dir_name, “sample.csv”)
with open(csv_path, “w”, encoding=“utf-8”) as f:
f.write(csv_content)

4. Config File (INI style)

config_content = “[Settings]\nAppName=RandomGenerator\nVersion=1.0.0\nEnabled=True”
config_path = os.path.join(dir_name, “sample.config”)
with open(config_path, “w”, encoding=“utf-8”) as f:
f.write(config_content)

5. PDF File

pdf_path = os.path.join(dir_name, “sample.pdf”)
html_content = “”"

@page { size: A4; margin: 20mm; background-color: #ffffff; } body { font-family: sans-serif; color: #333; } h1 { color: #2c3e50; border-bottom: 2px solid #eee; } p { line-height: 1.6; }

随机生成的 PDF 文档

这是一份自动生成的示例 PDF 文件,用于测试文件创建和打包功能。

  • 文档类型:PDF
  • 生成目的:演示
""" HTML(string=html_content).write_pdf(pdf_path)

6. ZIP File

zip_path = “all_files_archive.zip”
with zipfile.ZipFile(zip_path, ‘w’) as zipf:
for root, dirs, files in os.walk(dir_name):
for file in files:
zipf.write(os.path.join(root, file), file)

print(f"TXT: {txt_path}“)
print(f"MD: {md_path}”)
print(f"CSV: {csv_path}“)
print(f"CONFIG: {config_path}”)
print(f"PDF: {pdf_path}“)
print(f"ZIP: {zip_path}”)

图片1598×1306 193 KB

网友解答:
--【壹】--:

说明在后台上虚拟机了终于,御三家最晚的一家


--【贰】--:

恭喜 Google 的 Gemini 3.1 Pro 跟上了 OpenAI 的 o1 preview 的脚步


--【叁】--:

诶,我三点的时候让他给我生成word都给我的是代码呀,难绷


--【肆】--:

那是因为ai studio没有适配PDF,没有从数据中解析出PDF
底层是支持的

PixPin2026-04-2817-22-57959×899 39 KB
PixPin2026-04-2817-23-14960×900 87.9 KB


--【伍】--:

刚才在aistudio试了试,还不能生成pdf文件。应该不是我的问题。


--【陆】--:

确实够晚的,gpt 和 claude 文件处理都出了八百年了。


--【柒】--:

Gemini网页确实很多功能上得好慢,落后GPT一截


--【捌】--:

这个貌似是 Gemini 官网独占功能。


--【玖】--:

那么多三方服务都走google oauth,按理说gemini推虚拟机有先天优势,最容易做代理的全平台能力集成了


看起来也支持 interleaved thinking 了,像 claude 一样回复一段做一段工具调用,再回复一段

image1090×488 79.5 KB

标签:人工智能
问题描述:

如题,
看代码是直接在后台沙盒执行 Python 代码生成的文件。

代码

import os
import zipfile
from weasyprint import HTML

Create a directory for the files

dir_name = “random_files”
os.makedirs(dir_name, exist_ok=True)

1. TXT File

txt_content = “这是一个随机生成的文本文件内容。\n包含一些基本的文字描述。”
txt_path = os.path.join(dir_name, “sample.txt”)
with open(txt_path, “w”, encoding=“utf-8”) as f:
f.write(txt_content)

2. Markdown File

md_content = “# 随机 Markdown 文件\n\n## 章节 1\n这是 Markdown 格式的演示内容。\n- 列表项 A\n- 列表项 B”
md_path = os.path.join(dir_name, “sample.md”)
with open(md_path, “w”, encoding=“utf-8”) as f:
f.write(md_content)

3. CSV File

csv_content = “ID,Name,Value\n1,Alpha,100\n2,Beta,200\n3,Gamma,300”
csv_path = os.path.join(dir_name, “sample.csv”)
with open(csv_path, “w”, encoding=“utf-8”) as f:
f.write(csv_content)

4. Config File (INI style)

config_content = “[Settings]\nAppName=RandomGenerator\nVersion=1.0.0\nEnabled=True”
config_path = os.path.join(dir_name, “sample.config”)
with open(config_path, “w”, encoding=“utf-8”) as f:
f.write(config_content)

5. PDF File

pdf_path = os.path.join(dir_name, “sample.pdf”)
html_content = “”"

@page { size: A4; margin: 20mm; background-color: #ffffff; } body { font-family: sans-serif; color: #333; } h1 { color: #2c3e50; border-bottom: 2px solid #eee; } p { line-height: 1.6; }

随机生成的 PDF 文档

这是一份自动生成的示例 PDF 文件,用于测试文件创建和打包功能。

  • 文档类型:PDF
  • 生成目的:演示
""" HTML(string=html_content).write_pdf(pdf_path)

6. ZIP File

zip_path = “all_files_archive.zip”
with zipfile.ZipFile(zip_path, ‘w’) as zipf:
for root, dirs, files in os.walk(dir_name):
for file in files:
zipf.write(os.path.join(root, file), file)

print(f"TXT: {txt_path}“)
print(f"MD: {md_path}”)
print(f"CSV: {csv_path}“)
print(f"CONFIG: {config_path}”)
print(f"PDF: {pdf_path}“)
print(f"ZIP: {zip_path}”)

图片1598×1306 193 KB

网友解答:
--【壹】--:

说明在后台上虚拟机了终于,御三家最晚的一家


--【贰】--:

恭喜 Google 的 Gemini 3.1 Pro 跟上了 OpenAI 的 o1 preview 的脚步


--【叁】--:

诶,我三点的时候让他给我生成word都给我的是代码呀,难绷


--【肆】--:

那是因为ai studio没有适配PDF,没有从数据中解析出PDF
底层是支持的

PixPin2026-04-2817-22-57959×899 39 KB
PixPin2026-04-2817-23-14960×900 87.9 KB


--【伍】--:

刚才在aistudio试了试,还不能生成pdf文件。应该不是我的问题。


--【陆】--:

确实够晚的,gpt 和 claude 文件处理都出了八百年了。


--【柒】--:

Gemini网页确实很多功能上得好慢,落后GPT一截


--【捌】--:

这个貌似是 Gemini 官网独占功能。


--【玖】--:

那么多三方服务都走google oauth,按理说gemini推虚拟机有先天优势,最容易做代理的全平台能力集成了


看起来也支持 interleaved thinking 了,像 claude 一样回复一段做一段工具调用,再回复一段

image1090×488 79.5 KB

标签:人工智能