MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Wrap in SVG plugin? (https://www.mobileread.com/forums/showthread.php?t=255300)

DiapDealer 04-18-2015 03:20 PM

Quote:

Originally Posted by Doitsu (Post 3085852)
IMHO, it's only fair to mention that the most sophisticated part of the plugin code wasn't written by me. :)

Well, if sophistication is the bar being set, I'm pretty sure I haven't written much Python code at all. :D

rubeus 07-04-2015 04:17 PM

Is there a way to have the dropdown box showing sorted img-keys?

Ok that was easy :)

replace
Code:

        image['values'] = img_dic.keys()
with
Code:

        image['values'] = sorted(img_dic.keys())
Why is

Code:

        image['values'] = img_dic.keys().sort()
exporting an empty list?

DiapDealer 07-04-2015 05:37 PM

Quote:

Originally Posted by rubeus (Post 3128652)
Why is

Code:

        image['values'] = img_dic.keys().sort()
exporting an empty list?

The sort() method of a list modifies the list in place, but returns None. To do what you want with the list method, you'd have to do something like:

Code:

image['values'] = img_dic.keys()
image['values'].sort()
print image['values']

The 'sort' list method was all that was available prior to Python 2.4. The builtin function 'sorted' (available from Python 2.4+) builds a new sorted list from any iterable--and is imminently handier most times--as you've no doubt discovered. ;)

Code:

print sorted(img_dic.keys())

rubeus 07-05-2015 01:20 AM

Quote:

Originally Posted by DiapDealer (Post 3128681)
The sort() method of a list modifies the list in place, but returns None.

:smack:

:thanks:


All times are GMT -4. The time now is 08:03 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.