{"id":589,"date":"2020-07-28T13:31:42","date_gmt":"2020-07-28T20:31:42","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=589"},"modified":"2020-07-28T13:36:19","modified_gmt":"2020-07-28T20:36:19","slug":"86-stop-execution-of-python-script","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/07\/86-stop-execution-of-python-script\/","title":{"rendered":"#86 Stop execution of python script?"},"content":{"rendered":"<p>#86 Stop execution of python script?<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport sys\nsys.exit(&quot;Error message&quot;)\n<\/pre>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom sys import exit\nexit(0) # Successful exit\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#86 Stop execution of python script? import sys sys.exit(&quot;Error message&quot;) from sys import exit exit(0) # Successful exit<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-589","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-9v","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2219,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/06\/431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file\/","url_meta":{"origin":589,"position":0},"title":"#431 HyperMesh python script to create nodes using coordinates from csv file","author":"gantovnik","date":"2024-06-24","format":false,"excerpt":"Finally, I read how to write a script for HyperMesh in python. In this example, the script reads the coordinates of points from a cvs file. [code language=\"python\"] import os import hm import hm.entities as e from hwx import gui import csv model=hm.Model() os.chdir(r\"D:\\projects\\wordpress\\ex431\") with open('ex431_coordinates.csv', mode ='r') as file:\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":951,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/09\/172-get-book-meta-from-isbn-in-python\/","url_meta":{"origin":589,"position":1},"title":"#172 Get book info from ISBN","author":"gantovnik","date":"2021-09-05","format":false,"excerpt":"#172 Get book info from ISBN [code language=\"python\"] import sys from isbntools.app import * meta_dict=meta(\"156032712X\") title=meta_dict[\"Title\"] title=title.replace(\" \",\".\") author=meta_dict[\"Authors\"][0] author=author.replace(\" \",\".\") year=meta_dict[\"Year\"] isbn=meta_dict[\"ISBN-13\"] filename = title + \".\" + author + \".\" + year + \".\" + isbn + \".pdf\" print(filename) } [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1090,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/189-mandelbrot-set-using-python\/","url_meta":{"origin":589,"position":2},"title":"#189 Mandelbrot set using python","author":"gantovnik","date":"2021-11-13","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt # This determines the number of colors used in the plot. # The larger the value, the longer the script will take. max_iterations = 50 # These parameters define the boundaries of the plot x_min, x_max = -2.5, 1.5 y_min,\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex189.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":3616,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/08\/445-hypermesh-python-script-for-renumbering-the-elements-and-nodes\/","url_meta":{"origin":589,"position":3},"title":"#445 HyperMesh python script for renumbering the elements and nodes","author":"gantovnik","date":"2024-08-13","format":false,"excerpt":"import hm import hm.entities as ent elems = hm.Collection(model,ent.Element) model.renumbersolverid(collection=elems,start_id=1,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0) nodes = hm.Collection(model,ent.Node) model.renumbersolverid(collection=nodes,start_id=1000,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0)","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":845,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/149-optimization-in-python\/","url_meta":{"origin":589,"position":4},"title":"#149 Optimization in python","author":"gantovnik","date":"2021-01-24","format":false,"excerpt":"#149 Optimization in python [code language=\"python\"] import os import numpy as np from scipy.optimize import minimize os.chdir(r'D:\\projects\\wordpress\\ex149') os.getcwd() def obj(x): return (1-x[0])**2 + 100*(x[1]-x[0]**2)**2 def con(x): g=np.zeros(2) g[0]=1-x[0]**2-x[1]**2 g[1]=5-x[0]-3*x[1] return g x0=[5.0,5.0] constraints = {'type': 'ineq','fun': con} options={'disp':True} res = minimize(obj,x0,constraints=constraints,options=options) print('x =',res.x) print('f =',res.fun) print(res.success) [\/code] Output: [code language=\"python\"]\u2026","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":847,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/150-optimization-with-a-module-in-python\/","url_meta":{"origin":589,"position":5},"title":"#150 Optimization with a module in python","author":"gantovnik","date":"2021-01-24","format":false,"excerpt":"#150 Optimization with a module in python ex150.py [code language=\"python\"] import os import numpy as np from scipy.optimize import minimize, Bounds from structure import structure os.chdir(r'D:\\projects\\wordpress\\ex150') os.getcwd() def runoptimization(params,stressmax): objhist=[] def objcon(x): mass,stress=structure(x,params) f=mass g=stressmax-stress objhist.append(mass) return f,g xlast=[] flast=[] glast=[] def obj(x): nonlocal xlast,flast,glast if not np.array_equal(x,xlast): flast,glast =\u2026","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex150-300x200.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=589"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/589\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}