all AI news
Cheat sheet for development in Python
April 28, 2024, 8:12 a.m. | Tomoyuki KOYAMA
DEV Community dev.to
Snippet
Environemnt Variables
import os
os.getenv("ENV_VAR_NAME", "default_value")
os — Miscellaneous operating system interfaces — Python 3.12.3 documentation
Command Line Argument
import argparse
parser = argparse.ArgumentParser(description='Parse command line options.')
parser.add_argument('integers', metavar='c', type=int, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)')
args = parser.parse_args(['--sum', '7', '-1', '42'])
print(args.accumulate(args.integers))
argparse — Parser for command-line options, arguments and sub-commands — Python 3.12.3 documentation
Random number
import random
x = random.randint(0, 100) # 0 <= …
argparse command command line development documentation import integer integers interfaces line max miscellaneous operating system python python 3 sum type variables
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
Data Engineer
@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania
Artificial Intelligence – Bioinformatic Expert
@ University of Texas Medical Branch | Galveston, TX
Lead Developer (AI)
@ Cere Network | San Francisco, US
Research Engineer
@ Allora Labs | Remote
Ecosystem Manager
@ Allora Labs | Remote
Founding AI Engineer, Agents
@ Occam AI | New York