Python Forum
[SOLVED] Requiring help running an old Python script (non Python savvy user)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Requiring help running an old Python script (non Python savvy user)
#7
(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
Reply


Messages In This Thread
RE: Requiring help running an old Python script (non Python savvy user) - by Miletkir - Jan-16-2021, 05:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 3 627 May-27-2024, 01:57 AM
Last Post: Alice12
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 226 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Trying to generating multiple json files using python script dzgn989 4 336 May-10-2024, 03:09 PM
Last Post: deanhystad
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 642 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  ChromeDriver breaking Python script genericusername12414 1 422 Mar-14-2024, 09:39 AM
Last Post: snippsat
  using PowerShell from Python script for mounting shares tester_V 8 697 Mar-12-2024, 06:26 PM
Last Post: tester_V
  No Internet connection when running a Python script basil_555 8 861 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 849 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Is possible to run the python command to call python script on linux? cuten222 6 931 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  run SQL without user intervention python dawid294 0 277 Jan-19-2024, 01:11 PM
Last Post: dawid294

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020