{"id":303180,"date":"2020-05-07T15:00:48","date_gmt":"2020-05-07T15:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303180"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303180","title":{"rendered":"py-to-js"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500892\/\">\n<h2><b>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 python \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 JS<\/b><\/h2>\n<p>  <\/p>\n<h3>\u041f\u0440\u0438\u0432\u0435\u0442! \u0412\u043e\u043e\u0431\u0449\u0435\u043c \u043c\u043d\u0435 14, \u044f \u0443\u0447\u0435\u043b \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043e\u043f\u043b\u043e\u0448\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0437\u0430\u043d\u043e\u0432\u043e. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Python \u2555<\/h3>\n<p>  <\/p>\n<h4>GitHub \u2014 <a href=\"https:\/\/github.com\/hoopengo\/py-to-js\" rel=\"nofollow\">github.com\/hoopengo\/py-to-js<\/a><\/h4>\n<p>  <\/p>\n<blockquote><p>\u041d\u0430\u0434 \u0447\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e:<\/p>\n<p>  1. py-to-js<br \/>  2. ryno<br \/>  3. \u0420\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043a\u043e\u0434\u0430<\/p><\/blockquote>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u0442\u0443\u043f\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0431\u0430\u0433\u0430\u043c\u0438 \u0438 \u0442\u043f. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0435\u0445\u0430\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>interp.py<\/code> \u0438\u043b\u0438 \u043a\u0430\u043a-\u0442\u043e \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0438 \u0432\u043f\u0438\u0448\u0435\u043c \u0442\u0443\u0434\u0430 \u044d\u0442\u043e:<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"python\">pyfile = open('testpy.py', 'r', encoding = 'UTF-8') count = -1 with open('open.js', 'w', encoding = 'UTF-8') as f: \tpy = pyfile.readlines() \tcc, c, tab, local = 1, 0, 0, 0 \tvariables = [] \tf.write('&quot;use strict&quot;;' + '\\n' * 2) \tf.write('''\/\/ Thanks for using py-to-js \/\/ I develop this with hearth''' + '\\n' * 2) \tfor num in py: \t\tcount += 1 \t\ttab = py[count].count('\\t') \t\t# basic concepts \t\tif '=' in num and not 'print' in num and not '==' in num and not '!=' in num: \t\t\tname = num.replace('\\n', '') \t\t\tlet = 'let ' \t\t\tif name.startswith('\\t'): \t\t\t\tlet = '\\tlet ' \t\t\t\tname = name.replace('\\t', '') \t\t\tif name in variables: \t\t\t\tlet = '' \t\t\tvariables.append(name) \t\t\tf.write( let + f&quot;{name}&quot; + ';' + '\\n' * 2) \t\telif 'if' in num: \t\t\tcondition = num.replace('\\n', '').replace('if', '').replace(':', '') \t\t\tif_ = 'if ' \t\t\tif condition.startswith('\\t'): \t\t\t\tcondition = condition.replace('\\t', '') \t\t\t\tif_ = '\\tif ' \t\t\t\tcc += 1 \t\t\telse: \t\t\t\tcc = 1 \t\t\tf.write( if_ + '(' + f'{condition}' + ' )' + ' {' + '\\n') \t\telif 'def' in num: \t\t\tcon = num.replace('\\n', '').replace('def', '').replace(':', '') \t\t\tdef_ = 'function' \t\t\tif con.startswith('\\t'): \t\t\t\tcon = condition.replace('\\t', '') \t\t\t\tdef_ = '\\tfunction' \t\t\t\tcc += 1 \t\t\telse: \t\t\t\tcc = 1 \t\t\tf.write( def_  + f'{con}' + ' {' + '\\n') \t\t# basic commands \t\telif 'print' in num: \t\t\tcommand = num.replace('\\n', '') \t\t\tif command.startswith('\\t'): \t\t\t\tcommand = command.replace('\\t', '') \t\t\tf.write('\\t' + f'{ command.replace(&quot;print&quot;, &quot;console.log&quot;)}'+ ';' + '\\n') \t\ttry: \t\t\tif py[count + 1].count('\\t') &lt; tab and py[count + 1] != '\\n': \t\t\t\tif local == 0: \t\t\t\t\tf.write('}' + '\\n') \t\t\t\t\tc += 1 \t\t\t\telif local &gt; 0: \t\t\t\t\tf.write('}' * local + '\\n') \t\t\t\t\tc += 1 * local \t\t\t\t\tlocal = 0 \t\t\telif py[count + 1].count('\\t') &gt;= tab and py[count + 1].count('\\t') != 0 and py[count + 1] != '\\n': \t\t\t\tif 'def' in py[count + 1] or 'if' in py[count + 1]: \t\t\t\t\tlocal += 1 \t\texcept: \t\t\tpass \t\ttry: \t\t\tif '\\t' in py[count] and not '\\t' in py[count + 1] and py[count + 1] != '\\n': \t\t\t\tf.write('}' * (cc - c) + '\\n' * 2) \t\t\t\tc = 0 \t\texcept: \t\t\tf.write('}' * (cc - c)) \t\t\tc = 0 print('''Programm has been compiled.. 1.def tests 2.add class''')<\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0432 \u043f\u043e\u043b\u0435 open \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u0430\u0439\u043b. \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0442\u0443\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u043c\u043e\u0433\u0443 \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0430\u0445. \u041a\u0441\u0442\u0430\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0442\u043e, \u0447\u0442\u043e \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u0432 1-\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u043f\u0438\u043b\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0442.\u0434. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u044b. \u0421\u043e\u0437\u0434\u0430\u0451\u043c <code>testpy.py<\/code> \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u044d\u0442\u043e:<\/p>\n<pre><code class=\"python\">i = 0 b = 0 c = 0 if i == 0: \tprint('i = 0') \tif b == 0: \t\tprint('b = 0') \t\tif c == 0: \t\t\tprint('c = 0') \tif b != 0: \t\tprint('b != 0') \t\tif c != 0: \t\t\tprint('c != 0')<\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448 \u043d\u0435\u0434\u043e py-to-js \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0442 \u044d\u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"javascript\">&quot;use strict&quot;;  \/\/ Thanks for using py-to-js \/\/ I develop this with hearth  let i = 0;  let b = 0;  let c = 0;  if (i == 0) {     console.log('i = 0');     if (b == 0) {         console.log('b = 0');         if (c == 0) {             console.log('c = 0');         }     }     if (b != 0) {         console.log('b != 0');         if (c != 0) {             console.log('c != 0');         }     } }<\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/500892\/\"> https:\/\/habr.com\/ru\/post\/500892\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/500892\/\">\n<h2><b>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 python \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 JS<\/b><\/h2>\n<p>  <\/p>\n<h3>\u041f\u0440\u0438\u0432\u0435\u0442! \u0412\u043e\u043e\u0431\u0449\u0435\u043c \u043c\u043d\u0435 14, \u044f \u0443\u0447\u0435\u043b \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043e\u043f\u043b\u043e\u0448\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0437\u0430\u043d\u043e\u0432\u043e. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Python \u2555<\/h3>\n<p>  <\/p>\n<h4>GitHub \u2014 <a href=\"https:\/\/github.com\/hoopengo\/py-to-js\" rel=\"nofollow\">github.com\/hoopengo\/py-to-js<\/a><\/h4>\n<p>  <\/p>\n<blockquote><p>\u041d\u0430\u0434 \u0447\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e:<\/p>\n<p>  1. py-to-js<br \/>  2. ryno<br \/>  3. \u0420\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043a\u043e\u0434\u0430<\/p><\/blockquote>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u0442\u0443\u043f\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0431\u0430\u0433\u0430\u043c\u0438 \u0438 \u0442\u043f. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0435\u0445\u0430\u043b\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>interp.py<\/code> \u0438\u043b\u0438 \u043a\u0430\u043a-\u0442\u043e \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0438 \u0432\u043f\u0438\u0448\u0435\u043c \u0442\u0443\u0434\u0430 \u044d\u0442\u043e:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303180","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303180"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303180\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}