Day: February 12, 2021

Python Example – Write a Python program to get the users environment

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the users environment.   Sample Solution Python Code: import os print() print(os.environ) print() Sample Output: environ({‘SHLVL’: ‘3’, ‘COMP_WORDBREAKS’: ‘ \t\n”\’><;|&(:’, ‘LESSC LOSE’: ‘/usr/bin/lesspipe %s %s’, ‘TERM’: ‘xterm’, ‘LS_COLORS’: ‘rs =0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:c d=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow =34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj= 01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31: *.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01; 31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01; 31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz= 01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:* .sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=0 1;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.g …

Python Example – Write a Python program to extract the filename from a given path

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to extract the filename from a given path.   Sample Solution Python Code: import os print() print(os.path.basename(‘/users/system1/student1/homework-1.py’)) print() Sample Output: homework-1.py   Write a Python program to extract the filename from a given path Free Machine Learning & Data Science Coding …

Python Example – Write a Python program to get the name of the host on which the routine is running

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the name of the host on which the routine is running.   Sample Solution Python Code: import socket host_name = socket.gethostname() print() print(“Host name:”, host_name) print() Sample Output: Host name: server   Write a Python program to get the …

Python Example – Write a Python program to get the system time

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the system time. Note : The system time is important for debugging, network information, random number seeds, or something as simple as program performance.   Sample Solution: Python Code: import time print() print(time.ctime()) print() Sample Output: Thu Apr 29 …

Python Example – Write a Python program to list the special variables used within the language

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to list the special variables used within the language.   Sample Solution Python Code: s_var_names = sorted((set(globals().keys()) | set(__builtins__.__dict__.keys())) – set(‘_ names i’.split())) print() print( ‘\n’.join(‘ ‘.join(s_var_names[i:i+8]) for i in range(0, len(s_var_names), 8)) ) print() Sample Output: ArithmeticError AssertionError AttributeError BaseException …

Python Example – Write a Python program to check whether a string is numeric

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check whether a string is numeric.   Sample Solution Python Code: str = ‘a123’ #str = ‘123’ try: i = float(str) except (ValueError, TypeError): print(‘\nNot numeric’) print() Sample Output: Not numeric   Write a Python program to check whether a …

Python Example – Write a Python program to convert a byte string to a list of integers

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to convert a byte string to a list of integers.   Sample Solution Python Code: x = b’Abc’ print() print(list(x)) print() Sample Output: [65, 98, 99]   Write a Python program to convert a byte string to a list of integers …