python

Getting output from server side python script

Hey, I'm doing this project where we are supposed to connect a javascript client side application/web page on server A with a python server side script on server B. I need to get the output from the python script and store it into a variable but am running into some problems. I was trying to use XMLHttpRequest for this, and even though ...

sympy: How to return an expression in terms of other expression(s)

I'm fairly new to sympy and have what might be a basic question. Or I might simply be misinterpreting how sympy is supposed to be used. Is there a way to create an expression that is not represented by atoms, but by a combination of other expressions? Ex: >>> from sympy.physics.units import * >>> expr1 = m/s >>> expr2 = mile/hour >>>...

How to get module variable in function from another module?

I'd like to define a helper function that has the ability to modify a module-level variable (with known name) from surrounding context without explicitly passing it, e.g. # mod1.py mod_var = 1 modify_var() # mod_var modified print mod_var The problem is - I can't reference variable by mod1.mod_var, because I want to use helper functio...

Integration of Python console into a GUI C++ application

I'm going to add a python console widget (into a C++ GUI) below some other controls: Many classes are going to be exposed to the python code, including some access to GUI (maybe I'll consider PyQt). Should I run the Python code in a separate thread? I think it's a good approach, because GUI won't be frozen while executing long co...

Handling an "Inventory" (complex associations) with django + appengine

I'm writing a web application to manage a "game". Here are the models: class Character(db.Model): # Bio name = db.StringProperty() player = db.StringProperty() level = db.IntegerProperty() class Item(db.Model): name = db.StringProperty() description = db.StringProperty() value = db.StringProperty() class In...

What optimizations does Python do without the -O flags?

I had always assumed that the Python interpreter did no optimizations without a -O flag, but the following is a bit strange: >>> def foo(): ... print '%s' % 'Hello world' ... >>> from dis import dis >>> dis(foo) 2 0 LOAD_CONST 3 ('Hello world') 3 PRINT_ITEM 4 PRINT_NEW...

Python's subprocess.Popen() and source

A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is: proc = subprocess.Popen( "ls && source houdini_setup", shell = True, executable = "/bin/bash", ) There is a daemon that listens to port 5001 and runs the above s...

Model form is crashing on a foreign key in django

So I'm trying to create a new feed within the Admin page and its crashing with the error IntegrityError: lifestream_feed.lifestream_id may not be NULL, form['lifestream'] is set but form.instance.lifestream is not. form.fields even shows that lifestream is a django.forms.models.ModelChoiceField Here is the code: class FeedCreationFo...

scipy linregress function erroneous standard error return?

Hello, I have a weird situation with scipy.stats.linregress seems to be returning an incorrect standard error: >>> from scipy import stats >>> x = [5.05, 6.75, 3.21, 2.66] >>> y = [1.65, 26.5, -5.93, 7.96] >>> gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y) >>> gradient 5.3935773611970186 >>> intercept -16.28112...

Access scanner from Java or Python (or something else if it's technically motivated) in Linux (but Windows would be nice)

Hi, I want to write a system for handling important documents in my home. This is the user story for getting a new document: I "Add new document" and am prompted to scan it using my combined printer/scanner. I view the scanned copy to see it's of good enough quality. Which it has. The system tells me to mark it with number N, which I ...

Python ctypes addressof CFuncType

Related to my other question How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address. C code: extern "C" _declspec(dllexport) int addr(int (*func)()) { int r = (int)func; return r; } Python code: def test(): return 42 t = CFUNCTYPE(c_int) f = t(test) pr...

How should I convert this long and complex PHP style URL query string to a Django url?

I'm converting a small PHP application to Django. One section has a long query string, indicating how a widget is to be displayed. There are a few required parameters and several optional ones. The current urls read like: app.php?id=102030&size=large&auto=0&bw=1&extra=1 The id and size are required, but auto, bw and extra are option...

How do I make these Perl regexs Python compatible?

I have these two lines in an old Perl script. When I write the Python equivalent I get all sorts of errors like valueerror: invalid \x escape, and stuff about encoding. $line =~ s/[^\x{8}-\x{7B}]/ /ig; $line =~ s/(Û|²|°|±|É|¹|Í)/ /g; What do I need to do to get them working in Python? ...

python-re: How do I match an alpha character.

How can I match an alpha character with a regular expression. I want a character that is in \w but is not in \d. I want it unicode compatible that's why I cannot use [a-zA-Z]. ...

Fractions with decimal precision

Is there a pure python implementation of fractions.Fraction that supports longs as numerator and denominator? Unfortunately, exponentiation appears to be coded in to return a float (ack!!!), which should at least support using decimal.Decimal. If there isn't, I suppose I can probably make a copy of the library and try to replace occurre...

PyQt + shortcut to trigger a button

How do I configure keyboard shortcuts to click specific buttons in a PyQT app? Eg: Ctrl+1 to click one button while Ctrl+2 to click the other? ...

why 'setprofile' print this.

import sys def a(): print 'aaa' def profiler(frame, event, arg): print event, frame.f_code.co_name, frame.f_lineno, "->", arg # profiler is activated on the next call, return, or exception sys.setprofile(profiler) a() print call a 5 -> None#what is it aaa return a 6 -> None#what is it return <module> 12 -> None#what is it ...

How to trigger Google Analytics events from Python?

I'm developing a site that has a REST API and I'd like to track the API usage using Google Analytics events. Is there a straightforward way to trigger GA events from Python that doesn't involve loading up an entire webbrowser component just to send a javascript request? ...

How to upload images using an API Key that gives you permission to upload? [Python source code included]

The documentation of the API shows source code on how to accomplish this in Python: #!/usr/bin/python import pycurl c = pycurl.Curl() values = [ ("key", "YOUR_API_KEY"), ("image", (c.FORM_FILE, "file.png"))] # OR: ("image", "http://example.com/example.jpg"))] c.setopt(c.URL, "http://imgur.com/api/upload.xml") ...

how do i regex search for weird non-ascii characters in python?

I'm using the following regex basically to search for and delete these characters. invalid_unicode = re.compile(ur'(Û|²|°|±|É|¹|Í)') My source code in ascii encoded, and whenever I try to run the script it spits out: SyntaxError: Non-ASCII character '\xdb' in file ./release.py on line 273, but no encoding declared; see http://www.pyt...