Python provides csv.DictWriter for outputting CSV to a file.
What is the simplest way to output CSV to a string or to stdout?
For example, given a 2D array like this:
[["a b c", "1,2,3"],
["i \"comma-heart\" you", "i \",heart\" u, too"]]
return the following string:
"a b c, \"1, 2, 3\"\n\"i \"\"comma-heart\"\" you\", \"i \"\",heart...
I'm trying to pick up Python. As part of the learning process I'm porting a project I wrote in Java to Python. I'm at a section now where I have a list of CSV headers of the form:
headers = [a, b, c, d, e, .....]
and separate lists of groups that these headers should be broken up into, e.g.:
headers_for_list_a = [b, c, e, ...]
header...
i have text file which i want to erase in C++ and python . How to do it?Do i have to assign the file pointer to a null value string?
...
http://github.com/creationix/node-git
Reading blog posts from a repository. If not, how would you do it (chaching, ...)?
...
I got many, many files to be uploaded to the server, and I just want a way to avoid duplicates.
Thus, generating a unique and small key value from a big string seemed something that a checksum was intended to do, and hashing seemed like the evolution of that.
So I was going to use hash md5 to do this. But then I read somewhere that "MD...
Hello.
I'm having a problem with the module subprocess.
I'm running a script from python through:
subprocess.Popen('./run_pythia.sh',shell=True).communicate()
and sometimes it just blocks and it doesn't finish to execute the script. Before I was using .wait() instead of .communicate() but then because of this:
http://dcreager.net/2...
I'm consuming (via urllib/urllib2) an API that returns XML results. The API always returns the total_hit_count for my query, but only allows me to retrieve results in batches of, say, 100 or 1000. The API stipulates I need to specify a start_pos and end_pos for offsetting this, in order to walk through the results.
Say the urllib reques...
I am having some trouble getting appscript installed on OS/X 10.6.3 / Python 2.6.1. When I issue
sudo easy_install appscript
I get "unable to execute gcc-4.2: No such file or directory". Even when I do export CC=/Developer/usr/bin/gcc-4.2 (a valid gcc-4.2 executable), easy_install barks.
What could be the issue?
Disclaimer: OS/X new...
This question concerns two implementations of counters which are intended to scale without sharding (with a tradeoff that they might under-count in some situations):
http://appengine-cookbook.appspot.com/recipe/high-concurrency-counters-without-sharding/ (the code in the comments)
http://blog.notdot.net/2010/04/High-concurrency-counter...
I currently have setup a Python script that uses feedparser to read a feed and parse it. However, I have recently come across a problem with the date parsing. The feed I am reading contains <modified>2010-05-05T24:17:54Z</modified> - which comes up in Python as a datetime object - 2010-05-06 00:17:54. Notice the discrepancy: the feed ent...
I'm 99+% still using python 2.x, but I'm trying to think ahead to the day when I switch.
So, I know that using comparison operators (less/greater than, or equal to) on heterogeneous types that don't have a natural ordering is no longer supported in python3.x -- instead of some consistent (but arbitrary) result we raise TypeError instead...
I have 4 reasonably complex r scripts that are used to manipulate csv and xml files. These were created by another department where they work exclusively in r.
My understanding is that while r is very fast when dealing with data, it's not really optimised for file manipulation. Can I expect to get significant speed increases by conv...
Hey all-
I'm doing some performance-critical Python work and want to create a function that removes a few elements from a list if they meet certain criteria. I'd rather not create any copies of the list because it's filled with a lot of really large objects.
Functionality I want to implement:
def listCleanup(listOfElements):
i =...
How can I find as many date patterns as possible from a text file by python? The date pattern is defined as:
dd mmm yyyy
^ ^
| |
+---+--- spaces
where:
dd is a two digit number
mmm is three-character English month name (e.g. Jan, Mar, Dec)
yyyy is four digit year
there are two spaces as separators
Thanks!
...
heya,
We have an Excel file with a worksheet containing people records.
1. Phone Number Sanitation
One of the fields is a phone number field, which contains phone numbers in the format e.g.:
+XX(Y)ZZZZ-ZZZZ
(where X, Y and Z are integers).
There are also some records which have less digits, e.g.:
+XX(Y)ZZZ-ZZZZ
And others with ...
Using Django templates in Google App Engine (on Python), is it possible to compare a template variable to an integer in an {% if %} block?
views.py:
class MyHandler(webapp.RequestHandler):
def get(self):
foo_list = db.GqlQuery(...)
...
template_values['foos'] = foo_list
template_values['foo_count'] =...
Hey all-
I'm using ParallelPython to develop a performance-critical script. I'd like to share one value between the 8 processes running on the system. Please excuse the trivial example but this illustrates my question.
def findMin(listOfElements):
for el in listOfElements:
if el < min:
min = el
import pp
min...
This is Part 2 of this question and thanks very much for David's answer. What if I need to extract dates which are bounded by two keywords?
Example:
text = "One 09 Jun 2011 Two 10 Dec 2012 Three 15 Jan 2015 End"
Case 1 bounding keyboards: "One" and "Three"
Result expected: ['09 Jun 2011', '10 Dec 2012']
Case 2 bounding keyboards: "Tw...
I am using python lxml library to parse html pages:
import lxml.html
# this might run indefinitely
page = lxml.html.parse('http://stackoverflow.com/')
Is there any way to set timeout for parsing?
...
Hi,
I have a raster file (basically 2D array) with close to a million points. I am trying to extract a circle from the raster (and all the points that lie within the circle. Using ArcGIS is exceedingly slow for this. Can anyone suggest any image processing library that is both easy to learn and powerful and quick enough for something li...