Ir al contenido principal

Entradas

Mostrando las entradas etiquetadas como Python

I have been playing with pdb for debugging code (introductory level)

Well, this is time to talk about something I have been playing, the pdb standard module python provides. I'll talk in the context of py 3.7+ since there are differences that improve how to work with this. Well, first of all, as you should found in this field and coding experiences and challenges. You have to deal with bugs, unexpected errors, or even worst, unexpected behavior which sometimes is most difficult to trace. Here are some lights on how to use it, this is really useful if your life is coding :). Consider the following commands table. Command Description s Execute the current line and stop at the first possible occasion. n Continue the execution until the next line in the current function is reached or it returns. p Shows the values of variables in context code. ll List the whole source code for the current function or frame l In contrast to ll, this command shows a shorter snippet of code. l. If you pass the param . to this command, it will show you always 11 li...

Algoritmos en ciencias de la computación, parte 1: búsquedas binarias

En la práctica los algoritmos nos ayudan a resolver problemas en diferentes escalas de complejidad y para diferentes situaciones, es por ello que vale la pena revisar y sobre todo practicarlos regularmente, todo con la finalidad de fortalecer nuestro entendimiento y sobre todo nuestra habilidad de resolver problemas y también mejorar la calidad de nuestro código fuente, independientemente del lenguaje de programación que utilicemos. En esta ocasión revisaremos con detalle uno de los métodos de búsquedas más utilizados y estudiados en las ciencias de la computación. El método de búsquedas binarias se utiliza mucho en situaciones en donde requieres hacer búsquedas de manera eficiente y sobre todo rápidas, es por ello que analizaremos un ejemplo y correremos algunas pruebas (en mi caso utilizaré Python, sin embargo intentaré compartirles la versión en Java posteriormente). Imaginemos el siguiente ejem...

How a feature collection of points should looks like

¿How a feature collection of points should looks like? Do not forget, this is a JSON notation. {     "type": "FeatureCollection",     "features": [{         "type": "Feature",         "geometry": {             "type": "Point",             "coordinates": [-105.02, 39.61]         },         "properties": {             "prop0": "value0"         }     }] }; For example the small code above can be added to a Leaflet library to see how this run. intelimapa.com is using this approach for feeding its clients maps.

Python para escribir archivos en el sistema de archivos

Recientemente me contactó un amigo que programa en Java, y resulta que está haciendo algún tipo de integración en un sistema donde hace su residencia y me pidió un ejemplo sobre cómo generar archivos en texto plano con python. Aquí el ejemplo: params = { "foo": "This is a string", "bar": 200 } filename = 'texto_python.txt' file_to_write = open(filename,'w') file_to_write.write('El contenido del archivo es: {0} y esto un número {1} \n'.format(params["foo"], params["bar"])) file_to_write.write('Más texto.') file_to_write.close() Es un ejercicio básico pero siempre necesario. Ver en repo https://github.com/jonanx779/python-stuffs/blob/master/writing_file.py