跳至主要内容

bat 详解

:: 创建一个字符串
:: This program just displays Hello World 
@echo off
set message=Hello World 
echo %message%
:: 输出Hello World



:: 创建一个空字符串
:: 通过在初始化期间不为其分配任何值来创建一个空字符串
:: 要检查是否存在空字符串,您需要将变量名称括在方括号中,并将其与方括号中的值进行比较
@echo off
SET a=
SET b=Hello 
if "%a%"=="" (echo "String A is empty") 
if "%b%"=="" (echo "String B is empty ")
:: 输出 String A is empty



:: 字符串插值是通过将常量,变量,文字和表达式的值包含在字符串文字中来构造新的String值的方法
@echo off 
SET a=He llo 
SET b=World
SET /A d=50 
SET c=%a% and %b% %d%
echo %c%
:: 输出 He llo  and World 50



:: 
@echo off
set str=Hello World
call :strLen str strlen
echo String is %strlen% characters long
exit /b

:strLen
setlocal enabledelayedexpansion

:strLen_Loop
   if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop
(endlocal & set %2=%len%)
goto :eof
:: 输出 String is 11 characters long



:: 提取左边字符串
:: 关键是0,5用于指定需要显示的字符。在这种情况下,我们说应该显示字符0到5
@echo off 
set str=Helloworld
echo %str%

set str=%str:~0,5%
echo %str%
:: 输出 Helloworld
::      Hello



:: 提取中间字符串
:: 关键是5,10用于指定需要显示的字符。在这种情况下,我们希望显示字符5到10
@echo off 
set str=Helloworld 
echo %str%

set str=%str:~5,10% 
echo %str%
:: 输出 Helloworld
::      world



:: 从字符串末尾提取字符,:~-8取后7位
@echo off
set str=This message needs changed. 
echo %str% 

set str=%str:~-8% 
echo %str%
:: 输出 This message needs changed.
::      hanged.



:: 删除子字符串
:: 使用:'stringtoberemoved'=命令从字符串中删除了“ is”一词
@echo off 
set str=Batch scripts is easy. It is really easy. 
echo %str% 

set str=%str:is=% 
echo %str%
:: 输出 Batch scripts is easy. It is really easy.
::      Batch scripts  easy. It  really easy.



:: 删除两端
:: 需要注意的关键是1,-1用于删除字符串的第一个和最后一个字符
@echo off 
set str=Batch scripts is easy. It is really easy 
echo %str% 

set str=%str:~1,-1% 
echo %str%
:: 输出 Batch scripts is easy. It is really easy
::      atch scripts is easy. It is really easy



:: 删除字符串中的所有空格
:: 关键是: =运算符用于删除字符串中的所有空格。
@echo off 
set str=This string    has    a  lot  of spaces 
echo %str% 

set str=%str: =% 
echo %str%
:: 输出 This string    has    a  lot  of spaces
::      Thisstringhasalotofspaces



:: 替换字符串
@echo off 
set str=This message needs changed. 
echo %str% 

set str=%str:needs=has% 
echo %str%
:: 输出 This message needs changed.
::      This message has changed.



:: 创建数组并访问
@echo off 
set a[0]=1 
echo %a[0]%



@echo off 
set list=1 2 3 4 
for %%a in (%list%) do (echo %%a)
pause
:: 输出
:: 1
:: 2
:: 3
:: 4



@echo off
set a[0]=1 
set a[1]=2 
set a[2]=3 
echo The first element of the array is %a[0]% 
echo The second element of the array is %a[1]% 
echo The third element of the array is %a[2]%
:: 输出
:: The first element of the array is 1
:: The second element of the array is 2
:: The third element of the array is 3



:: 修改数组
@echo off 
set a[0]=1  
set a[1]=2  
set a[2]=3 
Rem Adding an element at the end of an array 
set a[3]=4 
echo The last element of the array is %a[3]%
:: 输出
:: The last element of the array is 4



@echo off 
set a[0]=1 
set a[1]=2  
set a[2]=3 
Rem Setting the new value for the second element of the array 
set a[1]=5 
echo The new value of the second element of the array is %a[1]%
:: 输出
:: The new value of the second element of the array is 5 



:: 变量延迟的启动语句是“setlocal enabledelayedexpansion”,
:: 并且变量要用一对叹号“!!”括起来(注意要用英文的叹号)
:: set:设置 local:本地(环境变量)enable:能够 delayed:延迟 expansion:扩展
:: setlocal enabledelayedexpansion就是扩展本地环境变量延迟
@echo off 
setlocal enabledelayedexpansion 
set topic[0]=comments 
set topic[1]=variables 
set topic[2]=Arrays 
set topic[3]=Decision making 
set topic[4]=Time and date 
set topic[5]=Operators 

for /l %%n in (0,1,5) do ( 
   echo !topic[%%n]! 
)

:: 输出
:: comments  
:: variables  
:: Arrays  
:: Decision making  
:: Time and date  
:: Operators  



:: 数组的长度是通过迭代数组中的值列表来完成的,因为没有直接函数来确定数组中元素的数量
@echo off 
set Arr[0]=1 
set Arr[1]=2 
set Arr[2]=3 
set Arr[3]=4 
set "x=0" 
:SymLoop 

if defined Arr[%x%] ( 
   call echo %%Arr[%x%]%% 
   set /a "x+=1"
   GOTO :SymLoop 
)
echo "The length of the array is" %x%
:: 输出
:: 1  
:: 2  
:: 3  
:: 4  
:: "The length of the array is" 4


:: (0 1 3) 即(start step end)0 1 2 3
@echo off 
set obj[0].Name=Joe 
set obj[0].ID=1 
set obj[1].Name=Mark 
set obj[1].ID=2 
set obj[2].Name=Mohan 
set obj[2].ID=3 
FOR /L %%i IN (0 1 2) DO  (
   call echo Name = %%obj[%%i].Name%%
   call echo Value = %%obj[%%i].ID%%
)
:: 输出
:: Name = Joe 
:: Value = 1 
:: Name = Mark 
:: Value = 2 
:: Name = Mohan 
:: Value = 3 



:: if(condition) do_something
:: 'if'语句中的值是区分大小写的
:: 如果set的是字符串,则=前后不能有空格
@echo off 
SET /A a = 5 
SET /A b = 10 
SET /A c = %a% + %b% 
if %c%==15 echo "The value of variable c is 15" 
if %c%==10 echo "The value of variable c is 10"
:: 输出 "The value of variable c is 15" 



@echo off 
SET str1=String1 
SET str2=String2 

if %str1%==String1 echo "The value of variable String1" 
if %str2%==String3 echo "The value of variable c is String3"
:: 输出 "The value of variable String1" 



:: If (condition) (do_something) ELSE (do_something_else)
@echo off 
SET /A a = 5 
SET /A b = 10
SET /A c = %a% + %b% 

if %c%==15 (echo "The value of variable c is 15") else (echo "Unknown value") 
if %c%==10 (echo "The value of variable c is 10") else (echo "Unknown value")
:: 输出
:: "The value of variable c is 15"
:: "Unknown value"



@echo off 
SET str1=String1 
SET str2=String2 

if %str1%==String1 (echo "The value of variable String1") else (echo "Unknown value") 
if %str2%==String3 (echo "The value of variable c is String3") else (echo "Unknown value")
:: 输出
:: "The value of variable String1"
:: "Unknown value"



:: 检查命令行参数
@echo off 
echo %1 
echo %2 
echo %3 
if %1%==1 (echo "The value is 1") else (echo "Unknown value") 
if %2%==2 (echo "The value is 2") else (echo "Unknown value") 
if %3%==3 (echo "The value is 3") else (echo "Unknown value")
:: 以上代码保存在一个名为test.bat的文件中,并执行test.bat 1 2 4
:: 输出
:: 1 
:: 2 
:: 4 
:: "The value is 1" 
:: "The value is 2" 
:: "Unknown value"



