Questions tagged «python»

Python是一种多范式,动态类型的多用途编程语言。它旨在快速学习,理解和使用并强制使用干净统一的语法。请注意,Python 2自2020年1月1日起已不再受支持。不过,对于特定于版本的Python问题,请添加[python-2.7]或[python-3.x]标签。使用Python变体或库(例如Jython,PyPy,Pandas,Numpy)时,请将其包含在标签中。

2
如何确定数字是否为任何类型的int(核心或numpy,带符号或不带符号)?
我需要测试变量是否为类型的int,或任何的np.int*,np.uint*优选使用单一的条件(即没有or)。 经过一些测试,我猜想: isinstance(n, int)将仅与int和np.int32(或np.int64取决于平台)匹配, np.issubdtype(type(n), int)似乎所有的匹配int和np.int*,但不匹配np.uint*。 这导致两个问题:将 np.issubdtype匹配任何一种带符号的整数?可以一次检查数字是否为带符号的整数或无符号的整数吗? 这是关于整数的测试,测试应返回False浮点型。
70 python  numpy  types 

4
为什么我的递归函数返回None?
我有一个自称的函数: def get_input(): my_var = input('Enter "a" or "b": ') if my_var != "a" and my_var != "b": print('You didn\'t type "a" or "b". Try again.') get_input() else: return my_var print('got input:', get_input()) 现在,如果我仅输入“ a”或“ b”,则一切正常: Type "a" or "b": a got input: a 但是,如果我输入其他内容,然后输入“ a”或“ b”,则会得到以下信息: Type "a" or …


6
python能够在多个内核上运行吗?
问题:由于python使用“ GIL”,python是否能够同时运行其单独的线程? 信息: 看完这篇文章后,我对python是否能够利用多核处理器的不确定性产生了怀疑。尽管python做得很好,但认为它缺乏如此强大的功能实在是很奇怪。因此,我感到不确定,因此决定在这里提问。如果我编写的程序是多线程的,那么它是否可以在多个内核上同时执行?

2
具有Python 3.8的Jupyter Notebook-NotImplementedError
最近升级到Python 3.8,并已安装jupyter。但是,当尝试运行时jupyter notebook出现以下错误: File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ) File "c:\users\user\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader raise NotImplementedError NotImplementedError 我知道ProactorEventLoop默认情况下Windows上的Python 3.8已切换为默认设置,因此我怀疑它与此相关。 Jupyter目前不支持Python 3.8?有没有解决的办法?

10
OS X 10.8升级后Python点破
升级到Mac OS X 10.8(Mountain Lion),并在尝试致电时出现以下错误$ pip: Traceback (most recent call last): File "/usr/local/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module> working_set.require(__requires__) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require needed = self.resolve(parse_requirements(requirements)) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve raise DistributionNotFound(req) # XXX put more info …
69 python  macos  pip 


8
Thrift,协议缓冲区,JSON,EJB等的性能比较?
我们正在研究传输/协议解决方案,并且即将进行各种性能测试,因此我认为我应该与社区联系,以了解他们是否已经这样做: 有没有人比较Linux上的EJB3,Thrift和协议缓冲区,对简单的回显服务以及针对各种消息大小的序列化/反序列化进行了服务器性能测试? 主要的语言是Java,C / C ++,Python和PHP。 更新:我仍然对此很感兴趣,如果有人做了进一步的基准测试,请告诉我。另外,非常有趣的基准测试显示压缩的JSON与Thrift / Protocol Buffer的性能相似/更好,因此我也将JSON引入了这个问题。


8
更新Django数据库以反映现有模型中的更改
我已经定义了一个模型,并通过创建了它的关联数据库manager.py syncdb。现在,我已经向模型添加了一些字段,我syncdb再次尝试了,但是没有输出出现。尝试从模板访问这些新字段时,出现“ No Such Column”异常,使我相信syncdb实际上并未更新数据库。这里正确的命令是什么?

4
Ubuntu 12.04中缺少Python.h
我使用以下命令在Ubuntu 12.04上安装了一个名为RYU的openflow控制器: sudo pip install ryu 我试图使用ryu-manager运行python文件,如下所示。 sudo ryu-manager simple_switch.py Traceback (most recent call last): File "/usr/local/bin/ryu-manager", line 19, in <module> import gevent ImportError: No module named gevent 然后,我尝试使用以下命令安装gevent: sudo pip install gevent gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c gevent/core.c -o build/temp.linux-x86_64-2.7/gevent/core.o gevent/core.c:4:20: fatal …

7
ctypes错误:libdc1394错误:无法初始化libdc1394
我正在尝试将程序编译为一个共享库,可以在使用ctypes的Python代码中使用该共享库。 使用以下命令,库可以正常编译: g++ -shared -Wl,-soname,mylib -O3 -o mylib.so -fPIC [files] `pkg-config --libs --cflags opencv` 但是,当我尝试使用ctypes导入它时 from ctypes import * mylib = CDLL("/path/to/mylib.so") print mylib.test() // Expected output: Hello World 我收到以下错误: libdc1394 error: Failed to initialize libdc1394 这是怎么回事?

2
为什么zeromq在本地主机上不起作用?
该代码非常有用: import zmq, json, time def main(): context = zmq.Context() subscriber = context.socket(zmq.SUB) subscriber.bind("ipc://test") subscriber.setsockopt(zmq.SUBSCRIBE, '') while True: print subscriber.recv() def main(): context = zmq.Context() publisher = context.socket(zmq.PUB) publisher.connect("ipc://test") while True: publisher.send( "hello world" ) time.sleep( 1 ) 但是这段代码不起作用: import zmq, json, time def recv(): context = zmq.Context() subscriber = …

8
安装MySQL-python
尝试在Ubuntu / Linux Box上安装MySQL-python时出现以下故障,下面是问题所在,sh: mysql_config: not found 有人可以建议我怎么做吗? rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded Running setup.py egg_info for package MySQL-python sh: mysql_config: not found Traceback (most recent call last): File "<string>", line 14, in <module> File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module> metadata, options = get_config() …
69 python  mysql 

2
通过docker-compose在Pycharm上运行Python控制台
我在通过docker-compose使用远程python解释器运行pycharm时遇到一些问题。当我按下运行按钮时,除Python控制台外,其他所有功能都运行良好,仅显示以下消息: “错误:无法从docker-compose输出中找到服务“ web”的容器名称” 我真的不明白,如果我docker-compose.yml提供web服务,为什么它会让我继续显示。 有什么帮助吗? 编辑: docker-compose.yml version: '2' volumes: dados: driver: local media: driver: local static: driver: local services: beat: build: Docker/beat depends_on: - web - worker restart: always volumes: - ./src:/app/src db: build: Docker/postgres ports: - 5433:5432 restart: always volumes: - dados:/var/lib/postgresql/data jupyter: build: Docker/jupyter command: jupyter notebook …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.