python

Send Info from Script to Module Python

Hi I wonder how you can send info over to a module An Example main.py Looks like this from module import * print helloworld() module.py looks like this def helloworld(): print "Hello world!" Anyway i want to send over info from main.py to module.py is it possible? ...

dead simple Django file uploading not working :-((

Hello, I am trying desperately to do a very simple file upload with Django, without (for now) bothering with templating & co. My HTML is: <form id="uploader" action="bytes/" enctype="multipart/form-data" method="post" > <input type="file" name="uploaded"/> <input type="submit" value="upload"/...

Python Regular Expression Substitution

I have a block of text, and for every regex match, I want to substitute that match with the return value from another function. The argument to this function is of course the matched text. I have been having trouble trying to come up with a one pass solution to this problem. It feels like it should be pretty simple. ...

How to dynamically load a Python class

Given a string of a Python class, e.g. 'my_package.my_module.MyClass', what is the best possible way to load it? In other words I am looking for a Class.forName() function in Python. It needs to work on Google App Engine. Preferably this would be a function that accepts the FQN of the class as a string, and returns a reference to the c...

Creating an inheritable Python type with PyCxx

A friend and I have been toying around with various Python C++ wrappers lately, trying to find one that meets the needs of both some professional and hobby projects. We've both honed in on PyCxx as a good balance between being lightweight and easy to interface with while hiding away some of the ugliest bits of the Python C api. PyCxx is ...

jcc.initVM() doesn't return when mod_wsgi is configured as daemon mode

I am using mod-wsgi with django, and in django I use pylucene to do full text search. While mod-wsgi is configured to be embedded mode, there is no problem at all. But when mod-wsgi is configured to be daemon mode, the apache just gets stuck, and the browser just keep loading but nothing appears. Then I identity the problem to be the ...

SQLAlchemy and empty columns

When I try to insert a new record into the database using SQLAlchemy and I don't fill out all values, it tries to insert them as "None" (instead of omitting them). It then complains about "can't be null" errors. Is there a way to have it just omit columns from the sql query if I also omitted them when declaring the instance? ...

Hide Folders/ File with Python

is it any way to hide folders/ files with python. Im working a huge project (a vulnerability scanner) the project creates alot of files and folders, so back to the question, is it any way to make a script that hides files and folders. ...

Delete Chars in Python

does anybody know how to delete all characters behind a specific character?? like this: http://google.com/translate_t into http://google.com ...

In the windows python console, how to make Tab = four spaces?

Hello I would like that when I am in the python console tabbing will give me four spaces. Any ideas? ...

Python 3.0 smtplib

I have a very simple piece of code that I used in previous versions of Python without issues (version 2.5 and prior). Now with 3.0, the following code give the error on the login line "argument 1 must be string or buffer, not str". import smtplib smtpserver = 'mail.somedomain.com' AUTHREQUIRED = 1 # if you ne...

Simple unique non-priority queue system

I'm working on a simple web crawler in python and I wan't to make a simple queue class, but I'm not quite sure the best way to start. I want something that holds only unique items to process, so that the crawler will only crawl each page once per script run (simply to avoid infinite looping). Can anyone give me or point me to a simple qu...

Skipping Iterations in Python

I have a loop going, but there is the possibility for exceptions to be raised inside the loop. Which of course would stop it all together. I want to catch the exceptions and basically just skip to the next iteration in the loop. Is there a keyword or way to do this? ...

Python extend with an empty list bug?

Why does python 2.5.2 have the following behavior >>>[2].extend([]) == [2] False >>> [2].extend([]) == None True $ python --version Python 2.5.2 I assume I'm not understanding something here, but intuitively I'd think that [2].extend([]) should yield [2] ...

Fully transparent windows in Pygame?

Is it possible to get a fully transparent window in Pygame (see the desktop through it)? I've found how to create a window without a frame, but there doesn't seem to be any obvious way to make it transparent. I'd be willing to tie into system-specific technology/frameworks as long as there are solutions for both Windows and Mac OS X, b...

Parsing "From" addresses from email text

I'm trying to extract email addresses from plain text transcripts of emails. I've cobbled together a bit of code to find the addresses themselves, but I don't know how to make it discriminate between them; right now it just spits out all email addresses in the file. I'd like to make it so it only spits out addresses that are preceeded b...

What causes Python socket error?

File "C:\Python25\lib\SocketServer.py", line 330, in __init__ self.server_bind() File "C:\Python25\lib\BaseHTTPServer.py", line 101, in server_bind SocketServer.TCPServer.server_bind(self) File "C:\Python25\lib\SocketServer.py", line 341, in server_bind self.socket.bind(self.server_address) File "<string>", line 1, in...

Removing the TK icon on Python Tkinter windows

Does anybody know how to make the icon not show up? I'm looking for a way to have no icon at all. (Not a replacement) ...

Does python have something like C++'s using keyword?

In C++ you can often drastically improve the readability of your code by careful usage of the "using" keyword, for example: void foo() { std::vector< std::map <int, std::string> > crazyVector; std::cout << crazyVector[0].begin()->first; } becomes void foo() { using namespace std; // limited in scope to foo vector< ma...

Django Model API reverse lookup of many to many relationship through intermediary table

I have a Resident and can not seem to get the set of SSA's the resident belongs to. I've tried res.ssa_set.all() .ssas_set.all() and .ssa_resident_set.all(). Can't seem to manage it. What's the syntax for a reverse m2m lookup through another table? EDIT: I'm getting an 'QuerySet as no attribute' error. Erm? class SSA(models.Model): ...