:: “if”语句的一种特殊情况是“if defined”,用于测试变量的存在
:: if defined somevariable somecommand
@echo off 
SET str1 = String1 
SET str2 = String2 

if defined str1 echo "Variable str1 is defined"
if defined str3 (echo "Variable str3 is defined") else (echo "Variable str3 is not defined")
:: 输出
:: "Variable str1 is defined"
:: "Variable str3 is not defined"



:: “if”语句的另一种特殊情况是“if exist”,用于测试文件是否存在
:: If exist somefile.ext do_something
:: 假定C驱动器中有一个名为set2.txt的文件,并且没有名为set3.txt的文件
@echo off 
if exist C:\set2.txt echo "File exists" 
if exist C:\set3.txt (echo "File exists") else (echo "File does not exist")
:: 输出
:: "File exists" 
:: "File does not exist"



:: 嵌套If语句
:: if(condition1) if (condition2) do_something
@echo off
SET /A a = 5
SET /A b = 10
if %a%==5 if %b%==10 echo "The value of the variables are correct"
:: 输出
:: "The value of the variables are correct"



:: 批处理文件的执行是逐行进行的,而每一行上的命令也是依次运行的。
:: 但是,通常希望在跳过其他部分的同时执行批处理文件的特定部分。跳到特定部分的功能由“goto”命令一个单词提供。
:: 目标部分的开头以一行标记,该行的名称前带有冒号。因此脚本执行将跳过“某些命令”,而从“标签”开始。
:: 标签可以是脚本中任何位置的行,包括“goto”命令之前的行。“goto”命令通常出现在“if”语句中。
:: if (condition) goto :label
:: exit /b 0 批处理文件末尾的EXIT /B将停止执行批处理文件 在批处理文件的末尾使用EXIT /B <exitcodes>返回自定义返回码
@echo off 
SET /A a = 5

if %a%==5 goto :labela 
if %a%==10 goto :labelb

:labela 
echo "The value of a is 5" 

exit /b 0

:labelb 
echo "The value of a is 10"
:: 输出
:: "The value of a is 5" 



:: 算术运算符
@echo off
SET /A a = 5
SET /A b = 10
SET /A c = %a%+%b%
echo %c%
SET /A c = %a%-%b%
echo %c%
SET /A c = %b%*%a%
echo %c%
SET /A c = %b%/%a%
echo %c%
SET /A c =%b% %% %a%
echo %c%
:: 输出
:: 15
:: -5
:: 50
:: 2
:: 0



:: 关系运算符
:: EQU== NEQ!= LSS<
:: LEQ<= GTR> GEQ>=
@echo off 
SET /A a = 5 
SET /A b = 10 
if %a% EQU %b% echo A is equal to than B 
if %a% NEQ %b% echo A is not equal to than B 
if %a% LSS %b% echo A is less than B 
if %a% LEQ %b% echo A is less than or equal B
if %a% GTR %b% echo A is greater than B 
if %a% GEQ %b% echo A is greater than or equal to B
:: 输出
:: A is not equal to than B 
:: A is less than B 
:: A is less than or equal B



:: 逻辑运算符
:: AND,OR,XOR,NOT
@echo off
SET /A a = 5
SET /A b = 10
IF %a% LSS 10 (IF %b% GTR 0 (ECHO %a% is less than 10 AND %b% is greater than 0))
:: 输出
:: 5 is less than 10 AND 10 is greater than 0



@echo off
SET /A a = 5
SET /A b = 10

IF %a% GEQ 10 (
   IF %b% LEQ 0 (
      ECHO %a% is NOT less than 10 OR %b% is NOT greater than 0
   ) ELSE (
      ECHO %a% is less than 10 OR %b% is greater than 0
   )
) ELSE (
   ECHO %a% is less than 10 OR %b% is greater than 0
)
:: 输出
:: 5 is less than 10 OR 10 is greater than 0



