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.
Related
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.
"""
I tried with SASpy but it's not working. I am able to open the SAS .egp file but not able to run the multiple scripts within in sequence.
import os, sys, subprocess
def OpenProject(sas_exe, egp_path):
sasExe = sas_exe
sasEGpath = egp_path
subprocess.call([sasExe, sasEGpath])
sas_exe = path\path\
egp_path = path\path\path\
OpenProject(sas_exe, egp_path)
This depends a bit on exactly what the workflow is. A few side notes, then the full solution.
First: EGP is not really intended to store production processes, in my opinion. EGP should really be used for development, then production is done with .sas (text) files. EGP can directly store the nodes as .sas files; ask a new question about that if you want to know more, but it's pretty easy to figure out. Best practice is to have EGP save the code modules as .sas files, then run those - SASPy will easily do that for you.
Second: If you use SAS's built-in Git connectivity, then you can do this a bit more easily I suspect. Consider doing that if you already use Git for your other processes. Again, then you end up with a .sas file, and can directly run that via SASPy.
So: how can you do this in Python, with the assumption you do have to use the .egp itself, without too many different moving parts? The key here is the .egp format. EGP is a container file, which is actually a .zip format container that has in it, among other things, all of the SAS code you want to run, as text. Text in xml format, but still, text.
You can write a python program that opens the .egp as a .zip file, using the zipfile library, and then use xml.etree.ElementTree to parse the project.xml file inside that project. Exactly what you do from there depends on your particular details, and is well out of scope for a Stack Overflow answer, but if you do better visually you can simply rename the .egp to .zip and then open in unzip program of your choice, then browse project.xml in your text editor, and find the nodes and code related to those nodes.
You can then extract the .sas code as text, and submit it directly via SASPy, or extract it to a .sas file and then submit that however you prefer (SASPy or something else).
I do something similar to this for a project - I don't actually run code from it, I'm just parsing it to verify that the correct programs were synced from the EGP to production - but it would be trivial to actually submit the code from what I've written, which is about 50 lines of code total. I may write a SGF paper this year or next year on this topic, in which case I'll try and remember to submit it here - or you can head over to my github page and see if it's there (in the future!).
For someone that worked with PDF files for years that is probably an easy one, so here's my problem:
I processed several PDF files with my Python script using pdfminer.six and I now came across files with a value of "90" in the "/Rotate" key.
This totally ruined my script, although the orientation of the PDF is correct when I open it up in any PDF viewer.
I was successful with something called "cpdf" and the function "-upright" but since it is not Python I wont integrate this into my script.
So what I need to do, is to set the "/Rotate" key to 0 before processing it.
Any ideas how to do this using pdfminer(.six) and/or PyPDF2/4 ?
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.
I'm working on a script to create an OpenOffice document. After this i want to save the file. Maybe later also as an PDF.. Google doesn't give me any information how to fix this..
My question here is: What method should be used to save an openoffice-writer document?
Thanks in advance!
You should look at this similar question which answer covers both MSWord and OOWriter (by the way, creating a Word file could be the easiest to be read with OpenOffice).
How can I create a Word document using Python?
Alexis
You can create a rtf file with pyrtf or it's variants, and for pdf you can use reportlab. These are libraries for use in python, not to control remotely oo. There are other libraries for other formats.