Latest recipes tagged "c"http://code.activestate.com/recipes/tags/c/new/2016-12-11T16:28:50-08:00ActiveState Code RecipesSimulate C's switch statement (Python) 2016-12-11T16:28:50-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580730-simulate-cs-switch-statement/ <p style="color: grey"> Python recipe 580730 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/features/">features</a>, <a href="/recipes/tags/language/">language</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/switch/">switch</a>). </p> <p>This recipe shows a Python construct that can behave somewhat like C's switch statement. It is not a perfect one-to-one simulation. But it does have some of the features of the C switch. One feature not supported is the fall-through feature in C's switch.</p> Add function to Python's __builtin__ module through C API - makefile (Text) 2015-10-16T12:11:36-07:00airweenhttp://code.activestate.com/recipes/users/4192997/http://code.activestate.com/recipes/579111-add-function-to-pythons-__builtin__-module-through/ <p style="color: grey"> Text recipe 579111 by <a href="/recipes/users/4192997/">airween</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/makefile/">makefile</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Makefile for add function to __builtin__ module through C API.</p> <p>C source is here:</p> <p><a href="https://code.activestate.com/recipes/579110-add-function-to-__builtin__-module-through-c-api/" rel="nofollow">https://code.activestate.com/recipes/579110-add-function-to-__builtin__-module-through-c-api/</a></p> <p>Python script is here:</p> <p><a href="https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/</a></p> Add function to Python's __builtin__ module through C API (C) 2015-10-16T12:11:58-07:00airweenhttp://code.activestate.com/recipes/users/4192997/http://code.activestate.com/recipes/579110-add-function-to-pythons-__builtin__-module-through/ <p style="color: grey"> C recipe 579110 by <a href="/recipes/users/4192997/">airween</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/builtins/">builtins</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/exten/">exten</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Add function to __builtin__ module through C API</p> <p>Sometimes it need to embedding a Python script to a C code, and it references to a function, which also provided by the same C code. Then you have to import the module, as you defined in your C code.</p> <p>But this import would be skipped, if you add your function to your __builtin__ module. In Python3 (3.5), there is the PyModule_AddFunctions() function, but in the previous versions, you can make it like this snippet.</p> <p>See these recipes:</p> <p>Makefile: <a href="https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/</a></p> <p>Python script: <a href="https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/</a></p> Pachebel Cannon in C (Python) 2013-08-13T21:08:45-07:00Bhttp://code.activestate.com/recipes/users/4187518/http://code.activestate.com/recipes/578640-pachebel-cannon-in-c/ <p style="color: grey"> Python recipe 578640 by <a href="/recipes/users/4187518/">B</a> (<a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/cannon/">cannon</a>, <a href="/recipes/tags/in/">in</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/pachebel/">pachebel</a>). </p> <p>only works in windows</p> Random Number Game (C) 2012-03-29T03:47:52-07:00Jacob A. Bridgeshttp://code.activestate.com/recipes/users/4181498/http://code.activestate.com/recipes/578088-random-number-game/ <p style="color: grey"> C recipe 578088 by <a href="/recipes/users/4181498/">Jacob A. Bridges</a> (<a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/guessing/">guessing</a>, <a href="/recipes/tags/number/">number</a>). </p> <p>An old game I created freshman year of college. For use on Windows OS only. (The code contains a few Windows system calls.)</p> csc prototype to arduino board with python API. part II (Python) 2010-12-26T12:20:48-08:00cheeng shu chinhttp://code.activestate.com/recipes/users/163970/http://code.activestate.com/recipes/577521-csc-prototype-to-arduino-board-with-python-api-par/ <p style="color: grey"> Python recipe 577521 by <a href="/recipes/users/163970/">cheeng shu chin</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/serial/">serial</a>). Revision 2. </p> <p>This is the Python API for my arduino uno board. this is base on what i posted in <a href="http://code.activestate.com/recipes/577520-csc-prototype-to-arduino-board-with-python-api-par/?in=user-163970">Part I</a> .. I didn't spend time to comments it... I'll do it once free soon. Please study it and extend it and share among open source members especially in python... :)</p> <p>The file name is "cscarduino.py"</p> <p>if you facing "Pyserial Invalid Handle" issue in your 64bit windows 7 server, Please refer to this:</p> <ol> <li><a href="http://permalink.gmane.org/gmane.comp.python.tutor/67030">link1</a></li> <li><a href="http://www.mail-archive.com/tutor@python.org/msg46974.html">link2</a></li> </ol> csc prototype to arduino board with python API. part I (C) 2010-12-26T12:14:33-08:00cheeng shu chinhttp://code.activestate.com/recipes/users/163970/http://code.activestate.com/recipes/577520-csc-prototype-to-arduino-board-with-python-api-par/ <p style="color: grey"> C recipe 577520 by <a href="/recipes/users/163970/">cheeng shu chin</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/serial/">serial</a>). Revision 2. </p> <p>Few day ago, i'm try out arduino UNO robotic board. found it not that easy to use (C &lt;--> Python). I wrote a arduino UNO prototype to serial API, which can interface to any programming Language. as long as the programming Language can interface to virtual serial port and using serial API, this recipe can be use... Requirement:</p> <p>Upload this recipes to arduino uno with my prototype code (name "csc.pde" as below)</p> <p>Base concept:</p> <ol> <li>wait from serial reply "?" and ready for read</li> <li>pass function name as string to arduino uno</li> <li>pass all argument as string to arduino uno</li> <li>read result as string from arduino uno</li> </ol> <p>Can easy extend it to support:</p> <ol> <li>python API(open source and i like most) in part II</li> <li>other arduino board</li> <li>Bluetooth with serial interface</li> <li>any PC can control the arduino board easily via your prefer Language.</li> <li>interrupt </li> </ol> <p>Future add-on:</p> <ol> <li>Json string passing to arduino</li> <li>Json Reply from arduino</li> <li>thread base design</li> <li>Interrupt direct call</li> </ol> <p>Please study it and extend it and share among open source members especially in python... :)</p> <p>Next <a href="http://code.activestate.com/recipes/577521-csc-prototype-to-arduino-board-with-python-api-par/">Part II</a></p>