@echo off
SET /A a = 5
IF NOT %a%==6 echo "A is not equal to 6"
:: 输出
:: "A is not equal to 6"



:: 赋值运算符
@echo off
SET /A a = 5
SET /A a+=5
echo %a%
SET /A a-=5
echo %a%
SET /A a*=5
echo %a%
SET /A a/=5
echo %a%
SET /A a%=5
echo %a%
:: 输出
:: 10
:: 5
:: 25
::5
:: 5



:: 按位运算符
@echo off
SET /A "Result = 48 & 23"
echo %Result%
SET /A "Result = 16 | 16"
echo %Result%
SET /A "Result = 31 ^ 15"
echo %Result%
:: 输出
:: 16
:: 16
:: 16



:: 重定向是一种获取命令输出并将该输出重定向到其他输出媒体的概念
:: command > filename − Redirect command output to a file. 覆盖
:: command >> filename − APPEND into a file. 追加
:: command < filename − Type a text file and pass the text to command.
:: command 2> file − Write standard error of command to file (OS/2 and NT).
:: command 2>> file − Append standard error of command to file (OS/2 and NT).
:: commandA | commandB − Redirect standard output of commandA to standard input of command.

:: 此命令将命令输出重定向到文件
@echo off 
ipconfig>C:\details.txt

:: 此命令将命令的输出附加到文件中
@echo off
systeminfo>>C:\details.txt

:: 该命令键入一个文本文件,并将文本传递给命令
@echo off
SORT < C:\Example.txt

:: 该命令将命令的标准 错误写入文件
DIR C:\ >List_of_C.txt 2>errorlog.txt
:: 将命令的标准 错误附加到文件
DIR D:\ >List_of_C.txt 2>>errorlog.txt

:: 将选项“y”(即“是”的值)传递给del命令。这将导致删除所有扩展名为txt的文件
Echo y | del *.txt






: 批处理文件中的一种常见做法是将程序的输出发送到日志文件
: >运算符将stdout或stderr发送或重定向到另一个文件

: 0 “标准输入”文件称为stdin,包含程序/脚本的输入
: 1 “标准输出”文件称为stdout,用于写入输出以在屏幕上显示
: 2 “ Standard Err”文件(称为stderr)包含任何错误消息,可在屏幕上显示

test.bat > testlog.txt 2> testerrors.txt

: 命令Dir C:\的stdin重定向到文件list.txt
Dir C:\ > list.txt

: 将数字2附加到重定向过滤器,则它将stderr重定向到文件list.txt
Dir C:\ 2> list.txt

: 使用文件号和'&'前缀组合stdout和stderr流
DIR C:\ > lists.txt 2>&1

: 伪文件NUL用于丢弃程序的任何输出。下面的示例显示通过将输出发送到NUL来丢弃命令DIR的输出
Dir C:\ > NUL


: 命令提示符将接受用户输入的所有输入,直到获得EOF字符为止。稍后,它将所有输入发送到文件lists.txt
TYPE CON > lists.txt



: 批处理脚本中没有直接的while语句,但是我们可以使用if语句和标签很容易地实现此循环
: while实现的整个代码都放在标签内。
: 必须在while循环实现开始之前设置或初始化计数器变量。
: while条件的表达式是使用'if'语句完成的。如果表达式的计算结果为true,则执行'if'循环内的相关代码。
: 需要在'if'语句中适当增加一个计数器,以便while实现可以在某个时间点终止。
: 最后,我们将返回标签,以便我们可以再次评估“ if”语句。
@echo off
SET /A "index = 1"
SET /A "count = 5"
:while
if %index% leq %count% (
   echo The value of index is %index%
   SET /A "index = index + 1"
   goto :while
)
: 输出
: The value of index is 1
: The value of index is 2
: The value of index is 3
: The value of index is 4
: The value of index is 5



