In python you can do something like this to import a module using a string filename, and assign its namespace a variable on the local namespace.
x = __import__(str)
I'm wondering if there is a related function that will take take a string of Python code, instead of a path to a file with Python code, and return its namespace as a varia...
I'm doing something stupid, and I'm not sure what it is. I have a the following urls.py in the root of my django project:
from django.conf.urls.defaults import *
from django.conf import settings
urlpatterns = patterns('',
(r'^$', include('preview_signup.urls')),
)
In my preview_signup module (django app) I have the following url...
I have a python script bundled into a application (I'm on a mac) and have the application set to be able to open .zip files. But when I say "open foo.zip with bar.py" how do I access the file that I have passed to it?
Additional info:
Using tkinter.
What's a good way to debug this, as there is no terminal to pass info to?
...
I need to create a webserver that will respond to GET requests by serving pages from a specified folder, as well as log the pages the user is GETting, and the IP of the user.
The main trouble comes from me not knowing how to serve the directory listing to the user when overriding the do_GET method. Here is my code so far:
#!/usr/bin/...
Can someone provide me with some example code. I am fairly fluent with python but can't figure this out. So i will be generating a list with say "x" elements from other code. I need Tkinter to display a "x" buttons that can be checked on or off. Then once the user has selected whichever ones they want, they will press GO and more code wi...
I've written a mixin class that's designed to be layered on top of a new-style class, for example via
class MixedClass(MixinClass, BaseClass):
pass
What's the smoothest way to apply this mixin to an old-style class? It is using a call to super in its __init__ method, so this will presumably (?) have to change, but otherwise I'd l...
I just installed Python 2.7, but IDLE is currently broken on OS X 10.6.4. Is there anyway I can revert to the earlier, Apple installed, version? A simple PATH adjustment, perhaps?
Right now $PATH looks like this for me:
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin...
I'm trying to get a sense of the similarities between languages in syntax. How similar are Python, jQuery and C? I started programming in Actionscript 3 and then moved on to Javascript , then went on and learned Prototype, and then I started using jQuery and found that the syntax is very different. So is jQuery more like C and Python?
...
I'm using PyQt and am running into this issue. If my import statements are:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
then pylint gives hundreds of "Unused import" warnings. I'm hesitant to just turn them off, because there might be other unused imports that are actually useful to see. Another option would be to do this:...
I have a PDF that has some in depth explanation for an example in the Sphinx documentation for a package I have. Is there a way to easily include the PDF in my project (and have it copy over when I build the docs)? I tried linking to it with :doc: but this did not copy it over.
...
Hello, I am writing a simple commandline script that uses raw_input, but it doesn't seem to work.
This code:
print "Hello!"
raw_input("")
Produces this error:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
raw_input("")
TypeError: 'str' object is not callable
I have never encountered this error before,...
EDIT
I actually called object.__new__(cls), and I didn't realize that by this I built an object of class cls! Thanks for pointing this out to me.
ORIGINAL QUESTION
The documentation says
If new() does not return an
instance of cls, then the new
instance’s init() method will not
be invoked.
However, when I return object.__...
Can anyone, please, explain to me what's going on here. It seems that Python refuses to work (with twill) when I am trying to log in to my mailbox on Yahoo:
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
*************************...
how can I calculate number of days between two dates ignoring weekends ?
...
First time working with the HTMLParser module. Trying to use standard string formatting on the ouput, but it's giving me an error. The following code:
import urllib2
from HTMLParser import HTMLParser
class LinksParser(HTMLParser):
def __init__(self, url):
HTMLParser.__init__(self)
req = urllib2.urlopen(url)
...
I try to move email from mailbox's gmail to another one, Just curious that UID of each email will change when move to new mailbox ?
...
I have a class that knows its existing instances. Sometimes I want the class constructor to return an existing object instead of creating a new one.
class X:
def __new__(cls, arg):
i = f(arg)
if i:
return X._registry[i]
else:
return object.__new__(cls)
# more stuff here (such as __...
Why is there so many Pythons installed in /usr/bin for my Snow Leopard? What decides which one is the System Python?
When I simply type "python" it is 2.6.1 ~ but this doesn't seem to be the "System Python", why not? How does one change system Python and what are the drawbacks?
...
hi can u help me with this problem
...
I've two classes: Question and Answer. A question may have 0 or many answers.
class Question(Base):
__tablename__ = "questions"
answers = relationship('Answer', backref='question',
primaryjoin="Question.id==Answer.question_id")
class Answer(Base):
__tablename__ = "answers"
Now I want to find al...