The usual way to do this is something like the following.
test1.py
def some_func(): print 'in test 1, unproductive' if __name__ == '__main__': # test1.py executed as script # do something some_func()
service.py
import test1 def service_func(): print 'service func' if __name__ == '__main__': # service.py executed as script # do something service_func() test1.some_func()
Related Posts:
- Replace ‘ with \’ in a string
- How can I install pip on Windows?
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- Difference between import numpy and import numpy as np
- No module named ‘sklearn.cross_validation’
- Maximum and Minimum values for ints
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- python capitalize first letter only
- Is there a short contains function for lists?
- ImportError: No module named pandas. Pandas installed pip
- How to Execute a Python Script in Notepad++?
- Get Color Palettes from ColorHunt.co in Python
- What does the Pydoc module do?
- size of NumPy array
- Best way to strip punctuation from a string
- How can I explicitly free memory in Python?
- filename.whl is not supported wheel on this platform
- What is the meaning of [:] in python [duplicate]
- Finding and replacing elements in a list
- socket.error: [Errno 48] Address already in use
- No module named MySQLdb
- TypeError: Missing 1 required positional argument: ‘self’
- Convert a tensor to numpy array in Tensorflow?
- How to import the class within the same directory or sub directory?
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- What is __pycache__?
- Permission denied error by installing matplotlib
- Python equivalent of a given wget command
- How to find list intersection?
- Error while Executing jupyter notebook: [Errno 2] No such file or directory
- ValueError: max() arg is an empty sequence
- Split by comma and strip whitespace in Python
- How to remove punctuation marks from a string in Python 3.x using .translate()?
- Calculating Covariance with Python and Numpy
- What is the easiest way to remove all packages installed by pip?
- In practice, what are the main uses for the new “yield from” syntax in Python 3.3?
- Subplot for seaborn boxplot
- Dump a NumPy array into a csv file
- How to delete a character from a string using Python
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Inverse of a matrix using numpy
- NameError: name ‘self’ is not defined
- gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)
- How to print colored text to the terminal
- TypeError: can only concatenate list (not “str”) to list
- What’s the idiomatic syntax for prepending to a short python list?
- Exit while loop in Python
- How do I check if a list is empty?
- IndexError: list index out of range and python
- Don’t understand why UnboundLocalError occurs (closure) [duplicate]
- OSError – Errno 13 Permission denied
- ImportError: No module named ‘Queue’
- ImportError: No Module Named bs4 (BeautifulSoup)
- How to calculate rolling / moving average using python + NumPy / SciPy?
- How to fix “Attempted relative import in non-package” even with __init__.py
- Errno 13 Permission denied Python
- How to get all possible combinations of a list’s elements?
- Converting strings to floats in a DataFrame
- Pylint “unresolved import” error in Visual Studio Code
- Errno 13 Permission denied Python
- How to stop Python closing immediately when executed in Microsoft Windows
- Error: “dictionary update sequence element #0 has length 1; 2 is required” on Django 1.4
- module has no attribute
- How to print number with commas as thousands separators?
- double for loops in python
- Convert hex string to int in Python
- Function to close the window in Tkinter
- Is there a way to specify which pytest tests to run from a file?
- What does the Ellipsis object do?
- ImportError: No module named cv2
- ./xx.py: line 1: import: command not found
- How do I run pip on python for windows?
- How to get the text cursor position in Windows?
- python NameError: global name ‘__file__’ is not defined
- Rename specific column(s) in pandas
- How to create a numpy array of lists?
- Issue with virtualenv – cannot activate
- Can I set max_retries for requests.request?
- Why do I get this error “TypeError: ‘method’ object is not iterable”?
- How to obfuscate Python code effectively?
- Controlling mouse with Python
- can we use XPath with BeautifulSoup?
- how to check which version of nltk, scikit learn installed?
- How do I add two sets?
- How to count the number of files in a directory using Python
- Are nested try/except blocks in Python a good programming practice?
- Getting a name error when trying to input a string [duplicate]
- Complex number troubles with numpy
- Running shell command and capturing the output
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Python copy files to a new directory and rename if file name already exists
- How to append new data onto a new line
- Building a list inside a list in python
- Python 3 integer division [duplicate]
- numpy/scipy/ipython:Failed to interpret file as a pickle
- What is the Python equivalent of static variables inside a function?
- Python – difference between two strings
- Flask-framework: MVC pattern
- Installing win32gui python module