💾 Archived View for squid.flounder.online › cheatsheet › programming › python.gmi captured on 2023-01-29 at 02:47:20. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Return to Squid's World

Return to Cheat Sheets

Python

Common Libraries Used

sys

time

os

pandas

Common

Taking Arguments

import sys
arguments = sys.argv 

Handling CSVs

Reading CSVs

with open('path/to/file','r') as file:
    file.read() # reads all the file into one string
    file.readlines() # reads the file into a list of lines
    file.close() # sometimes it helps to do this

Writing to CSVs

with open('/path/to/file','w') as file:
    file.write(string) # writes a string into the file
    file.writelines(list) # writes a list into the file line by line
    file.close() # sometimes it helps to do this

Appending to CSVs

with open('/path/to/file','a') as file:
    file.write(string) # same as with writing, same with file.writelines too
    file.close() # sometimes it helps to do this

os

Run Shell Command from Python

os.system('command')

Return to Squid's World