LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2024, 12:11 PM   #1
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
Python: Argument requires 3 arguments (1 given)


I'm trying to move toward python now. Working on bindings for my c library I've been working on. the prompt_input_getline() function I'm trying to call takes a single string parameter in the c code. I just cannot for the life of me sort this out. Been googling awhile. Here is the c function for reference.

Code:
char *
prompt_input_getline(const char * prompt)
{
  assert(prompt);
  
  // declare & initialize
  char * retval = NULL;

  // print & get input
  prompt_print(prompt);
  retval = getline_stdin_mem_alloc();
  if (retval) {
    no_more_newline(retval);
  }

  return(retval);
}
This is my current python testing. Maybe I'm trying something more advanced than I'm ready for.

Code:
#!/usr/bin/python3
# python bindings for libjmgeneral.so

import ctypes
from ctypes import *
import pathlib

lib = pathlib.Path().absolute() / "/usr/local/lib/libjmgeneral.so"
libjmgen_lib = ctypes.CDLL(lib)

def random_gen(a, b):
	return libjmgen_lib.random_gen(a, b)
  
def clear_ptr(a):
  libjmgen_lib.clear_ptr(a)

def prompt_input_getline(a):
  libjmgen_lib.prompt_input_getline.argtypes = [c_char_p,c_char_p,c_char_p]
  libjmgen_lib.prompt_input_getline.restypes = c_char_p
  b_string = a.encode('utf-8')
  print(libjmgen_lib.prompt_input_getline("lol"))
  
prompt_input_getline("lol")
 
Old 01-15-2024, 02:31 PM   #2
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Original Poster
Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
Found it. I don't know if it's ideal but I got my result. Now to free the memory.

Code:
#!/usr/bin/python3
# python bindings for libjmgeneral.so

import ctypes
from ctypes import *
import pathlib

lib = pathlib.Path().absolute() / "/usr/local/lib/libjmgeneral.so"
libjmgen_lib = ctypes.CDLL(lib)

def random_gen(a, b):
	return libjmgen_lib.random_gen(a, b)
  
def clear_ptr(a):
  libjmgen_lib.clear_ptr(a)

def prompt_input_getline(a):
  func_call = libjmgen_lib.prompt_input_getline
  func_call.argtypes = [c_char_p]
  func_call.restype = c_char_p
  result = libjmgen_lib.prompt_input_getline(a.encode('utf-8'))
  return result.decode('utf-8')
  #return(libjmgen_lib.prompt_input_getline(b_string))
  
y = prompt_input_getline("lol")
print(y)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Trying to install RadeonOpenCompute which requires Python 3.8 but my Kubuntu has Python 3.9 doumamuzan Linux - Newbie 3 06-25-2021 02:32 PM
Have newer python, but an app requires older python postcd Linux - General 2 05-05-2014 12:35 AM
Problem: Upgrading Firefox, it requires pangocairo, which requires pango with cairo supports murtuzanaqvi Linux - Newbie 1 08-27-2010 06:58 AM
Adobe Acrobate Reader Requires A Plugin-That Requires Open LDAP That Requires Berkely Old_Fogie Slackware 10 05-08-2006 05:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration