Revision

Python Made Easy: Science and Math Edition

Sep-Dec 2025 batch, Vikrant Patil

Date: 01 Nov 2025

Click here for All Notes

© Vikrant Patil

List and Tuple

ones = [1, 1, 1, 1, 1, 1]
ones[0] = 3 # you can modify the list
ones
[3, 1, 1, 1, 1, 1]
onest = (1, 1, 1, 1, 1, 1)
onest[2]
1
onest[2] = 6
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 onest[2] = 6

TypeError: 'tuple' object does not support item assignment

tuple is called as immutable object. Any object once created , it can not be modified later.

  • tuple
  • str
  • int/float

dictionary

students = ["Alice", "Alex", "Hans Solo", "Luke"]
students[0]
'Alice'
students[2]
'Hans Solo'
firstname = ["Alice", "Alex", "Hans", "Luke"]
lastname = ["Wondergirl", "Lion", "Solo", "Skywalker"]
firstname[0], lastname[0]
('Alice', 'Wondergirl')
[(firstname[0],lastname[0]),
 (firstname[1], lastname[1]),
 (firstname[2], lastname[2])]
[('Alice', 'Wondergirl'), ('Alex', 'Lion'), ('Hans', 'Solo')]
studtent0 = {"firstname": "Alice",
            "lastname": "Wondergirl",
            "age": 10}
students1 = {"firstname": "Hans",
            "lastname": "Solo",
            "age": 25}
studtent0['firstname']
'Alice'
students1['age']
25
!pip install audio-metadata
Collecting audio-metadata

  Downloading audio_metadata-0.11.1-py3-none-any.whl.metadata (7.0 kB)

Collecting attrs<19.4,>=18.2 (from audio-metadata)

  Downloading attrs-19.3.0-py2.py3-none-any.whl.metadata (9.0 kB)

Collecting bidict<1.0.0 (from audio-metadata)

  Downloading bidict-0.23.1-py3-none-any.whl.metadata (8.7 kB)

Collecting bitstruct<9.0,>=6.0 (from audio-metadata)

  Downloading bitstruct-8.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.3 kB)

Collecting more-itertools<9.0,>=4.0 (from audio-metadata)

  Downloading more_itertools-8.14.0-py3-none-any.whl.metadata (30 kB)

Collecting pendulum!=2.0.5,!=2.1.0,<=3.0,>=2.0 (from audio-metadata)

  Downloading pendulum-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.9 kB)

Collecting pprintpp<1.0.0 (from audio-metadata)

  Downloading pprintpp-0.4.0-py2.py3-none-any.whl.metadata (7.9 kB)

Collecting tbm-utils<3.0,>=2.3 (from audio-metadata)

  Downloading tbm_utils-2.6.0-py3-none-any.whl.metadata (3.7 kB)

Collecting wrapt<2.0,>=1.0 (from audio-metadata)

  Downloading wrapt-1.17.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.metadata (6.4 kB)

Requirement already satisfied: python-dateutil>=2.6 in /home/vikrant/usr/local/default/lib/python3.11/site-packages (from pendulum!=2.0.5,!=2.1.0,<=3.0,>=2.0->audio-metadata) (2.9.0.post0)

Requirement already satisfied: tzdata>=2020.1 in /home/vikrant/usr/local/default/lib/python3.11/site-packages (from pendulum!=2.0.5,!=2.1.0,<=3.0,>=2.0->audio-metadata) (2024.1)

Collecting time-machine>=2.6.0 (from pendulum!=2.0.5,!=2.1.0,<=3.0,>=2.0->audio-metadata)

  Downloading time_machine-2.19.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.metadata (2.5 kB)

Requirement already satisfied: six>=1.5 in /home/vikrant/usr/local/default/lib/python3.11/site-packages (from python-dateutil>=2.6->pendulum!=2.0.5,!=2.1.0,<=3.0,>=2.0->audio-metadata) (1.16.0)

