브라우저의 파이썬? 좋아 어서 해보자!
다음은 GSS에 대한 일부 컨텍스트입니다https://www.sitepoint.com/introducing-gss-grid-style-sheets/.
간단한 Hello World로 시작해 볼까요?
먼저 폴더 호출 pyscript를 만들고 해당 폴더 내에 index.html을 만듭니다.
확인 기본 HTML 레이아웃을 사용할 수 있습니다.
`
<!DOCTYPE html
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
`
That's perfect! Just not formatted! and there is a reason for that which I will get to.
Ok so with our template lets add a head section and pop a couple of CDN links
<pre><code>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
</pre></code>
And now we have a simple tag we can use which is , which allows us to write some python and basically run it!
So let's remove the heading and paragraph tag and replace it with the following:
`
<py-script>
def helloworld():
welcome = False
if welcome:
print('Hello World')
else:
print('Not today please')
helloworld()
</py-script>
`
So this is the reason we do not format the code and that is purely down the fact it seems if you try and format it the page will fail to load through indentation errors.
So our final file should look like so:
`
<!Doctype html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script>
def helloworld():
welcome = False
if welcome:
print('Hello World')
else:
print('Not today please')
helloworld()
</py-script>
</body>
</html>
`
And if you run it in the browser you will be greeted with our else message and python is running. Now it does take some time to render and would work well in a dashboard setting but I wouldn't like to use it in a website environment as it would take a while to load the page to the user.
Also if we look at the console we have a full output as to what's going on and if you do get errors you get a full break down of what's going on there.
So anyway yeah its fun, its delightful but where would I use it? I'm not sure I would...
Edit, please excuse the code examples and the rendering of the HTML code blocks, trying to escape HTML in markdown is a real pain.
Reference
이 문제에 관하여(브라우저의 파이썬? 좋아 어서 해보자!), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/grahammorby/python-in-the-browser-ok-lets-do-it-4a5b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)