i wasn't sure whether to put this in the pythonista forum but i've been working solely in the editorial python console so it's mostly a python editorial question.
so i've been able to do some "good stuff" with the python console in editiorial.. i've managed to generate a lot of text that i mostly just print to the console. but i would like to be able to send that output programmatically to a new document in my local folder.
i checked the online documentation in the console and searched a bunch online today but am not finding the info i need. i was wondering if anybody could point me in the right direction to do (any of) the following
keep in mind i'm on the road and i have to run editorial on my aging handheld (ie i don't have access to editorial on an ipad or a mac any time soon!)
1) i obviously need to create a new file in editorial using python, so i'm wondering how to do that? since i've programmed this thing in code from the start, i'd really love not having to jump back with any workflow integration. that way everything is self-contained in my script file
fwiw, it looks like i might be able to access a document that is currently open but i don't want to have to do that b/c it breaks the rule about the script containing all the functionality by itself / inherently.
2) once i get a file pointer in #1, i can write to it. but i'm trying to figure out the best way to do this.
as of now my script is already written and uses simple print statements to send TONS of output beautifully to the console screen.
so i'm thinking:
2a) if i can redirect console output so that it goes to both console AND the file pointer that might be simplest. kind of like you do on the linux / unix command line
but that might not be possible so..
2b) i'm wondering if there is some other way to capture / redirect all that print output to a single variable simply by directing the console out to a variable using some python construct. i think i've done this in the past with other languages but i forgot what it's called.
otherwise, i think i'm just going to have to rewrite some of my code to concatenate all that text using variables inline in the code where i currently have print statements which is going to require some extra refactoring.
i guess i'm not sure if i can just append LOTS of text to a simple text variable over MANY iterations or i need to store the text generated in the each iteration of the loop in an array.
in sum, i'm looking for the simplest way to do #1 and #2 with as little refactoring in my script as possible
3) as i'm generating the text in my script, web content p tags are currently converted to text on the fly which leave no double spacing between paragraphs in the text. so i'm wondering what the best way in python is to replace all single new line / paragraph breaks in the text contained in my content variables with two new lines
i hope that all makes sense.
any help is greatly appreciated.
thx