Can I share the import files with lots of python scripts -


i have lots of python scripts, share common module following sample

how extract them file common_includes.py

and in each python file, need require common_includes

    #!usr/bin/python3     # -*- coding: utf-8 -*-     import requests     import itertools     html.parser import htmlparser     lxml import etree     import lxml     import lxml.html html     bs4 import beautifulsoup     import json     import requests     import os     import urllib.parse     import urllib.request     import urllib.error     re import sub     decimal import decimal     pdb import set_trace     import datetime     import pymongo     import yaml     concurrent.futures import threadpoolexecutor 

create python file .py containing imports listed , make file name common_includes.py (from example). when want link file other ones, include @ top.

import sys sys.path.append(r'c:\users\python scripts') # filepath import common_includes # filename | not add .py 

you need use sys module if common_includes file not located in same directory file you're working with.

now, when importing can either use:

import common_includes import common_includes ci common_includes import *  #using modules (os module example) common_includes.os ci.os os 

to check linked, run blank file code provided @ top , use 1 of modules.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -