[scribus] python script result
Gregory Pittman
gpittman at iglou.com
Wed Apr 21 13:22:59 UTC 2021
On 4/21/21 9:13 AM, Gregory Pittman wrote:
> On 4/21/21 3:56 AM, JLuc wrote:
>> Le 21/04/2021 à 01:00, Gregory Pittman a écrit :
>>> On 4/20/21 5:15 PM, JLuc wrote:
>>> I would say just experiment.
>>> If a Scribus script writes to a file, what does a shell script say when it reads the file?
>>> You could write the python so that it saves str(value), though when the shell script reads the file, that may not make any difference.
>>> On the other hand, when python reads a file, it reads numbers as strings, so you have to convert to use them as a number in python.
>>
>> I also tried outputing that string to a file.
>> I started with the sample files on the wiki :
>> https://wiki.scribus.net/canvas/Export_all_text
>>
>> But i kept having issues :
>> the "except Exception, e:" syntax looks wrong
>> i had to change it to " except Exception as e:"
>> and then it works fine.
>> I'm not at ease enough with python so as to fix it in the wiki
>> (all the more since there are several python versions).
>>
>> Allthough i now got a shell-only script to do it,
>> I also tried a page-count file-export scribus-python script :
>>
>> #!/usr/bin/env python
>> # -*- coding: utf-8 -*-
>> import scribus
>> pagenum = scribus.pageCount()
>> T=[]
>> T.append('pagecount=' + str(pagenum) + '\n\n')
>> output_file = open('pagecount.txt', 'w')
>> output_file.writelines(T)
>> output_file.close()
>>
>> But i got this error :
>>
>> Traceback (most recent call last):
>> File "<string>", line 11, in <module>
>> File "<string>", line 8, in <module>
>> OSError: [Errno 30] Système de fichiers accessible en lecture seulement: 'pagecount.txt'
>> (EN : "read-only file : 'pagecount.txt'")
>>
>> Do you see what's wrong here ?
>
> Hmm. Perhaps you are trying to create 'pagecount.txt' in a directory that does not have write permissions?
>
When I run ExtractText.py with a messageBox() to show the file saved to it shows me './pagecount.txt' to perhaps you should add that ./ at the beginning...
Greg
More information about the scribus
mailing list