1/21/2023

** 100 stock related terms - 1

 ** 100 stock related terms - 1 


Stock

A stock, also known as a share or a security, represents a unit of ownership in a company. When a company wants to raise capital, it can issue shares of stock, which are then bought and sold on a stock exchange or over-the-counter market. The total number of shares outstanding represents the total number of shares of stock that have been issued by a company and are currently held by shareholders.


Each stock gives the holder a proportionate ownership in the company, and usually comes with voting rights, allowing shareholders to vote on important matters such as the election of the board of directors and major corporate decisions. Shareholders are also entitled to a portion of the company's profits, which is paid out in the form of dividends.


Stocks can be bought and sold on a stock exchange, and their value can change based on a variety of factors, such as the company's financial performance, economic conditions, and investor sentiment. Investing in stocks can be a way for individuals to participate in the growth of a company and potentially earn a return on their investment.

------------------------------------------------------------------------


Share

A share, also known as a stock or a security, represents a unit of ownership in a company. When a company wants to raise capital, it can issue shares of stock, which are then bought and sold on a stock exchange or over-the-counter market. The total number of shares outstanding represents the total number of shares of stock that have been issued by a company and are currently held by shareholders.


Each share gives the holder a proportionate ownership in the company, and usually comes with voting rights, allowing shareholders to vote on important matters such as the election of the board of directors and major corporate decisions. Shareholders are also entitled to a portion of the company's profits, which is paid out in the form of dividends.


Shares can be bought and sold on a stock exchange, and their value can change based on a variety of factors, such as the company's financial performance, economic conditions, and investor sentiment. Investing in shares can be a way for individuals to participate in the growth of a company and potentially earn a return on their investment.

------------------------------------------------------------------------


Equity

Equity is the value of an asset after all liabilities are subtracted. In the context of a business, equity represents the residual value of the business to its owners, also known as shareholders. It is the value of the company that would be left over for the shareholders if all liabilities were paid off and all assets were sold.


In a company, equity can be broken down into different types such as common stock, preferred stock, and retained earnings. Common stock represents the ownership of the company and gives shareholders the right to vote on certain matters, such as the election of board of directors and major corporate decisions. Preferred stock is a type of equity that has a higher claim on assets and earnings than common stock, but generally does not have voting rights. Retained earnings are the portion of a company's profits that are retained by the company rather than being distributed as dividends to shareholders.


Equity is an important measure of a company's financial health and stability, as it represents the company's net worth and its ability to generate future cash flow.

------------------------------------------------------------------------


Dividend

A dividend is a distribution of a portion of a company's earnings to a class of its shareholders. Dividends are usually paid out in cash, but can also be paid out in the form of additional shares of stock or other assets. Dividends are usually paid out on a regular basis, such as quarterly or annually, to shareholders of record on a specific date.


Dividends are typically paid by mature, stable companies that have a consistent stream of earnings and cash flow, and that have a surplus of cash that they do not need to reinvest in the business. Dividends can be a valuable source of income for investors, and can also be a sign of a company's financial health and stability.


It's important to note that not all companies pay dividends, and some companies may choose to reinvest their earnings in order to grow their business or to pay off debt. Also, companies can decide to change their dividend policy, they can increase, decrease or even suspend it.

------------------------------------------------------------------------


Stock market

A stock market is a marketplace where stocks of publicly traded companies are bought and sold. These markets, also known as equity markets, provide a platform for companies to raise capital by issuing and selling shares of stock to the public, and for investors to buy and sell those shares. The most famous stock markets are the New York Stock Exchange (NYSE) and the NASDAQ in the United States, and the Tokyo Stock Exchange, the London Stock Exchange, and the Hong Kong Stock Exchange.


The stock market is also known as the secondary market as it is where investors buy and sell securities that have been previously issued by companies, unlike the primary market, where companies raise capital by issuing new securities.


The stock market is a key component of the global economy and can be a valuable source of long-term growth for investors. However, the stock market can be volatile and prices can fluctuate dramatically, depending on a variety of factors such as economic conditions, political developments, and corporate performance.

------------------------------------------------------------------------


IPO

An initial public offering (IPO) is the process by which a privately held company raises capital by issuing and selling shares of stock to the public for the first time. IPOs allow companies to raise funds from a broad range of investors, including institutions and individual investors, by selling shares in the company.


When a company decides to go public, it hires an investment bank or underwriter to help it prepare for the IPO. This includes valuing the company, determining the number and price of shares to be sold, and creating a prospectus, which is a document that provides detailed information about the company and the offering to potential investors.


After the shares are sold to the public, they can be traded on a stock exchange, such as the NYSE or NASDAQ. IPOs can be a significant event for a company and its shareholders as it provides access to capital and liquidity, and also brings greater visibility and public scrutiny.


It's important to note that IPOs can be a high-risk investment as the stock price of newly public companies may be highly volatile and can fluctuate significantly in the short term.

------------------------------------------------------------------------


Bull market

A bull market is a period of time in which stock prices, as well as other securities, are on an upward trend, typically characterized by widespread optimism and positive investor sentiment. A bull market is typically defined as a sustained rise in the market of 20% or more from a recent low. The term "bull market" comes from the way bulls attack, which is by thrusting their horns up.


During a bull market, investors may experience significant gains, and many investors may choose to buy stocks, which can further contribute to the upward trend. Bull markets can be caused by a variety of factors, including economic growth, low unemployment, low inflation, and positive corporate earnings.


It is important to note that bull markets are a normal part of the economic cycle, and are typically followed by bear markets, which are characterized by falling prices and negative investor sentiment.

------------------------------------------------------------------------


Bear market

A bear market is a period of time in which stock prices, as well as other securities, are on a downward trend, typically characterized by widespread pessimism and negative investor sentiment. A bear market is typically defined as a decline of 20% or more from the market's most recent high. The term "bear market" comes from the way bears attack their prey, which is by swiping down.


During a bear market, investors may experience significant losses, and many investors may choose to sell their stocks, which can further contribute to the downward trend. Bear markets can be caused by a variety of factors, including economic recession, high inflation, rising interest rates, or political uncertainty.


It is important to note that bear markets are a normal part of the economic cycle, and are typically followed by bull markets, which are characterized by rising prices and positive investor sentiment.

------------------------------------------------------------------------


Market capitalization

Market capitalization, also known as "market cap," is a measure of the total value of a publicly traded company's outstanding shares of stock. It is calculated by multiplying the current stock price by the number of outstanding shares. Market capitalization is used to classify a company as a large-cap, mid-cap, or small-cap stock, and can also be used to compare the relative size of different companies.


For example, a company with a market capitalization of $10 billion would be considered a large-cap company, while a company with a market capitalization of $500 million would be considered a small-cap company. It is important to note that market capitalization is not the same as a company's financial performance, it is just one way to classify the size of a company and for investors to get an idea of how much a company is worth.

------------------------------------------------------------------------


Ticker symbol

A ticker symbol is a short code used to uniquely identify a publicly traded company and its stock or other securities listed on an exchange. The ticker symbol is typically a combination of letters, and is used to efficiently and quickly identify a specific stock or other security among the thousands traded on an exchange. Ticker symbols are also known as stock symbols, trading symbols, or stock codes. They are usually one to five letters long, and are listed on stock exchange and financial websites to identify the security being traded and to retrieve the current stock prices and other financial data.

