2019年8月14日 星期三

直接在cmd中開啟 python ?


相信大家都對cmd很熟了,
但如果想從cmd直接進入python可能有些人會碰上某些麻煩,
其實在安裝python時就可以設定了,
只要你在安裝成勾選"Add python.exe to Path"就可以了。

若安裝時沒勾選
只須按照下列的步驟。

1.  找到Python 安裝的位置。

2.  找到"Python .exe"後點選右鍵>內容>並把它的位置複製下來  ↓



參考資料:http://ya06061.pixnet.net/blog/post/31913475-%E7%9B%B4%E6%8E%A5%E5%9C%A8cmd%E4%B8%AD%E9%96%8B%E5%95%9F-python-%3F

Python連接MySQL資料庫


Python連接MySQL資料庫

第一次建立的資料庫host = “localhost”和user = “root” 這兩項會是一樣的,其中的database = “maxdb”這欄是選擇要使用哪一個database,如果想選擇database再填寫即可,而password = “password”這塊要填寫當初安裝MySQL資料庫時自己所設定的密碼。
# Connect MySQL
import mysql.connector
maxdb = mysql.connector.connect(
  host = "127.0.0.1",
  user = "root",
  password = "password",
  database = "maxdb",
  )
cursor=maxdb.cursor()

Python新增MySQL資料

首先建立database可以參考#Create db的段落指令,
建立好後再來是新增裡面的table可以參考#Create table的段落指令,
是輸入欄位名稱和數據資料可以參考#Insert Multiple Records的段落指令,如果database和table有重複建立的話是無法運行的唷。
# Create db
cursor.execute("CREATE DATABASE maxdb")

# Create table
cursor.execute("CREATE TABLE users (name VARCHAR(255), age INTEGER(99), user_id INTEGER AUTO_INCREMENT PRIMARY Key)")

# Insert Multiple Records
sqlStuff = "INSERT INTO users (name, age) VALUES (%s,%s)"
records = [("Steve", 24),
           ("Max", 25),
           ("Chang" ,26),]
cursor.executemany(sqlStuff, records)
maxdb.commit()

Python讀取MySQL資料

利用Python讀取MySQL的資料,要留意的是其中Where name Like ‘M%’,M%這部分是讀取name欄位內所有M開頭的名稱,如果要指定特定名稱的話,可以寫成Where name = ‘Max’即可。
 # Read
cursor.execute("SELECT * FROM users Where name Like 'M%'")
result = cursor.fetchall()
for row in result:
    print(row)

Python更新MySQL資料

利用Python更新MySQL的資料,其中WHERE user_id = 3,這部分是使用不重複的欄位(像是id)更新,如果用欄位name來更新資料的話,名稱可能重複所以要留意可能會有多欄位被修改。
# Update
update_users = "UPDATE users SET age = 23 WHERE user_id = 3"
cursor.execute(update_users)
maxdb.commit()

Python刪除MySQL資料

利用Python清理MySQL內table的資料,DROP TABLE的功能使用上要特別留心,是沒辦法復原資料的唷!
# Delete
delete_users = "DELETE FROM users WHERE user_id = 4"
cursor.execute(delete_users)
maxdb.commit()

# Delete Drpo Table
delete_table = "DROP TABLE IF EXISTS users"
cursor.execute(delete_table)

資料來源:https://www.maxlist.xyz/2018/09/23/python_mysql/

2017年3月17日 星期五

不要讓迴圈吃完資源

            Application.DoEvents()
            System.Threading.Thread.Sleep(1)

數值顯示指定字串顯示位數,不足補0

Dim k as string="555"
Dim Q as string="ABC"

Debug.Print(K.PadLeft(6, "0"))   '顯示為000555

Debug.Print(K.PadLeft(6, "$"))   '顯示為$$$555   (注意,後面的字串只能一個位元)
Debug.Print(K.PadLeft(6, "$NT"))   '顯示為$$$555 (如果後面字串不是一個位元,則會以第一個位元為主)

Debug.Print(K.PadLeft(6, "Z"))   '顯示為ZZZABC

2017年1月11日 星期三

判斷路徑資料夾是否存在及建立資料夾

VB.NET
判別路徑資料夾是否存在:
 If Not IO.Directory.Exists("Path+資料夾名稱") Then

            '如不存在,建立資料夾
            IO.Directory.CreateDirectory("Path+資料夾名稱")
 End If


判別路徑檔案是否存在:
 System.IO.File.Exists("Path+FileName")

2015年7月15日 星期三

從文字檔讀取(Visual Basic)

程式碼:從文字檔讀取 (Visual Basic)

Visual Studio .NET 2003

這個範例使用 StreamReader 類別的 ReadToEnd 方法,將文字檔的內容讀入字串。

範例

Dim file As New System.IO.StreamReader("c:\test.txt")
Dim words As String = file.ReadToEnd()
file.Close()



資料來源  
https://msdn.microsoft.com/zh-tw/library/cc464082(v=vs.71).aspx

生小孩 黃道 吉時網

http://www.huangli.cc/

2015年6月10日 星期三

How to: Upload a File in Visual Basic

How to: Upload a File in Visual Basic

Visual Studio 2013
The UploadFile method can be used to upload a file and store it to a remote location. If the ShowUI parameter is set to True, a dialog box is displayed that shows the progress of the download and allows users to cancel the operation.

To upload a file

  • Use the UploadFile method to upload a file, specifying the source file's location and the target directory location as a string or URI (Uniform Resource Identifier).This example uploads the file Order.txt tohttp://www.cohowinery.com/uploads.aspx.
    My.Computer.Network.UploadFile(
      "C:\My Documents\Order.txt",
      "http://www.cohowinery.com/upload.aspx")
    

To upload a file and show the progress of the operation

  • Use the UploadFile method to upload a file, specifying the source file's location and the target directory location as a string or URI. This example uploads the file Order.txt tohttp://www.cohowinery.com/uploads.aspx without supplying a user name or password, shows the progress of the upload, and has a time-out interval of 500 milliseconds.
    My.Computer.Network.UploadFile(
      "C:\My Documents\Order.txt",
      "http://www.cohowinery.com/upload.aspx", "", "", True, 500)
    

To upload a file, supplying a user name and password

  • Use the UploadFile method to upload a file, specifying the source file's location and the target directory location as a string or URI, and specifying the user name and the password. This example uploads the fileOrder.txt to http://www.cohowinery.com/uploads.aspx, supplying the user name anonymous and a blank password.
    My.Computer.Network.UploadFile(
      "C:\My Documents\Order.txt",
      "http://www.cohowinery.com/upload.aspx", "anonymous", "")
    

The following conditions may throw an exception:

2015年4月28日 星期二

IPCAM 範例 佔存

http://www.camera-sdk.com/p_37-how-to-connect-to-an-onvif-camera-and-display-the-image-in-c-onvif.html

2015年4月23日 星期四

載入氣象資料

http://www.todroid.com/creating-a-weather-app-in-android-studio/
http://www.survivingwithandroid.com/2014/05/how-to-develop-android-weather-app.html
功能概述

可以抓取當地氣象
目前沒有測試
先放這  晚點再來

用YAHOO 氣象API
http://www.survivingwithandroid.com/2014/02/android-weather-app-using-yahoo-provider.html

設計自己的按鈕外觀



還沒開始測試
先把找到資料放在這裡

http://fecbob.pixnet.net/blog/post/43004092-%E3%80%90android%E3%80%91%E8%A8%AD%E8%A8%88%E8%87%AA%E5%B7%B1%E7%9A%84%E6%8C%89%E9%88%95%E5%A4%96%E8%A7%80

限制應用程式只能直立,禁止橫向

限制應用程式只能直立,禁止橫向

setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
or 


AndroidManifest.xml:

在 <activity  裡面加上

android:screenOrientation="portrait" (指定為直向)    

<!--參數為 landscape為橫向 portrait為縱向 nosensor為關閉重力感應器-->



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ack.test2" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">


        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <!--限制螢幕為直向 str-->
            android:screenOrientation="portrait"
            <!--參數為 landscape為橫向 portrait為縱向 nosensor為關閉重力感應器-->
            <!--限制螢幕為直向 end-->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>





android:configChanges="keyboard|keyboardHidden|orientation" 
(告訴系統,我要自己處理轉向問題)   需要在 Manifest.xml 中加上底下的敘述。

android 一些教學 資料

Android


http://www.raywenderlich.com/78576/android-tutorial-for-beginners-part-2

http://blog.csdn.net/ryantang03/article/details/9237643

Global Caché


http://www.automatedhome.co.uk/reviews/review-ip-control-of-your-ir-gear-with-global-cache-itach-ip2ir.html

如何在Android上繪出折線圖、條狀圖、圓餅圖

在網路上看到的
會不見

先記在這裡

晚點再來測試



2015年4月21日 星期二

安裝 Android Studio

請連結  http://developer.android.com/sdk/installing/index.html
下載
 

載完就開始安裝 
我是都下一步 下一步
 
我選預設 因為我甚麼都沒裝
 
我答應~~~

 
我答應~~~
 

還是預設
 
 
我先選2G 現在的智慧型手持式裝置 也差不多
 
 
依然預設
 

安裝瞜   1%   2% ........

 
 
啟動畫面沒抓
 
 
安裝完畢
 
現在的開發工具 越來越人性化了



第一次啟動 Android Studio 就錯誤

一啟動就錯誤
 (我發現原來是我的網路有問題 無法連線)

發現 SDK 沒裝

所以 找了一下

其實 他們有統包案裝檔
進入 http://developer.android.com/sdk/installing/index.html








全部的安裝檔

網路復原 自動下載 SDK

安裝完畢


終於看到 畫面了

2015年4月17日 星期五

異機備援 修改

1.先進入  ect/dev 找到新硬碟資料夾
2.修改

  進入 ect/
  編輯 fstab 檔案
   更改 硬碟序號
ata-STXXXXX-

修改方式 vi fstab

fstab 存放路徑   ect/ 下面


vi 指令

i 修改
esc 離開修改模式

w 存檔
q 離開
q! 不存檔 離開

===============
確認系統開機錯誤  指令如下 確認錯誤點
journalctl -b



linux 電源管理 語法

电源管理

安装 polkit 后才可以一般用户身份使用电源管理。
如果你正登录在一个本地的systemd-logind用户会话,且当前没有其它活动的会话,那么以下命令无需root权限即可执行。否则(例如,当前有另一个用户登录在某个tty),systemd 将会自动请求输入root密码。
重启:
$ systemctl reboot
退出系统并停止电源:
$ systemctl poweroff
待机:
$ systemctl suspend
休眠:
$ systemctl hibernate
混合休眠模式(同时休眠到硬盘并待机):
$ systemctl hybrid-sleep