: “FOR”构造为批处理文件提供循环功能。以下是用于处理值列表的“ for”语句的常见构造。
: FOR %%variable IN list DO do_something
: 变量声明以变量名开头的%%符号完成。
: 为其执行“ for”语句的值的列表在IN子句之后定义。
: do_something代码块是针对值列表的每次迭代都需要执行的代码
@echo off 
FOR %%F IN (1 2 3 4 5) DO echo %%F
: 输出
: 1
: 2
: 3
: 4
: 5



: “for”语句还具有在一系列值之间移动的能力

: FOR /L %%variable IN (lowerlimit,Increment,Upperlimit) DO do_something
: /L开关用于表示该循环用于遍历范围。
: 变量声明–此步骤对于整个循环仅执行一次,并用于声明将在循环中使用的任何变量。在批处理脚本中,变量声明以变量名开头的%%完成。
: IN列表包含3个值。下限,增量和上限。因此,循环将从下限开始,然后移至上限值,每次以“增量”值进行迭代。
: do_something代码块是每次迭代都需要执行的代码。
@ECHO OFF 
FOR /L %%X IN (0,1,5) DO ECHO %%X
: 输出
: 0
: 1
: 2
: 3
: 4
: 5



: 经典的“ for”语句
@echo off 
SET /A i = 1 
:loop 

IF %i%==5 GOTO END 
echo The value of i is %i% 
SET /a i=%i%+1 
GOTO :LOOP 
:END
: 输出
: The value of index is 1
: The value of index is 2
: The value of index is 3
: The value of index is 4




: 'for'语句还可用于检查命令行参数
@ECHO OFF 
:Loop 

IF "%1"=="" GOTO completed 
FOR %%F IN (%1) DO echo %%F 
SHIFT 
GOTO Loop 
:completed

: 假设上面的代码存储在一个名为Test.bat的文件中。
: 如果批处理文件将命令行参数1,2和3作为Test.bat 1 2 3传递,则上述命令将产生以下输出
: 输出
: 1
: 2
: 3



: 断言执行
@echo off 
SET /A "index=1" 
SET /A "count=5" 
:while 
if %index% leq %count% ( 
   if %index%==2 goto :Increment 
      echo The value of index is %index% 
:Increment 
   SET /A "index=index + 1" 
   goto :while 
)
: 输出
: The value of index is 1 
: The value of index is 3 
: The value of index is 4 
: The value of index is 5 



: call命令在批处理脚本中调用一个函数
: call :function_name
: 定义主程序时要注意的一件事是确保将EXIT /B %ERRORLEVEL%语句放入主程序中,以将主程序的代码与函数分开
@echo off 
SETLOCAL 
CALL :Display 
EXIT /B %ERRORLEVEL% 
:Display 
SET /A index=2 
echo The value of index is %index% 
EXIT /B 0
: 输出
: The value of index is 2 




: Call :function_name parameter1, parameter2… parametern
: 使用代字号(~)字符以及参数的位置号从函数中访问参数
@echo off
SETLOCAL
CALL :Display 5 , 10
EXIT /B %ERRORLEVEL%
:Display
echo The value of parameter 1 is %~1
echo The value of parameter 2 is %~2
EXIT /B 0
: 输出
: The value of parameter 1 is 5
: The value of parameter 2 is 10



: 示例演示如何使用返回值调用函数
: 返回值在函数中使用set命令和波浪号(~)字符以及参数的位置编号进行设置
@echo off
SETLOCAL
CALL :SetValue value1,value2
echo %value1%
echo %value2%
EXIT /B %ERRORLEVEL%
:SetValue
set "%~1=5"
set "%~2=10"
EXIT /B 0
: 输出
: 5
: 10


: 没有称为%10的参数。通过使用SHIFT运算符可以避免此限制。
: 批处理文件处理完第一个参数后,可以将它们移动(只需插入一行,仅使用SHIFT命令即可),导致%1获得值B,%2获得值C等
@ECHO OFF
:Loop

