Topics

cpython and ironpython 'argparse' modules not compatible?

Djordje Spasic
 

I am trying to convert the following cpython 2.7 script into an ironpython script.
The only line that I tried to change is, line 19. It was replaced to:

    from xml import etree

as lxml does not seem to exist in ironpython?

The issue is that script crashes on line 129, where the following function is called:

def parse_args():

    parser = argparse.ArgumentParser(description='Converts a CSV file to an OSM file')

    parser.add_argument('csv_file', help='CSV file to read')

    parser.add_argument('output_file', help='Output file name')

    parser.add_argument('--csv-dialect', default='excel',

        help='The csv dialect, i.e. the algorithm used to interpret the textual data. '

             'Can be one of: ' + ', '.join(csv.list_dialects()))

    parser.add_argument('--csv-encoding', default='utf-8',

            help='Character encoding of the CSV file. Examples: utf-8, latin1')

    parser.add_argument('--lon', dest='longitude_field', default='longitude',

        help='Name of the field that contains the longitude')

    parser.add_argument('--lat', dest='latitude_field', default='latitude',

        help='Name of the field that contains the latitude')

    parser.add_argument('--translator', help='Python file to import that '

        'contains special translation methods to transform the tags.')

    parser.add_argument('-f', '--force', dest='force_overwrite', action='store_true',

        help='Force overwriting the destination file.')

    return parser.parse_args()

What would be the reason for this?

Does this mean that "argparse" module lacks some of the function from cpython to ironpython?

Any help would be much appreciated, as this exceeds my level of knowledge of either of pythons.
I have IronPython 2.7.7 installed.

Alex Earl
 

What error are you getting?


On Fri, Nov 2, 2018 at 1:45 PM Djordje Spasic via Groups.Io <issworld2000=yahoo.com@groups.io> wrote:

I am trying to convert the following cpython 2.7 script into an ironpython script.
The only line that I tried to change is, line 19. It was replaced to:

    from xml import etree

as lxml does not seem to exist in ironpython?

The issue is that script crashes on line 129, where the following function is called:

def parse_args():

    parser = argparse.ArgumentParser(description='Converts a CSV file to an OSM file')

    parser.add_argument('csv_file', help='CSV file to read')

    parser.add_argument('output_file', help='Output file name')

    parser.add_argument('--csv-dialect', default='excel',

        help='The csv dialect, i.e. the algorithm used to interpret the textual data. '

             'Can be one of: ' + ', '.join(csv.list_dialects()))

    parser.add_argument('--csv-encoding', default='utf-8',

            help='Character encoding of the CSV file. Examples: utf-8, latin1')

    parser.add_argument('--lon', dest='longitude_field', default='longitude',

        help='Name of the field that contains the longitude')

    parser.add_argument('--lat', dest='latitude_field', default='latitude',

        help='Name of the field that contains the latitude')

    parser.add_argument('--translator', help='Python file to import that '

        'contains special translation methods to transform the tags.')

    parser.add_argument('-f', '--force', dest='force_overwrite', action='store_true',

        help='Force overwriting the destination file.')

    return parser.parse_args()

What would be the reason for this?

Does this mean that "argparse" module lacks some of the function from cpython to ironpython?

Any help would be much appreciated, as this exceeds my level of knowledge of either of pythons.
I have IronPython 2.7.7 installed.

Alex Earl
 

Also, IronPython 2.7.7 has significant compatibility issues with CPython, it is highly recommended that you upgrade to 2.7.9.


On Fri, Nov 2, 2018 at 1:49 PM Slide <slide.o.mix@...> wrote:
What error are you getting?

On Fri, Nov 2, 2018 at 1:45 PM Djordje Spasic via Groups.Io <issworld2000=yahoo.com@groups.io> wrote:

I am trying to convert the following cpython 2.7 script into an ironpython script.
The only line that I tried to change is, line 19. It was replaced to:

    from xml import etree

as lxml does not seem to exist in ironpython?

The issue is that script crashes on line 129, where the following function is called:

def parse_args():

    parser = argparse.ArgumentParser(description='Converts a CSV file to an OSM file')

    parser.add_argument('csv_file', help='CSV file to read')

    parser.add_argument('output_file', help='Output file name')

    parser.add_argument('--csv-dialect', default='excel',

        help='The csv dialect, i.e. the algorithm used to interpret the textual data. '

             'Can be one of: ' + ', '.join(csv.list_dialects()))

    parser.add_argument('--csv-encoding', default='utf-8',

            help='Character encoding of the CSV file. Examples: utf-8, latin1')

    parser.add_argument('--lon', dest='longitude_field', default='longitude',

        help='Name of the field that contains the longitude')

    parser.add_argument('--lat', dest='latitude_field', default='latitude',

        help='Name of the field that contains the latitude')

    parser.add_argument('--translator', help='Python file to import that '

        'contains special translation methods to transform the tags.')

    parser.add_argument('-f', '--force', dest='force_overwrite', action='store_true',

        help='Force overwriting the destination file.')

    return parser.parse_args()

What would be the reason for this?

Does this mean that "argparse" module lacks some of the function from cpython to ironpython?

Any help would be much appreciated, as this exceeds my level of knowledge of either of pythons.
I have IronPython 2.7.7 installed.

Djordje Spasic
 

Hi @Alex Earl,

Please accept my apology for never replying to your questions. For some reason I never received an email notification that you posted two replies in this topic. Out of curiosity I came to see if topic is still here, and saw your replies.

 

I uninstalled IronPython 2.7.7 and installed the 2.7.9 but got the same issue.

I am trying to run the upper .py file within ipy.exe console application, with the following command:
    execfile(r"C:\test\csv2osm.py")

After that the ipy.exe window crashes the same way it did with IronPython 2.7.7.

 

When I try to run the same .py file in cmd window:
    "C:\Program Files\IronPython 2.7\ipy.exe" "C:\test\csv2osm.py"

I am getting the following error message:

usage: csv2osm.py [-h] [--csv-dialect CSV_DIALECT]

                  [--csv-encoding CSV_ENCODING] [--lon LONGITUDE_FIELD]

                  [--lat LATITUDE_FIELD] [--translator TRANSLATOR] [-f]

                  csv_file output_file

csv2osm.py: error: too few arguments

Alex Earl
 

The same invocation works with Python 2.7?


On Sun, Nov 25, 2018, 12:28 Djordje Spasic via Groups.Io <issworld2000=yahoo.com@groups.io> wrote:

Hi @Alex Earl,

Please accept my apology for never replying to your questions. For some reason I never received an email notification that you posted two replies in this topic. Out of curiosity I came to see if topic is still here, and saw your replies.

 

I uninstalled IronPython 2.7.7 and installed the 2.7.9 but got the same issue.

I am trying to run the upper .py file within ipy.exe console application, with the following command:
    execfile(r"C:\test\csv2osm.py")

After that the ipy.exe window crashes the same way it did with IronPython 2.7.7.

 

When I try to run the same .py file in cmd window:
    "C:\Program Files\IronPython 2.7\ipy.exe" "C:\test\csv2osm.py"

I am getting the following error message:

usage: csv2osm.py [-h] [--csv-dialect CSV_DIALECT]

                  [--csv-encoding CSV_ENCODING] [--lon LONGITUDE_FIELD]

                  [--lat LATITUDE_FIELD] [--translator TRANSLATOR] [-f]

                  csv_file output_file

csv2osm.py: error: too few arguments

Djordje Spasic
 

Hi Earl,

You are right. I just got the same error message in python 2.7 ("csv2osm.py: error: too few arguments").

I will try to contact the author of the script.
I apologize for disturbance.