FNCS / fncs

Framework for Network Co-Simulation
Other
21 stars 15 forks source link

Python 3.0 suppport for fncs.py #16

Closed craig8 closed 6 years ago

craig8 commented 6 years ago

The following example code is one way of "fixing" it to work with both 2.7 and 3.5 versions of python.

import sys

def initialize(config=None):

    if config:
        if sys.verion_info[0] < 3:
            _initialize_config(config)
        else:
            cbuf = ctypes.create_string_buffer(config.encode())
            _initialize_config(cbuf)
    else:
        _initialize()
jeffdaily commented 6 years ago

I have had to make similar changes to other projects to support py2/3. There are other functions that take string arguments that will need to be updated, as well.

if sys.version_info.major < 3: def b(x): return str(x) def isstr(s): return isinstance(s, basestring) else: import codecs def b(x): return codecs.latin_1_encode(str(x))[0] def isstr(s): return isinstance(s, str)

Then, any call that takes a str, the str would be wrapped by the b() function. That ensures that I have a C-string available to pass to the fncs functions.

Would that work?

From: Craig [mailto:notifications@github.com] Sent: Friday, November 10, 2017 12:38 PM To: FNCS/fncs fncs@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [FNCS/fncs] Python 3.0 suppport for fncs.py (#16)

The following example code is one way of "fixing" it to work with both 2.7 and 3.5 versions of python.

import sys

def initialize(config=None):

if config:

    if sys.verion_info[0] < 3:

        _initialize_config(config)

    else:

        cbuf = ctypes.create_string_buffer(config.encode())

        _initialize_config(cbuf)

else:

    _initialize()

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/FNCS/fncs/issues/16, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA3MOIvLglhJgFVeLqg4iDwesHBYgUO3ks5s1LQzgaJpZM4QaFDy.

afisher1 commented 6 years ago

this is currently supported in develop