我想知道如何从cmd提示符打开时从python脚本中输入变量?我知道使用c会做类似的事情:
int main( int argc, char **argv ) {
int input1 = argv[ 0 ]
int input2 = argv[ 1 ]
.....
}
Run Code Online (Sandbox Code Playgroud)
如何在python中实现同样的结果?
我试图在VS C++ express 2010中编译c代码,但我得到以下错误跟踪:
1>------ Build started: Project: test4, Configuration: Release Win32 ------
1>cl : Command line error D8045: cannot compile C file 'test4.c' with the /clr option
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
当我尝试使用cpp扩展编译时,我得到此错误跟踪:
1>------ Build started: Project: test4, Configuration: Release Win32 ------
1> test4.cpp
1>c:\documents and settings\rkelly1\desktop\io\test4\test4\pt_ioctl.c(86): error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or …Run Code Online (Sandbox Code Playgroud) 我有一个使用阻塞套接字来接收数据的服务.我遇到的问题是,如果仍在等待数据,我不知道如何正确关闭套接字.下面是我如何打开和等待数据的简短说明:我不想实现超时,因为根据python文档,套接字必须阻塞才能使用makefile.
因为我刚接触使用套接字进行编程,所以我可能会完全错误.
编辑:
应该注意的是,我无法改变服务器的运行方式.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
reader = s.makefile("rb")
line = reader.readline()
Run Code Online (Sandbox Code Playgroud) 下面是一个代码片段,其中包含我正在运行的python脚本化Windows服务的错误跟踪.它似乎在Windows XP上的python 2.7中正常工作,但我使用的生产机器在Windows Server 2003上运行python 2.5.我遇到的主要错误'error' object has no attribute 'errno'是我做的事情对于适用于2.7的python 2.5来说是根本错误的吗?
代码剪辑:
try:
if s == None:
s = self.connect()
char = s.recv(1)
line += char
except socket.timeout:
if s != None:
s.close()
s = None
continue
except socket.error, socket_error:
servicemanager.LogErrorMsg(traceback.format_exc())
if socket_error.errno == errno.ECONNREFUSED:
if s != None:
s.close()
time.sleep(60)
s =None
continue
else:
if s != None:
s.close()
os._exit(-1)
else:
pass
Run Code Online (Sandbox Code Playgroud)
错误跟踪剪辑:
if socket_error.errno == errno.ECONNREFUSED:
AttributeError: 'error' object has no attribute 'errno'
%2: %3
Run Code Online (Sandbox Code Playgroud) 假设我有一个格式的字符串HHMMSS.SS如何将其转换为时间对象?
这就是我认为你会这样做的方式:
import time
time.strptime(timestring, '%H%M%S')
Run Code Online (Sandbox Code Playgroud)
但是%S,根据时间文档,不考虑秒的分数.
根据python 2.7.3文档multiprocessing.Event是"克隆"的threading.Event.但是,当我使用以下代码时:
from multiprocessing import Event
test = Event()
test.set()
test.isSet()
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误:
AttributeError: 'Event' Object has no attribute 'isSet'
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?为什么多处理事件没有一个方法来检查它是否已设置?
编辑:结果是is_set在多处理事件类中...仍然是文档撒谎
只是想知道为什么
import sys
exit(0)
Run Code Online (Sandbox Code Playgroud)
给我这个错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in ?
exit(0)
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
但
from sys import exit
exit(0)
Run Code Online (Sandbox Code Playgroud)
工作良好?
这是我到目前为止的代码:
import email, imaplib
user = 'some username'
pwd = 'some password'
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user, pwd)
m.select("[Gmail]/All Mail")
resp, data = m.fetch(1, "(RFC822)")
email_body = data[0][1]
mail = email.message_from_string(email_body)
print mail
Run Code Online (Sandbox Code Playgroud)
我目前收到的电子邮件有一堆奇怪的格式.我希望收到电子邮件正文作为纯文本字符串.
这是我在尝试安装MySQL-python-1.2.3时遇到的错误.有任何想法吗?
Traceback (most recent call last):
File "C:\Documents and Settings\Desktop\MySQL-python-1.2.3\setup.py", line 15, in <module>
metadata, options = get_config()
File "C:\Documents and Settings\Desktop\MySQL-python-1.2.3\setup_windows.py", line 7, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
试图在Windows XP机器上的Python 2.7上安装它
我想知道为什么当我使用MySQL Query Browser并双击表名时,sql语句如下所示:
SELECT * FROM database.table t;
Run Code Online (Sandbox Code Playgroud)
其中t =表格的第一个字母......这封信的目的是什么?我只是好奇
python ×8
mysql ×2
c ×1
database ×1
email ×1
imap ×1
import ×1
input ×1
networking ×1
python-2.7 ×1
sockets ×1
sql ×1
table-alias ×1
time ×1