Find whether a sequence of degrees can form a simple graph | Havel-Hakimi Algorithm

Learn examples from DataCamp guru:

The concept of current working directory (CWD) becomes important here. Consider CWD as a folder inside which Python runs. Whenever files are called by their name alone, Python assumes that it runs in the CWD, which means that the name-only reference will only succeed if the file is in the Python CWD.

Note . The folder where the Python script is executed is called Current Directory. This is not the path where the Python script is located.

Getting the current working directory

Python provides OS module for interacting with the operating system. This module is included in the standard Python utility. All functions in the os module call OSError for invalid or unavailable file names and paths or other arguments that are of the correct type but are not accepted by the operating system.

# Python program to explain the os.getcwd () method

  
# import of the os module

import os 

 
# Get current work
# directory (CWD)

cwd = os.getcwd () 

  
# Print current job
# directory (CWD)

print ( "Current working directory:" )

print (cwd) 

Exit:

Note. To learn more about os.getcwd () click here

Get script path

os.path.realpath () can be used to get the path to the current Pyhton script. Actually

# Python program to get
# script path

 

 

import os

 
# Get current job # catalog (CWD)

cwd = os.getcwd () 

print ( "Current Directory:" , cwd)

 
# Get directory
# script

script = os.path.realpath (__ file__)

print ( "SCript path:" , script)

Output:

Note. To learn more about os.path.realpath () click here .

Learn examples from DataCamp guru: