python

Separate Admin/User authentication system in Django

I've recently started learning/using django; I'm trying to figure out a way to have two separate authentications systems for administrators and users. Rather than create a whole new auth system, I'd like to leverage django's built-in functionality (i.e. session management, @login_required decorator, etc.). Specifically, I want to have ...

Are Python's bools passed by value?

I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged. This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way? ...

Percentage with variable precision

I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters. How can I write this in Python? The "%.8f" string formatting works decently, but I need to keep the last three characters after the last string of nine...

http checks python

Hi gentlemen, learning python here, I want to check if anybody is running a web server on my local network, using this code, but it gives me a lot of error in the concole. #!/usr/bin/env python import httplib last = 1 while last <> 255: url = "10.1.1." + "last" connection = httplib.HTTPConnection("url", 80) conn...

Is there any python library for parsing dates and times from a natural language?

What I'm looking for is something that can translate 'tomorrow at 6am' or 'next moday at noon' to the appropriate datetime objects. ...

Combining Dictionaries Of Lists In Python

I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q. Example: Original List: (1, 2), (1, 3), (2, 3) Resultant Dictionary: {1:[2, 3], 2:[3]} Furthermore, I would like to efficiently combine these dict...

How to download any(!) webpage with correct charset in python?

Problem When screen-scraping a webpage using python one has to know the character encoding of the page. If you get the character encoding wrong than your output will be messed up. People usually use some rudimentary technique to detect the encoding. They either use the charset from the header or the charset defined in the meta tag or t...

How to define a class in Python

Quite simple, I'm learning python and I can't find a reference that tells me how to write the following: public class Team { private String name; private String logo; private int members; public Team(){} // getters/setters } Later: Team team = new Team(); team.setName( "Oscar" ); team.setLogo( "http://......

How close is Python to being able to wrap it in a workbook type skin?

With my luck this question will be closed too quickly. I see a tremendous possibility for a python application that basically is like a workbook. Imagine if you will that instead of writing code you select from a menu of choices. For example, the File menu would have an open command that lets the user navigate to a file or directory o...

Aggregating multiple feeds with Universal Feed Parser

Having great luck working with single-source feed parsing in Universal Feed Parser, but now I need to run multiple feeds through it and generate chronologically interleaved output (not RSS). Seems like I'll need to iterate through URLs and stuff every entry into a list of dictionaries, then sort that by the entry timestamps and take a sl...

wxpython -- threads and window events

I have a wxPython application (http://www.OpenSTV.org) that counts ballots using methods that have multiple rounds. I'd like to do two things: (1) For a large number of ballots, this can be a bit slow, so I'd like to show the user a progress dialog so he doesn't think the application is frozen. (2) I'd like to allow the user to break ...

Problem loading transparent background sprites in pygame

I'm trying to load a transparent image into pygame using the following code: def load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', fullname raise SystemExit, message image = imag...

In Python in GAE, what is the best way to limit the risk of executing untrusted code?

I would like to enable students to submit python code solutions to a few simple python problems. My applicatoin will be running in GAE. How can I limit the risk from malicios code that is sumitted? I realize that this is a hard problem and I have read related Stackoverflow and other posts on the subject. I am curious if the restrictions ...

Passing a list of kwargs?

Can I pass a list of kwargs to a method for brevity? This is what i'm attempting to do: def method(**kwargs): #do something keywords = (keyword1 = 'foo', keyword2 = 'bar') method(keywords) ...

SQLAlchemy - MapperExtension.before_delete not called

Hi everybody, I have question regarding the SQLAlchemy. I have database which contains Items, every Item has assigned more Records (1:n). And the Record is partially stored in the database, but it also has an assigned file (1:1) on the filesystem. What I want to do is to delete the assigned file when the Record is removed from the datab...

How to treat the first line of a file differently in Python?

I often need to process large text files containing headers in the first line. The headers are often treated differently to the body of the file, or my processing of the body is dependent on the headers. Either way I need to treat the first line as a special case. I could use simple line iteration and set a flag: headerProcessed = false...

Guidance on optimising Python runtime for embedded systems with low system resources

My team is incorporating the Python 2.4.4 runtime into our project in order to leverage some externally developed functionality. Our platform has a 450Mhz SH4 application core and limited memory for use by the Python runtime and application. We have ported Python, but initial testing has highlighted the following hurdles: a) start-...

how to obtain physical drives in Windows

I'm programming in Python with a wrapper of the kernel32 dll, so I can use any functions of this dll, like GetLogicalDrives(), for instance. I'm trying to obtain the information of the physical drives, even if they are not mounted. I've seen a question similar to this, but I need the information of the not mounted drives. All methods I'v...

Web Service client in Python using ZSI - "Classless struct didn't get dictionary"

I am trying to write a sample client in Python using ZSI for a simple Web Service. The Web Service WSDL is following: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd...

Python 2.5 and 2.6 and Numpy compatibility problem

In the computers of our laboratory, which have Python 2.6.2 installed in them, my program, which is an animation of the 2D random walk and diffusion, works perfectly. However, I can't get the exact same program to work on my laptop, which has Python 2.5. By that not working, I mean the animation is screwed; the axis always changes ever...