브라우저의 파이썬? 좋아 어서 해보자!

그래서 여기에서 역사를 좀 해봅시다. 이 아이디어가 미친 것처럼 보이지만 기쁨과 매력으로 나를 채우는 것을 볼 수 있습니다. 그래서 저는 꽤 오랫동안 프론트엔드 개발자였습니다. 15년 동안 저는 모든 트렌드를 보았고 모든 종류의 물결을 탔습니다! GSS를 기억하십니까? 그래, CSS를 위한 자바스크립트 폴리필, 내 말은 누가 좋은 JS에서 그리드를 원하지 않겠다는 뜻이야! 그때는 2014년이었지만 지금은 2022년이고 브라우저에 Python이 있습니다! 그리고 동료 개발자들 저는 Python을 좋아합니다! 천국에서 만든 성냥!

다음은 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>
&lt;head>
&lt;link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
&lt;script defer src="https://pyscript.net/alpha/pyscript.js">&lt;/script>
&lt;/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">&lt;/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.

좋은 웹페이지 즐겨찾기