(Jan-16-2021, 03:47 PM)buran Wrote: there is 2to3 tool that makes automatic conversion.
I verified and I indeed have 2to3.py in my Python scripts. I gave it a try following the documentation and got:
Output:>>> $ 2to3 GMLMaker.py
File "<stdin>", line 1
$ 2to3 GMLMaker.py
^
SyntaxError: invalid syntax
So I instead went to the "Run" tab in IDLE, and used the "Run... customized", then used my file name as input, and got:Output:RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored D:/Milky/GMLMaker.py
--- D:/Milky/GMLMaker.py (original)
+++ D:/Milky/GMLMaker.py (refactored)
@@ -47,7 +47,7 @@
DIST_LIMIT_AND_HABITABLE,\
DIST_LIMIT_AND_TWO_HABITABLE,\
TWO_CLOSEST_HABITABLE_AND_TWO_NEIGHBOR\
- = range(13)
+ = list(range(13))
DEFAULT_ALGORITHM = TWO_CLOSEST_NEIGHBORS
class SpectralClass:
@@ -61,7 +61,7 @@
CLASS_M,\
CLASS_X,\
NUM_CLASSES\
- = range(9)
+ = list(range(9))
encode = {
CLASS_O:"O",\
@@ -117,7 +117,7 @@
YG,\
ZG,\
ABS_MAG\
- = range(17)
+ = list(range(17))
class StarField:
"""used to index into a starNode tuple"""
@@ -128,14 +128,14 @@
LUMINOSITY,\
DISTANCE,\
LOCALE\
- = range(7)
+ = list(range(7))
class Coord:
"""used to index into an XYZ locale tuple"""
XG,\
YG,\
ZG\
- = range(3)
+ = list(range(3))
class BBCoord:
"""used to index into an bounding box"""
@@ -143,7 +143,7 @@
TOP_Y,\
RIGHT_X,\
BOTTOM_Y\
- = range(4)
+ = list(range(4))
class SystemField:
"""used to index into a starSystem node"""
@@ -156,14 +156,14 @@
SYSTEM_STARS,\
AT_LEAST_ONE_HABITABLE,\
PRINT_LOCALE\
- = range(9)
+ = list(range(9))
class LinkField:
"""used to index into a link node"""
START_INDEX,\
DEST_INDEX,\
DISTANCE\
- = range(3)
+ = list(range(3))
#******************************************************************************
# Function definitions
@@ -231,7 +231,7 @@
if locale[Coord.YG] > boundingBox[BBCoord.BOTTOM_Y]:
boundingBox[BBCoord.BOTTOM_Y] = locale[Coord.YG]
- print("Loading #%d: %s" % (index, starNode[1]))
+ print(("Loading #%d: %s" % (index, starNode[1])))
# find star system that the new star belongs in
theSystemIndex = GetSystemAt(starSystems, locale)
@@ -264,7 +264,7 @@
starSystems[theSystemIndex] = starSystemNode
except csv.Error:
- print("LoadStars: Error parsing" + theFileName + ".csv")
+ print(("LoadStars: Error parsing" + theFileName + ".csv"))
boundingBox[BBCoord.LEFT_X] = math.floor(boundingBox[BBCoord.LEFT_X])
boundingBox[BBCoord.TOP_Y] = math.floor(boundingBox[BBCoord.TOP_Y])
@@ -293,7 +293,7 @@
# so if link x to y is stored, new link y to x will NOT be stored
theKey = "%d:%d" % ([destIndex, startIndex][startIndex < destIndex],
[destIndex, startIndex][startIndex >= destIndex])
- if not starLinks.has_key(theKey):
+ if theKey not in starLinks:
starLinks[theKey] = (startIndex, destIndex, linkLength)
linkFile.write("[%s]\t%.1fpc to\t[%s]\n" % (startName, linkLength, destName))
return starLinks
@@ -460,7 +460,7 @@
for systemIndex in starSystems:
forbiddenStars = []
index += 1
- print("Calculating Star %d of %d" % (index, numStars))
+ print(("Calculating Star %d of %d" % (index, numStars)))
starLinks = linkFunction(starSystems[systemIndex], starSystems,
starLinks, linkFile, forbiddenStars)
linkFile.close()
@@ -485,7 +485,7 @@
numStars = len(starSystems)
for systemIndex in starSystems:
index += 1
- print("Printing Star %d of %d" % (index, numStars))
+ print(("Printing Star %d of %d" % (index, numStars)))
aStarSystem = starSystems[systemIndex]
nameBuffer = aStarSystem[SystemField.SYSTEM_NAME].replace(
", ", "\n")
@@ -543,7 +543,7 @@
numLinks = len(starLinks)
for linkIndex in starLinks:
index += 1
- print("Printing link %d of %d" % (index, numLinks) )
+ print(("Printing link %d of %d" % (index, numLinks) ))
aStarLink = starLinks[linkIndex]
startSystem = starSystems[aStarLink[LinkField.START_INDEX]]
destSystem = starSystems[aStarLink[LinkField.DEST_INDEX]]
RefactoringTool: Files that need to be modified:
RefactoringTool: D:/Milky/GMLMaker.py
So apparently it worked and made further changes? Why ending in "Files that need to be modified"? The result is obscure to me. I also don't get why $ 2to 3
doesn't work.Anyway, I still get the error when doing the same "Run... customized" with the GMLMaker.py:
Error:Traceback (most recent call last):
File "D:\Milky\GMLMaker.py", line 606, in <module>
starfilePrefix = starfileName[:-4]
NameError: name 'starfileName' is not defined