Readin file csv with shared object

I’m trying to create a shared object with Python to read csv file and be used by a C application.

So I’m having a really hard time doing this.

my code is here:

`from cffi import FFIimport csvimport io
ffi = FFI()
ffi.cdef("""void processCsv(const char[], const char[], const char[]);void processCsvFile(const char[], const char[], const char[]);""")
def process_csv(csv_data, selected_columns, row_filter_definitions):# Parse the CSV datacsv_reader = csv.DictReader(io.StringIO(csv_data.decode('utf-8')))headers = csv_reader.fieldnames
# Parse selected columns
if selected_columns:
    selected_columns = selected_columns.decode('utf-8').split(',')
else:
    selected_columns = headers

# Parse filters
filters = []
if row_filter_definitions:
    for line in row_filter_definitions.decode('utf-8').split('n'):
        if line:
            if '=' in line:
                header, value = line.split('=')
                op = '='
            elif '>' in line:
                header, value = line.split('>')
                op = '>'
            elif '<' in line:
                header, value = line.split('<')
                op = '<'
            filters.append((header, op, value))

# Apply filters and select columns
output = io.StringIO()
csv_writer = csv.DictWriter(output, fieldnames=selected_columns)
csv_writer.writeheader()

for row in csv_reader:
    match = all((op == '=' and row[header] == value) or 
                (op == '>' and row[header] > value) or 
                (op == '<' and row[header] < value) for header, op, value in filters)
    if match:
        csv_writer.writerow({col: row[col] for col in selected_columns})

print(output.getvalue(), end='')
def process_csv_file(csv_file_path, selected_columns, row_filter_definitions):with open(csv_file_path.decode('utf-8'), 'r') as f:process_csv(f.read().encode('utf-8'), selected_columns, row_filter_definitions)your textffi.set_source("_csv_processor","""#include <stdio.h>
void process_csv(const char csv[], const char selectedColumns[], const char rowFilterDefinitions[]);void process_csv_file(const char csvFilePath[], const char selectedColumns[], const char rowFilterDefinitions[]);
void processCsv(const char csv[], const char selectedColumns[], const char rowFilterDefinitions[]) {process_csv(csv, selectedColumns, rowFilterDefinitions);}
void processCsvFile(const char csvFilePath[], const char selectedColumns[], const char rowFilterDefinitions[]) {process_csv_file(csvFilePath, selectedColumns, rowFilterDefinitions);}""")
if name == "main":ffi.compile(verbose=True)`

And i’m generating this code with:

  • python3 csv_processor.py

so, when i try:

  • gcc -o programa_c programa_c.c -L. -l_csv_processor -lpython3.10

i’m receive it’s error:

  • /27818bb096b67c55a7a954c23cec29630e6d644e$ gcc -o programa_c programa_c.c -L. -l_csv_processor -lpython3.10
    /usr/bin/ld: cannot find -l_csv_processor: No such file or directory
    collect2: error: ld returned 1 exit status

the code in c is here:

`#include <stdio.h>
void processCsv(const char[], const char[], const char[]);void processCsvFile(const char[], const char[], const char[]);
int main(){const char csv[] = "header1,header2,header3n1,2,3n4,5,6n7,8,9";processCsv(csv, "header1,header3", "header1>1nheader3<9");
const char csv_file[] = "data.csv";
processCsvFile(csv_file, "header1,header3", "header1>1nheader3<9");

return 0;
}`and i need:
  • Implement a library that processes CSV files, applying filters and selecting columns as specified. The solution must be able to integrate with the interface defined in C below.
/**
 * Process the CSV data by applying filters and selecting columns.
 *
 * @param csv The CSV data to be processed.
 * @param selectedColumns The columns to be selected from the CSV data.
 * @param rowFilterDefinitions The filters to be applied to the CSV data.
 *
 * @return void
 */
void processCsv(const char[], const char[], const char[]);

/**
 * Process the CSV file by applying filters and selecting columns.
 *
 * @param csvFilePath The path to the CSV file to be processed.
 * @param selectedColumns The columns to be selected from the CSV data.
 * @param rowFilterDefinitions The filters to be applied to the CSV data.
 *
 * @return void
 */
void processCsvFile(const char[], const char[], const char[]);

processCsv

  • csv: String with CSV data, where each line represents a record and the columns are separated by commas.
    • Example: “header1,header2,header3n1,2,3n4,5,6”
  • selectedColumns: A string where the names of the columns to be selected are separated by commas.
    • Example: “header1,header3”
  • rowFilterDefinitions: A string where each filter is defined on a new line, in the format header(comparador)valor.
    • Example: “header1>1nheader2=2nheader3<6”

processCsvFile

  • csvFilePath: String with the CSV file path.
    • Example: “path/to/csv_file.csv”
  • selectedColumns: A string where the names of the columns to be selected are separated by commas.
    • Example: “header1,header3”
  • rowFilterDefinitions: A string where each filter is defined on a new line, in the format header(comparador)valor.
    • Example: “header1>1nheader2=2nheader3<6”

I don’t know where I could be going wrong, as I’ve never worked with this type of application, it’s the first time

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật