Python2021. 11. 10. 10:52

1에서 10까지 값 만들기

import numpy as np

# 1~10까지 만들기
a = np.arange(1,11)

print(a)

결과 : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

만들어진 1~10까지 더하기 : 누적합(Cumulative Sum) : np.cumsum

# 1~10까지 더하기
b = np.cumsum(a)

print(b)

결과 : [ 1 3 6 10 15 21 28 36 45 55]

* 수학 공식

( 첫번째 값 + 마지막 값 ) * 갯수 / 2 

(1+10) * 10 / 2 = 55

Posted by 비니미니파파
Python2021. 11. 3. 16:04

def 함수명(파라미터1, 파라미터2 ....)

# sum 함수 선언
def sum(x,y):
    return x+y

# sum 함수 호출
sum(3,4)

 

간단하죠 ^^

Posted by 비니미니파파
Python2021. 11. 3. 15:55
import matplotlib.pyplot as plt  
import numpy as np

# 선그래프
plt.plot([1,2,3,4])
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.show()

# 선모양
x = np.arange(0., 10., 0.3) # 0에서 10미만 0.3 증가
y = x**2                    # x의 2 제곱
line = plt.plot(x, y)
plt.setp(line, color='r', linewidth=3.0)  # 선모양
plt.show()

Posted by 비니미니파파

먼저 nodejs 가 설치되어 있어야 한다.

프로젝트 디렉토리를 생성 한다. ( 예 : pjtest )

visual studio code 를 실행 후 폴더를 연다.

nodejs 나 electron 개발 시 visual studio code 가 좀 더 편한거 같다.

터미널을 연다.

터미널에서

~> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (pjtest)
version: (1.0.0)
description: Test Project
entry point: (index.js)
test command: start
git repository:
keywords:
author:
license: (ISC) MIT
About to write to C:\dev\vstudio\workspace\pjTest\package.json:
{
  "name": "pjtest",
  "version": "1.0.0",
  "description": "Test Project",
  "main": "index.js",
  "scripts": {
    "test": "start"
  },
  "author": "",
  "license": "MIT"
}


Is this OK? (yes) y

package.json 이 생성되었으면 반은 성공

일렉트론을 설치해 보자

~> npm install --save-dev electron

added 87 packages, and audited 88 packages in 21s

6 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

설치완료 스타트(start) 스크립트 설정

package.json 을 열고 script 부분을 아래와 같이 변경한다.

  "scripts": {
    "start": "electron ."
  },

{
  "name": "pjtest",
  "version": "1.0.0",
  "description": "Test Project",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "electron": "^13.1.9"
  }
}

설정은 끝났다. 실행할 파일을 만든다. ( index.js , main.html )

index.js

const { app, BrowserWindow } = require('electron')
const path = require('path')

function createWindow() {
    const mainWindow = new BrowserWindow({
        width: 800,
        height: 600
    })

    mainWindow.loadFile('main.html')

}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', function () {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') app.quit()
})

main.html 을 만든다.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    We are using Node.js <span id="node-version"></span>,
    Chromium <span id="chrome-version"></span>,
    and Electron <span id="electron-version"></span>.
  </body>
</html>

터미널에서 실행해 본다.

~> npm start

 

끝...

자세한 공부는 아래에서 하자.

https://www.electronjs.org/docs/tutorial/quick-start

Posted by 비니미니파파
Python2021. 8. 5. 17:53

시작일~종료일 까지 반복 하는 Python 코드

datetime, timedelta

 

from datetime import datetime, timedelta

# 시작일,종료일 설정
start = "2021-08-01"
last = "2021-08-04"

# 시작일, 종료일 datetime 으로 변환
start_date = datetime.strptime(start, "%Y-%m-%d")
last_date = datetime.strptime(last, "%Y-%m-%d")

# 종료일 까지 반복
while start_date <= last_date:
    dates = start_date.strftime("%Y-%m-%d")
    print(dates)

    # 하루 더하기
    start_date += timedelta(days=1)

 

Posted by 비니미니파파