我正在为我的父亲制作一个程序,将一些非常旧的文件转换为准html,以便可以将其转换为pdf。由于他使用的格式类似于1990年的格式,因此无法使用正确的格式进行转换,因此在这种情况下格式化非常重要。所以我用Python编写了这个脚本。
import tkinter as tk
from tkinter import filedialog
import os
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
file_name = file_path.split(".")
with open(file_path , "r") as f_old, open(file_name[0] + ".html", "w") as f_new:
f_new.write('<p style="font-family:monospace;page-break-after: always;">')
for line in f_old:
newline = line.replace(" " , " ")
newline = newline.replace("" , '</p></br><p style="font-family:monospace;page-break-after: auto;">')
newline = line.replace(" " , " ")
newline = newline.replace("" , '</p></br><p style="font-family:monospace;page-break-after: auto;">')
newline = newline + "</br>"
newline = newline.replace("E" , ' ')
newline = newline.replace("F" , ' ')
newline = newline.replace("" , ' ')
newline = newline.replace("" , ' ')
newline = newline.replace("M" , ' ')
newline = newline.replace("P" , ' ')
f_new.write(newline)
它做得很好,但是我需要它在32位系统上工作并且可执行。因此我了解了cx_freeze。我确保已安装32位python并安装了cx_freeze。我准备了setup.py
import cx_Freeze
import sys
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("pdf.py", base=base)]
cx_Freeze.setup(
name = "pdf",
option = {"build_exe": {"packages":["tkinter"]}},
version = "0.1",
description = "konwerter",
executables = executables
)
cx_freeze准备了exe版本,它在我的64位PC上也可以正常运行,与脚本相同。它不适用于我在virtualbox中设置的32位XP。它给我“不是有效的win32应用程序”错误
对于错误,一切似乎都可以正常进行,并且exe在64位PC上可以运行,但是在cx_freeze中,我注意到了此警告消息。
C:\Users\arnat\Desktop\Python\gotowe>Python setup.py build
C:\Users\arnat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'option'
warnings.warn(msg)
running build
Missing modules:
? __main__ imported from bdb, pdb
? _frozen_importlib imported from importlib, importlib.abc
? _frozen_importlib_external imported from importlib, importlib._bootstrap, importlib.abc
? _posixsubprocess imported from subprocess
? _winreg imported from platform
? grp imported from shutil, tarfile
? java.lang imported from platform
? org.python.core imported from copy, pickle
? os.path imported from os, pkgutil, py_compile, tracemalloc, unittest, unittest.util
? posix imported from os
? pwd imported from http.server, posixpath, shutil, tarfile, webbrowser
? termios imported from tty
? vms_lib imported from platform
This is not necessarily a problem - the modules may not be needed on this platform.
我不知道哪里出了问题。对于我的错误之处,我将不胜感激。谢谢。