osx - How do I open a text file in TextEdit from Python on Mac? -


  Other: tkMessageBox.showinfo ('Report created', 'Your report was created successfully') file = 'Student Report.txt' os.system ('TextEdit' + file)  

I am writing a program that reports the data from a database, writes that in a text file Data and then launch that text file so that it can be printed.

How do I get it?

I have tried to use a web browser, but there is no luck.

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

  Open NAME-Open Open Files and Directories [-e] [-t] [-f] [-F] [-W] [-r] [-N] [-G] ] [-H] [-B bundle_identifier] [-app] File ... [--args arg1 ...] Details Open command opens a file (or a directory or URL), such as you double click the file icon If an application name is not specified, the default of the default through launch services The default application is used to open specified files. If the file is in the form of a URL, then the file will be opened as a URL You can specify one or more file names (or path names) that are interpreted relative to the current working directory of the shell or terminal window. is. For example, the following com-com will open all word files in the current working directory: Open *. Doctor applications applications participate in enterprise variables such as you have directly launched the application through your complete path. This behavior was also present in Tiger.  

You should also use it instead of os.system , because it is very easy to avoid issues that avoid:

< Pre> import subprocess subprocess. Call (['open', '-a', 'text edit', file])

Comments