Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)

I've been creating Python scripts for basic tasks at work and never truly tried packaging them for others to utilize. Presently I have been assigned out to create a Python wrapper for a REST API. I have definitely no clue on the best way to begin and I need assistance. 

What I currently have

(Simply need to be explicit as could really be expected) I have the virtualenv prepared, it's additionally up in github, the .gitignore document for python is there too, besides, the requests library for cooperating with the REST API. That is it.

Look at the present director tree

.

├── bin

│   └── /the usual stuff/

├── include

│   └── /the usual stuff/

├── lib

│   └── python2.7

│       └── /the usual stuff/

├── local

│   └── /the usual stuff/

└── README.md

27 directories, 280 files

I don't have a clue where to put the .py documents, on the off chance that I actually make one. 

What I needed to do: 

Make a python module which is install-able with "pip install ..." 

On the off chance that conceivable, I need an overall step by step measure on composing Python modules.

1 Answer

0 votes
by (26.4k points)

A module is a document containing Python definitions and proclamations (Statements). The file name is the module name with the addition .py 

make hello.py then compose the accompanying function as its substance: 

def helloworld():

   print "hello"

Then import hello:

>>> import hello

>>> hello.helloworld()

'hello'

>>>

To group many .py documents put them in an organizer (folder). Any organizer with a __init__.py is viewed as a module by python and you can call them a package 

|-HelloModule

  |_ __init__.py

  |_ hellomodule.py

You can go about with the import statement on your module the typical way.

Click on this link for more information

Wanna become a Python expert? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 16, 2019 in Python by leealex956 (7.3k points)

Browse Categories

...