我正在使用killableprocess包(构建在子进程之上)来运行进程每当我在脚本中运行"killableprocess.Popen(command)"代码时,我都会收到以下错误:
File "killableprocess.py", line 157, in _execute_child
winprocess.AssignProcessToJobObject(self._job, hp)
File "winprocess.py", line 37, in ErrCheckBool
raise WinError()
WindowsError [error 5] Access is denied
Exception TypeError: "'NoneType' object is not callable" in <bound method AutoHANDLE.__del__ of <AutoHANDLE object at 0x025D42B0>> ignored
Run Code Online (Sandbox Code Playgroud)
但是当我从python交互式控制台(python 2.6)运行它时它工作正常.这可能意味着当我从脚本运行时存在权限问题,但我不知道如何解决它们.我尝试从我以管理员身份运行的cmd运行脚本,但它没有帮助.尝试寻找类似的帖子,但没有找到任何好的解决方案.希望在这里找到一些帮助我在Windows上运行,特别是Windows 7 Ultimate x64,如果有任何帮助的话.
谢谢
我是maven的新手.
我有一个项目,我尝试用maven3构建.
当我运行命令时,mvn -X clean install
我收到了错误.
[root@localhost]# mvn -X clean install
Apache Maven 3.0.4 (r1232337; 2012-01-17 14:14:56+0530)
Maven home: /usr/local/maven
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-279.9.1.el6.x86_64", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/local/maven/conf/settings.xml
[DEBUG] Reading user settings from /root/.m2/settings.xml
[DEBUG] Using local repository at /root/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /root/.m2/repository …
Run Code Online (Sandbox Code Playgroud) 我试图计算股票收益数据的连续上涨天数 - 所以如果正日是1而负数是0,那么列表y=[0,0,1,1,1,0,0,1,0,1,1]
应该返回z=[0,0,1,2,3,0,0,1,0,1,2]
.
我已经找到了一个在代码行数方面很整洁的解决方案,但速度非常慢:
import pandas
y=pandas.Series([0,0,1,1,1,0,0,1,0,1,1])
def f(x):
return reduce(lambda a,b:reduce((a+b)*b,x)
z=pandas.expanding_apply(y,f)
Run Code Online (Sandbox Code Playgroud)
我猜我在整个列表中循环太多次了.有没有一种很好的Pythonic方法可以实现我想要的,而只需要浏览一次数据?我自己可以写一个循环,但想知道是否有更好的方法.
谢谢!
我使用函数numpy.append时遇到问题.我将以下函数编写为更大的代码片段的一部分,但是,我的错误在以下内容中重现:
data = [
[
'3.5', '3', '0', '0', '15', '6',
'441', 'some text', 'some more complicated data'
],
[
'4.5', '5', '1', '10', '165', '0',
'1', 'some other text', 'some even more complicated data'
]
]
def GetNumpyArrey(self, index):
r = np.array([])
for line in data:
np.append(r, float(line[index]))
print r
Run Code Online (Sandbox Code Playgroud)
index <6.结果是:
>> []
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
非常感谢 !
当我尝试将新表添加到python/flask时 -
class UserRemap(db.Model):
name = db.Column(db.String(40))
email = db.Column(db.String(255))
password = db.Column(db.String(64))
flag = db.Column(db.String(1))
def __init__(self, name, email, password):
self.email = email
self.name = name
self.password = password
self.flag='N'
Run Code Online (Sandbox Code Playgroud)
这是表模式 -
mysql> desc UserRemap;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| name | varchar(40) | NO | | NULL | |
| password | varchar(64) | NO | | NULL | |
| email | varchar(255) | NO | …
Run Code Online (Sandbox Code Playgroud) 我正在用sqlalchemy创建表.
user = Table('users', Metadata,
Column('datecreated', TIMESTAMP,
server_default=text('CURRENT_TIMESTAMP')),
Column('datemodified', TIMESTAMP,
server_onupdate=text('CURRENT_TIMESTAMP')),
)
Run Code Online (Sandbox Code Playgroud)
但是这不会设置DEFAULT ON UPDATE CURRENT_TIMESTAMP.
我查看这个链接, 你如何让SQLAlchemy在更新CURRENT_TIMESTAMP上覆盖MySQL,但是对于文字,我需要在create table definition中连接它.
Thx提前:)
我希望在Sphinx中提及相同的功能,reStructuredText显示/隐藏代码片段.但该帖子上没有共享代码.
我在Windows 8中使用CMD,并且我将代码页设置为65001(chcp 65001
).我使用的是Python 2.7.2(ActivePython 2.7.2.5),我将PYTHONSTARTUP环境变量设置为"bootstrap.py".
bootstrap.py:
import codecs
codecs.register(
lambda name: name == 'cp65001' and codecs.lookup('UTF-8') or None
)
Run Code Online (Sandbox Code Playgroud)
这让我打印ASCII:
>>> print 'hello'
hello
>>> print u'hello'
hello
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用非ASCII字符打印Unicode字符串时得到的错误对我来说毫无意义.在这里,我尝试打印一些包含北欧符号的字符串(为了便于阅读,我在打印件之间添加了额外的换行符):
>>> print u'æøå'
??øåTraceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory
>>> print u'åndalsnes'
??ndalsnes
>>> print u'åndalsnesæ'
??ndalsnesæTraceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 22] Invalid argument
>>> print …
Run Code Online (Sandbox Code Playgroud) 我不能确定生成的ID是否是连续的,如果没有,是否还有其他方法可以获得它们?
class BaseDao(object):
def __init__(self,pooldb):
self.pooldb = pooldb
def insertmany(self,sql,args):
conn,cur = None,None
try:
conn = pooldb.dedicated_connection()
cur = conn.cursor()
num=cur.executemany(sql,args)
if num <= 0:
raise Exception("insert failure with num equals zero")
lastrowid = int(cur.lastrowid)
return [range(lastrowid - num + 1,lastrowid+1)]
except:
conn.rollback()
traceback.print_exc()
raise Exception("error happened when insert sql=%s args=%s " % (sql,str(args)))
finally:
if cur:
cur.close()
if conn:
conn.close()
Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
files = sorted(os.listdir('dumps'), key=os.path.getctime)
Run Code Online (Sandbox Code Playgroud)
目标是根据创建时间对列出的文件进行排序.但是由于os.listdir只提供文件名而不是绝对路径,即os.path.getctime抛出异常
OSError: [Errno 2] No such file or directory: 'very_important_file.txt'
有这种情况的解决方法还是我需要编写自己的排序功能?
python ×8
mysql ×2
sqlalchemy ×2
append ×1
build ×1
executemany ×1
listdir ×1
maven-3 ×1
mysql-python ×1
numpy ×1
os.path ×1
packaging ×1
pandas ×1
pom.xml ×1
statistics ×1
subprocess ×1
windows ×1
windows-8 ×1
windowserror ×1