How to use new_line method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

md2lt.py

Source:md2lt.py Github

copy

Full Screen

1import sys2import codecs3import re 4# from Unicode_VN import *5sys.stdout = codecs.getwriter('utf_8')(sys.stdout)6sys.stdin = codecs.getreader('utf_8')(sys.stdin)7f = codecs.open('test.md', encoding='utf-8').read().splitlines();8i = -19file = codecs.open("assets/latex/out.tex", "w", "utf-8")10# file.write()11############## TITLE #############3312first_line = "%!TEX root = book.tex"13file.write(first_line+'\n')14########### HEADERS ####################15HEADERS = [None, None, ' \\section', ' \\subsection', ' \\subsubsection', ' \\textbf']16c = 0 17in_math_mode = False18in_code_mode = False19in_fig_mode = False20in_tab_mode = False21in_ital_mode = False 22in_bold_mode = False 23in_comment_mode = False 24BASE_URL = 'http://machinelearningcoban.com'25def myfind(s, ch):26 return [i for i, ltr in enumerate(s) if ltr == ch]27def convert_links(string):28 # print(a, b, c, d)29 id1 = string.find('[')30 if id1 == -1:31 # return string[:id1+1] + convert_links(string[id1+1:])32 return string 33 # find ]34 str2 = string[:id1]35 s2 = string[id1:]36 id2 = s2.find(']')37 if id2 == -1:38 return string[:id1+ id2 + 1] + convert_links(string[id1 + id2 +1:])39 if s2[id2 + 1] != '(':40 return string[:id1 + id2 + 2]+ convert_links(string[id1 + id2 + 2:])41 s3 = s2[id2 +1:]42 id3 = s3.find(')')43 if id3 == -1:44 return string[:id1 + id2 + id3 + 1] + convert_links(string[id1 + id2 + id3 + 1:])45 link = string[id1 + id2 +2: id1 + id2 + id3+1]46 display_name = string[id1 + 1: id1 + id2]47 if 'http' not in link:48 link = BASE_URL + link 49 return str2 + '\\href{' + link + '}{' + \50 display_name + '}' + convert_links(string[id1 + id2 + id3+2:])51str0 = 'alsfd `ksf` lkf `jksdf `'52def inlinecode(str0):53 id1 = str0.find('`')54 if id1 == -1:55 return str0 56 str1 = str0[id1 + 1:]57 id2 = str1.find('`')58 if id2 == -1:59 return str0 60 return str0[:id1] + '\\pythoninline{'+str0[id1+1:id1+id2+1] + '}' + \61 inlinecode(str0[id1+id2+2:])62print(inlinecode(str0))63add_title = False 64in_layout_mode = False65ignore_flag = True 66for line in f:67 # print(68 c += 169 new_line = ' '+line.rstrip('\r') + ' '70 print(new_line)71 # if not in_layout_mode and '---' in new_line:72 # in_layout_mode = True 73 # ############# catch title 74 # if in_layout_mode:75 # if '---' in new_line:76 # in_layout_mode = False 77 if not add_title:78 if 'title' in new_line:79 add_title = True 80 # first : 81 id1 = new_line.index(':')82 str1 = new_line[id1+1:]83 #second :84 id2 = str1.index(':')85 id3 = str1[id2:].index('"')86 title = str1[id2 + 2:id2 + id3]87 print(id1, id2, id3, title)88 file.write('\\chapter{' +title + '}\n')89 else:90 if ignore_flag:91 if '---' in new_line:92 ignore_flag = False 93 else:94 continue 95 if ignore_flag:96 continue97 c += 1 98 # print(c)99 #### math 100 101 ## in code mode 102 if '```' in new_line:103 in_code_mode = not in_code_mode 104 if in_code_mode: 105 new_line = ' \\begin{lstlisting}[language=Python]\r'106 file.write(new_line[1:]+'\n')107 continue 108 else: 109 new_line = ' \\end{lstlisting}\r'110 file.write(new_line[1:]+'\n')111 continue 112 if in_code_mode:113 file.write(new_line[1:]+'\n')114 continue 115 new_line = inlinecode(new_line)116 117 new_line = new_line.replace('\\_', '_')118 new_line = new_line.replace(' **', ' \\textbf{')119 new_line = new_line.replace('[**', '[\\textbf{')120 new_line = new_line.replace('(**', '(\\textbf{')121 new_line = new_line.replace('{**', '{\\textbf{')122 new_line = new_line.replace('** ', '} ')123 new_line = new_line.replace('**]', '}]')124 new_line = new_line.replace('**)', '})')125 new_line = new_line.replace('**}', '}}')126 new_line = new_line.replace('**.', '}.')127 new_line = new_line.replace('**,', '},')128 new_line = new_line.replace('**:', '}:')129 new_line = new_line.replace('**!', '}!')130 new_line = new_line.replace(' * ', '\t\\item ')131 new_line = new_line.replace(' *', ' \\textit{')132 new_line = new_line.replace('(*', '(\\textit{')133 new_line = new_line.replace('[*', '[\\textit{')134 new_line = new_line.replace('{*', '{\\textit{')135 new_line = new_line.replace('* ', '} ')136 new_line = new_line.replace('*)', '})')137 new_line = new_line.replace('*]', '}]')138 new_line = new_line.replace('*}', '}}')139 # new_line = new_line.replace('*}', '}}')140 new_line = new_line.replace('*,', '},')141 new_line = new_line.replace('*.', '}.')142 new_line = new_line.replace(' __', ' \\textbf{')143 new_line = new_line.replace('[__', '[\\textbf{')144 new_line = new_line.replace('(__', '(\\textbf{')145 new_line = new_line.replace('{__', '{\\textbf{')146 new_line = new_line.replace('__ ', '} ')147 new_line = new_line.replace('__]', '}]')148 new_line = new_line.replace('__)', '})')149 new_line = new_line.replace('__}', '}}')150 new_line = new_line.replace('__:', '}}')151 new_line = new_line.replace('__.', '}.')152 new_line = new_line.replace('__,', '},')153 new_line = new_line.replace(' _', ' \\textit{')154 new_line = new_line.replace('(_', '(\\textit{')155 new_line = new_line.replace('[_', '[\\textit{')156 new_line = new_line.replace('{_', '{\\textit{')157 new_line = new_line.replace('_ ', '} ')158 new_line = new_line.replace('_)', '})')159 new_line = new_line.replace('_]', '}]')160 new_line = new_line.replace('_}', '}}')161 new_line = new_line.replace('_}', '}}')162 new_line = new_line.replace('_:', '}:')163 new_line = new_line.replace('_,', '},')164 new_line = new_line.replace('_;', '};')165 new_line = new_line.replace('_.', '}.')166 new_line = new_line.replace('\\\(', '$')167 new_line = new_line.replace('\\\[', '\\begin{equation*}')168 new_line = new_line.replace('\\\]', '\\end{equation*}')169 new_line = new_line.replace('\\\|', '\\|')170 new_line = new_line.replace('\\\)', '$')171 ## if comment line -> continue 172 if '<!--' in new_line:173 in_comment_mode = True 174 if '-->' in new_line:175 in_comment_mode = False 176 continue177 if in_comment_mode:178 if '-->' in new_line:179 in_comment_mode = False 180 else:181 continue182 if '<a name=' in new_line:183 continue184 185 #### Header 186 line = new_line187 if line[1] == '#' and not in_code_mode:188 h = 1189 while line[h] == '#':190 h += 1 191 levels = h -1192 # find next letter193 while line[h] in '0123456789. ':194 h += 1 195 new_line = HEADERS[min(levels,5)] + '{' + line[h:-1] + '}'196 # line = new_line 197 new_line = convert_links(new_line)198 file.write(new_line[1:]+'\n')...

