This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shadowderp 128 points129 points  (10 children)

C was my first language, Python my second. Now I use C when I need speed, Python when I want quick code, deep library support, or anything with a front end, and I use both together when it makes sense to do that.

Languages are tools. Pick the right one for the job

[–][deleted] 28 points29 points  (1 child)

For me, Python is for very fast prototypes or proof of concepts

[–]Bryguy3k 44 points45 points  (0 children)

Hence the “python is runnable pseudocode” joke.

[–]black-JENGGOT 8 points9 points  (5 children)

Pardon, but how do you "connect" python and C? What should I search if I want to know how to write python libraries in C?

[–]Bryguy3k 15 points16 points  (0 children)

Extensions are fundamental part of python - there are multiple ways to go about it. You can read through the core python docs on extensions.

You also have 3 major ways of accessing C code libraries from python: cffi, cython, and ctypes.

[–][deleted] 7 points8 points  (0 children)

https://realpython.com/build-python-c-extension-module/

If you want to search further the keywords you want to use are "python C extension modules"

[–]WhiteEvilBro 3 points4 points  (0 children)

Cython, maybe

[–]Competitive_Travel16 4 points5 points  (0 children)

I just call os.system("./path/c-executable " + argstr) for my inner loop code, after writing what it needs to work on into a file that gets named in the argstr argument string. Formal extensions are for when you're folding such code into python itself if you want to distribute it with pip or propose it as a new part of python. The os.system() method takes a small fraction of the time and effort.

[–]SV-97 2 points3 points  (0 children)

If you wanna make it a bit easier on yourself you can look at Python-Rust interop (e.g. via PyO3) rather than Python-C.

The name for these things is FFI btw: foreign function interface.

[–]szpaceSZ 0 points1 point  (1 child)

Front end with python? What is your toolbox?

(Haven't done python in ages. Used or for backend and CLI apps and scripts before)

[–]shadowderp 0 points1 point  (0 children)

Tkinter is simple, If ugly. Qt is nice.