python-2.4

Python try/except not working

≯℡__Kan透↙ 提交于 2020-06-27 08:49:08
问题 Trying to get the try/except statement working but having problems. This code will take a txt file and copy the file that is in location row 0 to location of row 1. It works however if i change one of the paths to invalid one it generates an error ftplib.error_perm however the except command is not picking up and everything stops. What am i doing wrong? Python 2.4 import csv import operator import sys import os import shutil import logging import ftplib import tldftp def docopy(filename): ftp

How do I setup virtualenv environments for Python 2.4 and 2.5 versions on Windows?

时间秒杀一切 提交于 2020-06-09 10:27:58
问题 I have this installed on Windows 7 Python 2.7.6 (my default, with virtualenv installed) Python 2.4.4 Python 2.5.4 Python 2.6.6 Python 3.3.3 virtualenv 1.10.1 I want to test code on all of those python installations. (Similar quesion Multiple python versions using virtualenv -p (and virtualenvwrapper-win) on Windows does not answer this.) This is what I tried so far: Python 2.4 gives a syntax error (creates an environment but with PY27 installed!): >virtualenv -p c:\apps\Python24\python.exe

How do I setup virtualenv environments for Python 2.4 and 2.5 versions on Windows?

ぐ巨炮叔叔 提交于 2020-06-09 10:27:39
问题 I have this installed on Windows 7 Python 2.7.6 (my default, with virtualenv installed) Python 2.4.4 Python 2.5.4 Python 2.6.6 Python 3.3.3 virtualenv 1.10.1 I want to test code on all of those python installations. (Similar quesion Multiple python versions using virtualenv -p (and virtualenvwrapper-win) on Windows does not answer this.) This is what I tried so far: Python 2.4 gives a syntax error (creates an environment but with PY27 installed!): >virtualenv -p c:\apps\Python24\python.exe

Why can I only use a reader object once?

↘锁芯ラ 提交于 2020-01-13 21:42:03
问题 I'm trying to read a column of numbers into python with the csv module. I get the following behavior: import csv f=open('myfile.txt','r') reader=csv.reader(f) print [x for x in reader] # This outputs the contents of "myfile.txt", # broken up by line. print [x for x in reader] # This line prints an empty list. Why is this happening? Is there some reason the reader object can only be used once? 回答1: Same reason here: >>> li=[1,2,3,4,5,6,7,8,9] >>> it=iter(li) >>> print [x for x in it], [x for x

Why can I only use a reader object once?

喜欢而已 提交于 2020-01-13 21:39:11
问题 I'm trying to read a column of numbers into python with the csv module. I get the following behavior: import csv f=open('myfile.txt','r') reader=csv.reader(f) print [x for x in reader] # This outputs the contents of "myfile.txt", # broken up by line. print [x for x in reader] # This line prints an empty list. Why is this happening? Is there some reason the reader object can only be used once? 回答1: Same reason here: >>> li=[1,2,3,4,5,6,7,8,9] >>> it=iter(li) >>> print [x for x in it], [x for x

Error 13 Permission Denied Python

懵懂的女人 提交于 2020-01-03 04:35:12
问题 I am trying to write a code to compare directories (sub directories and files within), then copy the contents of the other directory (files only including files in the sub-directories) to the other directory. I imported everything then I have this: dst = "C:/somefolder" path = "C:/otherplace" compare = filecmp.dircmp(path,dst) ans = compare.right_only for fil in ans: if len(ans)>0: shutil.copy2(dst,path) i have tried other routes using os.listdir but i always seem to end up at the error

Change in Python built in round() function between 2.4 and 2.7

做~自己de王妃 提交于 2020-01-02 05:48:05
问题 Has the built in round() function in Python changed between 2.4 and 2.7? Python 2.4: Python 2.4.6 (#1, Feb 12 2009, 14:52:44) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f = 1480.39499999999998181010596454143524169921875 >>> round(f,2) 1480.4000000000001 >>> Python 2.7: Python 2.7.1 (r271:86832, May 13 2011, 08:14:41) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 Type "help", "copyright", "credits" or "license

JSON module for python 2.4?

久未见 提交于 2019-12-31 18:55:11
问题 I'm accustomed to doing import json in Python 2.6, however I now need to write some code for Python 2.4. Is there a JSON library with a similar interface that is available for Python 2.4? 回答1: The json module in Python 2.6 is mostly the same as the simplejson third-party module, which is available for Python 2.4 as well. You can just do: try: import json except ImportError: import simplejson as json 回答2: Now, a few years later, simplejson does only support python 2.5+. No more simplejson for

Saving stdout from subprocess.Popen to file, plus writing more stuff to the file

廉价感情. 提交于 2019-12-30 00:27:14
问题 I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to a file. Because the output is sometimes large enough to overwhelm subprocess.PIPE, causing the script to hang, I send the stdout directly to the log file. I want to have my script write something to the beginning and end of the file, and between the two subprocess.Popen calls. However, when I look at my log file, anything

Timing out urllib2 urlopen operation in Python 2.4

假装没事ソ 提交于 2019-12-24 10:05:08
问题 I've just inherited some Python code and need to fix a bug as soon as possible. I have very little Python knowledge so please excuse my ignorance. I am using urllib2 to extract data from web pages. Despite using socket.setdefaulttimeout(30) I am still coming across URLs that hang seemingly indefinitely. I want to time out the extraction and have got this far after much searching the web: import socket socket.setdefaulttimeout(30) reqdata = urllib2.Request(urltocollect) def handler(reqdata): ?