8) reading and writing to files in Python

I'm having some brain failure in understanding reading and writing text to a file (Python 2.4). # The string, which has an a-acute in it. ss = u'Capitxe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) ("u'Capitxe1n'", "'Capitxc3xa1n'") print ss, ss8 print >> open('f1','w'), ss8 >>> file('f1').read() 'Capitxc3xa1nn' So I type in Capitxc3xa

8)用Python读写文件

理解阅读和写文本到文件(Python 2.4)时,我遇到了一些大脑故障。 # The string, which has an a-acute in it. ss = u'Capitxe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8) (“u'Capit xe1n'”,“'Capit xc3 xa1n'”) print ss, ss8 print >> open('f1','w'), ss8 >>> file('f1').read() 'Capitxc3xa1nn' 所以我在文件f2中输入Capitxc3xa1n到我最喜欢的编辑器中。 然后: >>

2 lists, and finding maximum product from 2 lists

I have two lists made of numbers(integers); both have 2 million unique elements. I want to find number a from list 1 and b from list 2, that - 1)a*b should be maximized. 2)a*b has to be smaller than certain limit. here's what I came up with: maxpq = 0 nums = sorted(nums, reverse=True) nums2 = sorted(nums2, reverse=True) for p in nums: n = p*dropwhile(lambda q: p*q>sqr, nums2).nex

2列表,并从2个列表中查找最大产品

我有两个由数字组成的列表(整数); 都有200万个独特的元素。 我想查找列表1中的数字a和列表2中的b, 1)a*b should be maximized. 2)a*b has to be smaller than certain limit. 这是我想到的: maxpq = 0 nums = sorted(nums, reverse=True) nums2 = sorted(nums2, reverse=True) for p in nums: n = p*dropwhile(lambda q: p*q>sqr, nums2).next() if n>maxpq: maxpq=n print maxpq 有什么建议么

Can't pip ,the command on mac , search packages in local path not on the net

I have already download some packages, but Terminal always search those packages on the net when i use the command pip install package for instance, i want to install pygame (pygame-1.9.1-release………….dmg)which already in my mac and the path would be /Users/**/Downloads/ Install pygame: $ pip install pygame Terminal show the following message to me: Downloading/unpacking pygame-1.9.1

不能点击,在mac上的命令,在本地路径搜索包不在网上

我已经下载了一些软件包, 但终端总是在我使用该命令时在网上搜索这些软件包 pip安装包 例如, 我想安装pygame(pygame-1.9.1-release ............ .dmg),它已经在我的mac中,路径是/ Users / ** / Downloads / 安装pygame: $ pip安装pygame 终端向我显示以下消息:下载/解压缩pygame-1.9.1无法获取索引基URL https://pypi.python.org/simple/找不到满足要求的任何下载pygame-1.9.1清理。 ..没有发现任何发现p

Python packages not installing in virtualenv using pip

I'm having trouble installing twisted pip --version pip 1.1 from /home/chris/GL/GLBackend/glenv/lib/python2.7/site-packages/pip-1.1-py2.7.egg (python 2.7) Create a virtual environment chris@chris-mint ~/GL/GLBackend $ sudo virtualenv -p python2.7 glenv Running virtualenv with interpreter /usr/bin/python2.7 New python executable in glenv/bin/python2.7 Also creating executable in glenv/bi

Python包不使用pip在virtualenv中安装

我在安装扭曲时遇到问题 pip --version pip 1.1 from /home/chris/GL/GLBackend/glenv/lib/python2.7/site-packages/pip-1.1-py2.7.egg(python 2.7) 创建一个虚拟环境 chris@chris-mint ~/GL/GLBackend $ sudo virtualenv -p python2.7 glenv 使用解释器/usr/bin/python2.7运行virtualenv glenv / bin / python2.7中的新python可执行文件同时在glenv / bin / python中创建可执行文件安装distribute ................ ...

A Pythonic way to read CSV with row and column headers

Let's have a CSV table with row and column headers, eg: , "Car", "Bike", "Boat", "Plane", "Shuttle" "Red", 1, 7, 3, 0, 0 "Green", 5, 0, 0, 0, 0 "Blue", 1, 1, 4, 0, 1 I want to get row and column headers, ie: col_headers = ["Car", "Bike", "Boat", "Plane", "Shuttle"] row_headers = ["Red", "Green", "Blue"] data = [[1, 7, 3, 0, 0], [5, 0, 0, 0, 0], [1, 1, 4, 0, 1]] Of course I

用行列标题读取CSV的Pythonic方法

我们来看一个带有行和列标题的CSV表格,例如: , "Car", "Bike", "Boat", "Plane", "Shuttle" "Red", 1, 7, 3, 0, 0 "Green", 5, 0, 0, 0, 0 "Blue", 1, 1, 4, 0, 1 我想获得行和列标题,即: col_headers = ["Car", "Bike", "Boat", "Plane", "Shuttle"] row_headers = ["Red", "Green", "Blue"] data = [[1, 7, 3, 0, 0], [5, 0, 0, 0, 0], [1, 1, 4, 0, 1]] 当然,我可以做类似的事情 import csv with op

