How to Use Variables from another Python File

This tutorial will show how to use variables from one Python file in another. The first step in using another Python file is to use the built in keyword import . Import is used to import Python libraries modules. Here is a List of useful keywords

When using import , the file being imported will be executed when the Python file importing it is ran.

For this example, there are two Python Files the first file is named and the file being imported is named

import Second
#printing X var from Second

In the file the Second file will be imported. Then the X variable from the will be printed out.

X= 5
    # If X is Greater than 5
    if X> 3:
        print("Greater Value")
    # X less than five
    print("Run Complete")

The Second file consist of a try statement that checks if the X variable is greater than 3.

Note: the finally will always run.

Output :

Greater Value

Android Studio Loading Animation Between Activities

Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the…

Android Studio Tutorial SeekBar

SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value…

Python Ethereum Block Chain Interaction with Web3

This tutorial will show how to interact with the Ethereum blockchain using Python. To start, the Python library Web3 will need to be installed. The Web3 library allows you to interact with a local or remote Ethereum node, using a HTTP or IPC connection. Using Web3 you will be able to create smart contracts on…

Python chr()

The chr() function returns a character that represents the specified unicode. Syntax chr(i) The chr() method takes only one integer as argument.The range may vary from 0 to 1,1141,111(0x10FFFF in base 16).The chr() method returns a character whose unicode point is num, an integer.If an integer is passed that is outside the range then the method returns…

Python callable()

The callable() method checks if a object is callable. Callable objects are True if object is callable and False if object is not callable. Syntax & Parameters callable(object)  The callable() method takes one argument, an object and returns one of the two values: returns True, if the object appears to be callable.returns False, if the…

Python bytes()

bytes() returns an immutable bytes object, made up of a sequence of integers in the range 0 <=x < 256. The returned bytes sequence is immutable. A mutable bytes sequence can be used instead by calling is bytearry() . Syntax bytes(]]) bytes() takes three optional parameters: source – initialize the array of bytes. Can be String…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s