Downloading audio_metadata-0.11.1-py3-none-any.whl (41 kB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.9/41.9 kB 2.2 MB/s eta 0:00:00

Downloading attrs-19.3.0-py2.py3-none-any.whl (39 kB)

Downloading bidict-0.23.1-py3-none-any.whl (32 kB)

Downloading bitstruct-8.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (82 kB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.9/82.9 kB 776.7 kB/s eta 0:00:001m35.6 MB/s eta 0:00:01

Downloading more_itertools-8.14.0-py3-none-any.whl (52 kB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 52.2/52.2 kB 2.1 MB/s eta 0:00:00

Downloading pendulum-3.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (384 kB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 384.9/384.9 kB 1.4 MB/s eta 0:00:00[36m0:00:01m eta 0:00:01

Downloading pprintpp-0.4.0-py2.py3-none-any.whl (16 kB)

Downloading tbm_utils-2.6.0-py3-none-any.whl (12 kB)

Downloading wrapt-1.17.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (82 kB)

   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.4/82.4 kB 2.0 MB/s eta 0:00:00m eta 0:00:01

Downloading time_machine-2.19.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (32 kB)

Installing collected packages: pprintpp, wrapt, more-itertools, bitstruct, bidict, attrs, time-machine, pendulum, tbm-utils, audio-metadata

  Attempting uninstall: attrs

    Found existing installation: attrs 23.2.0

    Uninstalling attrs-23.2.0:

      Successfully uninstalled attrs-23.2.0

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

jsonschema 4.22.0 requires attrs>=22.2.0, but you have attrs 19.3.0 which is incompatible.

referencing 0.35.1 requires attrs>=22.2.0, but you have attrs 19.3.0 which is incompatible.

Successfully installed attrs-19.3.0 audio-metadata-0.11.1 bidict-0.23.1 bitstruct-8.21.0 more-itertools-8.14.0 pendulum-3.0.0 pprintpp-0.4.0 tbm-utils-2.6.0 time-machine-2.19.0 wrapt-1.17.3
import audio_metadata
metadata = audio_metadata.load("/home/vikrant/Music/siddharth/AO_SD54_20200223_055000_Red_Junglefowl.mp3")
metadata
<MP3({
    'filepath': '/home/vikrant/Music/siddharth/AO_SD54_20200223_055000_Red_Junglefowl.mp3',
    'filesize': '1.83 MiB',
    'pictures': [],
    'streaminfo': <MP3StreamInfo({
        'bitrate': '256 Kbps',
        'bitrate_mode': <MP3BitrateMode.CBR>,
        'channel_mode': <MP3ChannelMode.MONO>,
        'channels': 1,
        'duration': '01:00',
        'layer': 3,
        'protected': False,
        'sample_rate': '48.0 KHz',
        'version': 1,
    })>,
    'tags': <ID3v2Frames({
        'artist': ['AudioMoth 243B1F055AD2F5A4'],
        'comment': [
            <ID3v2Comment({
                'description': '',
                'language': '',
                'text': 'Recorded at 05:50:00 23/02/2020 (UTC+5) by AudioMoth 243B1F055AD2F5A4 at gain setting 2 while battery state was 4.5V.',
            })>,
        ],
    })>,
})>
metadata['tags']['artist']
['AudioMoth 243B1F055AD2F5A4']
metadata.keys()
KeysView(['filepath', 'filesize', 'pictures', 'tags', '_obj', '_id3', 'streaminfo'])
students1.keys()
dict_keys(['firstname', 'lastname', 'age'])
metadata['tags'].keys()
KeysView(['artist', 'comment'])
sighting = {"name": "sparrow",
            "scientic_name": "passerdometicus",
            'location':"pashan",
            'date': "10-05-2025"}     
len(ones)
6
len(onest)
6
len(sighting)
4

file reading

filepath = "/home/vikrant/programming/work/github/PIER/Default Data/Common/Parameters/PhysicalPrimaryCarriers.csv"
with open(filepath) as f:
    data = f.read()
data
'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\nCOKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129\nTHERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872\nNATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812\nBIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8\nBIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56\nCRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404\nBIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968\n'
with open(filepath) as f:
    print(f.readline())
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity
with open(filepath) as f:
    print(f.readline())
    print(f.readline())
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity

COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129
with open(filepath) as f:
    line1 = f.readline()
    line2= f.readline()
line1
'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\n'
line2
'COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129\n'
print("hello")
print("there")
hello
there
print("hello", end=",")
print("there")
hello,there
print("hello", end=",")
print("there", end=",")
hello,there,
with open(filepath) as f:
    print(f.readline(), end="")
    print(f.readline(), end="")
    print(f.readline(), end="")
    print(f.readline(), end="")
    print(f.readline(), end="")
    print(f.readline(), end="")
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity
COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129
THERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872
NATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812
BIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8
BIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56

conditons

filepath.endswith(".csv")
True
filepath.endswith(".xlsx")
False
if filepath.endswith(".csv"):
    read_csv_file(filepath)
else:
    print("Unkown format")
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[53], line 2
      1 if filepath.endswith(".csv"):
----> 2     read_csv_file()
      3 else:
      4     print("Unkown format")

NameError: name 'read_csv_file' is not defined
def read_csv_file(filepath):
    with open(filepath) as fhandle:
        return fhandle.read()
read_csv_file(filepath)
'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\nCOKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129\nTHERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872\nNATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812\nBIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8\nBIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56\nCRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404\nBIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968\n'
if filepath.endswith(".csv"):
    data = read_csv_file(filepath)
else:
    print("Unkown format")
data
'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\nCOKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129\nTHERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872\nNATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812\nBIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8\nBIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56\nCRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404\nBIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968\n'
def read_first_sheet(xlscfile):
    pass


def load_file(filepath):
    if filepath.endswith(".csv"):
        return read_csv_file(filepath)
    elif filepath.endswith(".xlsx"):
        return read_first_sheet(filepath)
    elif filepath.endswith(".wave") or filepath.endswith(".mp3"):
        return audio_metadata.load(filepath)
    else:
        print("Unknown format")
audiofile = "/home/vikrant/Music/siddharth/AO_SD54_20200223_055000_Red_Junglefowl.mp3"
if filepath.endswith(".csv"):
    print("x")
if filepath.endswith(".xlsx"):
    print("y")
if filepath.endswith(".csv"):
    print("z")  
x
z
if filepath.endswith(".csv"):
    print("x")
elif filepath.endswith(".xlsx"):
    print("y")
elif filepath.endswith(".csv"):
    print("z")  
x

loop

students
['Alice', 'Alex', 'Hans Solo', 'Luke']
for s in students:
    print(s)
Alice
Alex
Hans Solo
Luke
for s in students:
    print(s*2)
AliceAlice
AlexAlex
Hans SoloHans Solo
LukeLuke
for s in students:
    print("hello", s)
hello Alice
hello Alex
hello Hans Solo
hello Luke
for number in ones:
    print(number)
3
1
1
1
1
1
ones
[3, 1, 1, 1, 1, 1]
count = 1
for number in ones:
    print(count, number)
    count = count + 1
1 3
2 1
3 1
4 1
5 1
6 1
def countlist(itemlist):
    count = 1
    for item in itemlist:
        print(count, item)
        count += 1 # count = count + 1
countlist(students)
1 Alice
2 Alex
3 Hans Solo
4 Luke
for key in students1:
    print(key)
firstname
lastname
age
for key in students1:
    print(key, students1[key])
firstname Hans
lastname Solo
age 25
for c in "jkashdjkas jhgasd ash":
    print(c, end=",")
j,k,a,s,h,d,j,k,a,s, ,j,h,g,a,s,d, ,a,s,h,
expenses = [45.0, 120.0, 110.0, 100.0, 500.0, 1130.0]
sum(expenses)
2005.0
s = 0 
for expense in expenses:
     s += expense   
print(s)
2005.0
students
['Alice', 'Alex', 'Hans Solo', 'Luke']
s = 0 
for expense in expenses:
     s = s + expense   
[45.0, 120.0, 110.0, 100.0, 500.0, 1130.0]

s = 0
s = 0 + 45
s = 0 + 45 + 120
s = 
  Cell In[82], line 4
    s = 0 +
           ^
SyntaxError: invalid syntax
def mysum(numbers):
    s = 0
    for n in numbers:
        s = s + n
    return s
mysum(ones)
8
def product(numbers):
    p = 1
    for n in numbers:
        p = p * n   # p *= n
    return p
product(ones)
3
range(5)
range(0, 5)
range(1, 6)
range(1, 6)
for i in range(1, 6):
    print(i)
1
2
3
4
5
for i in range(5):
    print(i)
0
1
2
3
4
for i in range(5):
    print("hello")
hello
hello
hello
hello
hello
firstname
['Alice', 'Alex', 'Hans', 'Luke']
lastname
['Wondergirl', 'Lion', 'Solo', 'Skywalker']
for i in range(4):
    print(firstname[i], lastname[i])
Alice Wondergirl
Alex Lion
Hans Solo
Luke Skywalker
students
['Alice', 'Alex', 'Hans Solo', 'Luke']
upper_students = []
for s in students:
    S = s.upper()
    upper_students.append(S)
upper_students
['ALICE', 'ALEX', 'HANS SOLO', 'LUKE']
nums = [2, 3, 1, 4, 4, 6]
sqrs = []
for n in nums:
    sqrs.append(n*n)
sqrs
[4, 9, 1, 16, 16, 36]
stud_tuples = []
for i in range(4):
    pair = (firstname[i], lastname[i])
    stud_tuples.append(pair)
stud_tuples
[('Alice', 'Wondergirl'),
 ('Alex', 'Lion'),
 ('Hans', 'Solo'),
 ('Luke', 'Skywalker')]
filepath
'/home/vikrant/programming/work/github/PIER/Default Data/Common/Parameters/PhysicalPrimaryCarriers.csv'
with open(filepath) as f:
    for line in f:
        print(line, end="")
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity
COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129
THERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872
NATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812
BIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8
BIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56
CRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404
BIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968
line = "'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\n"
line.split(",")
["'EnergyCarrier",
 'BalancingArea',
 'BalancingTime',
 'PhysicalUnit',
 'EnergyUnit',
 'DomEnergyDensity',
 'ImpEnergyDensity\n']
line = "'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\n"
line.strip().split(",")
["'EnergyCarrier",
 'BalancingArea',
 'BalancingTime',
 'PhysicalUnit',
 'EnergyUnit',
 'DomEnergyDensity',
 'ImpEnergyDensity']
def extract_columns(f):
    headerline = f.readline().strip() # first line
    return headerline.split(",")

def make_line_dictionary(columnnames, values):
    linedict = {}
    count = len(columnnames)
    for i in range(count):
        linedict[columnnames[i]] = values[i]
    return linedict

def read_file_as_list_of_dict(filepath):
    with open(filepath) as f:
        columnnames = extract_columns(f)
        columncount = len(columnnames)
        file_as_dict = []
        for line in f:
            linetokens = line.strip().split(",")
            d = make_line_dictionary(columnnames, linetokens)
            file_as_dict.append(d)
        return file_as_dict
read_file_as_list_of_dict(filepath)
[{'EnergyCarrier': 'COKING_COAL',
  'BalancingArea': 'SUBGEOGRAPHY1',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'MT',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '20.55566931',
  'ImpEnergyDensity': '24.17925129'},
 {'EnergyCarrier': 'THERMAL_COAL',
  'BalancingArea': 'SUBGEOGRAPHY1',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'MT',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '17.20718765',
  'ImpEnergyDensity': '22.60872'},
 {'EnergyCarrier': 'NATGAS',
  'BalancingArea': 'MODELGEOGRAPHY',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'BCM',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '37.6812',
  'ImpEnergyDensity': '37.6812'},
 {'EnergyCarrier': 'BIOGAS',
  'BalancingArea': 'MODELGEOGRAPHY',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'BCM',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '22.8',
  'ImpEnergyDensity': '22.8'},
 {'EnergyCarrier': 'BIOMASS',
  'BalancingArea': 'MODELGEOGRAPHY',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'MT',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '15.56',
  'ImpEnergyDensity': '15.56'},
 {'EnergyCarrier': 'CRUDE',
  'BalancingArea': 'MODELGEOGRAPHY',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'MT',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '43.12404',
  'ImpEnergyDensity': '43.12404'},
 {'EnergyCarrier': 'BIOMASS_WASTE',
  'BalancingArea': 'MODELGEOGRAPHY',
  'BalancingTime': 'YEAR',
  'PhysicalUnit': 'MT',
  'EnergyUnit': 'PJ',
  'DomEnergyDensity': '13.648968',
  'ImpEnergyDensity': '13.648968'}]
filedict = read_file_as_list_of_dict(filepath)
filedict[0]
{'EnergyCarrier': 'COKING_COAL',
 'BalancingArea': 'SUBGEOGRAPHY1',
 'BalancingTime': 'YEAR',
 'PhysicalUnit': 'MT',
 'EnergyUnit': 'PJ',
 'DomEnergyDensity': '20.55566931',
 'ImpEnergyDensity': '24.17925129'}
filedict[-1]
{'EnergyCarrier': 'BIOMASS_WASTE',
 'BalancingArea': 'MODELGEOGRAPHY',
 'BalancingTime': 'YEAR',
 'PhysicalUnit': 'MT',
 'EnergyUnit': 'PJ',
 'DomEnergyDensity': '13.648968',
 'ImpEnergyDensity': '13.648968'}
f = open(filepath)
f.readline()
'EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity\n'
for line in f:
    print(line)
COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129

THERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872

NATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812

BIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8

BIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56

CRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404

BIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968
f.readline()
''
f.close()
with open(filepath) as f:
    for line in f:
        print(line)
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity

COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129

THERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872

NATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812

BIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8

BIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56

CRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404

BIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968
with open(filepath) as f:
    for line in f:
        print(line.strip())
EnergyCarrier,BalancingArea,BalancingTime,PhysicalUnit,EnergyUnit,DomEnergyDensity,ImpEnergyDensity
COKING_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,20.55566931,24.17925129
THERMAL_COAL,SUBGEOGRAPHY1,YEAR,MT,PJ,17.20718765,22.60872
NATGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,37.6812,37.6812
BIOGAS,MODELGEOGRAPHY,YEAR,BCM,PJ,22.8,22.8
BIOMASS,MODELGEOGRAPHY,YEAR,MT,PJ,15.56,15.56
CRUDE,MODELGEOGRAPHY,YEAR,MT,PJ,43.12404,43.12404
BIOMASS_WASTE,MODELGEOGRAPHY,YEAR,MT,PJ,13.648968,13.648968

modules

import random
random.random()
0.07442612590420605
random.choice(students)
'Alice'
random.choice(students)
'Luke'
random.choice(students)
'Luke'
random.choice(filedict)
{'EnergyCarrier': 'BIOMASS',
 'BalancingArea': 'MODELGEOGRAPHY',
 'BalancingTime': 'YEAR',
 'PhysicalUnit': 'MT',
 'EnergyUnit': 'PJ',
 'DomEnergyDensity': '15.56',
 'ImpEnergyDensity': '15.56'}
random.choice(filedict)
{'EnergyCarrier': 'BIOGAS',
 'BalancingArea': 'MODELGEOGRAPHY',
 'BalancingTime': 'YEAR',
 'PhysicalUnit': 'BCM',
 'EnergyUnit': 'PJ',
 'DomEnergyDensity': '22.8',
 'ImpEnergyDensity': '22.8'}
import datetime
date1 = datetime.datetime(year= 2025, month=10, day=24)
date2 = datetime.datetime(year= 2025, month=10, day=22)
date1 
datetime.datetime(2025, 10, 24, 0, 0)
date2
datetime.datetime(2025, 10, 22, 0, 0)
date1 > date2
True
date2 > date1
False
date1
datetime.datetime(2025, 10, 24, 0, 0)
date1 + datetime.timedelta(days=3)
datetime.datetime(2025, 10, 27, 0, 0)
import os
os.getcwd() # current working directiory
'/home/vikrant/programming/work/github/vikrant.dev/python-made-easy-science-math'
os.listdir("/home/vikrant/programming/explorations/")
['main.py~',
 'web',
 'poetry',
 'python',
 'filerename.R',
 'filerename.R~',
 'marp-sample.md',
 'scheme',
 'octave',
 'gridpath',
 'android',
 'squeak',
 'ocaml',
 '__pycache__',
 'clisp',
 'vagrant-vms',
 'android_app',
 'c',
 'emacs',
 'ds',
 'erlang',
 'marp-sample.html',
 'paraview',
 'iterators.py',
 'mkdocs',
 'icfp2011',
 'haskell',
 'docker',
 'lambda-retreat-22',
 'marp-sample.md~',
 'java',
 'ssl',
 'iterators.py~',
 '.svn']
os.path.isfile(filepath)
True
os.path.isdir(filepath)
False
os.listdir("/home/vikrant/Pictures/5amclub_vikrant/")
['26__.jpg',
 '28.jpeg',
 '21.JPG',
 '41.JPG',
 '00.jpeg',
 '24.jpeg',
 '26_.jpeg',
 '06.JPG',
 '30.jpeg',
 '23.jpeg',
 '31.jpeg',
 '05.JPG',
 '34.jpeg',
 '07.JPG',
 '52.JPG',
 '50.JPG',
 '33.jpeg',
 '27.jpeg',
 '26.jpeg',
 '29.jpeg',
 '51.JPG',
 '20.JPG',
 '04.jpeg',
 '40.JPG',
 '25.jpeg']
folder= "/home/vikrant/Pictures/5amclub_vikrant/"
for file in os.listdir(folder):
    print(file)
26__.jpg
28.jpeg
21.JPG
41.JPG
00.jpeg
24.jpeg
26_.jpeg
06.JPG
30.jpeg
23.jpeg
31.jpeg
05.JPG
34.jpeg
07.JPG
52.JPG
50.JPG
33.jpeg
27.jpeg
26.jpeg
29.jpeg
51.JPG
20.JPG
04.jpeg
40.JPG
25.jpeg
folder= "/home/vikrant/Pictures/5amclub_vikrant/"
for file in os.listdir(folder):
    print(os.path.join(folder, file)) 
/home/vikrant/Pictures/5amclub_vikrant/26__.jpg
/home/vikrant/Pictures/5amclub_vikrant/28.jpeg
/home/vikrant/Pictures/5amclub_vikrant/21.JPG
/home/vikrant/Pictures/5amclub_vikrant/41.JPG
/home/vikrant/Pictures/5amclub_vikrant/00.jpeg
/home/vikrant/Pictures/5amclub_vikrant/24.jpeg
/home/vikrant/Pictures/5amclub_vikrant/26_.jpeg
/home/vikrant/Pictures/5amclub_vikrant/06.JPG
/home/vikrant/Pictures/5amclub_vikrant/30.jpeg
/home/vikrant/Pictures/5amclub_vikrant/23.jpeg
/home/vikrant/Pictures/5amclub_vikrant/31.jpeg
/home/vikrant/Pictures/5amclub_vikrant/05.JPG
/home/vikrant/Pictures/5amclub_vikrant/34.jpeg
/home/vikrant/Pictures/5amclub_vikrant/07.JPG
/home/vikrant/Pictures/5amclub_vikrant/52.JPG
/home/vikrant/Pictures/5amclub_vikrant/50.JPG
/home/vikrant/Pictures/5amclub_vikrant/33.jpeg
/home/vikrant/Pictures/5amclub_vikrant/27.jpeg
/home/vikrant/Pictures/5amclub_vikrant/26.jpeg
/home/vikrant/Pictures/5amclub_vikrant/29.jpeg
/home/vikrant/Pictures/5amclub_vikrant/51.JPG
/home/vikrant/Pictures/5amclub_vikrant/20.JPG
/home/vikrant/Pictures/5amclub_vikrant/04.jpeg
/home/vikrant/Pictures/5amclub_vikrant/40.JPG
/home/vikrant/Pictures/5amclub_vikrant/25.jpeg
os.rename?
Signature: os.rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Docstring:
Rename a file or directory.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
  descriptor open to a directory, and the respective path string (src or dst)
  should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
  If they are unavailable, using them will raise a NotImplementedError.
Type:      builtin_function_or_method
src = "/home/vikrant/Pictures/5amclub_vikrant/26__.jpg"
dest = "/home/vikrant/Pictures/5amclub_vikrant/26_renamed.jpg"
os.rename(src, dest)
os.listdir(folder)
['28.jpeg',
 '21.JPG',
 '41.JPG',
 '00.jpeg',
 '24.jpeg',
 '26_.jpeg',
 '06.JPG',
 '30.jpeg',
 '23.jpeg',
 '31.jpeg',
 '05.JPG',
 '34.jpeg',
 '07.JPG',
 '52.JPG',
 '50.JPG',
 '26_renamed.jpg',
 '33.jpeg',
 '27.jpeg',
 '26.jpeg',
 '29.jpeg',
 '51.JPG',
 '20.JPG',
 '04.jpeg',
 '40.JPG',
 '25.jpeg']