From DoomWiki.org Warning: You are not logged in. Your IP address will be recorded in this page's edit history. Anti-spam check. Do not fill this in! == drawmaps.py script for Python 3 == Since [[Omgifol]] has supported Python 2.7 & Python 3 since 0.3.0, your scaling-supported drawmaps.py maybe can be updated for Python 3? I tried following the [[Omgifol#Drawing_maps]] example using https://www.gamers.org/~fpv/drawmaps.py but Python 3.7.8 gave a syntax error. <pre> File "drawmaps.py", line 73 print "\t%0.2f: %d x %d" % (1.0 / scale, xsize, ysize) </pre> I believe Python 3 deprecated its {{c|print}} ''statement'' supporting C {{c|printf()}}-like arguments. But it can be updated to use string formatting passed into the {{c|print()}} ''function'': <pre> print('\t{0:f2}: {1} x {2}'.format(1.0 / scale, xsize, ysize)) </pre> --[[User:Afterglow|Afterglow]] ([[User talk:Afterglow|talk]]) 22:13, 10 October 2020 (CDT) : Thanks for the heads-up, as a Python noob :-) I wasn't aware of this. I added it as a comment, and also to the other printf-like statement at the end, but not making it the default because one of my (aging) systems is still on Python 2.x. --[[User:Xymph|Xymph]] ([[User talk:Xymph|talk]]) 12:49, 11 October 2020 (CDT) :: https://gist.github.com/derekmd/f00cbb7cca65129b933f91086e76e1f1 is the updated script that works in Python 3. String parameterization actually doesn't need to be changed - simply modify the {{c|print}} statements to be {{c|print()}} functions by adding parenthesis. The only other change is a {{c|list#sort()}} line requiring an update: a) explicitly name the 'key' parameter for the lambda b) only use the single parameter passed into the lambda. (Line 80 now matches the lambda in Omgifol 0.4.0's {{c|demo/drawmaps.py}} file.) :: I believe these changes will be backwards compatible with Python 2.--[[User:Afterglow|Afterglow]] ([[User talk:Afterglow|talk]]) 14:26, 11 October 2020 (CDT) ::: Yup it works. But why change part b of the sort call? --[[User:Xymph|Xymph]] ([[User talk:Xymph|talk]]) 15:24, 11 October 2020 (CDT) :::: Using the {{c|key:}} parameter, Python doesn't pass the 'b' argument to the {{c|list#sort()}} lambda for relative comparisons between items. https://docs.python.org/3/howto/sorting.html#key-functions :::: ''...a key parameter to specify a function ... to be called on each list element '''prior''' to making comparisons.'' :::: Further down the page there's a {{c|cmp}} parameter example that can be used for the old lambda definition, but it requires the script to have different code for Python 2 and 3. https://docs.python.org/3/howto/sorting.html#the-old-way-using-the-cmp-parameter :::: In the case of drawmaps.py, the sort order is a binary true/false and each item can compute its rank in isolation. i.e., a linedef knows if it's 2-sided or not. Return 0 (false) when it's 2-sided, 1 (true) for 1-sided. The linedefs array will be sorted ascending 0 to 1 making 2-sided drawn first, then 1-sided. So the updated lambda is faster than performing an explicit comparison of every linedef combination. The one-argument lambda also works in Python 2 and Python 3. --[[User:Afterglow|Afterglow]] ([[User talk:Afterglow|talk]]) 15:46, 11 October 2020 (CDT) ::::: My link updated. Thanks for the explanation. --[[User:Xymph|Xymph]] ([[User talk:Xymph|talk]]) 16:13, 11 October 2020 (CDT) Summary: All contributions to DoomWiki.org are considered to be released under the CC BY-SA 4.0 International (see Doom Wiki:Copyrights for details). By contributing, you agree to be bound by the Terms of Use. Your changes will be visible immediately. Please enter a summary of your changes above. Do not submit copyrighted images or text without permission! This includes text taken from in-game codices or logbooks, or from official instruction manuals, strategy guides, and other such books. This project is not affiliated with id Software, Raven Software, ZeniMax Media, Bethesda SoftWorks, or any other commercial software developer or publisher. Use of trademarked logos and other protected intellectual property is solely for the purpose of analysis and critical commentary on the identified products and associated fan community activity, and does not imply any endorsement by any of these organizations or their employees, past or present. Upload images to the wiki. Don't forget to categorize pages! For testing, please use a sandbox. View this template Cancel | Editing help (opens in new window)