I am trying to merge three fields in each line of a CSV file using Python. This would be simple, except some of the fields are surrounded by double quotes and include commas. Here is an example:
,,Joe,Smith,New Haven,CT,"Moved from Portland, CT",,goo,
Is there a simple algorithm that could merge fields 7-9 for each line in this format...
Trying to understand how you're supposed to read files in python. This is what I've done and it isn't working quite properly:
import os.path
filename = "A 180 mb large file.data"
size = os.path.getsize(filename)
f = open(filename, "r")
contents = f.read()
f.close()
print "The real filesize is", size
print "The read filesize is", len(...
I'm looking to set up my development environment at home for writing Windows applications in Python.
For my first piece, I'm writing a simple, forms-based application that stores data input as XML (and can read that information back.) I do want to set up the tools I'd use professionally, though, having already done a round of didactic p...
I can check for a module in Python doing something like:
try:
import some_module
except ImportError:
print "No some_module!"
But I don't want to use try/except. Is there a way to accomplish this? (it should work on Python 2.5.x.)
Note: The reason for no using try/except is arbitrary, it is just because I want to know if there is ...
python purple says it needs dbms and debhelper in order to run, but I don't run debian. Is there a way to get this running on a different linux? or in cygwin?
...
I have now bumped into this problem twice recently and am curious if there is a solution.
So I have a module that confilcts with a python builtin. For example, say I have a myapp.email module defined in myapp/email.py.
Now anywhere in my code I can reference myapp.email just fine. However, I need to reference the builtin Python email...
Is there a way to limit amount of data downloaded by python's urllib2 module ? Sometimes I encounter with broken sites with sort of /dev/random as a page and it turns out that they use up all memory on a server.
...
I have a model like this:
class Group(db.Model):
name = db.StringProperty()
description = db.TextProperty()
Sometimes when executing queries like:
groups = Group.all().order("name").fetch(20)
or
groups = Group.all()
I'm getting error massages like this:
Traceback (most recent call last):
File "/opt/google_appengine/google/a...
If you don't know, python turtle is an application for helping people learn python.
You are given a python interpreter and an onscreen turtle that you can pass directions to using python.
go(10) will cause the turtle to move 10 pixels
turn(10) will cause it to turn 10 degrees clockwise
now look at this
code:
import random
while(1)...
I have smth like this:
class X():
def __init__(self):
self.__name = None
def _process_value(self, value):
# do smth
pass
def get_name(self):
return self.__name
def set_name(self, value):
self.__name = self._process_value(value)
name = property(get_name, set_name)
Can I re...
I'm running a Python server with mod_python, and I've run into some issues with configuration variables. This is actually two questions rolled into one, because I think they are highly related:
I need a way to configure variables that will be available in Python while running. I currently just have a module that sets some name-value ...
Construct is a DSL implemented in Python used to describe data structures (binary and textual). Once you have the data structure described, construct can parse and build it for you. Which is good ("DRY", "Declarative", "Denotational-Semantics"...)
Usage example:
# code from construct.formats.graphics.png
itxt_info = Struct("itxt_info",...
Is there a cross platform way to get the monitor's refresh rate in python (2.6)? I'm using Pygame and PyOpenGL, if that helps.
I don't need to change the refresh rate, I just need to know what it is.
...
Im looking for a way to present a flexible font, that will increase and decrease in size according to to the size of the screen resolution. I want to be able to do this without the HTML window class. Is there a way? I thought I've done quite a bit of googling without success.
EDIT
This seems a good question, I changed the title to r...
I have a structure such this works :
import a.b.c
a.b.c.foo()
and this also works :
from a.b import c
c.foo()
but this doesn't work :
from a import b.c
b.c.foo()
nor does :
from a import b
b.c.foo()
How can I do the import so that b.c.foo() works?
...
I have a excel file. With many columns . I need to make multiple files using this
Eg: 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2. So these are the excel columns with each having many rows. I need one file which would contain 0 0 0 0 0 1 1 1 1 1 2 then second will contain only the second no 0 0 0 0 0 1 1 1 1 1 2....similarly the ot...
Hi all,
I am interested to trigger a certain action upon receiving an email from specific
address with specific subject. In order to be able to do so I need to implement
monitoring of my mailbox, checking every incoming mail (in particular, i use gmail).
what is the easiest way to do that?
Thank you,
Sasha
...
I have a string of this form
s='arbit'
string='%s hello world %s hello world %s' %(s,s,s)
All the %s in string have the same value (i.e. s).
Is there a better way of writing this? (Rather than listing out s three times)
...
Hello,
When I try to automatically download a file from some webpage using Python,
I get Webpage Dialog window (I use IE). The window has two buttons, such as 'Continue' and 'Cancel'. I cannot figure out how to click on the Continue Button. The problem is
that I don't know how to control Webpage Dialog with Python. I tried to use
win...
What is the recommended way to terminate unexpectedly long running threads in python ? I can't use SIGALRM, since
Some care must be taken if both
signals and threads are used in the
same program. The fundamental thing to
remember in using signals and threads
simultaneously is: always perform
signal() operations in the main ...