Getting Started with Python

Python
https://www.runoob.com/python/python-tutorial.html
# Python2
https://www.runoob.com/manual/pythontutorial/docs/html/
# Python3
https://www.runoob.com/python3/python3-tutorial.html

install Python, Numpy, Scipy, and Matplotlib  https://blog.youkuaiyun.com/sh20100621/article/details/91350577

matplotlib https://blog.youkuaiyun.com/sh20100621/article/details/91351434

numpy & scipy https://blog.youkuaiyun.com/sh20100621/article/details/80848509

Download and installation:
Refer to 最实用windows 下python+numpy安装_包包蔡的博客-优快云博客
Python27 : Windows x86 MSI installer for Windows XP
Python36 : Windows x86-64 executable installer for Windows 10
1. download Python27 from https://www.python.org/downloads/
python-2.7.15.msi
* Install and Add Python.exe to Path
2. download numpy for Python27 from https://pypi.python.org/pypi/numpy
numpy-1.14.5-cp27-none-win32.whl

download scipy for Python 27 from https://pypi.org/project/scipy/
* install numpy and scipy
3. run cmd
d:\>notepad install.bat
edit
: install python27

python -m pip install --upgrade pip
pip install numpy-1.14.5-cp27-none-win32.whl

pip install scipy-1.1.0-cp27-none-win32.whl

python -m pip install matplotlib

:: python -m pip install -U pip setuptools
:: pip install numpy scipy matplotlib
:: install python35
:: python-3.5.3.exe
:: python-3.5.3-amd64.exe
:: numpy-1.14.5-cp35-none-win32.whl
:: numpy-1.14.5-cp35-none-win_amd64.whl
:: scipy-1.1.0-cp35-none-win32.whl
:: scipy-1.1.0-cp35-none-win_amd64.whl
::
:: python36
:: python-3.6.5.exe
:: python-3.6.5-amd64.exe
:: numpy-1.14.5-cp36-none-win32.whl
:: numpy-1.14.5-cp36-none-win_amd64.whl
:: scipy-1.1.0-cp36-none-win32.whl
:: scipy-1.1.0-cp36-none-win_amd64.whl
save
d:\>install
d:\>Python
>>>import numpy as np
>>>np.random.rand(4,4)

>>>import scipy

>>>import matplotlib
>>>exit()

Tutorial:
* http://www.runoob.com/python/python-tutorial.html

# solve systerm of nonlinear equations by using root, fsolve

# sample.py

# Refer to https://blog.youkuaiyun.com/your_answer/article/details/79170728
from scipy.optimize import root, fsolve, leastsq
import numpy as np
from matplotlib import pyplot as plt

def f1(x):
      return np.array([2*x[0]**2+3*x[1]-3*x[2]**3-7,
                    x[0]+4*x[1]**2+8*x[2]-10,
                    x[0]-2*x[1]**3-2*x[2]**2+1])
#
sol_root = root(f1,[0,0,0])
sol_fsolve = fsolve(f1,[0,0,0])
print(sol_root)
print(sol_fsolve)
#
def f2(x):
      return 2*np.sin(x)-x+2
#
x=np.linspace(-5,5,num=100)
y=f2(x)
root1=fsolve(f2,[1])
root2=root(f2,[1])
print(root1)
print(root2)
plt.plot(x,y,'r')
plt.show()

# end of sample.py

# https://blog.youkuaiyun.com/unixtch/article/details/78545382
# https://blog.youkuaiyun.com/u011702002/article/details/78078010
from scipy.optimize import fsolve, leastsq
from math import sin,cos
def f(x):
    x0 = float(x[0])
    x1 = float(x[1])
    x2 = float(x[2])
    return [
        5*x1+3,
        4*x0*x0 - 2*sin(x1*x2),
        x1*x2-1.5
        ]
x0 = [1,1,1]
result = fsolve(f,x0)
print("===================")
print()
print("求解函数名称:",fsolve.__name__)
print("解:",result)
print("各向量值:",f(result))
#拟合函数来求解
h = leastsq(f,x0)
print("===================")
print()
print("求解函数名称:",leastsq.__name__)
print("解:",h[0])
print("各向量的值:",f(h[0]))


常见错误:

o IndentationError:expected an indented block
* https://blog.youkuaiyun.com/gaokao2011/article/details/76209020

# sample.py
str = "Hello World!"
print (str)
import math
x = math.pi

print(x)
arg1 = 1
arg2 = 2
def sum(arg1,arg2):
 total = arg1 + arg2
 return total
y = sum(arg1,arg2)
print(y)
def sub(arg1,arg2):
 total = arg1 - arg2
 return total
z = sub(arg1,arg2)
print(z)
# end of sample.py
# How to use function of different Python file
# https://www.cnblogs.com/jiuyigirl/p/7146223.html
# a.py
def sum(arg1, arg2):
    total = arg1 + arg2
    return total
# end of a.py
# b.py
import a
x = a.sum(1,2)
print '1 + 2 =', x

# end of b.py

# ch70.py
sigma_x = -70
sigma_y = 0
tau_x = 50
import ch7
z = ch7.result(sigma_x, sigma_y, tau_x)
print z
print 'sigma1 = ', z[0]
print 'sigma2 = ', 0
print 'sigma3 = ', z[1]
print 'alpha0 = ', z[2]
print 'tau_max = ', z[3]
# end of ch70.py
# ch7.py
import math
def result(sigma_x, sigma_y, tau_x):
    OC = 0.5 * (sigma_x + sigma_y)
    CH = 0.5 * (sigma_x - sigma_y)
    radius = (CH**2 + tau_x**2)**0.5     
    alpha0 = 0.5 * math.atan(-tau_x/CH)
    z = [OC + radius, OC - radius, alpha0 * 180/math.pi, radius]
    return z

# end of ch7.py

# ch3.py
import math
def Wp(diameter, alpha):
    return math.pi * ( diameter ** 3.0 ) * (1.0 - alpha ** 4) / 16
def Diameter(Tmax, tau0):
    fenzi = 16.0 * Tmax
    fenmu = math.pi * tau0
    return [fenzi, fenmu, (fenzi/fenmu) ** (1.0 / 3.0)]
# end of ch3.py
# ch30.py
d0 = 24.0e-3
d1 = 18.0e-3
alpha = d1/d0
T_max = 1.5e2
import ch3
Tau_max = T_max / ch3.Wp(d0, alpha)
print Tau_max,'Pa'
print Tau_max/1e6,'MPa'
T_max = 1.5e3
tau0 = 50.0e6
diameter_min = ch3.Diameter(T_max, tau0)
print diameter_min[2], 'm'
print diameter_min[2] * 1.0e3, 'mm'
# end of ch30.py
   
 

<think>好的,我现在要帮用户理解为什么其他语言如Python、Java、Go可以使用PadLocal,即使PadLocal本身没有提供这些语言的SDK。用户提到他们需要自建Wechaty Service,并通过gRPC桥接功能给其他语言使用。同时,用户还提供了参考链接,可能需要验证这个链接是否存在或者是否需要补充信息。 首先,我需要回顾之前的对话,确保这次回答和之前的一致。之前解释过Wechaty的多语言架构,强调PadLocal作为协议服务商,不直接提供客户端SDK,而是通过RPC让不同语言调用。用户现在可能已经了解了基本结构,但想深入其他语言如何具体操作。 接下来,用户的问题可能集中在如何实际搭建这个服务,以及具体的步骤。我需要明确说明Wechaty Service的作用,即作为中间层,将TypeScript的功能暴露给其他语言。可能需要解释gRPC在这里的角色,以及自建服务的流程。 用户提供的链接可能需要检查,但假设是官方文档的话,可能需要引导用户查阅相关部分。不过由于无法访问外部链接,我应该用通用的步骤来解释。 另外,用户可能有兴趣了解不同语言的具体示例,比如Java如何调用,或者Go的代码结构。这时候给出简单的代码示例会很有帮助,但需要确保正确性。 还需要注意用户可能的误区,比如认为每个语言都需要独立的PadLocal支持,而实际上只要Wechaty Service配置正确,任何客户端语言都可以通过gRPC调用。因此需要强调服务端和客户端的分离。 最后,总结关键点,确保用户理解自建Wechaty Service的步骤和各部分的作用,以及如何通过这种方式实现多语言支持。</think>--- ### **核心逻辑** **PadLocal 的跨语言支持依赖于 Wechaty 的 RPC 服务架构**: 无论使用 Python/Java/Go 等何种语言,均需通过 **自建 Wechaty Service(TypeScript 服务端)** 桥接到 PadLocal,语言客户端通过 **gRPC** 调用服务端能力。 --- ### **详细说明** #### **1. Wechaty Service 的核心作用** - **功能定位**: - 将 TypeScript 实现的微信协议操作(如登录、收发消息)**封装为 gRPC 接口**,供其他语言调用。 - 集成 PadLocal 协议服务,处理与微信服务器的直接通信。 - **代码示例**(服务端启动): ```bash # 安装依赖 npm install wechaty @wechaty/plugin-padlocal # 启动服务端(指定 PadLocal token) WECHATY_PUPPET_SERVICE_TOKEN=padlocal_你的token \ WECHATY_PUPPET=wechaty-puppet-service \ node bot.js ``` #### **2. 多语言客户端调用流程** - **通用步骤**: 1. **启动 Wechaty Service**(TypeScript 服务端,集成 PadLocal)。 2. **生成客户端代码**:通过 Protobuf 定义生成对应语言的 gRPC 客户端。 3. **编写业务逻辑**:使用客户端调用服务端接口(如监听消息、发送回复)。 - **Python 示例**: ```python from wechaty_grpc import Wechaty bot = Wechaty() bot.on('message', lambda msg: print(f'收到消息: {msg.text}')) bot.start() # 连接到本地的 Wechaty Service ``` - **Java 示例**: ```java import io.github.wechaty.grpc.Wechaty; public class Demo { public static void main(String[] args) { Wechaty bot = Wechaty.instance(); bot.onMessage(message -> System.out.println("消息内容: " + message.getText())); bot.start(); } } ``` #### **3. PadLocal 的协作关系** - **关键点**: - PadLocal **仅需在 Wechaty Service 中配置一次**(通过 `WECHATY_PUPPET_SERVICE_TOKEN`),客户端无需感知 PadLocal 的存在。 - 协议实现的复杂性被隔离在服务端,客户端只需处理业务逻辑。 --- ### **自建 Wechaty Service 的必要性** | 场景 | 是否需要自建服务 | 原因 | |----------------------|------------------|------------------------------------------| | 使用官方托管服务 | 否 | 直接使用现成服务(如付费 PadLocal 服务) | | 私有化部署/协议定制 | 是 | 需控制服务端逻辑和协议实现 | --- ### **常见问题** - **Q1**: Go 语言如何调用 PadLocal? **A**: 1. 启动集成 PadLocal 的 Wechaty Service。 2. 使用 Go 的 gRPC 客户端生成工具(如 `protoc-gen-go`)生成客户端代码。 3. 调用生成的接口(示例): ```go client := wechaty.NewWechatyClient(conn) stream, _ := client.Message(context.Background()) for { msg, _ := stream.Recv() fmt.Println("Received:", msg.Text) } ``` - **Q2**: 自建服务的性能瓶颈? **A**: - gRPC 基于 HTTP/2,多语言调用效率较高,瓶颈通常在于微信协议本身的限制(如消息频率)。 --- ### **总结** - **核心路径**: **PadLocal → Wechaty Service(TypeScript)→ gRPC → 多语言客户端** - **关键优势**: 语言无关性:只需维护一套协议服务(TypeScript + PadLocal),所有客户端语言复用同一接口。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值