Best Python code snippet using molecule_python
RunCode.py
Source:RunCode.py
...28 if not os.path.exists(filename): return "";29 f = open(filename,"r"); d = f.read(); f.close(); return d.replace("\r","")30def file_write(filename,data):31 f = open(filename,"w"); f.write(data.replace("\r","")); f.close();32def file_prepender(filename, line):33 with open(filename, 'r+') as f:34 content = f.read()35 f.seek(0, 0)36 f.write(line.rstrip('\r\n') + '\n' + content)37def cleanAll():38 os.system("rm -rf " + path_codes + "*.out")39 os.system("rm -rf " + path_codes + "*.class")40 os.system("rm -rf " + path_codes + "*.jar")41 os.system("rm -rf " + path_codes + "*.pyc")42def CompileCode( submission_id, language ):43 if( language not in ('c', 'cpp', 'pas', 'java', 'py') ): return "CE"44 result = None45 cleanAll()46 logging.warning("COMPILE CLEAN")47 if language == "c":48 os.system("gcc " + path_codes + str(submission_id) + ".c -lm -lcrypt -O2 -pipe -ansi -ONLINE_JUDGE -w")49 os.system("mv a.out " + path_codes[:-1])50 executable_file = "a.out"51 elif language == "cpp":52 os.system("g++ " + path_codes + str(submission_id) + ".cpp")53 os.system("mv a.out " + path_codes[:-1])54 executable_file = "a.out"55 elif language == "pas":56 os.system("fpc " + path_codes + str(submission_id) + ".pas")57 elif language == "java":58 os.system("javac " + path_codes + str(submission_id) + ".java")59 os.system("bash " + path_codes + "compile_java.sh")60 executable_file = "main.jar"61 elif language == "py":62 file_prepender(path_codes + str(submission_id) + ".py", "#!/usr/bin/env python")63 os.system("python -m py_compile " + path_codes + str(submission_id) + ".py")64 os.chmod(path_codes + str(submission_id) + ".pyc", 0755)65 os.chmod(path_codes + str(submission_id) + ".py", 0755)66 executable_file = str(submission_id) + ".py"67 68 logging.warning("COMPILE FINISHED")69 if not os.path.exists(path_codes + executable_file): 70 result = CE_SIGNAL71 72 return result73def getExecutableFile(language, submission_id):74 if language == "c" or language == "cpp":75 return "a.out"76 elif language == "py":...
encrypt.py
Source:encrypt.py
...110 # Close111 enc_file.close()112 return out113 114def file_prepender(filename, data):115 with open(filename, 'r+') as f:116 content = f.read()117 f.seek(0, 0)118 f.write("<SIGNATURE>\n" + data + "</SIGNATURE>\n"+ content) 119 120def main():121 if len(sys.argv) < 2:122 print("Usage: %s t8p_file_1 [t8p_file_N]" % sys.argv[0])123 exit(1)124 125 for idx, arg in enumerate(sys.argv): 126 if idx > 0:127 if not os.path.exists(arg):128 print "Input Tuning Pack File (.t8p) '%s' does not exist" % arg129 exit(1)130 131 # Open the input file132 print "Encoding input file : %s" % arg 133 fh = open(arg)134 135 # Read rest of file136 data = fh.readlines()137 # Close the input file138 fh.close()139 # Define output file140 out_file = os.path.dirname(arg) + "\\" + os.path.basename(arg).split('.')[0] + ".t8x"141 142 # Create output files143 encode_file(out_file, data)144 145 # Create a MD5 hash of original file146 hash = hashlib.md5(open(arg, 'rb').read()).hexdigest()147 148 # Create a signature out of MD5 hash149 signature = sign_RSA(hash)150 151 # Add signature at beginning of file152 file_prepender(out_file, signature)153 154if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!