搜尋此網誌

2020年5月18日 星期一

How to read the screen resolution by python3.7


If we want to know the windows' screen resolution, we can use the win32api and win32con to get the value from windows.
The example as below.

import win32api, win32con

y = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
x = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)

print(x, ",", y)
The execution result:

2560 , 1080

Process finished with exit code 0









2020年5月15日 星期五

About the difference between os.exit () and sys.exit () in python

The sys.exit() the return code can be capture by caller, but os.exit() just end the process.

In the python documentation has below explain.
  • os.exit()

  • sys.exit()

2020年5月14日 星期四

How to create a requirement file of python project

For each project, we need a file that records the project's software package in the required format.
So we can use the freeze command to output the software package version.

The pip has command freeze that will list all software package version.
pip help message

We can use the freeze to export the requirement.txt.

The file will including the software package version.


How to install the software package in the new environment?


2020年2月16日 星期日

[Python] 練習



運算符描述
[] [:]下標,切片
**指數
~ + -按位取反, 正負號
* / % //乘,除,模,整除
+ -加,減
>> <<右移,左移
&按位與
^ |按位異或,按位或
<= < > >=小於等於,小於,大於,大於等於
== !=等於,不等於
is is not身份運算符
in not in成員運算符
not or and邏輯運算符
= += -= *= /= %= //= **= &= `^= >>= <<=`

複合運算example:
a  =  10 
b  =  3 
a  +=  b  #相當於:a = a + b 
a  *=  a  +  2  #相當於:a = a * (a + 2) 


練習:
Day1
"""練習1:華氏溫度轉換為攝氏溫度。提示:華氏溫度到攝氏溫度的轉換公式為:$C=(F - 32) \div 1.8$
"""
f = float(input('輸入華氏溫度:'))
c = (f-32) / 1.8print('輸入華氏溫度 %0.1f, 攝氏溫度 %0.1f' % (f,c))

Day2
# -*- coding: UTF-8 -*-"""英制单位英寸和公制单位厘米互换

1 mm = 0.03937 in
Version: 0.1
"""
value = float(input("Please input value:"))
unit = input("Is 'in' or 'mm'? ")

if unit == "mm":
    newvlaue = value * 0.03937    print(" %f mm == %f in" % (value, newvlaue))
else:
    newvalue = value / 0.03937    print(" %f in == %f mm" % (value, newvlaue))

PyDev console: starting.
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
runfile('D:/Python_project/Day1/Test.py', wdir='D:/Python_project/Day1')
Please input value:>? 500
Is 'in' or 'mm'? >? mm
 500.000000 mm == 19.685000 in