Let us have two files in the same directory. Files are called main.py
and another.py
.
First write a method in another.py
:
def do_something(): return "This is the do something method"
Then call the method from main.py
. Here is the main.py
:
import another print another.do_something()
Run main.py
and you will get output like this:
This is the do something method
N.B.: The above code is being executed using Python 2.7 in Windows 10.
Related Posts:
- How to send an email with Python?
- How do I define a function with optional arguments?
- Basic explanation of python functions
- What is the naming convention in Python for variable and function names?
- Call a function from another file?
- What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check fails)?
- IndexError: index 1 is out of bounds for axis 0 with size 1/ForwardEuler
- Apply function to each element of a list
- Python return list from function
- How to stop a function
- Repeating a function in Python
- python3 TypeError: ‘function’ object is not iterable
- How to get a function name as a string?
- Python: Can a function return an array and a variable?
- Call Python function from JavaScript code
- function is not defined error in Python
- Is there a math nCr function in python?
- Adding +1 to a variable inside a function
- Is there a math nCr function in python? [duplicate]
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Multiplication function with recursion in Python
- Run function from the command line
- 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++?
- ValueError: operands could not be broadcast together with shapes (5,) (30,)
- appending list but error ‘NoneType’ object has no attribute ‘append’
- Using Python 3 in virtualenv
- “Series objects are mutable and cannot be hashed” error
- Putting a simple if-then-else statement on one line [duplicate]
- matplotlib savefig() plots different from show()
- 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
- How do I insert a JPEG image into a python Tkinter window?
- Use a.any() or a.all()
- What is the difference between Spyder and Jupyter?
- What is the maximum recursion depth in Python, and how to increase it?
- subprocess.check_output return code
- Determine the type of an object?
- enumerate() for dictionary in python
- How to convert a PIL Image into a numpy array?
- How to get autocomplete in jupyter notebook without using tab?
- numpy with python: convert 3d array to 2d
- Max retries exceeded with URL in requests
- Create 3D array using Python
- How to load a tsv file into a Pandas DataFrame?
- Is it possible to ignore one single specific line with Pylint?
- Print list without brackets in a single row
- Get first row value of a given column
- AttributeError: ‘module’ object has no attribute
- In Python How can I declare a Dynamic Array
- Python module for converting PDF to text
- from sys import argv – what is the function of “script”
- How to properly ignore exceptions
- How to print instances of a class using print()?
- How to filter Pandas dataframe using ‘in’ and ‘not in’ like in SQL
- Create empty file using python [duplicate]
- TypeError: string indices must be integers, not str // working with dict
- How do I print colored output to the terminal in Python?
- Dictionary in a numpy array?
- What does the Ellipsis object do?
- How to concatenate items in a list to a single string?
- python pip on Windows – command ‘cl.exe’ failed
- pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
- Extract part of a regex match
- Python “SyntaxError: Non-ASCII character ‘\xe2’ in file”
- Why is there no tuple comprehension in Python?
- You are trying to add a non-nullable field ‘new_field’ to userprofile without a default
- How to calculate a Gaussian kernel matrix efficiently in numpy?
- AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
- 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?
- Scikit-learn GridSearch giving “ValueError: multiclass format is not supported” error
- Convert R code into Python code using rpy2
- PIL: DLL load failed: specified procedure could not be found
- “Cannot access setup.py: No such file or directory” – can’t run any .py files?
- How to delete a specific line in a file?
- How does ajax work 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
- Counting array elements in Python
- IPython, “name ‘plt’ not defined”
- How to append new data onto a new line
- Building a list inside a list in python
- ‘pyuic5’ is not recognized as an internal or external command
- ValueError: multiclass format is not supported
- Filtering a NumPy Array