python读取mac上的txt文件_如何在Mac上的Python中从TextEdit中打开文本文件?

在Python程序中创建报告并写入文本文件后,可以使用Mac上的`open`命令来启动TextEdit以打印该文件。通过调用`subprocess.call`并传入`open`、`-a`、`TextEdit`和文件路径参数,可以实现这个功能。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

else:

tkMessageBox.showinfo('Report Created', 'Your report was sucessfully created')

file = 'Student Report.txt'

os.system('TextEdit'+file)

I am writing a program that creates a report from data from a database, writes that data to a text file and then is supposed to launch that text file so that it can be printed.

How do I achieve this?

I have attempted to use webbrowser but no luck.

解决方案

You can use the /usr/bin/open OSX utility:

NAME

open -- open files and directories

SYNOPSIS

open [-e] [-t] [-f] [-F] [-W] [-R] [-n] [-g] [-h] [-b bundle_identifier] [-a application] file ... [--args arg1 ...]

DESCRIPTION

The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值