IF "%1"=="" GOTO Continue
   echo %1%
SHIFT
GOTO Loop
:Continue
: 如果以上代码存储在名为test.bat的文件中,并且该文件运行为
: test.bat a b c d e f g h i j
: 输出
: a
: b
: c
: d
: e
: f
: g
: h
: i
: j



: 文件输入
: 运行批处理文件时,它为您提供了传递命令行参数的选项,然后可以在程序中读取命令行参数以进行进一步处理。可以使用%运算符以及参数的数字位置从程序中调用批处理文件参数。以下是定义命令行参数的方式。
: %0是被调用的程序名称。%1是第一个命令行参数。%2是第二个命令行参数。直到%9
@echo off
echo The first parameter is %1
echo The second parameter is %2
echo The third parameter is %3
: 如果以上代码存储在名为test.bat的文件中,并且该文件运行为test.bat 5 10 15
: 输出
: The first parameter is 5
: The second parameter is 10
: The third parameter is 15



: 管道运算符(|)获取一个命令的输出(默认情况下为STDOUT),并将其定向到另一命令的输入(默认情况下为STDIN)
dir C:\ | sort
: 在此示例中,两个命令同时启动,但是sort命令暂停,直到收到dir命令的输出。sort命令使用dir命令的输出作为输入,然后将其输出发送到句柄1(即STDOUT)
: 以下是pipe命令的另一个示例。在此示例中,文件C:\new.txt的内容通过管道过滤器发送到sort命令
@echo off 
TYPE C:\new.txt | sort


: 通常,在处理管道命令时,管道操作符与重定向操作符一起使用可提供有用的功能。
: 例如,以下命令将首先获取C:\中定义的所有文件,然后使用pipe命令查找扩展名为.txt的所有文件。然后它将获取此输出并将其打印到文件AllText.txt。
dir C:\ | find "txt" > AllText.txt

: 要在同一命令中使用多个过滤器,请用管道(|)分隔过滤器。例如,以下命令搜索驱动器C:上的每个目录,查找包含字符串“Log”的文件名,然后一次在一个“命令提示符”窗口中显示它们-
dir c:\ /s /b | find "Log" | more

: 以下示例使用tasklist命令发送所有正在运行的任务的列表,并将输出发送到find命令。然后,find命令将查找记事本类型的所有进程,并将其显示在命令提示符下
tasklist | find "notepad"

: 以下示例使用tasklist命令发送所有正在运行的任务的列表,并将输出发送到more命令。然后,more命令将一次一页显示正在运行的任务列表。
tasklist | more

: 以下示例使用tasklist命令发送所有正在运行的任务的列表,并将输出发送到find命令。find命令将查找所有记事本类型的进程,然后使用重定向命令将内容发送到tasklist.txt文件。
tasklist | find "notepad" > tasklist.txt


评论

此博客中的热门博文

Chrome浏览器

谷歌搜索 双引号——精确搜索 冒号后加文件类型——搜索特定类型的结果 关键词 后 site:**——搜索特定网站的关键词 +、-关键词——实现特定需求筛选 Google中/——快捷键入浏览·搜索框 关键词后..——搜索特定范围(地点)关键词 intitle:关键词——搜索特定标题 用 puppeteer 直接运行 chrome 爬 https://github.com/puppeteer/puppeteer Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议 控制 Chrome 或 Chromium 。Puppeteer默认 无头 运行,但可以配置为运行完整(非无头)Chrome 或 Chromium。 了解如何为 Chrome 开发扩展程序 https://developer.chrome.com/docs/extensions/mv3/ 什么是Chrome插件 https://github.com/sxei/chrome-plugin-demo Google Workspace 状态信息中心 https://www.google.com/appsstatus#hl=zh&v=status 此页面提供属于“Google Workspace”的服务的状态信息 谷歌浏览器离线下载 https://support.google.com/chrome/answer/95346?co=GENIE.Platform%3DDesktop&hl=zh-Hans 企业版 https://cloud.google.com/chrome-enterprise/browser/download 也可以在谷歌浏览器 帮助中心 中搜索chrome https://www.google.com/intl/zh-CN/chrome/?standalone=1 chrome 打开新网页时不要覆盖 鼠标 中键(滚轮)点击超链接 ,或者右击超链接,选择新标签页打开, 还有点链接的同时按下 Ctrl 键也可以 谷歌在线翻译网页 http://translate.google.com/translate?u= http://www.dropitproject.com/index.php 打开chrome浏览器按 F6 ,等同于按 ...

数据库

http://sqlfiddle.com/#!4/42960/1 用于轻松在线测试和共享数据库问题及其解决方案的工具 https://livesql.oracle.com/apex/f?p=590:1000 学习和分享 SQL https://sqlzoo.net/ SQL 教程  数据库 数据库系统 最 流行的选择 包括: MySQL  (SQL) PostgreSQL  (SQL) Microsoft SQL Server  (SQL) SQLite  (SQL) MongoDB  (NoSQL) Redis  (NoSQL) MySQL 是一种开源 SQL 关系数据库,将数据组织到一个或多个表中,其中的数据类型可能相互关联。 它是垂直可扩展的,这意味着一台终极机器将为您完成工作。 它是目前四种数据库系统中应用最广泛的。 PostgreSQL (有时也称为 Postgres)也是一个开源 SQL 关系数据库,强调可扩展性和标准合规性。 它现在也可以处理 JSON,但它通常更适合结构化数据、垂直扩展以及符合 ACID 的需求,例如电子商务和金融交易。 Microsoft SQL Server 包括 Windows 上的 SQL Server、Linux 上的 SQL Server 和 Azure 上的 SQL。 这些也是建立在服务器上的关系数据库管理系统,其主要功能是根据软件应用程序的要求存储和检索数据。 SQLite 是一个开源的自包含、基于文件的“无服务器”数据库,以其可移植性、可靠性和即使在低内存环境中的良好性能而闻名。 MongoDB 是一个开源 NoSQL 文档数据库,旨在处理 JSON 并存储无模式数据。 它是水平可扩展的,这意味着多台较小的机器将为您完成工作。 它有利于灵活性和非结构化数据,以及缓存实时分析。 Redis 是一个开源的 NoSQL 内存数据结构存储。 它使用键值对来存储而不是文档。 Redis 以其灵活性、性能和广泛的语言支持而闻名。 它足够灵活,可以用作缓存或消息代理,并且可以使用列表、集合和散列等数据结构。 您选择的数据库类型应取决于您将使用该数据库的应用程序类型。 我们建议您查看结构化和非结构化数据库的优缺点,并根据您的用例进行选择。 Mongo...

tkinter 入门

查看tkinter版本 方法一: cmd直接输入 python -m tkinter 方法二: cmd输入python >>> import tkinter >>> tkinter._test() >>> tkinter.Tcl().eval('info patchlevel') 参考资料 https://www.geeksforgeeks.org/python-gui-tkinter/ https://likegeeks.com/python-gui-examples-tkinter-tutorial/ http://www.openbookproject.net/courses/python4fun/tkphone1.html tkinter框架 #导入(调用)tkinter模块 from tkinter import * #创建Tk()的对象,它实际上用于创建窗口 my_window = Tk() #调用mainloop()函数,用于窗口的无限循环。当我们点击关闭按钮或退出应用程序时,mainloop()函数终止 my_window.mainloop() print( id(my_window), type(my_window),dir(my_window) ) 输出 53949680 <class 'tkinter.Tk'> ['_Misc__winfo_getint', '_Misc__winfo_parseitem', '__class__',...] #遍历 for key in root.keys():     print(key,":",root[key]) 设置窗口标题 my_window.title("Demo") 更改左上角图标 my_window.iconbitmap(r'C:\src\dragon-face.ico') from pathlib import Path my_window.iconbitmap(Path('img/dr...