geekhack

geekhack Community => Off Topic => Topic started by: xtrafrood on Wed, 30 January 2019, 23:37:29

Title: Cython?
Post by: xtrafrood on Wed, 30 January 2019, 23:37:29
~30 lines of Python compiled into +3k lines of C.. So uh, any other GH users 'play' with Cython? Cython seems like an awesome box of the Pandora variety.
Title: Re: Cython?
Post by: pr0ximity on Thu, 31 January 2019, 05:33:56
I've wanted to try writing some C extensions for Python but never had a use case really. What do you do?
Title: Re: Cython?
Post by: Findecanor on Thu, 31 January 2019, 06:19:45
I wonder, how does Cython work together with C extensions for Python? Would they have to be modified extensively?
Title: Re: Cython?
Post by: xtrafrood on Thu, 31 January 2019, 08:14:13
IDK, I fed a small tkinter python script to Cython and it rendered a .c file for me to compile with gcc or mingw-w64.

Although my Cython usage is limited to this one instance, I can say my first binary output was a success.

When I execute the new tkinter script turned binary it renders a window with three buttons. From what I can tell there is no behavior difference. Which I think is interesting.
Title: Re: Cython?
Post by: joey on Thu, 31 January 2019, 09:49:22
IDK, I fed a small tkinter python script to Cython and it rendered a .c file for me to compile with gcc or mingw-w64.

Although my Cython usage is limited to this one instance, I can say my first binary output was a success.

When I execute the new tkinter script turned binary it renders a window with three buttons. From what I can tell there is no behavior difference. Which I think is interesting.

Paste the C code somewhere!
Title: Re: Cython?
Post by: xtrafrood on Thu, 31 January 2019, 10:44:08
IDK, I fed a small tkinter python script to Cython and it rendered a .c file for me to compile with gcc or mingw-w64.

Although my Cython usage is limited to this one instance, I can say my first binary output was a success.

When I execute the new tkinter script turned binary it renders a window with three buttons. From what I can tell there is no behavior difference. Which I think is interesting.

Paste the C code somewhere!

Okelydokely :).  I included the original (bad) python script too.

exit_menu.py (http://pastebin.com/nV6XwWWz) ... exit_menu.c (http://pastebin.com/ewDHvdt1)
Title: Re: Cython?
Post by: JP on Thu, 31 January 2019, 10:55:04
That is a big and scary C program  :eek: I am thinking even a simple hello world would also be similar.
Title: Re: Cython?
Post by: xtrafrood on Thu, 31 January 2019, 12:03:16
That is a big and scary C program  :eek: I am thinking even a simple hello world would also be similar.

Although I'd imagine collaboration with such a C program would be.. uh.. less than stellar, IIRC GUI creation requires a few more lines than the average Hello World program.