------------------------------------------------------------------------


3/07/2022

** Vocabulary

 ** Vocabulary


  • tackle* = to actively solve a problem (like a rugby player!!)
  • struggle* = to try hard and have a difficult time succeeding.
  • a last-mile problem* = the kind of problem that we can fix but don’t…
  • deliberate practice* = one of the kinds of practice I recommend as a Neurolanguage coach--when you practice something on purpose that you want to remember.
  • Sounds like someone I know*= an expression that means you hear a description and it reminds you of another person present…you or the person you’re talking to (or about) for example.
  • show up*= just taking time to consistently try something or work towards something--you don’t have to be perfect or even good because you’ll improve just through repetition.
  • To go out on a limb* = to take a risk/ to try something new

7/07/2021

** 주식 - 팁

 ** 주식 - 팁


` 키움증권 해외주식 출금 : 주식 매도 후 D+3일 이후 가능.


` 키움증권 국내주식 출금 : 주식 매도 후 D+2일 이후 가능. 



** 주식 - 목표주가

 ** 주식 - 목표주가


` 삼성전자 : 89,500원 / 12배


` 현대자동차 : 280,000원 / 7.5배


` KB금융 : 81,500원 / 5배


` 신한지주 : 65,500원 / 5배


` 하나금융지주 : 66,500원 / 5배


===============================


` LG전자 : 188,000원 / 7배



6/07/2020

Python - Itertools Module : Iterator Functions for Efficient Looping

** Itertools Module : Iterator Functions for Efficient Looping


==========================================

import itertools

counter = itertools.count()

for num in counter:
print(num)

---------------------------------

0
1
2
3
... 정지 명령을 내릴때 까지 계속 1씩 증가

==========================================
==========================================

import itertools

counter = itertools.count()

print(next(counter))

---------------------------------

0

---------------------------------

import itertools

counter = itertools.count()

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

0
1
2
3

==========================================
==========================================

import itertools

counter = itertools.count()

data = [100, 200, 300, 400]

daily_data = list(zip(itertools.count(), data))

print(daily_data)

---------------------------------

[(0, 100), (1, 200), (2, 300), (3, 400)]

==========================================
==========================================

import itertools

counter = itertools.count(start=5)

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

5
6
7
8

---------------------------------

import itertools

counter = itertools.count(start=5, step=5)

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

5
10
15
20

---------------------------------

import itertools

counter = itertools.count(start=5, step=-2.5)

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

5
2.5
0.0
-2.5

==========================================
==========================================







import itertools

data = [100, 200, 300, 400]

daily_data = list(zip(range(10), data))

print(daily_data)

---------------------------------

[(0, 100), (1, 200), (2, 300), (3, 400)]

---------------------------------

import itertools

data = [100, 200, 300, 400]

daily_data = list(itertools.zip_longest(range(10), data))

print(daily_data)

---------------------------------

[(0, 100), (1, 200), (2, 300), (3, 400), (4, None), (5, None), (6, None), (7, 

None), (8, None), (9, None)]

==========================================
==========================================

import itertools

counter = itertools.cycle([1, 2, 3])

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

1
2
3
1
2
3

---------------------------------

import itertools

counter = itertools.cycle(('On', 'Off'))

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

On
Off
On
Off
On
Off

---------------------------------

import itertools

counter = itertools.repeat(2, times=3)

print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))
print(next(counter))

---------------------------------

2Traceback (most recent call last):
  File "C:\Users\purunet\Documents\py9\ii.py", line 9, in <module>

2
2
    print(next(counter))
StopIteration

==========================================
==========================================

import itertools

counter = itertools.repeat(2, times=3)

squares = map(pow, range(10), itertools.repeat(2))

print(list(squares))

---------------------------------

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

---------------------------------

import itertools

counter = itertools.repeat(2, times=3)

squares = itertools.starmap(pow, [(0, 2), (1, 2), (2, 2)])

print(list(squares))

---------------------------------

[0, 1, 4]

==========================================
==========================================

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.combinations(letters, 2)

for item in result:
print(item)

---------------------------------

('a', 'b')
('a', 'c')
('a', 'd')
('b', 'c')
('b', 'd')
('c', 'd')

---------------------------------

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.permutations(letters, 2)

for item in result:
print(item)

---------------------------------

('a', 'b')
('a', 'c')
('a', 'd')
('b', 'a')
('b', 'c')
('b', 'd')
('c', 'a')
('c', 'b')
('c', 'd')
('d', 'a')
('d', 'b')
('d', 'c')

---------------------------------

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.product(numbers, repeat=4)

for item in result:
print(item)

---------------------------------