Separate vassal logging with uWSGI emperor mode

I'm running uWSGI 1.9.17 in emperor mode (with the default config from Trusty's uwsgi-emperor package), and the emperor's logs are piping into /var/log/uwsgi/emperor.log. The emperor.log file also contains all the stdout/err combined from each vassal, and I can't seem to get any of the vassals to log to a separate file. I've tried using the logto = /var/uwsgi/apps/vassal1.l

用uWSGI皇帝模式分开vassal记录

我在emperor模式下运行uWSGI 1.9.17(使用Trusty的uwsgi-emperor包的默认配置),并且将皇帝的日志输入到/var/log/uwsgi/emperor.log中。 emperor.log文件还包含从每个vassal组合的所有stdout / err,并且我似乎无法获得任何vassals来登录到单独的文件。 我试过使用logto = /var/uwsgi/apps/vassal1.log配置选项,但无济于事。 有没有人有任何想法如何让vassals记录到单独的文件? 为了从皇帝中分离诸侯记录,你可以使用

UWSGI not running Django project

I am trying to run this code uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data I am following this tutorial. But I am getting the below output. *** Starting uWSGI 2.0.11.2 (64bit) on [Thu Nov 5 04:42:12 2015] *** compiled with version: 4.8.4 on 04 November 2015 16:32:43 os: Linux-3.16.0-52-generic #71~14.04.1-Ubuntu SMP Fri Oct 23 17:24:53 UTC 2015 nodename: myproject machin

UWSGI没有运行Django项目

我正在尝试运行此代码 uwsgi --emperor / etc / uwsgi / vassals --uid www-data --gid www-data 我正在学习这个教程。 但是我得到了下面的输出。 *** Starting uWSGI 2.0.11.2 (64bit) on [Thu Nov 5 04:42:12 2015] *** compiled with version: 4.8.4 on 04 November 2015 16:32:43 os: Linux-3.16.0-52-generic #71~14.04.1-Ubuntu SMP Fri Oct 23 17:24:53 UTC 2015 nodename: myproject machine: x86_64 clock source

Cant get permissions right to run uWSGI Emperor

I'm having a hell of a time trying to get Ubuntu + uWSGI + nginx running as my web server. Below are my configs, and the information that is in my emperor.log file: nginx config: server { listen 80; server_name localhost; charset utf-8; client_max_body_size 5M; location / { try_files $uri @cc; } location @cc { include uwsgi_params;

不能获得运行uWSGI Emperor的权限

我有一段时间试图让Ubuntu + uWSGI + nginx作为我的Web服务器运行。 以下是我的配置,以及我的emperor.log文件中的信息: nginx配置: server { listen 80; server_name localhost; charset utf-8; client_max_body_size 5M; location / { try_files $uri @cc; } location @cc { include uwsgi_params; uwsgi_pass unix:/tmp/cc/cc_uwsgi.sock; } } uwsgi配

Running multiple uwsgi python versions

I'm trying to deploy django with uwsgi, and I think I lack understanding of how it all works. I have uwsgi running in emperor mode, and I'm trying to get the vassals to run in their own virtualenvs, with a different python version. The emperor configuration: [uwsgi] socket = /run/uwsgi/uwsgi.socket pidfile = /run/uwsgi/uwsgi.pid emperor = /etc/uwsgi.d emperor-tyrant = true master = tr

运行多个uwsgi python版本

我试图用uwsgi部署django,我想我对它的工作原理缺乏了解。 我有uwsgi在皇帝模式下运行,我试图让vassals在自己的virtualenvs中运行,使用不同的python版本。 皇帝配置: [uwsgi] socket = /run/uwsgi/uwsgi.socket pidfile = /run/uwsgi/uwsgi.pid emperor = /etc/uwsgi.d emperor-tyrant = true master = true autoload = true log-date = true logto = /var/log/uwsgi/uwsgi-emperor.log 附庸: uid=django gid=django v

uWSGI Server log…permission denied to read file...which file?

I have a server running Django/Nginx/uWSGI with uWSGI in emperor mode, and the error log for it (the vassal-level error log, not the emperor-level log) has a continual permissions error every time it spawns a new worker, like so: Tue Jun 26 19:34:55 2012 - Respawned uWSGI worker 2 (new pid: 9334) Error opening file for reading: Permission denied Problem is, I don't know what file it'

uWSGI服务器日志...权限被拒绝读取文件...哪个文件?

我有一台服务器在皇帝模式下运行带有uWSGI的Django / Nginx / uWSGI,并且它的错误日志(附件级错误日志,而不是皇帝级日志)每次产生一个新的worker时都会有一个连续的权限错误,像这样: 星期二6月26日19:34:55 - 重生的uWSGI工作人员2(新的pid:9334) 打开读取文件时出错:权限被拒绝 问题是,我不知道它打开时有什么问题, 它不是日志文件,显然,因为我正在看它,而且它没有问题写入。 任何方式来找出? 我在Ub