Big picture

puska

New member
Hi,

I am wandering what is the big picture behind 11l. Aspect that interests me the most is, effectively, compiling python. The potential problem is with the python ecosystem where, for default implementation, many libraries are written in C. Is there some way to wrap them to be able to link to them either in 11l or from C++ source?
An example is csv library from Python standard Library which actualy calls _csv library written in C. Is there a way to use such libraries with 11l (or any plans that would enable it)?
 

puska

New member
Yes, here it goes (csv_test.py):

Code:
#!/usr/bin/env python3
# -*- coding: utf8 -*-

import csv

filename: str = "csv_test.csv"
with open(filename, 'r') as infile:
    records = [row for row in csv.DictReader(infile, delimiter='\t', quotechar='"')]
print(records)
I also put csv.py in the same directory with csv_test.py and changed imports (just changed from _csv import ... to import _csv) like this:

Python:
"""
csv.py - read/write/investigate CSV files
"""

import re
#from _csv import Error, __version__, writer, reader, register_dialect, \
#                 unregister_dialect, get_dialect, list_dialects, \
#                 field_size_limit, \
#                 QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
#                 __doc__
#from _csv import Dialect as _Dialect
#
#from io import StringIO
import _csv
import StringIO

__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
           "Error", "Dialect", "__doc__", "excel", "excel_tab",
           "field_size_limit", "reader", "writer",
           "register_dialect", "get_dialect", "list_dialects", "Sniffer",
           "unregister_dialect", "__version__", "DictReader", "DictWriter",
           "unix_dialect"]

...
and got following output when from 11l:

Syntax error: can not import module `_csv`: file '_csv.py' is not found
in file 'csv_imports.py', line 15
import _csv
_csv is an example of a C library that is compiled and called from csv.py.
My question is: is there a way to link to such libraries in 11l?
Sorrce code for that library is in the under python source tree: Modules/_csv.c
 

alextretyak

Administrator
Staff member
is there a way to link to such libraries in 11l?
No, currently there is no way to link with C libraries.

First of all, you should answer the following questions:
Why you need your Python code be compiled with the Python → 11l → C++ transpiler? Does it have performance issues? Have you tried PyPy for better performance?

I am wandering what is the big picture behind 11l.
Big picture behind 11l [at least right now] is the following: 11l is not intended to solve every possible problem in the world, but rather to find such problems, which it can solve most effectively.
 
Top