How do I make a generator?

Make sure you haven’t previously built one. In this tutorial, I’ll demonstrate how to get from the command-line to the terminal.

First, create a virtualenv. I’m using the official GitHub release because it includes a nice terminal-friendly interface that’ll open the terminal from within your workspace. Open the terminal, create the new directory, and create a new project. In the terminal, type:

$ virtualenv python3 -v pip install pycairo python setup.py develop

It doesn’t matter what your working directory looks like; it’s all gonna be C, so you don’t have a lot of control of that. I have a virtualenv with just the required Python dependencies and virtual filesystem.

The next step involves setting up environment variables. Let’s assume that you’re starting with virtualenv. We’ll need these variables:

PYTHONPATH : Path to the Python interpreter. It can be set directly, by placing the virtualenv in the PATH variable, but I prefer using a path relative to the environment variable (e.g., /home//.virtualenvs/python3 ).

: Path to the Python interpreter. It can be set directly, by placing the virtualenv in the variable, but I prefer using a path relative to the environment variable (e.g., ). VIRTUALENV : A temporary directory you’ll use for development.

When you run a project, the command you are about to run will be located there. The command is specified in the virtualenv settings file. For example, the following line would be equivalent to running python3 .

virtualenv myenv myenv/develop

Now you can create a new project in your virtual environment. Let’s assume that myenv is virtualenv/myenv/develop . In the command prompt, run these commands:

$ myenv create myenv/myenv/test

You’re almost done! In order to execute your project, you’ll need a shell script to do the thing! Here’s what myenv/bin/test.py looks like:

import sys @__init__ def hello(): print “Hello ” + str(sys.argv[1]) sys.exit(0) def greeting(): return “Goodbye ” + str(sys.argv[2]) print “World, I see you” print “Goodbye!” if __name__ == “__main__

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: