I'm trying to format a file so that it can be inserted into a database, the file is originally compressed and arround 1.3MB big.
Each line looks something like this:
398,%7EAnoniem+001%7E,543,480,7525010,1775,0
This is how the code looks like that parses this file:
Village = gzip.open(Root+'\\data'+'\\' +str(Newest_Date[0])+'\\...
I was writing a script to inspect python's version on my system and I've noticed that python -V writes to the error stream, while python -h, for instance, uses the standard output. Is there a good reason for this behavior?
...
Hey there, was wondering if anyone could help a newbie on SQL and Python. I thought I had a pretty decent grasp of it, however something odd happened recently.
Here is the the following code snipped from a larger portion:
try:
self.db.query("SELECT * FROM account WHERE email = '{0}' AND pass = '{1}'".format(self.mail.strip(self...
I have 2 lists each of equal size and am interested to combine these two lists and write it into a file.
alist=[1,2,3,5]
blist=[2,3,4,5]
--the resulting list should be like
[(1,2), (2,3), (3,4), (5,5)]
After that i want that to be written it to a file. How can i accomplish this?
...
I'm playing around with list comprehensions and I came across this little snippet on another site:
return ''.join([`num` for num in xrange(loop_count)])
I spent a few minutes trying to replicate the function (by typing) before realising the num bit was breaking it.
What does enclosing a statement in those characters do? From what I c...
i am trying to store some method callbacks but referring to it will keep the bound object alive, so i tried to keep a weakref to method but that doesn't seems to be possible?
so
Why can't i keep a weak ref. to method (see example below)
What is the best way to keep method ref? any thing in standard lib? Or I will have to keep function...
I have data which in theory is a list, but historically has been input by the user as a free form text field. Now I need to separate each item of the list so that each element can be analysed.
Simplified examples of my data as input by users:
one, two, three, four, five
one. two. three, four. five.
"I start with one, then do two, ma...
Not really too sure how to word this question, therefore if you don't particularly understand it then I can try again.
I have a file called example.txt and I'd like to import this into my Python program. Here I will do some calculations with what it contains and other things that are irrelevant.
Instead of me importing this file, goin...
Using Python module re, how to get the equivalent of the "\w" (which matches alphanumeric chars) WITHOUT matching the numeric characters (those which can be matched by "[0-9]")?
Notice that the basic need is to match any character (including all unicode variation) without numerical chars (which are matched by "[0-9]").
As a final note,...
I want to get the list of running processes on the Mac, similar to what you get from 'ps -ea'
I have tried os.popen('ps -ea') but this only lists a small subset of the processes, presumably those owned by the owning shell.
Other options I have tried are
'sh -c /bin/ps -ea'
'bash -c /bin/ps -ea'
'csh -c /bin/ps -ea'
Running as root vi...
I have a program which takes a long time to complete. I would like
it to be able to catch SIGINT (ctrl-c) and call the self.save_work() method.
As it stands, my signal_hander() does not work since
self is not defined by the time the program reaches signal_handler().
How can I set it up so self.save_work gets called after a SIGINT?
#...
Interestingly it also works on the shell.
[MY code which calls Model.objects.get_or_create(...)]
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 123, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 308, in ge...
I have 2 dimensional list created at runtime (the number of entries in either dimension is unknown). For example:
long_list = [ [2, 3, 6], [3, 7, 9] ]
I want to iterate through it by getting the ith entry from each list inside the long_list:
for entry in long_list.iter():
#entry will be [2, 3] then [3, 7] then [6, 9]
I know tha...
I'd like to:
Check a key / value at position i
Check to see if key / value contains a string
delete / store in another variable either the key / value
The equivelant of this Java code:
//Some list...
ArrayList<String> example;
...
//Index into data structure
example.get(i);
//Check for some string...
if (example.get(i).contains("som...
Hi,
I have a python (well, it's php now but we're rewriting) function that takes some parameters (A and B) and compute some results (finds best path from A to B in a graph, graph is read-only), in typical scenario one call takes 0.1s to 0.9s to complete. This function is accessed by users as a simple REST web-service (GET bestpath.php?f...
We are building out an app in Django and trying to nail down what the right ecommerce framework will be to work with in Django. We've heard of Satchmo. Any other suggestions on ways to approach ecommerce in Django that's clean, simple, cheap and easy to implement? Thanks!
...
Coming from a java background I'm used to having a bunch of properties files I can swap round at runtime dependent on what server I'm running on e.g. dev/production.
Is there a method in python to do similar, specifically on Google's App Engine framework?
At the minute I have them defined in .py files, obviously I'd like a better separ...
Basically, I have a lot of Python classes (representing our database schema) that look something like this:
from foo import xyz, b, c
class bar(object):
x = xyz()
y = b()
z = c()
...and I want to change it to this:
from foo import b, c
from baz import foobar
class bar(object):
x = foobar()
y = b()
z = c()
...
I'd like to fill MSWord bookmarks from a python script.
I can't find such functions in win32com(MSWord) or in PyUno(OpenOffice).
Does anyone know how to use bookmarks from Python?
...
How do I use poplib, and download mails as message instances from email.Message class from email module in Python?
I am writing a program, which analyzes, all emails for specific information, storing parts of the message into a database. I can download the entire mail as text, howver walking through text searching for attachments is dif...