Python

Simple HTTP server

python3 -m http.server 8000

Audio to base64

Don't forget the file extension!

'''
Example:
  audio_to_base64('sfx.ogg', 'o_sfx_audiosprite.txt')
'''

import base64
def audio_to_base64(input_name, output_name):
  enc = base64.b64encode(open(input_name, "rb").read())
  output_file = open(output_name, "a+")
  output_file.write(enc)
  output_file.close()

Enumerate

A decent way to iterate a list

values = ["a", "b", "c"]

for count, value in enumerate(values):
  print(count, value)

Rename files

#import os
#os.rename(r'file_path\OLD_file_name.file_type',r'file_path\NEW_file_name.file_type')

import os

path = os.getcwd()
nomi = os.listdir(path)
estensione = ".png"

for n in nomi:
  if os.path.splitext(n)[1] == estensione:
    pezzi = n.split(',')
    if len(pezzi) > 1:
      os.rename(n, pezzi[1] + estensione)

Another way:

import os

folder = "./"

for file_name in os.listdir(folder):
  new_name = file_name.replace("a", "renamed_")
  os.rename(file_name, folder + new_name)