(0, 0, 0, 0)
(0, 0, 0, 1)
(0, 0, 0, 2)
(0, 0, 0, 3)
(0, 0, 1, 0)
(0, 0, 1, 1)
(0, 0, 1, 2)
(0, 0, 1, 3)
(0, 0, 2, 0)
(0, 0, 2, 1)
(0, 0, 2, 2)
(0, 0, 2, 3)
(0, 0, 3, 0)
(0, 0, 3, 1)
(0, 0, 3, 2)
(0, 0, 3, 3)
(0, 1, 0, 0)
(0, 1, 0, 1)
(0, 1, 0, 2)
(0, 1, 0, 3)
(0, 1, 1, 0)
(0, 1, 1, 1)
(0, 1, 1, 2)
(0, 1, 1, 3)
(0, 1, 2, 0)
(0, 1, 2, 1)
(0, 1, 2, 2)
(0, 1, 2, 3)
(0, 1, 3, 0)
(0, 1, 3, 1)
(0, 1, 3, 2)
(0, 1, 3, 3)
(0, 2, 0, 0)
(0, 2, 0, 1)
(0, 2, 0, 2)
(0, 2, 0, 3)
(0, 2, 1, 0)
(0, 2, 1, 1)
(0, 2, 1, 2)
(0, 2, 1, 3)
(0, 2, 2, 0)
(0, 2, 2, 1)
(0, 2, 2, 2)
(0, 2, 2, 3)
(0, 2, 3, 0)
(0, 2, 3, 1)
(0, 2, 3, 2)
(0, 2, 3, 3)
(0, 3, 0, 0)
(0, 3, 0, 1)
(0, 3, 0, 2)
(0, 3, 0, 3)
(0, 3, 1, 0)
(0, 3, 1, 1)
(0, 3, 1, 2)
(0, 3, 1, 3)
(0, 3, 2, 0)
(0, 3, 2, 1)
(0, 3, 2, 2)
(0, 3, 2, 3)
(0, 3, 3, 0)
(0, 3, 3, 1)
(0, 3, 3, 2)
(0, 3, 3, 3)
(1, 0, 0, 0)
(1, 0, 0, 1)
(1, 0, 0, 2)
(1, 0, 0, 3)
(1, 0, 1, 0)
(1, 0, 1, 1)
(1, 0, 1, 2)
(1, 0, 1, 3)
(1, 0, 2, 0)
(1, 0, 2, 1)
(1, 0, 2, 2)
(1, 0, 2, 3)
(1, 0, 3, 0)
(1, 0, 3, 1)
(1, 0, 3, 2)
(1, 0, 3, 3)
(1, 1, 0, 0)
(1, 1, 0, 1)
(1, 1, 0, 2)
(1, 1, 0, 3)
(1, 1, 1, 0)
(1, 1, 1, 1)
(1, 1, 1, 2)
(1, 1, 1, 3)
(1, 1, 2, 0)
(1, 1, 2, 1)
(1, 1, 2, 2)
(1, 1, 2, 3)
(1, 1, 3, 0)
(1, 1, 3, 1)
(1, 1, 3, 2)
(1, 1, 3, 3)
(1, 2, 0, 0)
(1, 2, 0, 1)
(1, 2, 0, 2)
(1, 2, 0, 3)
(1, 2, 1, 0)
(1, 2, 1, 1)
(1, 2, 1, 2)
(1, 2, 1, 3)
(1, 2, 2, 0)
(1, 2, 2, 1)
(1, 2, 2, 2)
(1, 2, 2, 3)
(1, 2, 3, 0)
(1, 2, 3, 1)
(1, 2, 3, 2)
(1, 2, 3, 3)
(1, 3, 0, 0)
(1, 3, 0, 1)
(1, 3, 0, 2)
(1, 3, 0, 3)
(1, 3, 1, 0)
(1, 3, 1, 1)
(1, 3, 1, 2)
(1, 3, 1, 3)
(1, 3, 2, 0)
(1, 3, 2, 1)
(1, 3, 2, 2)
(1, 3, 2, 3)
(1, 3, 3, 0)
(1, 3, 3, 1)
(1, 3, 3, 2)
(1, 3, 3, 3)
(2, 0, 0, 0)
(2, 0, 0, 1)
(2, 0, 0, 2)
(2, 0, 0, 3)
(2, 0, 1, 0)
(2, 0, 1, 1)
(2, 0, 1, 2)
(2, 0, 1, 3)
(2, 0, 2, 0)
(2, 0, 2, 1)
(2, 0, 2, 2)
(2, 0, 2, 3)
(2, 0, 3, 0)
(2, 0, 3, 1)
(2, 0, 3, 2)
(2, 0, 3, 3)
(2, 1, 0, 0)
(2, 1, 0, 1)
(2, 1, 0, 2)
(2, 1, 0, 3)
(2, 1, 1, 0)
(2, 1, 1, 1)
(2, 1, 1, 2)
(2, 1, 1, 3)
(2, 1, 2, 0)
(2, 1, 2, 1)
(2, 1, 2, 2)
(2, 1, 2, 3)
(2, 1, 3, 0)
(2, 1, 3, 1)
(2, 1, 3, 2)
(2, 1, 3, 3)
(2, 2, 0, 0)
(2, 2, 0, 1)
(2, 2, 0, 2)
(2, 2, 0, 3)
(2, 2, 1, 0)
(2, 2, 1, 1)
(2, 2, 1, 2)
(2, 2, 1, 3)
(2, 2, 2, 0)
(2, 2, 2, 1)
(2, 2, 2, 2)
(2, 2, 2, 3)
(2, 2, 3, 0)
(2, 2, 3, 1)
(2, 2, 3, 2)
(2, 2, 3, 3)
(2, 3, 0, 0)
(2, 3, 0, 1)
(2, 3, 0, 2)
(2, 3, 0, 3)
(2, 3, 1, 0)
(2, 3, 1, 1)
(2, 3, 1, 2)
(2, 3, 1, 3)
(2, 3, 2, 0)
(2, 3, 2, 1)
(2, 3, 2, 2)
(2, 3, 2, 3)
(2, 3, 3, 0)
(2, 3, 3, 1)
(2, 3, 3, 2)
(2, 3, 3, 3)
(3, 0, 0, 0)
(3, 0, 0, 1)
(3, 0, 0, 2)
(3, 0, 0, 3)
(3, 0, 1, 0)
(3, 0, 1, 1)
(3, 0, 1, 2)
(3, 0, 1, 3)
(3, 0, 2, 0)
(3, 0, 2, 1)
(3, 0, 2, 2)
(3, 0, 2, 3)
(3, 0, 3, 0)
(3, 0, 3, 1)
(3, 0, 3, 2)
(3, 0, 3, 3)
(3, 1, 0, 0)
(3, 1, 0, 1)
(3, 1, 0, 2)
(3, 1, 0, 3)
(3, 1, 1, 0)
(3, 1, 1, 1)
(3, 1, 1, 2)
(3, 1, 1, 3)
(3, 1, 2, 0)
(3, 1, 2, 1)
(3, 1, 2, 2)
(3, 1, 2, 3)
(3, 1, 3, 0)
(3, 1, 3, 1)
(3, 1, 3, 2)
(3, 1, 3, 3)
(3, 2, 0, 0)
(3, 2, 0, 1)
(3, 2, 0, 2)
(3, 2, 0, 3)
(3, 2, 1, 0)
(3, 2, 1, 1)
(3, 2, 1, 2)
(3, 2, 1, 3)
(3, 2, 2, 0)
(3, 2, 2, 1)
(3, 2, 2, 2)
(3, 2, 2, 3)
(3, 2, 3, 0)
(3, 2, 3, 1)
(3, 2, 3, 2)
(3, 2, 3, 3)
(3, 3, 0, 0)
(3, 3, 0, 1)
(3, 3, 0, 2)
(3, 3, 0, 3)
(3, 3, 1, 0)
(3, 3, 1, 1)
(3, 3, 1, 2)
(3, 3, 1, 3)
(3, 3, 2, 0)
(3, 3, 2, 1)
(3, 3, 2, 2)
(3, 3, 2, 3)
(3, 3, 3, 0)
(3, 3, 3, 1)
(3, 3, 3, 2)
(3, 3, 3, 3)

---------------------------------

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.combinations_with_replacement(numbers, 4)

for item in result:
print(item)

---------------------------------

(0, 0, 0, 0)
(0, 0, 0, 1)
(0, 0, 0, 2)
(0, 0, 0, 3)
(0, 0, 1, 1)
(0, 0, 1, 2)
(0, 0, 1, 3)
(0, 0, 2, 2)
(0, 0, 2, 3)
(0, 0, 3, 3)
(0, 1, 1, 1)
(0, 1, 1, 2)
(0, 1, 1, 3)
(0, 1, 2, 2)
(0, 1, 2, 3)
(0, 1, 3, 3)
(0, 2, 2, 2)
(0, 2, 2, 3)
(0, 2, 3, 3)
(0, 3, 3, 3)
(1, 1, 1, 1)
(1, 1, 1, 2)
(1, 1, 1, 3)
(1, 1, 2, 2)
(1, 1, 2, 3)
(1, 1, 3, 3)
(1, 2, 2, 2)
(1, 2, 2, 3)
(1, 2, 3, 3)
(1, 3, 3, 3)
(2, 2, 2, 2)
(2, 2, 2, 3)
(2, 2, 3, 3)
(2, 3, 3, 3)
(3, 3, 3, 3)

==========================================
==========================================

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

combined = itertools.chain(letters, numbers, names)

for item in combined:
print(item

---------------------------------

a
b
c
d
0
1
2
3
LinuxerHAN
SeokDu

==========================================
==========================================

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.islice(range(10), 5)

for item in result:
print(item)

---------------------------------

0
1
2
3
4

---------------------------------

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.islice(range(10), 1, 5)

for item in result:
print(item)

---------------------------------

0
1
2
3
4

---------------------------------

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.islice(range(10), 1, 5, 2)

for item in result:
print(item)
---------------------------------

1
3

==========================================
==========================================

import itertools

with open('test.log', 'r') as f:
header = itertools.islice(f, 3)

for line in header:
print(line)

---------test.log-------------------

Date: 2020-06-07
Author: LinuxerHAN
Description: This is a sample log file

Okay, so this is a sample entry.
I'm going to write a few more lines here.
For the sake of this video, let's pretend this log file is thousands 

and thousands of lines... okay?

---------------------------------

Date: 2020-06-07

Author: LinuxerHAN

Description: This is a sample log file

---------------------------------

import itertools

with open('test.log', 'r') as f:
header = itertools.islice(f, 3)

for line in header:
print(line)

---------test.log-------------------

Date: 2020-06-07
Author: LinuxerHAN
Description: This is a sample log file

Okay, so this is a sample entry.
I'm going to write a few more lines here.
For the sake of this video, let's pretend this log file is thousands 

and thousands of lines... okay?

---------------------------------

Date: 2020-06-07

Author: LinuxerHAN

Description: This is a sample log file

---------------------------------

import itertools

with open('test.log', 'r') as f:
header = itertools.islice(f, 3)

for line in header:
print(line, end='')

---------test.log-------------------

Date: 2020-06-07
Author: LinuxerHAN
Description: This is a sample log file

Okay, so this is a sample entry.
I'm going to write a few more lines here.
For the sake of this video, let's pretend this log file is thousands 

and thousands of lines... okay?

---------------------------------

Date: 2020-06-07
Author: LinuxerHAN
Description: This is a sample log file

==========================================
==========================================

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = itertools.compress(letters, selectors)

for item in result:
print(item)

---------------------------------
a
b
d

==========================================
==========================================

import itertools

def lt_2(n):
if n < 2:
return True
return False

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = filter(lt_2, numbers)

for item in result:
print(item)

---------------------------------

0
1

---------------------------------

import itertools

def lt_2(n):
if n < 2:
return True
return False

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = itertools.filterfalse(lt_2, numbers)

for item in result:
print(item)

---------------------------------

2
3

---------------------------------

import itertools

def lt_2(n):
if n < 2:
return True
return False

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3, 2, 1, 0]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = itertools.filterfalse(lt_2, numbers)

for item in result:
print(item)

---------------------------------

2
3
2

---------------------------------

import itertools

def lt_2(n):
if n < 2:
return True
return False

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3, 2, 1, 0]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = itertools.dropwhile(lt_2, numbers)

for item in result:
print(item)

---------------------------------

2
3
2
1
0

---------------------------------

import itertools

def lt_2(n):
if n < 2:
return True
return False

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3, 2, 1, 0]
names = ['LinuxerHAN', 'SeokDu']

selectors = [True, True, False, True]

result = itertools.takewhile(lt_2, numbers)

for item in result:
print(item)

---------------------------------

0
1

==========================================
==========================================

import itertools

letters = ['a', 'b', 'c', 'd']
numbers = [0, 1, 2, 3, 2, 1, 0]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.accumulate(numbers)

for item in result:
print(item)

---------------------------------

0
1
3
6
8
9
9

---------------------------------

import itertools
import operator


letters = ['a', 'b', 'c', 'd']
numbers = [1, 2, 3, 2, 1, 0]
names = ['LinuxerHAN', 'SeokDu']

result = itertools.accumulate(numbers, operator.mul)

for item in result:
print(item)

---------------------------------

1
2
6
12
12
0

==========================================
==========================================

import itertools


def get_state(person):
    return person['state']


people = [
    {
        'name': 'Linuxer HAN',
        'city': 'Gotham',
        'state': 'NY'
    },
    {
        'name': 'SeokDu HAN',
        'city': 'Kings Landing',
        'state': 'NY'
    },
    {
        'name': 'Corey Schafer',
        'city': 'Boulder',
        'state': 'CO'
    },
    {
        'name': 'Al Einstein',
        'city': 'Denver',
        'state': 'CO'
    },
    {
        'name': 'John Henry',
        'city': 'Hinton',
        'state': 'WV'
    },
    {
        'name': 'Randy Moss',
        'city': 'Rand',
        'state': 'WV'
    },
    {
        'name': 'Nicole K',
        'city': 'Asheville',
        'state': 'NC'
    },
    {
        'name': 'Jim Doe',
        'city': 'Charlotte',
        'state': 'NC'
    },
    {
        'name': 'Jane Taylor',
        'city': 'Faketown',
        'state': 'NC'
    }
]

person_group = itertools.groupby(people, get_state)

for key, group in person_group:
    print(key)
    for person in group:
        print(person)
    print()

---------------------------------

NY
{'name': 'Linuxer HAN', 'city': 'Gotham', 'state': 'NY'}
{'name': 'SeokDu HAN', 'city': 'Kings Landing', 'state': 'NY'}

CO
{'name': 'Corey Schafer', 'city': 'Boulder', 'state': 'CO'}
{'name': 'Al Einstein', 'city': 'Denver', 'state': 'CO'}

WV
{'name': 'John Henry', 'city': 'Hinton', 'state': 'WV'}
{'name': 'Randy Moss', 'city': 'Rand', 'state': 'WV'}

NC
{'name': 'Nicole K', 'city': 'Asheville', 'state': 'NC'}
{'name': 'Jim Doe', 'city': 'Charlotte', 'state': 'NC'}
{'name': 'Jane Taylor', 'city': 'Faketown', 'state': 'NC'}

---------------------------------

import itertools


def get_state(person):
    return person['state']


people = [
    {
        'name': 'Linuxer HAN',
        'city': 'Gotham',
        'state': 'NY'
    },
    {
        'name': 'SeokDu HAN',
        'city': 'Kings Landing',
        'state': 'NY'
    },
    {
        'name': 'Corey Schafer',
        'city': 'Boulder',
        'state': 'CO'
    },
    {
        'name': 'Al Einstein',
        'city': 'Denver',
        'state': 'CO'
    },
    {
        'name': 'John Henry',
        'city': 'Hinton',
        'state': 'WV'
    },
    {
        'name': 'Randy Moss',
        'city': 'Rand',
        'state': 'WV'
    },
    {
        'name': 'Nicole K',
        'city': 'Asheville',
        'state': 'NC'
    },
    {
        'name': 'Jim Doe',
        'city': 'Charlotte',
        'state': 'NC'
    },
    {
        'name': 'Jane Taylor',
        'city': 'Faketown',
        'state': 'NC'
    }
]

person_group = itertools.groupby(people, get_state)

for key, group in person_group:
    print(key, len(list(group)))

---------------------------------

NY 2
CO 2
WV 2
NC 3

==========================================


Python - Coding Problem: Creating Your Own Iterators

** Coding Problem: Creating Your Own Iterators


==========================================

my_sentence = Sentence('This is a test')

for word in my_sentence:
print(word)


# This should have the following output:
# This
# is
# a
# test

---------------------------------

class Sentence:

def __init__(self, sentence):
self.sentence = sentence
self.index = 0
self.words = self.sentence.split()

def __iter__(self):
return self

def __next__(self):
if self.index >= len(self.words):
raise StopIteration
index = self.index
self.index += 1
return self.words[index]


my_sentence = Sentence('This is a test')

for word in my_sentence:
print(word)

---------------------------------

This
is
a
test

==========================================
==========================================

class Sentence:

def __init__(self, sentence):
self.sentence = sentence
self.index = 0
self.words = self.sentence.split()

def __iter__(self):
return self

def __next__(self):
if self.index >= len(self.words):
raise StopIteration
index = self.index
self.index += 1
return self.words[index]


my_sentence = Sentence('This is a test')

print(next(my_sentence))
print(next(my_sentence))
print(next(my_sentence))
print(next(my_sentence))
print(next(my_sentence))

---------------------------------

is
a
test
    print(next(my_sentence))
  File "C:\Users\purunet\Documents\py9\ii.py", line 14, in __next__
    raise StopIteration
StopIteration

---------------------------------

class Sentence:

def __init__(self, sentence):
self.sentence = sentence
self.index = 0
self.words = self.sentence.split()

def __iter__(self):
return self

def __next__(self):
if self.index >= len(self.words):
raise StopIteration
index = self.index
self.index += 1
return self.words[index]

def sentence(sentence):
for word in sentence.split():
yield word


my_sentence = sentence('This is a test')


for word in my_sentence:
print(word)

---------------------------------

This
is
a
test

==========================================

6/05/2020

Python - Iterators and Iterables : What Are They and How Do They Work?

**  Iterators and Iterables : What Are They and How Do They Work?


==========================================

nums = [1, 2, 3]

for num in nums:
print(num)

---------------------------------

1
2
3

==========================================
==========================================

nums = [1, 2, 3]

print(dir(nums))

---------------------------------

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', 

'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', 

'__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', 

'__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', 

'__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', 

'__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 

'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 

'reverse', 'sort']

==========================================
==========================================

nums = [1, 2, 3]

print(next(nums))

---------------------------------

  File "C:\Users\purunet\Documents\py9\ii.py", line 7, in <module>
    print(next(nums))
TypeError: 'list' object is not an iterator


==========================================
==========================================

nums = [1, 2, 3]

i_nums = nums.__iter__()


print(i_nums)
print(dir(i_nums))

---------------------------------

<list_iterator object at 0x02461D18>
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', 

'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', 

'__iter__', '__le__', '__length_hint__', '__lt__', '__ne__', '__new__', '__next__', 

'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', 

'__sizeof__', '__str__', '__subclasshook__']

==========================================
==========================================

nums = [1, 2, 3]

i_nums = iter(nums)


print(i_nums)
print(dir(i_nums))

---------------------------------

<list_iterator object at 0x00E51D18>
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', 

'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', 

'__iter__', '__le__', '__length_hint__', '__lt__', '__ne__', '__new__', '__next__', 

'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', 

'__sizeof__', '__str__', '__subclasshook__']

==========================================
==========================================

nums = [1, 2, 3]

i_nums = iter(nums)


print(next(i_nums))

---------------------------------

1

==========================================
==========================================

nums = [1, 2, 3]

i_nums = iter(nums)


print(next(i_nums))
print(next(i_nums))
print(next(i_nums))

---------------------------------

1
2
3

==========================================
==========================================

nums = [1, 2, 3]

i_nums = iter(nums)


print(next(i_nums))
print(next(i_nums))
print(next(i_nums))
print(next(i_nums))

---------------------------------

1Traceback (most recent call last):
  File "C:\Users\purunet\Documents\py9\ii.py", line 10, in <module>

2
3
    print(next(i_nums))
StopIteration

==========================================
==========================================

nums = [1, 2, 3]

i_nums = iter(nums)


while True:
try:
item = next(i_nums)
print(item)
except StopIteration:
break

---------------------------------

1
2
3

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

nums = MyRange(1, 10)

for num in nums:
print(num)

---------------------------------

1
2
3
4
5
6
7
8
9

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

nums = MyRange(1, 10)

print(next(nums))

---------------------------------

1

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

nums = MyRange(1, 10)

print(next(nums))
print(next(nums))
print(next(nums))
print(next(nums))

---------------------------------

1
2
3
4

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

def my_range(start, end):
current = start
while current < end:
yield current
current += 1


nums = my_range(1, 10)

print(next(nums))
print(next(nums))
print(next(nums))
print(next(nums))

---------------------------------

1
2
3
4

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

def my_range(start, end):
current = start
while current < end:
yield current
current += 1


nums = my_range(1, 10)

for num in nums:
print(num)

---------------------------------

1
2
3
4
5
6
7
8
9

==========================================
==========================================

class MyRange:

def __init__(self, start, end):
self.value = start
self.end = end

def __iter__(self):
return self

def __next__(self):
if self.value >= self.end:
raise StopIteration
current = self.value
self.value += 1
return current

def my_range(start):
current = start
while True:
yield current
current += 1


nums = my_range(1)

for num in nums:
print(num)

---------------------------------

1에서부터 시작해서, 정지명령을 내릴 때 까지 계속 1씩 증가.

==========================================

Python - 참고

** 참고


==========================================


C:\Users\purunet\Documents\Flask_Blog>pip install flask-wtf
Collecting flask-wtf
  Downloading Flask_WTF-0.14.3-py2.py3-none-any.whl (13 kB)
Collecting WTForms
  Downloading WTForms-2.3.1-py2.py3-none-any.whl (169 kB)
     |████████████████████████████████| 169 kB 327 kB/s
Requirement already satisfied: itsdangerous in c:\users\purunet\appdata\local\pr
ograms\python\python38-32\lib\site-packages (from flask-wtf) (1.1.0)
Requirement already satisfied: Flask in c:\users\purunet\appdata\local\programs\
python\python38-32\lib\site-packages (from flask-wtf) (1.1.2)
Requirement already satisfied: MarkupSafe in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from WTForms->flask-wtf) (1.1.1)
Requirement already satisfied: Jinja2>=2.10.1 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-wtf) (2.11.2)
Requirement already satisfied: click>=5.1 in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from Flask->flask-wtf) (7.1.2)
Requirement already satisfied: Werkzeug>=0.15 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-wtf) (1.0.1)
Installing collected packages: WTForms, flask-wtf
Successfully installed WTForms-2.3.1 flask-wtf-0.14.3


==========================================

C:\Users\purunet\Documents\Flask_Blog>pip install email_validator
Collecting email_validator
  Downloading email_validator-1.1.1-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: idna>=2.0.0 in c:\users\purunet\appdata\local\pro
grams\python\python38-32\lib\site-packages (from email_validator) (2.9)
Collecting dnspython>=1.15.0
  Downloading dnspython-1.16.0-py2.py3-none-any.whl (188 kB)
     |████████████████████████████████| 188 kB 327 kB/s
Installing collected packages: dnspython, email-validator
Successfully installed dnspython-1.16.0 email-validator-1.1.1


==========================================

C:\Users\purunet\Documents\Flask_Blog>pip install flask_sqlalchemy
Collecting flask_sqlalchemy
  Downloading Flask_SQLAlchemy-2.4.1-py2.py3-none-any.whl (17 kB)
Collecting SQLAlchemy>=0.8.0
  Downloading SQLAlchemy-1.3.17-cp38-cp38-win32.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 364 kB/s
Requirement already satisfied: Flask>=0.10 in c:\users\purunet\appdata\local\pro
grams\python\python38-32\lib\site-packages (from flask_sqlalchemy) (1.1.2)
Requirement already satisfied: Werkzeug>=0.15 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask>=0.10->flask_sqlalchem
y) (1.0.1)
Requirement already satisfied: itsdangerous>=0.24 in c:\users\purunet\appdata\lo
cal\programs\python\python38-32\lib\site-packages (from Flask>=0.10->flask_sqlal
chemy) (1.1.0)
Requirement already satisfied: click>=5.1 in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from Flask>=0.10->flask_sqlalchemy) (
7.1.2)
Requirement already satisfied: Jinja2>=2.10.1 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask>=0.10->flask_sqlalchem
y) (2.11.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\purunet\appdata\loca
l\programs\python\python38-32\lib\site-packages (from Jinja2>=2.10.1->Flask>=0.1
0->flask_sqlalchemy) (1.1.1)
Installing collected packages: SQLAlchemy, flask-sqlalchemy
Successfully installed SQLAlchemy-1.3.17 flask-sqlalchemy-2.4.1


==========================================

C:\Users\purunet\Documents\Flask_Blog>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> from flaskblog import db
C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fla
sk_sqlalchemy\__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICAT
IONS adds significant overhead and will be disabled by default in the future.  S
et it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(

>>> db.create_all()
>>> from flaskblog import User, Post
>>> user_1 = User(username='LinuxerHAN', email='LinuxerHAN@gmail.com', password=
'password')
>>> db.session.add(user_1)
>>> user_2 = User(username='SeokDu', email='seokdu@demo.com', password='password
')
>>> db.session.add(user_2)
>>> db.session.commit()
>>> User.query.all()
[User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg'), User('SeokDu', 'seok
du@demo.com', 'default.jpg')]
>>> User.query.first()
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')
>>> User.query.filter_by(username='LinuxerHAN').all()
[User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')]
>>> User.query.filter_by(username='LinuxerHAN').first()
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')
>>> user = User.query.filter_by(username='LinuxerHAN').first()
>>> user
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')
>>> user.id
1
>>> user = User.query.get(1)
>>> user
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')
>>> user.posts
[]
>>> user.id
1
>>> post_1 = Post(title='Blog 1', content='First Post Content!', user_id=user.id
)
>>> post_2 = Post(title='Blog 2', content='Second Post Content!', user_id=user.i
d)
>>> db.session.add(post_1)
>>> db.session.add(post_2)
>>> db.session.commit()
>>> user.posts
[Post('Blog 1', '2020-05-24 13:22:56.712866'), Post('Blog 2', '2020-05-24 13:22:
56.713867')]
>>> for post in user.posts:
...     print(post.title)
...
Blog 1
Blog 2

>>> post = Post.query.first()
>>>
>>> post
Post('Blog 1', '2020-05-24 13:22:56.712866')
>>> post.user_id
1
>>> post.author
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')

>>> db.drop_all()
>>> db.create_all()
>>> User.query.all()
[]
>>> Post.query.all()
[]

==========================================

C:\Users\purunet\Documents\LinuxerHAN>tree/f
폴더 PATH의 목록입니다.
볼륨 일련 번호가 B273F7ED 840E:6930입니다.
C:.
│  run.py

└─flaskblog
    │  forms.py
    │  models.py
    │  routes.py
    │  site.db
    │  __init__.py
    │
    ├─snippets
    │      article.html
    │      main.html
    │      navigation.html
    │
    ├─static
    │      main.css
    │
    ├─templates
    │      about.html
    │      home.html
    │      layout.html
    │      login.html
    │      register.html
    │
    └─__pycache__
            forms.cpython-38.pyc
            models.cpython-38.pyc
            routes.cpython-38.pyc
            __init__.cpython-38.pyc

==========================================

C:\Users\purunet>pip install flask-bcrypt
Collecting flask-bcrypt
  Downloading Flask-Bcrypt-0.7.1.tar.gz (5.1 kB)
Requirement already satisfied: Flask in c:\users\purunet\appdata\local\programs\
python\python38-32\lib\site-packages (from flask-bcrypt) (1.1.2)
Collecting bcrypt
  Downloading bcrypt-3.1.7-cp38-cp38-win32.whl (26 kB)
Requirement already satisfied: Jinja2>=2.10.1 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-bcrypt) (2.11.2
)
Requirement already satisfied: click>=5.1 in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from Flask->flask-bcrypt) (7.1.2)
Requirement already satisfied: itsdangerous>=0.24 in c:\users\purunet\appdata\lo
cal\programs\python\python38-32\lib\site-packages (from Flask->flask-bcrypt) (1.
1.0)
Requirement already satisfied: Werkzeug>=0.15 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-bcrypt) (1.0.1)

Collecting cffi>=1.1
  Downloading cffi-1.14.0-cp38-cp38-win32.whl (165 kB)
     |████████████████████████████████| 165 kB 363 kB/s
Requirement already satisfied: six>=1.4.1 in c:\users\purunet\appdata\roaming\py
thon\python38\site-packages (from bcrypt->flask-bcrypt) (1.14.0)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\purunet\appdata\loca
l\programs\python\python38-32\lib\site-packages (from Jinja2>=2.10.1->Flask->fla
sk-bcrypt) (1.1.1)
Collecting pycparser
  Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
     |████████████████████████████████| 112 kB 2.2 MB/s
Building wheels for collected packages: flask-bcrypt
  Building wheel for flask-bcrypt (setup.py) ... done
  Created wheel for flask-bcrypt: filename=Flask_Bcrypt-0.7.1-py3-none-any.whl s
ize=5017 sha256=ca1e80cdcec68bef7a093c1a06048973aa8866a5cf060e97cd27e9b8cd191001

  Stored in directory: c:\users\purunet\appdata\local\pip\cache\wheels\8a\d9\0e\
dc762c4ebc76f581397a2e25991db6efd148640b5616ab9210
Successfully built flask-bcrypt
Installing collected packages: pycparser, cffi, bcrypt, flask-bcrypt
Successfully installed bcrypt-3.1.7 cffi-1.14.0 flask-bcrypt-0.7.1 pycparser-2.2
0


==========================================

C:\Users\purunet>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask_bcrypt import Bcrypt
>>> bcrypt = Bcrypt()
>>> bcrypt.generate_password_hash('testing')
b'$2b$12$mFAQ6BDudqfCpZPhMckeROvqlnaEsM5NgfwSeASq8bphdpZcCcpc.'
>>> bcrypt.generate_password_hash('testing').decode('utf-8')
'$2b$12$avJZl7.zrIANX69rakHJTO/rJ8602zoq7VXQVEb3lV8HOPFoaCCba'
>>> bcrypt.generate_password_hash('testing').decode('utf-8')
'$2b$12$pht9HoEEBCpPZdHz35wNpeGuc.27zH2lfJc.bzctjGJs2bqpoITf2'
>>> bcrypt.generate_password_hash('testing').decode('utf-8')
'$2b$12$B2euNgvatxQUY04ewJ5Jt.uk5SixLUoy28nEWnlWxNC67tTWmaVvS'

==========================================

>>> hashed_pw = bcrypt.generate_password_hash('testing').decode('utf-8')
>>> bcrypt.check_password_hash(hashed_pw, 'password')
False
>>> bcrypt.check_password_hash(hashed_pw, 'testing')
True

==========================================


C:\Users\purunet\Documents\LinuxerHAN>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flaskblog import db
C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fla
sk_sqlalchemy\__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICAT
IONS adds significant overhead and will be disabled by default in the future.  S
et it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(
>>> from flaskblog.models import User
>>> user = User.query.first()
>>> user
User('LinuxerHAN', 'LinuxerHAN@gmail.com', 'default.jpg')
>>> user.password
'$2b$12$V2KdD62Q6WJ7JBry4xTQveOjgEZjIjtlrj7KKfiwhVhh2nR5RR8CW'
>>>

==========================================


C:\Users\purunet\Documents\LinuxerHAN>pip install flask-login
Collecting flask-login
  Downloading Flask_Login-0.5.0-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: Flask in c:\users\purunet\appdata\local\programs\
python\python38-32\lib\site-packages (from flask-login) (1.1.2)
Requirement already satisfied: Werkzeug>=0.15 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-login) (1.0.1)
Requirement already satisfied: click>=5.1 in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from Flask->flask-login) (7.1.2)
Requirement already satisfied: itsdangerous>=0.24 in c:\users\purunet\appdata\lo
cal\programs\python\python38-32\lib\site-packages (from Flask->flask-login) (1.1
.0)
Requirement already satisfied: Jinja2>=2.10.1 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-login) (2.11.2)

Requirement already satisfied: MarkupSafe>=0.23 in c:\users\purunet\appdata\loca
l\programs\python\python38-32\lib\site-packages (from Jinja2>=2.10.1->Flask->fla
sk-login) (1.1.1)
Installing collected packages: flask-login
Successfully installed flask-login-0.5.0

==========================================

C:\Users\purunet\Documents\LinuxerHAN>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flaskblog.models import Post
C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fla
sk_sqlalchemy\__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICAT
IONS adds significant overhead and will be disabled by default in the future.  S
et it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(
>>> posts = Post.query.all()
>>> for post in posts:
...     print(post)
...
Post('My first Post', '2020-05-25 12:42:07.786133')
Post('A Second Post', '2020-05-25 14:07:08.138319')

>>>

==========================================

C:\Users\purunet\Documents\LinuxerHAN>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> s = Serializer('secret', 30)
>>> token = s.dumps({'user_id': 1}).decode('utf-8')
>>> token
'eyJhbGciOiJIUzUxMiIsImlhdCI6MTU5MDQ2MDI1NCwiZXhwIjoxNTkwNDYwMjg0fQ.eyJ1c2VyX2lk
IjoxfQ.jtMEIcCLnCQ42jUPm-AUXl0VR_jds6cdQotZ5Aifk67GuiZmaLnrQtWrpnM6QiqZUxLFeJNjk
9od8VYMk8XCog'
>>> s.loads(token)
{'user_id': 1}
>>> s.loads(token)
Traceback (most recent call last):
  File "", line 1, in
  File "C:\Users\purunet\AppData\Local\Programs\Python\Python38-32\lib\site-pack
ages\itsdangerous\jws.py", line 202, in loads
    raise SignatureExpired(
itsdangerous.exc.SignatureExpired: Signature expired
>>>

==========================================

C:\Users\purunet\Documents\LinuxerHAN>pip install flask-mail
Collecting flask-mail
  Downloading Flask-Mail-0.9.1.tar.gz (45 kB)
     |████████████████████████████████| 45 kB 68 kB/s
Requirement already satisfied: Flask in c:\users\purunet\appdata\local\programs\
python\python38-32\lib\site-packages (from flask-mail) (1.1.2)
Collecting blinker
  Downloading blinker-1.4.tar.gz (111 kB)
     |████████████████████████████████| 111 kB 547 kB/s
Requirement already satisfied: Jinja2>=2.10.1 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-mail) (2.11.2)
Requirement already satisfied: Werkzeug>=0.15 in c:\users\purunet\appdata\local\
programs\python\python38-32\lib\site-packages (from Flask->flask-mail) (1.0.1)
Requirement already satisfied: itsdangerous>=0.24 in c:\users\purunet\appdata\lo
cal\programs\python\python38-32\lib\site-packages (from Flask->flask-mail) (1.1.
0)
Requirement already satisfied: click>=5.1 in c:\users\purunet\appdata\local\prog
rams\python\python38-32\lib\site-packages (from Flask->flask-mail) (7.1.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\purunet\appdata\loca
l\programs\python\python38-32\lib\site-packages (from Jinja2>=2.10.1->Flask->fla
sk-mail) (1.1.1)
Building wheels for collected packages: flask-mail, blinker
  Building wheel for flask-mail (setup.py) ... done
  Created wheel for flask-mail: filename=Flask_Mail-0.9.1-py3-none-any.whl size=
7573 sha256=1c196c8f11ccb7fab4fb811cebc030397e8c4e28f068f8d8f19785b0f2bfa156
  Stored in directory: c:\users\purunet\appdata\local\pip\cache\wheels\98\bc\8c\
34c329e4d7efeaf7b9886db0c76d0b23170e54de443f688e3c
  Building wheel for blinker (setup.py) ... done
  Created wheel for blinker: filename=blinker-1.4-py3-none-any.whl size=13455 sh
a256=42f9c6ac0dcfe0462b0d67224988cbf450eeb3c70539a14b0182a2697f174104
  Stored in directory: c:\users\purunet\appdata\local\pip\cache\wheels\b7\a5\68\
fe632054a5eadd531c7a49d740c50eb6adfbeca822b4eab8d4
Successfully built flask-mail blinker
Installing collected packages: blinker, flask-mail
Successfully installed blinker-1.4 flask-mail-0.9.1

==========================================

C:\Users\purunet\Documents\LinuxerHAN>pip install django
Requirement already satisfied: django in c:\users\purunet\appdata\local\programs
\python\python38-32\lib\site-packages (3.0.6)
Requirement already satisfied: asgiref~=3.2 in c:\users\purunet\appdata\local\pr
ograms\python\python38-32\lib\site-packages (from django) (3.2.7)
Requirement already satisfied: pytz in c:\users\purunet\appdata\local\programs\p
ython\python38-32\lib\site-packages (from django) (2020.1)
Requirement already satisfied: sqlparse>=0.2.2 in c:\users\purunet\appdata\local
\programs\python\python38-32\lib\site-packages (from django) (0.3.1)

C:\Users\purunet\Documents\LinuxerHAN>python -m django --version
3.0.6

==========================================

C:\Users\purunet\Documents\LinuxerHAN>django-admin

Type 'django-admin help ' for help on a specific subcommand.

Available subcommands:

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly conf
igured (error: Requested setting INSTALLED_APPS, but settings are not configured
. You must either define the environment variable DJANGO_SETTINGS_MODULE or call
 settings.configure() before accessing settings.).


==========================================

C:\Users\purunet\Documents\LinuxerHAN>django-admin startproject django_project

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you
 apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 28, 2020 - 16:35:27
Django version 3.0.6, using settings 'django_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py startapp blog

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>tree/f
폴더 PATH의 목록입니다.
볼륨 일련 번호가 7995090C 840E:6930입니다.
C:.
│  db.sqlite3
│  manage.py

├─blog
│  │  admin.py
│  │  apps.py
│  │  models.py
│  │  tests.py
│  │  views.py
│  │  __init__.py
│  │
│  └─migrations
│          __init__.py

└─django_project
    │  asgi.py
    │  settings.py
    │  urls.py
    │  wsgi.py
    │  __init__.py
    │
    └─__pycache__
            settings.cpython-38.pyc
            urls.cpython-38.pyc
            wsgi.cpython-38.pyc
            __init__.cpython-38.pyc

==========================================

https://getbootstrap.com/docs/4.0/getting-started/introduction/#starter-template

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py makemigrat
ions
No changes detected

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py createsupe
ruser
Username (leave blank to use 'specialist'): LinuxerHAN
Email address: linuxerhan@gmail.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py makemigrat
ions
Migrations for 'blog':
  blog\migrations\0001_initial.py
    - Create model Post

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py sqlmigrate
 blog 0001
BEGIN;
--
-- Create model Post
--
CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "titl
e" varchar(100) NOT NULL, "content" text NOT NULL, "date_posted" datetime NOT NU
LL, "author_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIA
LLY DEFERRED);
CREATE INDEX "blog_post_author_id_dd7a8485" ON "blog_post" ("author_id");
COMMIT;

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
  Applying blog.0001_initial... OK


==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py shell
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post
>>> from django.contrib.auth.models import User
>>> User.objects.all()
, ]>
>>> User.objects.first()

>>> User.objects.filter(username='LinuxerHAN')
]>
>>> User.objects.filter(username='LinuxerHAN').first()

>>> user = User.objects.filter(username='LinuxerHAN').first()
>>> user

>>> user.id
1
>>> user.pk
1
>>> user = User.objects.get(id=1)
>>> user

>>> Post.objects.all()

>>> post_1 = Post(title='Blog 1', content='First Post Content!', author=user)
>>> Post.objects.all()

>>> post_1.save()
>>> Post.objects.all()
]>

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py shell
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post
>>> from django.contrib.auth.models import User
>>> Post.objects.all()
]>
>>> user = User.objects.filter(username='LinuxerHAN').first()
>>> user

>>> post_2 = Post(title='Blog 2', content='Second Post Content!', author_id=user
.id)
>>> post_2.save()
>>> Post.objects.all()
, ]>
>>> post = Post.objects.first()
>>> post.content
'First Post Content!'
>>> post.date_posted
datetime.datetime(2020, 6, 1, 10, 4, 19, 148035, tzinfo=)
>>> post.author

>>> post.author.email
'linuxerhan@gmail.com'
>>> user

>>> user.post_set
.RelatedManager object at 0x02B2D910>
>>> user.post_set.all()
, ]>
>>> user.post_set
.RelatedManager object at 0x02B2D910>
>>> user.post_set.all()
, ]>
>>> user.post_set.create(title='Blog 3', content='Third Post Content!')

>>> Post.objects.all()
, , ]>

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project> pip install django-crispy-
forms
Requirement already satisfied: django-crispy-forms in c:\users\purunet\appdata\l
ocal\programs\python\python38-32\lib\site-packages (1.9.1)

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py makemigrat
ions
No changes detected

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, blog, contenttypes, sessions, users
Running migrations:
  Applying users.0001_initial... OK

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py shell
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.auth.models import User
>>> user = User.objects.filter(username='LinuxerHAN').first()
>>> user

>>> user.profile

>>> user.profile.image

>>> user.profile.image.width
802
>>> user.profile.image.url
'profile_pics/default2.jpg'
>>> user = User.objects.filter(username='SeokDu').first()
>>> user

>>> user.profile.image


==========================================

>>> import json
>>> from blog.models import Post
>>> with open('posts.json') as f:
...     posts_json = json.load(f)
...
>>> for post in posts_json:
...     post = Post(title=post['title'], content=post['content'], author_id=post
['user_id'])
...     post.save()
...

==========================================

C:\Users\purunet\Documents\LinuxerHAN\django_project>python manage.py shell
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.paginator import Paginator
>>> posts = ['1', '2', '3', '4', '5']
>>> p = Paginator(posts, 2)
>>> p.num_pages
3
>>> for page in p.page_range:
...     print(page)
...
1
2
3
>>> p1 = p.page(1)
>>> p1

>>> p1.number
1
>>> p1.object_list
['1', '2']
>>> p1.has_previous()
False
>>> p1.has_next()
True
>>> p1.next_page_number()
2
>>> exit()


==========================================


5/27/2020

Python - Set Methods and Operations to Solve Common Problems

** Set Methods and Operations to Solve Common Problems


==========================================

s1 = set([1, 2, 3, 4, 5])

print(s1)

---------------------------------

{1, 2, 3, 4, 5}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}

print(s1)

---------------------------------

{1, 2, 3, 4, 5}

---------------------------------

==========================================

s1 = set()

print(s1)

---------------------------------

set()

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5, 1, 2, 3}

print(s1)

---------------------------------

{1, 2, 3, 4, 5}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s1.add(6)
print(s1)

---------------------------------

{1, 2, 3, 4, 5, 6}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s1.update([6, 7, 8])
print(s1)

---------------------------------

{1, 2, 3, 4, 5, 6, 7, 8}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s2 = {7, 8, 9}
s1.update([6, 7, 8], s2)
print(s1)

---------------------------------

{1, 2, 3, 4, 5, 6, 7, 8, 9}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s1.remove(5)
print(s1)

---------------------------------

{1, 2, 3, 4}

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s1.remove(6)
print(s1)

---------------------------------

    s1.remove(6)
KeyError: 6

---------------------------------

==========================================

s1 = {1, 2, 3, 4, 5}
s1.discard(6)
print(s1)

---------------------------------

{1, 2, 3, 4, 5}

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s1.intersection(s2)

print(s4)

---------------------------------

{2, 3}


---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s1.intersection(s2, s3)

print(s4)

---------------------------------

{3}

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s1.difference(s2)

print(s4)

---------------------------------

{1}

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s2.difference(s1)

print(s4)

---------------------------------

{4}

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s2.difference(s1, s3)

print(s4)

---------------------------------

set()

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s3.difference(s1, s2)

print(s4)

---------------------------------

{5}

---------------------------------

==========================================


s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s1.symmetric_difference(s2)

print(s4)

---------------------------------

{1, 4}

---------------------------------

==========================================

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}

s4 = s2.symmetric_difference(s1)

print(s4)

---------------------------------

{1, 4}

---------------------------------

==========================================

l1 = [1, 2, 3, 1, 2, 3]

l2 = list(set(l1))

print(l2)

---------------------------------

[1, 2, 3]

---------------------------------

==========================================

employees = ['Corey', 'Jim', 'Steven', 'April', 'Judy', 'Jenn', 'John', 'Jane']

gym_members = ['April', 'John', 'Corey']

developers = ['Judy', 'Corey', 'Steven', 'Jane', 'April']

result = set(gym_members).intersection(developers)

print(result)

---------------------------------

{'Corey', 'April'}

---------------------------------

==========================================

employees = ['Corey', 'Jim', 'Steven', 'April', 'Judy', 'Jenn', 'John', 'Jane']

gym_members = ['April', 'John', 'Corey']

developers = ['Judy', 'Corey', 'Steven', 'Jane', 'April']

result = set(employees).difference(gym_members, developers)

print(result)


---------------------------------

{'Jenn', 'Jim'}

---------------------------------

==========================================

employees = ['Corey', 'Jim', 'Steven', 'April', 'Judy', 'Jenn', 'John', 'Jane']

gym_members = ['April', 'John', 'Corey']

developers = ['Judy', 'Corey', 'Steven', 'Jane', 'April']

if 'Corey' in developers:
    print('Found!')

# O(n) for list
# O(1) for a set

---------------------------------

Found!

---------------------------------