I'm new to Python I'm currently on Py3k (Win).
I'm having trouble installing a .py
file. In fact, I want to use the recipes given at the bottom of the page. So I want to put them in a .i
and Import
in any of my source code.
So I copied all the recipes to a recipes.py
file and copied them to C: \ Python3k \ lib \ site-packages
.
Now, code> Import works fine, but when I try to call any function (eg. take
), Code> global name is not defined 'islice' ... so I thought, I should import itertools
at recipes.py
Do I still get this error? Do I need to change all the examples on the itertools. & Lt; Funcname & gt;
? How can I make a global import? Is this a new Py3k change? Am i missing something
Thanks in advance, :)
Two closely related issues
First of all, within Recipes, you need access to all itertools.
At the very least, this means that you
import itertools
at the top. But in this case you will need to qualify all these Iteratol functions as the itertools. & Lt; Funcname & gt;
, as you say (you can import it as , import it as
and then it. & Lt; phonka name & gt;
. )
Second, you can
<<< Code>But you will have to put all necessary functions in the list.
Finally, at least
This is dangerous because it pollutes your namespace with everything > to
itertools
, which is considered bad and unruly, but in this case is probably not terrible.
Second , you have the same problem with all of your code that uses recipes.py
; If you have to qualify or import everything explicitly, recipes from import
recipes of recipes. Take (...)
Or
take the import (...)
Comments
Post a Comment