Full Screen

Full Screen

nt_to_n3.py

Source:nt_to_n3.py Github

copy

Full Screen

1'''2This script was used to parse the NT file to N33Authors:4João Ferreira - 800415João Magalhães - 799236'''7ns0 = "@prefix ns0: <http://netflix-titles.com/pred/> ."8xsd = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> ."9with open('netflix_titles.nt') as ficheiro: 10 entities = []11 for line in ficheiro:12 entity = line.split(" ")[0]13 if entity not in entities:14 entities.append(entity)15 #entities.append( line.split(" ")[0] )16with open('netflix_titles.n3', 'w') as output:17 output.write(ns0+"\n")18 output.write(xsd)19output_str = ""20with open('netflix_titles.n3', 'w') as output: 21 22 for entity in entities:23 #print(entity)24 output_str = entity + "\n"25 26 with open('netflix_titles.nt') as ficheiro:27 for line in ficheiro:28 if line.startswith(entity) and "http://netflix-titles.com/dir/" not in line:29 if "pred/type" in line:30 new_line = line.replace("<http://netflix-titles.com/pred/type>", "ns0:type")31 new_line = new_line.replace(new_line.split(" ")[0], " ")32 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")33 #print(output_str +"|"+ new_line)34 output_str += new_line35 elif "pred/title" in line:36 new_line = line.replace("<http://netflix-titles.com/pred/title>", "ns0:title")37 new_line = new_line.replace(new_line.split(" ")[0], " ")38 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")39 #print(output_str + new_line)40 output_str += new_line41 elif "pred/directed_by" in line:42 new_line = line.replace("<http://netflix-titles.com/pred/directed_by>", "ns0:directed_by")43 new_line = new_line.replace(new_line.split(" ")[0], " ")44 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")45 #print(new_line)46 output_str += new_line47 elif "pred/cast" in line:48 new_line = line.replace("<http://netflix-titles.com/pred/cast>", "ns0:cast")49 new_line = new_line.replace(new_line.split(" ")[0], " ")50 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")51 #print(new_line)52 output_str += new_line53 elif "pred/country" in line:54 new_line = line.replace("<http://netflix-titles.com/pred/country>", "ns0:country")55 new_line = new_line.replace(new_line.split(" ")[0], " ")56 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")57 #print(new_line)58 output_str += new_line59 elif "pred/date_added" in line:60 new_line = line.replace("<http://netflix-titles.com/pred/date_added>", "ns0:date_added")61 new_line = new_line.replace(new_line.split(" ")[0], " ")62 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")63 #print(new_line)64 output_str += new_line65 elif "pred/release_year" in line:66 new_line = line.replace("<http://netflix-titles.com/pred/release_year>", "ns0:release_year")67 new_line = new_line.replace(new_line.split(" ")[0], " ")68 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")69 #print(new_line)70 output_str += new_line71 elif "pred/duration" in line:72 new_line = line.replace("<http://netflix-titles.com/pred/duration>", "ns0:duration")73 new_line = new_line.replace(new_line.split(" ")[0], " ")74 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")75 #print(new_line)76 output_str += new_line77 elif "pred/listed_in" in line:78 new_line = line.replace("<http://netflix-titles.com/pred/listed_in>", "ns0:listed_in")79 new_line = new_line.replace(new_line.split(" ")[0], " ")80 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string .")81 #print(new_line)82 output_str += new_line83 elif "pred/name" in line:84 new_line = line.replace("<http://netflix-titles.com/pred/name>", "ns0:name")85 new_line = new_line.replace(new_line.split(" ")[0], " ")86 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string ;")87 #print(new_line)88 output_str += new_line89 elif "pred/acted_in" in line:90 new_line = line.replace("<http://netflix-titles.com/pred/acted_in>", "ns0:acted_in")91 new_line = new_line.replace(new_line.split(" ")[0], " ")92 new_line = new_line.replace("<http://www.w3.org/2001/XMLSchema#string> .","xsd:string .")93 #print(new_line)94 output_str += new_line95 print(output_str)...

