Jump to content
×
×
  • Create New...

[Python] Code Translator 2 to 3


Recommended Posts

  • Moderator

M2 Download Center

Download Here ( Internal )

Hidden Content

    Give reaction to this post to see the hidden content.
( GitHub )

Python-Code-Translator-2-to-3

Is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code that works on all versions (py2.x - py3.x).

The standard library contains a rich set of fixers that will handle almost all code. A flexible and generic library, so it is possible to write your own fixers based on your purposes.

Warning: This tool purpose wasn't for doing the transition to python3, is just for the IDE purpose.

INSTALLATION
USING
  • Add your .py scripts to the modules folder.
  • Run main.bat
  • Take the output files and move them into your application.
FIXERS
print
  • Converts the print statement to the print() function.
  • Matching multiple formats, comments, and more.
Exception handling
  • Convert except to except BaseException, since BaseException is the base class for all built-in exceptions.
  • Converts except X, T to except X as T.
xrange
  • Renames xrange() to range() and wraps existing range() calls with list.
has_key
  • Changed dict.has_key(key) to dict..contains__(key)
dict
  • Fixes dictionary iteration methods. dict.iteritems() is converted to dict.items(), dict.iterkeys() to dict.keys(), and dict.itervalues() to dict.values(). Similarly, dict.viewitems(), dict.viewkeys() and dict.viewvalues() are converted respectively to dict.items(), dict.keys() and dict.values(). It also wraps existing usages of dict.items(), dict.keys(), and dict.values() in a call to list.
exec - TODO
  • Converts the exec statement to the exec() function.
apply - TODO
  • Removes usage of apply(). For example apply(function, *args, **kwargs) is converted to function(*args, **kwargs).
raise - TODO
  • Converts raise E, V to raise E(V), and raise E, V, T to raise E(V).with_traceback(T). If E is a tuple, the translation will be incorrect because substituting tuples for exceptions has been removed in 3.0.

 

You can use it together with Skeleton of Python modules for IDE, from @Takuma.

 

Download:

Hidden Content

    Give reaction to this post to see the hidden content.

  • Metin2 Dev 28
  • Love 33
  • Love 4
  • Good 18
  • Confused 1
  • Not Good 1
  • Dislove 1
Link to comment
Share on other sites

  • 1 month later...
  • Moderator

Update

  • implementation of the TODO tasks (exec/apply/raise, [...])
  • added the pip environment
  • added a library used for encoding detection of the python script files

Thanks to @ServerCommandParser for contributions.

 

 

 

  • Love 3
  • Good 1
Link to comment
Share on other sites

  • 3 months later...

Hey ! Sorry, i'm late, but I just tought about it because I'm upgradding my client to Py3. I think you fourgot something (And I have one in my system.py).

In python2 you can specifie a numeric type for numer like :

my_numeric = 0L

But it is no longer supported in Python3, and we need juse use :

my_numeric = 0

Same with 0j.

(Source: PEP 237)

Edited by Takuma
  • Metin2 Dev 5
  • Love 1
Link to comment
Share on other sites

  • 3 months later...
  • Web Developer

Hey, found some issues while using your translator.

They're all related to raise Exception, present in stringcommander.py, consolemodule.py and uidragonsoul.py

On stringcommander.py, in function Run in class Analyzer.

On consolemodule.py, there are 4 raise's "alone", without Exception, which makes the following functions bug.

On uidragonsoul.py, in function __SetItem in class DragonSoulRefineWindow.

Replacing all this raise's with the python 2 version they work fine.

  • Metin2 Dev 1

QJ0orbR.png

Metin2 Icon Database

Link to comment
Share on other sites

  • Moderator

I will update the repo when I will have some free time, right now I'm very busy with the university and the job.
For those who want to contribute to it, you can do a pull request in the GitHub repository.

  • Love 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Activity

    1. 0

      Looking for Someone to create the queries etc for armors and weapons

    2. 13

      Official Private Shop Search

    3. 944

      [40250] Reference Serverfile + Client + Src [15 Available Languages]

    4. 79

      GUI Teleport System

    5. 0

      inventory slot marking system cant compile

    6. 8

      Inventory Bug

    7. 63

      Metin2 Dev - Changelogs

  • Recently Browsing

    • No registered users viewing this page.

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.