Opening a docx document that is in a folder - python

I have looked all over for an answer and I can't find what I'm looking for and I'm sure it is simple.
Anyway I created a docx document with python docx and tkinter. Everything works well there now I'm looking to open that file as soon as it is saved. The only problem is I have no idea how to go about doing this. My first thought was...
f = open("path\\"+name_created_by_python+".docx", mode="r")
But as some (or all) know that doesn't work for physically opening a document. Any suggestions.
UPDATE/CLARIFICATION: I want the code to save the doc (which it does) and then immediately open it up so the user can view it without having to physically go to the folder it is located. I suppose the code above "opens" it but doesn't really open it in the way that I want or need.
Thanks in advance

So I found what I was looking for. Below is the code required for windows.
import os
os.startfile("path"+filename+".docx")
The +filename+ is the method used to give my docx document its specific name.

Related

Create direct file object in python

I have images in 100 folders and the search results are slow, so I want to access those images, so maybe I wanna do it with python(if it is faster), in the way that when we select all the files, and drag and drop them in windows. then I realized that drag and drop in windows uses Component Object Model this source.
So I want to know is there any way in python to have COMs of the image files in those 100 folders in the same place (a specific folder)? or in other words can we create COMs of other files, (equivalent of shortcuts), cause I know shortcuts for my purpose won't work.
The question in general is about how to access direct handles or COMs of files of different folders in one folder? if it's possible, please tell me how? to be simpler I want to have similar function of file shortcuts but not 'shortcuts' existing in windows, because for my purpose 'shortcuts' won't work, so I think it can be done with COMs.
tkinter equivalent question:
let me ask my question in other way, lets think I want to make a windows file search application in python with some library like tkinter, so one background part of my code finds the file paths of desired search results, and other part in gui('gui part'): wants to show the result files with ability of opening files from that gui or drag files from gui to other folder or applications, so how should I do the 'gui part'?
this tutorial suggested by #Thingamabobs is about getting external files into window(gui) of app, but I want the opposite, I mean having file handles to open, something like windows explorer
My question maybe wrong in case of misunderstanding the concept of COMs, so please provide me more relevant sources of use case of mine. finally if the title seems to be unsuitable, feel free to change it.
Based on an interpretation of the question, the following is an initial summary approach to a solution.
"""
This module will enable easy access to files spread across 100 plus
directories. A file should be as easy to open as clicking on a link.
Analysis:
Will any files be duplicated in any other directory? Do not know.
Will any file name be the same as another file in a different directory? Do
not know.
Initial design in pseudocode:
> Capture absolute path to each file in each directory.
> Store files information in python data structure
> for instance a list of tuples <path>,<filename>
> Once a data structure is determined use Tkinter, ttk.treeview to open a
file as easy as clicking on a link in the tree.
"""

Save Abjad ouput pdfs

I'm using Abjad to create pdf's of lilypond files my python program has written.
When I use the abjad.show() method, I get the image that I want, but I can't figure out how to save it as a pdf somewhere my program can use.
The documentation mentions something about changing the abjad_output_directory in the config.py file, but there's no other mention of the config.py file. I can't figure out where the pdf's are being saved to on my Mac.
Is there an easy way to simply save the generated pdf as a file in the same directory as the program I'm in?
The documentation for abjad.system.AbjadConfiguration might be helpful:
It mentions where the abjad.cfg file is, in which you can hopefully define an output directory, and
It has a method for finding the abjad output directory: abjad_output_directory
I have not been able to test this myself, but hopefully it is enough for you.
you can set the following keywords in show():
abjad.show(notes, output_directory=r"C:\path\to\somewhere", should_open=False)
Answering in case anyone else searches this question as it was hard to figure out.

Is there any solution to find the page breakpoint in python (for docx doccument)?

PLEASE REFER THE IMAGE FOR A BETTER UNDERSTANDNG I am developing an application which check the page break point of a DOCX file and if there is a page break point, then that page is ending at that point. I am literally fed up with many logics.
Hope i can get one.
Thanks and regards
.DOCX files seem to do something called a soft breakpoint between pages.
However, this seems to say that you can use from docx import nsprefixes to replace occurrences of page breaks with something more identifiable.

Script to search for text from PDF

Problem
On the Mac OS X platform, I would like to write a script, either in Python or Tcl to search for text within a PDF file and extract the relevant parts. I appreciate any help.
Background
I am writing scripts to look inside a PDF to determine if it is a bill, from what company, and for what period. Based on these information, I rename the PDF and move it to an appropriate directory. For example, file such as Statement_03948293929384.pdf might become 2012-07-15 Water Bill.pdf and moved to my Utilities folder.
What have I done so far?
I have searched for PDF-to-plain-text tools, but not found anything yet
I have looked into the Tcl wiki and found an example, but could not get it to work (I searched for text in PDF, but not found).
I am looking into pdf-parser.py by Didier Stevens
I heard of a Python package called pyPdf and will look at it next.
Update
I have found a command-line tool called pdftotext written by Glyph & Cog, LLC; built and packaged by Carsten Bluem. This tool is straight forward and it solves my problem. I am still looking out for those tools that can search PDF directly, without having to convert to text file.
I have successfully used PyODConverter to convert to/from PDFs (there is also a more powerful Java version). Once you have the PDF converted to text it should be trivial to do the searching. Also I believe iText should be capable of doing similar things, but I haven't tested it.

copy paste from a file to another file in python webdriver

Currently i am working on creating a template, my requirement is I should copy contents from a text document and paste it in the template which i am creating.
I want to know a method in python webdriver to do so, i searched in the web but ended up without finding a solution, i found a similar issue Copy odt file to clipboard and paste to another file with python 3.2> here but no solutions, any help will be grateful to me as i spent more time on this particular task.
Thanks in advance !
This is not much to do with the webdriver, but more to do with python. As in, how do you read an ODT file using Python? That is the core of what you are doing, so webdriver is not related to the question.
With that said, there is a standard library for this, so give it a go, this can interact with all MS Office and Open Office files:
https://github.com/mikemaccana/python-docx
There is also a COM-based library here that can interact with Word & Excel:
http://python.net/crew/pirx/spam7/
If it's OpenOffice based files, there is the ability to automate Open Office itself for whatever you are trying to do:
http://wiki.services.openoffice.org/wiki/Python
It depends on what type of text document (you only specified it was a 'text document') - if it is a simple .txt document this is very simple and easy.

Categories

Resources