How to install Python recipe file (.py)?

I am new to Python. I'm on Py3k (Win) right now.

I am having trouble installing the file .py. Basically, I want to use the recipes presented at the bottom of this . Therefore, I want to place them inside .pyand importin any of my source codes.

So, I copied all the recipes to a file recipes.pyand copied them to C:\Python3k\Lib\site-packages.

Now it importworks fine, but when I try to call some function from it (for example take), I got global name 'islice' is not defined... So, I realized, I have to add itertoolsimport torecipes.py

Am I still getting the same error? Do I need to change all instances to itertools.<funcname>? how can i make import global? Is this a new Py3k change? Is there something I can't see?

Thanks in advance:)

+3
source share
1 answer

There are two closely related problems.

First, in recipes.py you need access to all itertools.

At least that means what you need

import itertools

up. But in this case, you will need to qualify all the functions of itertools as itertools.<funcname>, as you say. (You can also use import itertools as it, then it.<funcname>.)

Secondly you can do

from itertools import islice, count, chain

but you will need to put all the necessary functions in a list.

, , , , -

from itertools import *

, , itertools, , , , .

-, , recipes.py; . ,

import recipes
recipes.take(...)

from recipes import take
take(...)
+7

Source: https://habr.com/ru/post/1766530/


All Articles