python
This is an old revision of the document!
Python
Find
- if someString.find('jpg') > 0:
Read Csv
- import csv
- file = open('Emp_Info.csv', 'r')
- try:
- reader = csv.reader(file)
- for each_row in reader:
- print(each_row)
- finally:
- file.close()
Lists
- create list - stock = []
- append to list - stock.append(“fred”)
Pip
- python -m pip install somePackage
- sudo python -m pip install email_to ←—————— does not work
error: externally-managed-environment
This environment is externally managed To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.
If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed.
For more information visit http://rptl.io/venv
Files
- open file - input = (“someFileLocation”, “r”)
- read a line - line = input.readline()
file_path = 'randomfile.txt'
file_text = open(file_path, "r")
a = True
while a:
file_line = file_text.readline()
if not file_line:
print("End Of File")
a = False
file_text.close()
file = open("randomfile.txt", "r")
while (f := file.read()):
process(f)
file.close()
Packages
- packages live in C:\Users\Donald\AppData\Local\Programs\Python\Python313\Lib\site-packages
- a pip install of exifread appeared to work but did not create this package in the above directory
- found it on Git, downloaded a zip, and copied the package to the site-packages directory
python.1768353430.txt.gz · Last modified: 2026/01/14 01:17 by donald
