python-3.4

How to emulate socket.socketpair on Windows

痞子三分冷 提交于 2019-12-04 12:46:05
The standard Python function socket.socketpair is unfortunately not available on Windows (as of Python 3.4.1), how can I write a replacement that works on both Unix and Windows? Python 3.5 includes Windows support for socket.socketpair() . For Python 2.7+, you can use the backports.socketpair package (which I authored) on PyPi: import socket import backports.socketpair s1, s2 = socket.socketpair() import socket import errno def create_sock_pair(port=0): """Create socket pair. If socket.socketpair isn't available, we emulate it. """ # See if socketpair() is available. have_socketpair = hasattr

No module named utils error on compiling py file

╄→尐↘猪︶ㄣ 提交于 2019-12-04 12:24:56
问题 I'm trying to run a .py file through the command prompt using the command "python filename.py". I've already set the environment variables for python after I installed it, so I don't get any error when I type python. The file I'm running imports a few directories, all of which are preexistent in the same directory as the file I'm running, apart from the file web.py, which I can't seem to locate in the directory, so I'm assuming it's somewhere inside the python package, I have downloaded. But,

How to use sys.path_hooks for customized loading of modules?

廉价感情. 提交于 2019-12-04 11:34:56
I hope the following question is not too long. But otherwise I cannot explain by problem and what I want: Learned from How to use importlib to import modules from arbitrary sources? (my question of yesterday) I have written a specfic loader for a new file type (.xxx). (In fact the xxx is an encrypted version of a pyc to protect code from being stolen). I would like just to add an import hook for the new file type "xxx" without affecting the other types (.py, .pyc, .pyd) in any way. Now, the loader is ModuleLoader , inheriting from mportlib.machinery.SourcelessFileLoader . Using sys.path_hooks

How to get an input from user in Pygame and save it as a variable? [duplicate]

我的未来我决定 提交于 2019-12-04 09:53:35
问题 This question already has an answer here : How to get text input from user in Pygame? (1 answer) Closed last year . My idea is I want to take some input from user in the game like name of user, then I want to put it on the screen.Maybe before starting the game or middle of the game, it matter. I tried InputBox etc. but it's not working actually, I tried some of modules like it but none of working, some of them just typing my text on the screen thats all, what I want is I want to take that

Unable to install GDAL in python 3 using pip (clang failed with exit status 1)

依然范特西╮ 提交于 2019-12-04 09:21:31
After running sudo pip3.4 install gdal from terminal (Mac OS X Mavericks) I obtain an error message saying that the 'col_port.h' file was not found and displaying the following error: command '/user/bin/clang/ failed with exit status 1 (the full message is below). I have gdal 1.11 (the complete framework version downloaded from kingchaos.com) and the most recent version of the Xcode command line tools -Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Here is the error that I get after running the sudo pip3.4 install gdal command: /usr/bin/clang -fno-strict-aliasing -Werror

How to install requests module in python 3.4 version on windows?

﹥>﹥吖頭↗ 提交于 2019-12-04 09:08:44
问题 What command should I use in command prompt to install requests module in python 3.4 version ??? pip install requests is not useful to install requests module in python 3.4 version. Because while running the script below error is coming ImportError : no module named 'requests' 回答1: python -m pip install requests or py -m pip install requests 回答2: On Windows, I found navigating to my Python folder via CMD worked cd C:\Python36\ and then running the commandline: python -m pip install requests

Foreign Key Reference for Django in Admin

谁说我不能喝 提交于 2019-12-04 08:38:07
I have been trying to solve this issue in Django admin but still cannot find the documentation. In my models.py , I have the following code: from django.db import models class Post(models.Model): title = models.CharField(max_length=200) author = models.ForeignKey('Author', blank=False) class Author(models.Model): first_name = models.CharField('First Name',max_length=50) last_name = models.CharField('Last Name', max_length=50, blank=True) description = models.CharField(max_length=500, blank=True) def __str__(self): return (self.first_name + ' ' + self.last_name) and in admin.py from django

'b' character added when using numpy loadtxt

守給你的承諾、 提交于 2019-12-04 08:30:01
问题 I tried to create an array from a text file. I saw earlier that numpy had a method loadtxt , so I try it, but it add some junk character before each row... # my txt file .--``--. .--` `--. | | | | `--. .--` `--..--` # my python v3.4 program import numpy as np f = open('tile', 'r') a = np.loadtxt(f, dtype=str, delimiter='\n') print(a) # my print output ["b' .--``--. '" "b'.--` `--.'" "b'| |'" "b'| |'" "b'`--. .--`'" "b' `--..--` '"] What are these 'b' and double quotes ? And where do they come

Nuitka on Windows

旧城冷巷雨未停 提交于 2019-12-04 07:54:28
Having problems to compile hello-world.py using Nuitka on windows. The command I am using is: nuitka --standalone --portable --remove-output --recurse-all --python-version=3.4 hello_world.py The error is: WindowsError: [Error 2] The system cannot find the file specified: File "C:\Users\win_user\Anaconda3\Lib\site-packages\nuitka\build\SingleExe.scons", line 866: shell = False File "c:\Python27\lib\subprocess.py", line 709: errread, errwrite) File "c:\Python27\lib\subprocess.py", line 957: startupinfo) Same code compiles & runs fine on Linux. Same code runs fine in interpreter on windows. The

Unexpected error reading GML graph

∥☆過路亽.° 提交于 2019-12-04 06:31:41
I have downloaded the gml file which contains the dolphins social network . Some time ago I did some analysis on that network running python 3.4 and networkx 1.9 on a a Windows7 machine, but now I am running on a Arch linux machine (with the same version of python but with networkx 1.10 ) and found an issue when tried to read the file. This is the code used to read the file: import networkx as nx nx.read_gml("dolphins.gml") And this is the stack trace of the error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 2, in read_gml File "/usr/lib/python3