[scribus] PDFfile causes looping to fail?

Jerry Stratton scribusjerry at hoboes.com
Tue Feb 26 17:52:44 UTC 2019


On Feb 26, 2019, at 8:38 AM, Gregory Pittman <gpittman at iglou.com> wrote:
> This isn't the way to use scribus.PDFfile(). I'm not sure if it's in the 1.4.7 documentation, but at least in 1.5.x, if you look under PDF Export from the menu, there is an explanation of the user of PDFfile() at the bottom:
> 
> pdf = scribus.PDFfile()
> pdf.file = 'MyFile.pdf'
> pdf.save()
> 
> scribus.PDFfile() creates a class which you can then do further actions on. 

Yes, thanks. But I’m aware of that (1.4.7 does include PDFfile documentation). My problem is not with using PDFfile to save, but with using PDFfile making loops on lists fail. That’s what the simplified script is meant to show. Why does calling PDFfile cause looping on lists to fail? It means not being able to use os.path.join because os.path.join loops on a list. It also means having to detect the end of a list in a for… in… loop and manually break from it, or the script will also fail; in each case calling PDFfile causes a “list assignment index out of range error” when looping on lists after the call.

If you’d like, you can use this less simple script:

import scribus

countDown = ['three', 'two', 'one']

pdf = scribus.PDFfile()
pdf.file = 'MyFile.pdf'
pdf.save()

for counter in countDown:
	scribus.messageBox('Countdown', counter)

For me, this still results in:

Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Users/jerry/bin/Scribus/testPDF.py", line 9, in <module>
    for counter in countDown:
IndexError: list assignment index out of range

Jerry

On 2/26/19 5:58 AM, Jerry Stratton wrote:
> I have the following script that I have simplified down to the basics:
> 
> ----------------------
> import scribus
> 
> countDown = ['three', 'two', 'one']
> 
> #scribus.PDFfile()
> for counter in countDown:
> 	scribus.messageBox('Countdown', counter)
> ----------------------
> 
> If I run it with scribus.PDFfile commented out, as above, it pops up a window for “three”, “two”, “one” as I expect. If I uncomment the scribus.PDFfile() line, however, I get the countdown, but after the final item I also get this error:
> 
> Traceback (most recent call last):
> File "<string>", line 8, in <module>
> File "/Users/jerry/bin/Scribus/testPDF.py", line 6, in <module>
>   for counter in countDown:
> IndexError: list assignment index out of range
> 
> The error appears to show up whenever a list is looped through; for example, os.path.join will fail with the same error:
> 
> ----------------------
> import scribus
> 
> scribus.PDFfile()
> os.path.join('/Users/', 'fred.pdf')
> ----------------------
> 
> Produces:
> 
> Traceback (most recent call last):
> File "<string>", line 8, in <module>
> File "/Users/jerry/bin/Scribus/testPDF.py", line 4, in <module>
>   os.path.join('/Users/', 'fred.pdf')
> File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.7/posixpath.py", line 67, in join
>   for b in p:
> IndexError: list assignment index out of range
> 
> I did a Google search on lists.scribus.info for “list assignment index out of range” and only found an unfinished discussion back in 2009.
> 
> Am I doing something wrong?
> 
> Currently I’m getting around it by not using os.path.join to create paths after calling PDFfile(), using string concatenation instead; and checking inside the loop if the loop variable is currently equal to the end variable,  breaking out if so. But that only works for unique lists, of course.




http://www.hoboes.com/Mimsy/
"After midnight, all things are possible."




More information about the scribus mailing list