python

Python Script to backup a directory

#Filename:backup_ver1 import os import time #1 Using list to specify the files and directory to be backed up source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py' #2 define backup directory destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse' #3 Setting the backup name targetBa...

Python: Set window focus on terminal

Hey, I have a python application that opens some plots for me and then asks the user for input. The problem is, that after opening the plot, the focus isn't on the terminal anymore, so you have to click or tab to it manually. I would like to set the focus to the terminal window with python - is that possible? I'm using gnuplot.py, may...

Passing in **kwargs from Flex over PyAMF

Anyone know if it is easily possible to send **kwargs over PyAMF from NetConnection.call()? I would like it. I could write a wrapper around the actual function and expose that and perform some parsing manually to determine the kwargs to pass in, but I don't want to do that. I will just use a normal argument list in that case. ...

What is the advantage of using static methods in Python?

I ran into unbound method error in python with the code class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices) After reading many helpful posts h...

Extending appengine's db.Property with caching

I'm looking to implement a property class for appengine, very similar to the existing db.ReferenceProperty. I am implementing my own version because I want some other default return values. My question is, how do I make the property remember its returned value, so that the datastore query is only performed the first time the property is ...

How to recovery source python code (.py) from .pyo file?

I need to convert a compiled python code (.pyo) to its source . I look in depython.net, but there is a problem. A warning; "File version older than 2.4." What should I do? Thanks. ...

What is the semantics of 'is' operator in Python?

How does is operator determine if two objects are the same? How does it work? I can't find it documented. ...

Batch select with SQLAlchemy

I have a large set of values V, some of which are likely to exist in a table T. I would like to insert into the table those which are not yet inserted. So far I have the code: for value in values: s = self.conn.execute(mytable.__table__.select(mytable.value == value)).first() if not s: to_insert.appen...

Set serial port pin high using python

Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how? ...

Python Copy Through Assignment?

I would expect that the following code would just initialise the dict_a, dict_b and dict_c dictionaries. But it seams to have a copy through effect: dict_a = dict_b = dict_c = {} dict_c['hello'] = 'goodbye' print dict_a print dict_b print dict_c As you can see the result is as follows: {'hello': 'goodbye'} {'hello': 'goodbye'} {'he...

Python: inserting double or single quotes around a string

Im using python to access a MySQL database and im getting a unknown column in field due to quotes not being around the variable. code below: cur = x.cnx.cursor() cur.execute('insert into tempPDBcode (PDBcode) values (%s);' % (s)) rows = cur.fetchall() How do i manually insert double or single quotes around the value of s? I've tryin...

how to embed a webpage using wx?

I need to show a webpage (a complex page with script and stuff, no static html) in a frame or something. It's for a desktop application, I'm using python 2.6 + wxPython 2.8.10.1. I need to catch some events too (mostly about changing page). I've found some samples using the webview module in a gtk application, but I couldn't have it work...

How to teach beginners reversing a string in Python?

I am teaching a course "Introduction to Computer Programming" to the first year math students. One has to assume that this is the first exposure of students to computer programming. Here are the main goals of my teaching: Students should learn and understand the basics of Python. Eventually they need to master sufficiently many Python ...

Is it possible to use re2 from Python?

i just discovered http://code.google.com/p/re2, a promising library that uses a long-neglected way (Thompson NFA) to implement a regular expression engine that can be orders of magnitudes faster than the available engines of awk, Perl, or Python. so i downloaded the code and did the usual sudo make install thing. however, that action h...

Where to find a list of all the possible HTML tags in Python?

Is there a standard module in Python that lists all the HTML tags? For example, I would like to do things like: if is_valid_html_tag('div'): print 'div is a valid tag' if is_not_valid_html_tag('boda'): print 'boda is not a valid tag' To do this I need a list of all tags in Python. I wonder if someone has assembled them alread...

As a newbie, where should I go if I want to create a small GUI program?

Hello, I'm a newbie with a little experience writing in BASIC, Python and, of all things, a smidgeon of assembler (as part of a videogame ROM hack). I wanted to create small tool for modifying the hex values at particular points, in a particular file, that would have a GUI interface. What I'm looking for is the ability to create small ...

Parsing/Tokenizing a String Containing a SQL Command

Are there any open source libraries (any language, python/PHP preferred) that will tokenize/parse an ANSI SQL string into its various components? That is, if I had the following string SELECT a.foo, b.baz, a.bar FROM TABLE_A a LEFT JOIN TABLE_B b ON a.id = b.id WHERE baz = 'snafu'; I'd get back a data structure/object somethin...

Can I override a query in DJango?

I know you can override delete and save methods in DJango models, but can you override a select query somehow to intercept and change a parameter slightly. I have a hashed value I want to check for, and would like to keep the hashing internal to the model. ...

In what order should the Python concepts be explained to absolute beginners?

I am teaching Python to undergraduate math majors. I am interested in the optimal order in which students should be introduced to various Python concepts. In my view, at each stage the students should be able to solve a non-trivial programming problem using only the tools available at that time. Each new tool should enable a simpler solu...

Is it possible to put a wx.window (frame/panel) over a wx.MenuBar?

Hi, I want to know if it's possible to put a frame or a panel over a menubar using wxpython? Thanks in advance! ...