Tag Archives: #mastery14

Learn To Program 2015-04-24 19:15:00

Mastery14

Los modulos en Python son archivos que generalmente se ejecutan desde la ruta C:\Python34\Lib de nuestra PC, por lo que si creamos un modulo Nombre.py no debemos olvidarnos de la extensión .py
Además, las funciones y variables no se pierden mientras el archivo subsista en la ruta de instalación, por lo que se puede usar un numero inteterminado de veces.
La manera de llamar el modulo importado se realiza de la siguiente manera:

import Nombre
Cuerpo del programa principal
    Nombre.Funcion(Parámetro)

return

Donde Nombre.Funcion es la función a llamar del modulo y Parámetro son los valores para que opere en caso de ser necesario, junto con el return.

Señalar para aclarar dudas que no es lo mismo el modulo que el programa principal, pues desde el programa principal que esta ubicado en ruta X, se llama al modulo generalmente ubicado en la ruta escrita, para que haga operaciones específicas de algo.

**********************
Programa hecho en Python:
**********************
https://github.com/A01630323/Learn-To-Program/blob/master/Mastery14a.py
https://github.com/A01630323/Learn-To-Program/blob/master/Mastery14b.py

Mastery14

Diego Plascencia Sanabria A01229988

For creating and using your own lybraries just follow the next steps:

-First, create the files on “mylibrary.cpp” and “mylibrary.h”

-Next, compile the library without the function main(), this will generate a file called “myfile.o”

-Next, create another file called “main.cpp” (it can be another name, but this one is easier), in this file you need to “mylibrary.h”

-Finally, Compile main.cpp and add the library “myfile.o” 

Hope it help you.

Mastery 14


Ya anteriormente se ha explicado lo que son los modulos y cvomo utilizarlos además de toda la lista de modulos existentes en Python ahora hablaremos de algo nuevo y es el como crear tus propio modulos y como ejecutarlos:

Imagina lo siguiente:
Python tiene una ventana principal una vez que accedes conocida como IDLE o “intérprete” en la cual puedes realizar todo tipo de funciones o acciones, y aquí es donde uno inserta los modulos ya determinados; pero, si tú quisieras llevar a cabo un programa más largo y complejo es necesario abrir un editor de texto en donde aquel nuevo archivo será ejecutado por el IDLE.

Ahora se llevará a caboo lo que sería la creación de nuevos módulos con los que se llevara a cabo determinadas acciones y por poner un ejemplo realizaré la creación de un modulo para obtener el valor factorial de cualquier número:

 

Para más información: http://docs.python.org.ar/tutorial/3/modules.html

 

 

 

 

modules

               Estos dos archivos son muy utiles si no entiendes sobre modulos, ami en lo personal me ayudaron mucho.

https://www.youtube.com/watch?v=d7lO0ZPw03E&feature=youtu.be

http://docs.python.org.ar/tutorial/3/modules.html

MODULES

Primero creas un programa con funciones, despues lo guardas y en otro programa importas el que hiciste anteriormente. Con el simple hecho de guardar en primer programa ya creaste el modulo ahora solo faltaria importarlo en otro programa para correrlo en python.

            Una regla importante esque cuando guardes el programa lo agas con “.py” para que se guarde como programa de python.

#mastery14 Creating and using a Python module

To create a python module you first have to create a new python program (in this case masteries.py) which contains functions (in this case hw() and gb())

Then, in order to use the module’s functions in another program you use import (name of the program)

After you have imported your module you can now use it’s functions by writing the name of the module (masteries) followed by a point and the name of the function inside that module (.hw() or .gb()) 

This will show the user:

Hello World (for hw())   and

Good bye (for gb()) (as shown in the picture above)

#Mastery14

Hi guys !! This is the Mastery14 entitled create libraries , and for this I found an article where I explain how to do it , plus you can ask questions about it , I found it interesting and quite helpful to know how to create a library in c ++.   Here I leave the link.

http://www.c.conclase.net/devcpp/?cap=libestatica  

Mastery 14

Aqui estan los pasos para crear una libreria en c++:

Primero tienes que crear un archivo .h y despues en ese archivo pones algun codigo, luego desde un archico .cpp lo incluyes de esta manera:

“mylibreria.h”

El archivo .h tienes que estar en la misma carpeta que el .cpp de otra forma tienes que especificar donde esta la libreria, algo como lo siguiente:

“documentos/prog/mylibreria.h”

 

Mastery 14

For Mastery 14, you must create use your own c++ libraries. Although this may seem complicated at first it is as easy as calling another function within a program. The onlly difference is that instead of calling a function within the same program, you create the functions in a seperate file (library) and call it simply by using a file header. 

Once entering the informationinto the seperate library you an name it anything but it must have a 

     .h

after the name. You can see this in my code below.

To call the library and include it in your program you must simply include a file header at the beginning of the code.

For example:

     #include “library.h”

or in my code below:

     #include “wsq8funcs.h”

Mastery 14

Creating your own and using C++ libraries

This time I decide to make a video about this. Enjoy!

Link to my awesome video

Mastery14

Creating your own and using C++ libraries
1) Create the files "mylibrary.h" and "mylibrary.cpp".
2) Only compile the library, and it shouldn’t have a "main()" function in it. This step will generate an object file called "myfile.o".
3) Create another file called something like "main.cpp". In main.cpp you need to "mylibrary.h".
4) Compile main.cpp and add the library from step 2 to link in (in this case "myfile.o"). If you don’t add this library, you’ll get a error message like "linker error – can’t find function definition", or something like that.

TC1017