Ok, I am trying to filter a list/dictionary passed to me and "clean" it up a bit, as there are certain values in it that I need to get rid of.
So, if it's looking like this:
"records": [{"key1": "AAA", "key2": "BBB", "key3": "CCC", "key4": "AAA"...}]
How would I quickly and easily run through it all and replace all values of "AAA" wi...
Im attempting to crop a pretty high res image and save the result to make sure its completed. However I keep getting the following error regardless of how I use the save method: SystemError: tile cannot extend outside image
from PIL import Image
# size is width/height
img = Image.open('0_388_image1.jpeg')
box = (2407, 804, 71, 796)
a...
Hi,
Is there a way to make a variable non-inheritable in python? Like in the following example: B is a subclass of A, but I want it to have its own SIZE value.
Could I get an Error to be raised (on __init__ or on getsize()) if B doesn't override SIZE?
class A:
SIZE = 5
def getsize(self): return self.SIZE
class B(A): pass
Edit...
I am looking for a good and well developed library for geometrical manipulations and evaluations in python, like:
evaluate the intersection between two lines in 2D and 3D (if present)
evaluate the point of intersection between a plane and a line, or the line of intersection between two planes
evaluate the minimum distance between a lin...
I have a regular list comprehension to load all lines of a file in a list
f = open('file')
try:
self._raw = [L.rstrip('\n') for L in f]
finally:
f.close()
Now I'd like to insert in the list each line 'n' times on the fly. How to do it inside the list comprehension ?
Tnx
...
I'm getting a getaddress error and after doing some sleuthing, it looks like it might be my corporate intranet not allowing the connection (I'm assuming due to security, although it is strange that IE works but won't allow Python to open a url). Is there a safe way to get around this?
Here's the exact error:
Traceback (most recent cal...
Hi, guys. I'm trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I'm trying to do.
What I'm doing is this. I have a list, A, and I have a function f which takes an item and returns a list. I can use a list comprehension to convert everything in A like so;
[f(a) for a in A]
But...
Is there a way to detect whether sys.stdout is attached to a console terminal or not? For example, I want to be able to detect if foo.py is run via:
$ python foo.py # user types this on console
OR
$ python foo.py > output.txt # redirection
$ python foo.py | grep .... # pipe
The reason I ask this question is that I want to make su...
I don't know if I'm thinking of this the right way, and perhaps somebody will set me straight.
Let's say I have a models.py that contains this:
class Order(models.Model):
customer = models.foreignKey(Customer)
total = models.charField(max_length=10)
has_shipped = models.booleanField()
class Product(models.Model):
sku = models....
A specific example: becoming familiar with django's project source code (core, contrib, utils, etc.). Example of a useful tool: ctags - it allows you to "jump" to the file+location where a function/method is defined. Wondering about other tools that developers use (example: is there a tool that given a function x(), lists the functions...
I have a utc timestamp in the IS8601 format and am trying to convert it to unix time. This is my console session:
In [9]: mydate
Out[9]: '2009-07-17T01:21:00.000Z'
In [10]: parseddate = iso8601.parse_date(mydate)
In [14]: ti = time.mktime(parseddate.timetuple())
In [25]: datetime.datetime.utcfromtimestamp(ti)
Out[25]: datetime.datetim...
I'm wondering if there's a reason that there's no first(iterable) in the Python built-in functions, somewhat similar to any(iterable) and all(iterable) (it may be tucked in a stdlib module somewhere, but I don't see it in itertools). first would perform a short-circuit generator evaluation so that unnecessary (and a potentially infinite ...
I am trying to learn Python, however I tried to run a script that is LITERALLY just:
print "Hello, World!"
And I get this error:
File "hello.py", line 1
print "Hello, World!"
^
SyntaxError: invalid syntax
What is going on!?
...
In Python, using calendar.timegm(), I get a 10 digit result for a unix timestamp. When I put this into Javscript's setTime() function, it comes up with a date in 1970. It evidently needs a unix timestamp that is 13 digits long. How can this happen? Are they both counting from the same date?
How can I use the same unix timestamp between...
Hi,
I am having issues with trying to convert an UTF-8 string to unicode. I get the error.
UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128)
I tried wrapping this in a try/except block but then google was giving me a system administrator error which was one line.
Can someone sugges...
Developing a project of mine I realize I have a need for some level of persistence across sessions, for example when a user executes the application, changes some preferences and then closes the app. The next time the user executes the app, be it after a reboot or 15 minutes, I would like to be able to retain the preferences that had be...
I tried to read a file in a view like this:
def foo(request):
f = open('foo.txt', 'r')
data = f.read()
return HttpResponse(data)
I tried to place the foo.txt in almost every folder in the project but it still returns
[Errno 2] No such file or directory:
'foo.txt'
So does anybody knows how to open a file in app engi...
This is my code :
print '1'
from Tkinter import *
print '2'
class myApp:
print '3'
def __init__(self,parent):
print '4'
## self.myparent = parent line1
print '11'
self.myContainer1 = Frame(parent)
print '12'
self.myContainer1.pack()
print '13'
self.button1...
See the title of this question. I want to play with the exception raised in the last command. _ didn't help me. Is there anything like that?
...
Hi, all,
I am trying to setup emacs for python development.
From what I read, it is recommended to use python-mode.el rather than the default python.el from Emacs 22.3. So I embark on the new adventure.
From what I understand, python-mode has the several dependencies, so I need to install rope, ropemode and ropemacs. Then on top of t...