我想知道在命令上执行的代码究竟是什么:
>>> from __future__ import braces
SyntaxError: not a chance
Run Code Online (Sandbox Code Playgroud)
所以,因为python是开源的,我打开C:\Python27\Lib\__future__.py并查看.令人惊讶的是,我发现没有处理导入braces模块的东西.
所以,我的问题是,处理这个问题的代码在哪里?当我运行该命令时会发生什么?
我在heroku上有一个Django应用程序,我提交并推动了很多次,但是在我最后一次试图推动时我得到了这个错误(我一直得到它):
$ git push heroku master
Counting objects: 16, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 24.22 KiB | 0 bytes/s, done.
Total 9 (delta 7), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: Build stream timed out, reverting to polling..........................
..............................................................................
Run Code Online (Sandbox Code Playgroud)
好像它不会停止.为什么会发生,我该怎么办?
谢谢.
我有一些IronPython从C#应用程序中调用的代码.
这段代码工作正常,直到我决定更改一个函数在一个线程中运行.
当在python线程中调用numpy函数时,InsufficientMemoryException抛出异常.
我搜索了解决方案,但没有找到.有人可以解释为什么会发生这种情况,我该如何解决?
我认为只有当我有两个线程使用时才会发生这种情况 numpy
我运行这样的代码:
C#:
_python.functionA(); # _python was created with "Python.CreateEngine()"
_python.functionA(); # twice on purpose
Run Code Online (Sandbox Code Playgroud)
Python:
my_python_script.py
import threading
import time
import numpy
def blah():
print numpy.array([100,100,0])
def functionA():
t = threading.Timer(0,blah)
t.start()
time.sleep(2)
Run Code Online (Sandbox Code Playgroud)
我得到了这个例外:
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 552, in _Thread__bootstrap_inner
self.run()
File "c:\Program Files\IronPython 2.7.1\Lib\threading.py", line 756, in run
self.function(*self.args, **self.kwargs)
File "C:\workspace\my_python_script.py", line 113, in blah …Run Code Online (Sandbox Code Playgroud) for comment_entry in comment_feed.entry:
content = comment_entry.ToString()
parse = BeautifulSoup(content)
for con in parse.find('ns0:content'):
print con.string
s = con.string
file.write(s.encode('utf8'))
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
File "channel_search.py", line 108, in youtube_search
file.write(s.encode('utf8'))
AttributeError: 'NoneType' object has no attribute 'encode'
Run Code Online (Sandbox Code Playgroud) 当我运行以下一行循环时,我得到了预期的输出.
for index in $(seq 1 5) ; do echo "$(date +"%Y%m%d" -d "20160301 $index day")"; done
20160302
20160303
20160304
20160305
20160306
Run Code Online (Sandbox Code Playgroud)
但是当我使用bash的edit-and-execute-command(control- x,control- e)并输入相同的一行循环时,我会得到输出,其中包含意外命令.
for index in $(seq 1 5) ; do echo "$(date +"%Y%m%d" -d "20160301 $index day")"; done
seq 1 5
date +"%Y%m%d" -d "20160301 $index day"
20160302
date +"%Y%m%d" -d "20160301 $index day"
20160303
date +"%Y%m%d" -d "20160301 $index day"
20160304
date +"%Y%m%d" -d "20160301 $index day"
20160305
date +"%Y%m%d" …Run Code Online (Sandbox Code Playgroud) 我在派生类的私有函数中使用的基类的受保护构造函数有问题:
基类:
class Socket
{
public:
virtual ~Socket();
// Constructors :
Socket();
protected:
Socket(SOCKET& s);
};
Run Code Online (Sandbox Code Playgroud)
派生类:
class Server : public Socket
{
public:
Server();
~Server();
private:
int ServerLoop();
};
Run Code Online (Sandbox Code Playgroud)
我尝试在 ServerLoop 函数中创建 Socket 对象
SOCKET client_sock = accept( m_socket, ( sockaddr* )&client_addr, &size );
Socket* Client = new Socket( client_sock );
^^^^^^
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
error C2248: 'NET_SOCKETS::Socket::Socket' : cannot access protected member
declared in class 'NET_SOCKETS::Socket'
Run Code Online (Sandbox Code Playgroud)
在 ^^^^ 的行中。是什么导致了这个错误?
我正在使用selenium2 RC和python客户端(selenium.py),我需要在服务器上获取selenium的版本.(例如"2rc2","2rc3"等)
是否有任何命令我可以发送到服务器获取其版本?
我需要将c ++ dll包装到python中.我正在使用ctypes模块.
c ++标题类似于:
class NativeObj
{
void func();
}
extern "C"
{
NativeObj* createNativeObj();
}; //extern "C"
Run Code Online (Sandbox Code Playgroud)
我想NativeObj用python代码创建然后调用它的func方法.
我写了这段代码并获得指针,NativeObj但我没有找到如何访问func
>>> import ctypes
>>> d = ctypes.cdll.LoadLibrary('dll/path')
>>> obj = d.createNativeObj()
>>> obj
36408838
>>> type(obj)
<type 'int'>
Run Code Online (Sandbox Code Playgroud)
谢谢.
以下代码使python崩溃:
import sys
sys.stdout = sys.stderr = None
print "goodbye world!"
Run Code Online (Sandbox Code Playgroud)
我知道没有真正的理由来编写这样的代码,但我想知道它为什么会崩溃.
我的第一个猜测是print命令失败,因为stdout被覆盖然后,在尝试引发异常时,引发了另一个异常,因为它stderr也被覆盖了.
因此在尝试引发异常时会出现堆栈溢出.
任何人都可以在这里解释背景中真正发生的事情吗?
这是一个堆栈溢出?
path='U:\\rmarshall\Work For Staff\\ROB\\_Downloads Folder\\'
file='file.pdf'
newFileName=time.strftime('%Y-%m-%d_')+row[1]+time.strftime('_%H:%M:%S')+'.pdf'
newFolderLocation='U:\\Company - do not alter\\'
os.rename(path+file,newFolderLocation+newFileName)
Run Code Online (Sandbox Code Playgroud)
当我跑步时,我得到:
>>> os.rename(path+file,newFolderLocation+newFileName)
OSError: [WinError 123] The filename, directory name, or volume label syntax is
incorrect: 'U:/Company - do not alter/2014-01-14_COMPANY NAME_13:55:23.pdf'
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到语法错误?
我有这个功能:
def binary_numbers(a):
for x in range(1, a):
return bin(x)
Run Code Online (Sandbox Code Playgroud)
我希望这个打印从0 my_input到此命令的每个二进制数.
print binary_numbers(my_input)
Run Code Online (Sandbox Code Playgroud)
所以,如果我写5作为参数,我希望它打印
0b0
0b1
0b10
0b11
0b100
0b101
Run Code Online (Sandbox Code Playgroud)
但是,当我用5调用它时,我得到的是:
>>> print binary_numbers(5)
'0b1'
Run Code Online (Sandbox Code Playgroud)
谁能解释我为什么?
python ×8
python-2.7 ×3
bash ×1
c# ×1
c++ ×1
constructor ×1
ctypes ×1
django ×1
file ×1
git ×1
heroku ×1
ironpython ×1
numpy ×1
protected ×1
python-3.x ×1
selenium-rc ×1
syntax-error ×1