Full Screen

Full Screen

01_main.py

Source:01_main.py Github

copy

Full Screen

1from random import *2f = open('title.csv', 'r')3j = open('new_title.csv', 'w')4line = f.readline()5new_line = ""6flag = 07for i in line:8 if (flag == 1):9 new_line += i10 if (flag == 0 and i == ','):11 flag = 112j.write(new_line)13while line:14 line = f.readline()15 new_line = ""16 flag = 017 for i in line:18 if (flag == 1):19 new_line += i20 if (flag == 0 and i == ','):21 flag = 122 j.write(new_line)23f.close()24j.close()25k = open('new_title.csv', 'r')26a = open('final_title.csv', 'w')27line = k.readline()28new_line = ""29flag = 030for i in reversed(line):31 if (flag == 2):32 new_line += i33 if (flag == 1 and i == ','):34 flag = 235 if (flag == 0 and i == ','):36 flag = 137new_line+= '\n'38a.write(new_line)39while line:40 line = k.readline()41 new_line = ""42 flag = 043 for i in reversed(line):44 if (flag == 2):45 new_line += i46 if (flag == 1 and i == ','):47 flag = 248 if (flag == 0 and i == ','):49 flag = 150 new_line+= '\n'51 a.write(new_line)52k.close()53a.close()54b = open('final_title.csv', 'r')55c = open('titles.csv', 'w')56line = b.readline()57new_line = ""58for i in reversed(line):59 if (i != '\n'):60 new_line += i61 62kek = randint(1, 1000)63kek = str(kek)64new_line = new_line + ',' + kek + '\n'65c.write(new_line)66while line:67 line = b.readline()68 new_line = ""69 for i in reversed(line):70 if (i != '\n'):71 new_line += i72 kek = randint(1, 1000)73 kek = str(kek)74 new_line = new_line + ',' + kek + '\n'75 c.write(new_line)76b.close()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful