excel寻找最小值当地最大/最小使用Python问题,怎么解决

更多频道内容在这里查看
爱奇艺用户将能永久保存播放记录
过滤短视频
暂无长视频(电视剧、纪录片、动漫、综艺、电影)播放记录,
按住视频可进行拖动
&正在加载...
收藏成功,可进入
查看所有收藏列表
当前浏览器仅支持手动复制代码
视频地址:
flash地址:
html代码:
通用代码:
通用代码可同时支持电脑和移动设备的分享播放
用爱奇艺APP或微信扫一扫,在手机上继续观看
当前播放时间:
一键下载至手机
限爱奇艺安卓6.0以上版本
使用微信扫一扫,扫描左侧二维码,下载爱奇艺移动APP
其他安装方式:手机浏览器输入短链接http://71.am/udn
下载安装包到本机:
设备搜寻中...
请确保您要连接的设备(仅限安卓)登录了同一爱奇艺账号 且安装并开启不低于V6.0以上版本的爱奇艺客户端
连接失败!
请确保您要连接的设备(仅限安卓)登录了同一爱奇艺账号 且安装并开启不低于V6.0以上版本的爱奇艺客户端
部安卓(Android)设备,请点击进行选择
请您在手机端下载爱奇艺移动APP(仅支持安卓客户端)
使用微信扫一扫,下载爱奇艺移动APP
其他安装方式:手机浏览器输入短链接http://71.am/udn
下载安装包到本机:
爱奇艺云推送
请您在手机端登录爱奇艺移动APP(仅支持安卓客户端)
使用微信扫一扫,下载爱奇艺移动APP
180秒后更新
打开爱奇艺移动APP,点击“我的-扫一扫”,扫描左侧二维码进行登录
没有安装爱奇艺视频最新客户端?
智普教育python培训就业班python随堂视频教程 47 第二大值方法2
正在检测客户端...
您尚未安装客户端,正在为您下载...安装完成后点击按钮即可下载
30秒后自动关闭
智普教育python培训就业班python随堂视频教程 47 第二大值方法2">智普教育python培训就业班python随堂视频教程 47 第二大值方法2
请选择打赏金额:
播放量12.7万
播放量数据:快去看看谁在和你一起看视频吧~
更多数据:
Copyright (C) 2018 & All Rights Reserved
您使用浏览器不支持直接复制的功能,建议您使用Ctrl+C或右键全选进行地址复制
正在为您下载爱奇艺客户端安装后即可快速下载海量视频
正在为您下载爱奇艺客户端安装后即可免费观看1080P视频
&li data-elem="tabtitle" data-seq="{{seq}}"& &a href="javascript:void(0);"& &span>{{start}}-{{end}}&/span& &/a& &/li&
&li data-downloadSelect-elem="item" data-downloadSelect-selected="false" data-downloadSelect-tvid="{{tvid}}"& &a href="javascript:void(0);"&{{pd}}&/a&
选择您要下载的《
色情低俗内容
血腥暴力内容
广告或欺诈内容
侵犯了我的权力
还可以输入
您使用浏览器不支持直接复制的功能,建议您使用Ctrl+C或右键全选进行地址复制keyring 11.0.0
Store and access your passwords safely.
Table of Contents
The Python keyring lib provides an easy way to access the system keyring service
from python. It can be used in any application that needs safe password storage.
The keyring library is licensed under both the
and the PSF license.
These recommended keyring backends are supported by the Python keyring lib:
Freedesktop
(requires )
Other keyring implementations are provided in the .
Install from Index
Install using your favorite installer. For example:
$ pip install keyring
On Linux, the recommended keyring relies on SecretStorage, which in
turn relies on dbus-python, but dbus-python does not install correctly
when using the Python installers, so dbus-python must be installed
as a system package. See
for details.
The basic usage of keyring is pretty simple: just call keyring.set_password
and keyring.get_password:
&&& import keyring
&&& keyring.set_password("system", "username", "password")
&&& keyring.get_password("system", "username")
'password'
Keyring supplies a keyring command which is installed with the
package. After installing keyring in most environments, the
command should be available for setting, getting, and deleting
passwords. For more information on usage, invoke with no arguments
or with --help as so:
$ keyring --help
$ keyring set system username
Password for 'username' in 'system':
$ keyring get system username
The command-line functionality is also exposed as an executable
package, suitable for invoking from Python like so:
$ python -m keyring --help
$ python -m keyring set system username
Password for 'username' in 'system':
$ python -m keyring get system username
The python keyring lib contains implementations for several backends. The
library will
automatically choose the keyring that is most suitable for your current
environment. You can also specify the keyring you like to be used in the
config file or by calling the set_keyring() function.
This section describes how to change your option in the config file.
The configuration of the lib is stored in a file named “keyringrc.cfg”. This
file must be found in a platform-specific location. To determine
where the config file is stored, run the following:
python -c "import keyring.util.platform_; print(keyring.util.platform_.config_root())"
Some keyrings also store the keyring data in the file system. To determine
where the data files are stored, run this command:
python -c "import keyring.util.platform_; print(keyring.util.platform_.data_root())"
To specify a keyring backend, set the default-keyring option to the
full path of the class for that backend, such as
keyring.backends.OS_X.Keyring.
If keyring-path is indicated, keyring will add that path to the Python
module search path before loading the backend.
For example, this config might be used to load the SimpleKeyring from the demo
directory in the project checkout:
default-keyring=simplekeyring.SimpleKeyring
keyring-path=/home/kang/pyworkspace/python-keyring-lib/demo/
In addition to the backends provided by the core keyring package for
the most common and secure use cases, there
are additional keyring backend implementations available for other
use-cases. Simply install them to make them available:
- “alternate”,
less common backends, originally part of the core package, but now
available for opt-in.
pure Python backend using the secret service DBus API for desktop
The interface for the backend is defined by keyring.backend.KeyringBackend.
Every backend should derive from that base class and define a priority
attribute and three functions: get_password(), set_password(), and
delete_password().
See the backend module for more detail on the interface of this class.
Keyring employs entry points to allow any third-party package to implement
backends without any modification to the keyring itself. Those interested in
creating new backends are encouraged to create new, third-party packages
in the keyrings namespace, in a manner modeled by the . See the setup.py file
in that project for a hint on how to create the requisite entry points.
Backends that prove essential may be considered for inclusion in the core
library, although the ease of installing these third-party packages should
mean that extensions may be readily available.
If you’ve created an extension for Keyring, please submit a pull request to
have your extension mentioned as an available extension.
The following is a complete transcript for installing keyring in a
virtual environment on Ubuntu 16.04.
No config file was used.:
$ sudo apt install python3-venv libdbus-glib-1-dev
$ pyvenv py3
$ source py3/bin/activate
$ pip install -U pip
$ pip install secretstorage dbus-python
$ pip install keyring
&&& import keyring
&&& keyring.get_keyring()
&keyring.backends.SecretService.Keyring object at 0x7f9b9c971ba8&
&&& keyring.set_password("system", "username", "password")
&&& keyring.get_password("system", "username")
'password'
API interface
The keyring lib has a few functions:
get_keyring(): Return the currently-loaded keyring implementation.
get_password(service, username): Returns the password stored in the
active keyring. If the password does not exist, it will return None.
set_password(service, username, password): Store the password in the
delete_password(service, username): Delete the password stored in
keyring. If the password does not exist, it will raise an exception.
In all cases, the parameters (service, username, password)
should be Unicode text. On Python 2, these parameters are accepted as
simple str in the default encoding as they will be implicitly
decoded to text. Some backends may accept bytes for these parameters,
but such usage is discouraged.
Python keyring lib is an open community project and highly welcomes new
contributors.
Repository:
Bug Tracker:
Mailing list:
This project makes use of automated releases via Travis-CI. The
simple workflow is to tag a commit and push it to Github. If it
passes tests on a late Python version, it will be automatically
deployed to PyPI.
Other things to consider when making a release:
first ensure that tests pass (preferably on Windows and Linux)
check that the changelog is current for the intended release
Travis-CI.
To run the tests yourself, you’ll want keyring installed to some environment
in which it can be tested. Recommended technique is described below.
Keyring prefers use of
to run tests.
Simply install and invoke tox.
This technique is the one used by the Travis-CI script.
The project was based on Tarek Ziade’s idea in . Kang Zhang
initially carried it out as a
project, and Tarek
mentored Kang on this project.
Py Version
Uploaded on
Python Wheel
Jason R. Coombs
Home Page:
Categories
Requires Distributions
collective. extra == 'testing'
pytest- extra == 'testing'
extra == 'docs'
sys_platform=="linux2" or sys_platform=="linux"
Requires Python: &=2.7
Package Index Owner:
Kang, tarek, benji, jaraco
Package Index Maintainer:
tarek, benji, jaraco
Copyright (C) ,匿名用户不能发表回复!|& & & &在看《剑指Offer》过程中,面试题47不用加减乘除做加法,给出的思路是使用二进制的异或以及与运算,总之就是使用二进制。但是在使用Python实现的过程中,对于正整数是没有问题的,但是对于负数,会出现死循环情况。这是为什么呢?因为在Python中,对于超出32位的大整数,会自动进行大整数的转变,这就导致了在右移位过程中,不会出现移到了0的情况,也就会造成了死循环。
& & &这里需要了解的是Python中整数实现的原理以及二进制中的移位等原理。
& & &已经知道了右移过程中大整数的自动转化,导致变不成0,那么只需要在移动的过程中加一下判断就行了,把craay的值和0xFFFFFFFF做一下比较就可以了,具体代码如下所示。
<span style="color: # def bit_add(n1, n2):
<span style="color: #
<span style="color: #
while carry:
<span style="color: #
s = n1 ^ n2
<span style="color: #
carry = 0xFFFFFFFF & ((n1 & n2) && 1)
<span style="color: #
carry = -(~(carry - 1) & 0xFFFFFFFF) if carry & 0x7FFFFFFF else carry
<span style="color: #
<span style="color: #
n2 = carry
<span style="color: #
& & &其实在Python中,可以直接使用内置函数sum求和,不过我感觉sum源码中会用到+?不确定,需要看源码才行。
<span style="color: # def add(n1, n2):
<span style="color: #
return sum([n1, n2])
阅读(...) 评论()Python 的 Socket 编程教程
这是用来快速学习 Python Socket 套接字编程的指南和教程。Python 的 Socket 编程跟 C 语言很像。
Python 官方关于 Socket 的函数请看
基本上,Socket 是任何一种计算机网络通讯中最基础的内容。例如当你在浏览器地址栏中输入 www.oschina.net 时,你会打开一个套接字,然后连接到 www.oschina.net 并读取响应的页面然后然后显示出来。而其他一些聊天客户端如 gtalk 和 skype 也是类似。任何网络通讯都是通过 Socket 来完成的。
本教程假设你已经有一些基本的 Python 编程的知识。
让我们开始 Socket 编程吧。
创建 Socket
首先要做的就是创建一个 Socket,socket 的 socket 函数可以实现,代码如下:
#Socket client example in python
import socket #for sockets
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket Created'
函数 socket.socket 创建了一个 Socket,并返回 Socket 的描述符可用于其他 Socket 相关的函数。
上述代码使用了下面两个属性来创建 Socket:
地址簇 : AF_INET (IPv4) 类型: SOCK_STREAM (使用 TCP 传输控制协议)
如果 socket 函数失败了,python 将抛出一个名为 socket.error 的异常,这个异常必须予以处理:
#handling errors in python socket programs
import socket #for sockets
import sys #for exit
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
sys.exit();
print 'Socket Created'
好了,假设你已经成功创建了 Socket,下一步该做什么呢?接下来我们将使用这个 Socket 来连接到服务器。
与 SOCK_STREAM 相对应的其他类型是 SOCK_DGRAM 用于 UDP 通讯协议,UDP 通讯是非连接 Socket,在这篇文章中我们只讨论 SOCK_STREAM ,或者叫 TCP 。
连接到服务器
连接到服务器需要服务器地址和端口号,这里使用的是 www.oschina.net 和 80 端口。
首先获取远程主机的 IP 地址
连接到远程主机之前,我们需要知道它的 IP 地址,在 Python 中,获取 IP 地址是很简单的:
import socket #for sockets
import sys #for exit
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
sys.exit();
print 'Socket Created'
host = 'www.oschina.net'
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print 'Hostname could not be resolved. Exiting'
sys.exit()
print 'Ip address of ' + host + ' is ' + remote_ip
我们已经有 IP 地址了,接下来需要指定要连接的端口。
import socket #for sockets
import sys #for exit
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
sys.exit();
print 'Socket Created'
host = 'www.oschina.net'
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print 'Hostname could not be resolved. Exiting'
sys.exit()
print 'Ip address of ' + host + ' is ' + remote_ip
#Connect to remote server
s.connect((remote_ip , port))
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
现在运行程序
$ python client.py
Socket Created
Ip address of www.oschina.net is 61.145.122.155
Socket Connected to www.oschina.net on ip 61.145.122.155
这段程序创建了一个 Socket 并进行连接,试试使用其他一些不存在的端口(如81)会是怎样?这个逻辑相当于构建了一个端口扫描器。
已经连接上了,接下来就是往服务器上发送数据。
使用 SOCK_STREAM/TCP 套接字才有“连接”的概念。连接意味着可靠的数据流通讯机制,可以同时有多个数据流。可以想象成一个数据互不干扰的管道。另外一个重要的提示是:数据包的发送和接收是有顺序的。
其他一些 Socket 如 UDP、ICMP 和 ARP 没有“连接”的概念,它们是无连接通讯,意味着你可从任何人或者给任何人发送和接收数据包。
sendall 函数用于简单的发送数据,我们来向 oschina 发送一些数据:
import socket #for sockets
import sys #for exit
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
print 'Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1]
sys.exit();
print 'Socket Created'
host = 'www.oschina.net'
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print 'Hostname could not be resolved. Exiting'
sys.exit()
print 'Ip address of ' + host + ' is ' + remote_ip
#Connect to remote server
s.connect((remote_ip , port))
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
#Send some data to remote server
message = &GET / HTTP/1.1\r\n\r\n&
#Set the whole string
s.sendall(message)
except socket.error:
#Send failed
print 'Send failed'
sys.exit()
print 'Message send successfully'
上述例子中,首先连接到目标服务器,然后发送字符串数据 &GET / HTTP/1.1\r\n\r\n& ,这是一个 HTTP 协议的命令,用来获取网站首页的内容。
接下来需要读取服务器返回的数据。
recv 函数用于从 socket 接收数据:
#Socket client example in python
import socket #for sockets
import sys #for exit
#create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print 'Failed to create socket'
sys.exit()
print 'Socket Created'
host = 'oschina.net';
port = 80;
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print 'Hostname could not be resolved. Exiting'
sys.exit()
#Connect to remote server
s.connect((remote_ip , port))
print 'Socket Connected to ' + host + ' on ip ' + remote_ip
#Send some data to remote server
message = &GET / HTTP/1.1\r\nHost: oschina.net\r\n\r\n&
#Set the whole string
s.sendall(message)
except socket.error:
#Send failed
print 'Send failed'
sys.exit()
print 'Message send successfully'
#Now receive data
reply = s.recv(4096)
print reply
下面是上述程序执行的结果:
$ python client.py
Socket Created
Ip address of oschina.net is 61.145.122.
Socket Connected to oschina.net on ip 61.145.122.155
Message send successfully
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 24 Oct :46 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Keep-Alive: timeout=20
Location: http://www.oschina.net/
oschina.net 回应了我们所请求的 URL 的内容,很简单。数据接收完了,可以关闭 Socket 了。
关闭 socket
close 函数用于关闭 Socket:
这就是了。
让我们回顾一下
上述的示例中我们学到了如何:
1. 创建 Socket 2. 连接到远程服务器 3. 发送数据 4. 接收回应
当你用浏览器打开 www.oschina.net 时,其过程也是一样。包含两种类型,分别是客户端和服务器,客户端连接到服务器并读取数据,服务器使用 Socket 接收进入的连接并提供数据。因此在这里 www.oschina.net 是服务器端,而你的浏览器是客户端。
接下来我们开始在服务器端做点编码。
服务器端编程
服务器端编程主要包括下面几步:
1. 打开 socket 2. 绑定到一个地址和端口 3. 侦听进来的连接 4. 接受连接 5. 读写数据
我们已经学习过如何打开 Socket 了,下面是绑定到指定的地址和端口上。
绑定 Socket
bind 函数用于将 Socket 绑定到一个特定的地址和端口,它需要一个类似 connect 函数所需的 sockaddr_in 结构体。
示例代码:
import socket
import sys
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
绑定完成后,就需要让 Socket 开始侦听连接。很显然,你不能将两个不同的 Socket 绑定到同一个端口之上。
绑定 Socket 之后就可以开始侦听连接,我们需要将 Socket 变成侦听模式。socket 的 listen 函数用于实现侦听模式:
s.listen(10)
print 'Socket now listening'
listen 函数所需的参数成为 backlog,用来控制程序忙时可保持等待状态的连接数。这里我们传递的是 10,意味着如果已经有 10 个连接在等待处理,那么第 11 个连接将会被拒绝。当检查了 socket_accept 后这个会更加清晰。
示例代码:
import socket
import sys
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
s.listen(10)
print 'Socket now listening'
#wait to accept a connection - blocking call
conn, addr = s.accept()
#display client information
print 'Connected with ' + addr[0] + ':' + str(addr[1])
运行该程序将会显示:
$ python server.py
Socket created
Socket bind complete
Socket now listening
现在这个程序开始等待连接进入,端口是 8888,请不要关闭这个程序,我们来通过 telnet 程序来进行测试。
打开命令行窗口并输入:
$ telnet localhost 8888
It will immediately show
$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
而服务器端窗口显示的是:
$ python server.py
Socket created
Socket bind complete
Socket now listening
Connected with 127.0.0.1:59954
我们可看到客户端已经成功连接到服务器。
上面例子我们接收到连接并立即关闭,这样的程序没什么实际的价值,连接建立后一般会有大量的事情需要处理,因此让我们来给客户端做出点回应吧。
sendall 函数可通过 Socket 给客户端发送数据:
import socket
import sys
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
s.listen(10)
print 'Socket now listening'
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
#now keep talking with the client
data = conn.recv(1024)
conn.sendall(data)
conn.close()
继续运行上述代码,然后打开另外一个命令行窗口输入下面命令:
$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
可看到客户端接收到来自服务器端的回应内容。
上面的例子还是一样,服务器端回应后就立即退出了。而一些真正的服务器像 www.oschina.net 是一直在运行的,时刻接受连接请求。
也就是说服务器端应该一直处于运行状态,否则就不能成为“服务”,因此我们要让服务器端一直运行,最简单的方法就是把 accept 方法放在一个循环内。
一直在运行的服务器
对上述代码稍作改动:
import socket
import sys
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
s.listen(10)
print 'Socket now listening'
#now keep talking with the client
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
data = conn.recv(1024)
reply = 'OK...' + data
if not data:
conn.sendall(reply)
conn.close()
很简单只是加多一个 while 1 语句而已。
继续运行服务器,然后打开另外三个命令行窗口。每个窗口都使用 telnet 命令连接到服务器:
$ telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
OK .. happy
Connection closed by foreign host.
服务器所在的终端窗口显示的是:
$ python server.py
Socket created
Socket bind complete
Socket now listening
Connected with 127.0.0.1:60225
Connected with 127.0.0.1:60237
Connected with 127.0.0.1:60239
你看服务器再也不退出了,好吧,用 Ctrl+C 关闭服务器,所有的 telnet 终端将会显示 &Connection closed by foreign host.&
已经很不错了,但是这样的通讯效率太低了,服务器程序使用循环来接受连接并发送回应,这相当于是一次最多处理一个客户端的请求,而我们要求服务器可同时处理多个请求。
处理多个连接
为了处理多个连接,我们需要一个独立的处理代码在主服务器接收到连接时运行。一种方法是使用线程,服务器接收到连接然后创建一个线程来处理连接收发数据,然后主服务器程序返回去接收新的连接。
下面是我们使用线程来处理连接请求:
import socket
import sys
from thread import *
HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
#Bind socket to local host and port
s.bind((HOST, PORT))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Start listening on socket
s.listen(10)
print 'Socket now listening'
#Function for handling connections. This will be used to create threads
def clientthread(conn):
#Sending message to connected client
conn.send('Welcome to the server. Type something and hit enter\n') #send only takes string
#infinite loop so that function do not terminate and thread do not end.
while True:
#Receiving from client
data = conn.recv(1024)
reply = 'OK...' + data
if not data:
conn.sendall(reply)
#came out of loop
conn.close()
#now keep talking with the client
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
#start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
start_new_thread(clientthread ,(conn,))
运行上述服务端程序,然后像之前一样打开三个终端窗口并执行 telent 命令:
$ telnet localhost 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcome to the server. Type something and hit enter
OK...cv 服务器端所在终端窗口输出信息如下:
$ python server.py
Socket created
Socket bind complete
Socket now listening
Connected with 127.0.0.1:60730
Connected with 127.0.0.1:60731
线程接管了连接并返回相应数据给客户端。
这便是我们所要介绍的服务器端编程。
到这里为止,你已经学习了 Python 的 Socket 基本编程,你可自己动手编写一些例子来强化这些知识。
你可能会遇见一些问题:Bind failed. Error Code : 98 Message Address already in use,碰见这种问题只需要简单更改服务器端口即可。
, 原创翻译
python 3.2能用不?
个人感觉这个作为入门真的很棒,通俗易懂,不过菜鸟想请教红薯大哥几个问题:
1.为何61.145.122.155访问时404错误呢?开源中国不是用的独立的物理服务器?
2.教程中选择了thread,为什么不用threading模块呢?
--- 共有 4 条评论 ---
需要在请求头里加 Host: oschina.net
好吧,又是一个装了好多网站的服务器,不感觉压力山大?
大概是买一个ip太贵了,不值得~
呵呵,要用域名访问:)
OSC 当然是独立服务器,无法用 IP 访问是为了防止一些未备案域名指向 OSC 服务器,导致 OSC 服务器被停。这是网监的要求。
--- 共有 1 条评论 ---
原来如此~
老大最近也在研究python了?
很多时假,学了python都不知道用它来做什么,大部份都是在爬网页
引用来自“红薯”的答案
OSC 当然是独立服务器,无法用 IP 访问是为了防止一些未备案域名指向 OSC 服务器,导致 OSC 服务器被停。这是网监的要求。 我们的网站上个月就出现这种现象了,
,ip访问返回404 &,怎么做的!
--- 共有 1 条评论 ---
在 Nginx 里配置 localhost 直接返回 404 正常能访问的域名都配置好虚拟主机
先收藏了!!
写的不错,建议大家还是用twisted 比较好些,省事, 大家看了就明白了。
如果是为了基础学习还是必须要看的。
--- 共有 1 条评论 ---
不错,这个只是看看基础了解下socket的流程,提高的话还是看看twisted 框架!

我要回帖

更多关于 matlab 寻找最小值 的文章

 

随机推荐