python

Fastest way to learn Python?

I have an interview for a Python job tomorrow through a personal connection. The thing is, I don't actually know Python although I've written a few programs and hacked around with Django and some other Python frameworks without really knowing what I was doing. An interview is a different matter. I'm planning on learning Python today even...

How do I write to the console in Google App Engine?

Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, using Google App Engin...

How can I do Unicode uppercase?

I have this: >>> print 'example' example >>> print 'exámple' exámple >>> print 'exámple'.upper() EXáMPLE What I need to do to print: EXÁMPLE (Where the 'a' gets its accute accent, but in uppercase.) I'm using Python 2.6. ...

Python __str__ and lists

Hello In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this: "[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]" Is there a way to get similar behav...

Transferring Python modules

Basically for this case, I am using the _winreg module in Python v2.6 but the python package I have to use is v2.5. When I try to use: _winreg.ExpandEnvironmentStrings it complains about not having this attribute in this module. I have successfully transferred other modules like comtypes from site-packages folder. But the problem is ...

Python: Downloading a large file to a local path and setting custom http headers

I am looking to download a file from a http url to a local file. The file is large enough that I want to download it and save it chunks rather than read() and write() the whole file as a single giant string. The interface of urllib.urlretrieve is essentially what I want. However, I cannot see a way to set request headers when downloadin...

Securely Erasing Password in Memory (Python)

How do you store a password entered by the user in memory and erase it securely after it is no longer need? To elaborate, currently we have the following code: username = raw_input('User name: ') password = getpass.getpass() mail = imaplib.IMAP4(MAIL_HOST) mail.login(username, password) After calling the login method, what do we need...

Python/urllib suddenly stops working properly

I'm writing a little tool to monitor class openings at my school. I wrote a python script that will fetch the current availablity of classes from each department every few minutes. The script was functioning properly until the uni's site started returning this: SIS Server is not available at this time Uni must have blocked my server...

How to convert html entities into symbols?

Hi, I have made some adaptations to the script from this answer. and I am having problems with unicode. Some of the questions end up being written poorly. Some answers and responses end up looking like: Yeah.. I know.. I’m a simpleton.. So what’s a Singleton? (2) How can I make the ’ to be translated to the right cha...

Dynamically creating a menu in Tkinter. (lambda expressions?)

I have a menubutton, which when clicked should display a menu containing a specific sequence of strings. Exactly what strings are in that sequence, we do not know until runtime, so the menu that pops up must be generated at that moment. Here's what I have: class para_frame(Frame): def __init__(self, para=None, *args, **kwargs): ...

Is there a way to overload += in python?

I know about the __add__ method to override plus, but when I use that to override +=, I end up with one of two problems: (1) if __add__ mutates self, then z = x + y will mutate x when I don't really want x to be mutated there. (2) if __add__ returns a new object, then tmp = z z += x z += y tmp += w return z will return something...

Python "round robin"

Given multiple (x,y) ordered pairs, I want to compare distances between each one of them. So pretend I have a list of ordered pairs: pairs = [a,b,c,d,e,f] I have a function that takes two ordered pairs and find the distance between them: def distance(a,b): from math import sqrt as sqrt from math import pow as pow d1 = pow...

Example of how to use msilib to create a .msi file from a python module

Can anyone give me an example of how to use python's msilib standard library module to create a msi file from a custom python module? For example, let's say I have a custom module called cool.py with the following code class Cool(object): def print_cool(self): print "cool" and I want to create an msi file using msilib tha...

Correct way to define Python source code encoding

PEP 263 defines how to define Python source code encoding. Normally, the first 2 lines of a Python file should start with: #!/usr/bin/python # -*- coding: <encoding name> -*- But I have seen a lot of files starting with: #!/usr/bin/python # -*- encoding: <encoding name> -*- -> encoding instead of coding. So what is the correct wa...

Python script - SCP on windows

Hi, How is it possible to do secure copy using python (windows native install - ActivePython). Unfortunately pexpect module is for unix only and we don't want cygwin locally. I wrote a script that based on pscp.exe win tool - but always stops at first execution becuse of fingerprint host id. and haven't found option to switch this off. ...

python eval() and globals()

I'm trying to execute a number of functions using eval() and I need to create some kind of environment for them to run. It is said in docs that you can pass globals as a second parameter to eval(). But it seems to not work in my case. Here's the simpified example (i tried two approaches, declaring variable global and using globals(), bot...

Identifying a map in groovy

While porting over a code fragment from python I've stumbled over a trivial problem: if isinstance(v['content'], dict): What would be the most elegant way to port this over to groovy? ...

Getting file path of imported module

How can I get the file path of a module imported in python. I am using Linux (if it matters). Eg: if I am in my home dir and import a module, it should return back the full path of my home directory. ...

How to I get scons to invoke an external script?

I'm trying to use scons to build a latex document. In particular, I want to get scons to invoke a python program that generates a file containing a table that is \input{} into the main document. I've looked over the scons documentation but it is not immediately clear to me what I need to do. What I wish to achieve is essentially what yo...

Seting up Python on IIS 5.1

Hello, I have this test python file import os print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>' print '<BODY>' print "<H1>This is A Sample Python CGI Script</H1>" print '<br>' if os.environ.has_key('REMOTE_HOST'): print "<p>You have accessed this site from IP: "+os.environ["REMOTE_H...