python

Problems with Tornado Web Server

Hello, I am using OSX 10.58 with the following versions: curl --version curl 7.16.4 (i386-apple-darwin9.0) libcurl/7.21.0 OpenSSL/0.9.7l zlib/1.2.3 Protocols: dict file ftp ftps http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp Features: IPv6 Largefile NTLM SSL libz sing /Library/Python/2.5/site-packages/setupto...

Positionally matching substrings in Python

How would you parse the ['i386', 'x86_64'] out of a string like '-foo 23 -bar -arch ppc -arch i386 -isysroot / -fno-strict-aliasing -fPIC'? >>> my_arch_parse_function('-foo 23 -bar -arch i386 -arch x86_64 -isysroot / -fno-strict-aliasing -fPIC') >>> ['i386', 'x86_64'] Can this be done using regex, or only using modules like PyParsin...

How to use csv.reader in python with french character like é,à,ç,ê,ë,...

I have a csv file like 120 column by 4500 row. I read the field "customer name" in the first column, first row. I then look fot this field in a second cvs file containing the "customer name , and customer ID" I write a new cvs file with "customer name", customer ID", and all the rest of the 119 colunm.and continue until end of first fi...

python: complicated loop through list

import csv import collections def do_work(): (data,counter)=get_file('thefile.csv') b=samples_subset1(data,counter,'/pythonwork/samples_subset4.csv',500) medications_subset2(b,['HYDROCODONE','MORPHINE','OXYCODONE']) def get_file(start_file): with open(start_file,'rb') as f: data=list(csv.reader(f)) counter=collections.d...

is it bad convention to call sys.argv from somewhere besides main function in python

I am writing a script and I have a function, call it f(), that needs one of the command line arguments (a filename it needs to open). However, f() is not called directly in the main function. I was wondering if it was bad coding convention to call sys.argv[1] straight from f()? If I don't I would have to pass it as an argument to all o...

Please help with Python Regex

I have this weirdly formatted URL. I have to extract the contents in '()'. Sample URL : http://sampleurl.com/(K(ThinkCode))/profile/view.aspx If I can extract ThinkCode out of it, I will be a happy man! I am having a tough time with regexing special chars like '(' and '/'. Any help is highly appreciated. Thanks much guys! ...

Is there an online interpreter for python 3?

Where can I find an online interpreter for Python 3? I'm learning Python but can't install it at work where I'd like to do some practice. Thanks! Sorry to repeat the question; I can't bump earlier posts and was just hoping there is one out there now. ...

Is there a Python ORM framework for interacting with data via XML-RPC?

I am working on a webapp that interacts with data via XML-RPC rather than with a direct connection to a database. I can execute SQL queries via an XML-RPC methods. I would like to interact with the data in an ORM framework fashion that has lazy/eager fetching, etc., although I can't seem to figure out how that would be possible with Py...

Removing values from a list in python

I have a large file of names and values on a single line separated by a space: name1 name2 name3.... Following the long list of names is a list of values corresponding to the names. The values can be 0-4 or na. What I want to do is consolidate the data file and remove all the names and and values when the value is na. For instance, t...

python: iterating through array

i have a list like this: brand_names={'MORPHINE':['ASTRAMORPH','AVINZA','CONTIN','DURAMORPH','INFUMORPH', 'KADIAN','MS CONTIN','MSER','MSIR','ORAMORPH', 'ORAMORPH SR','ROXANOL','ROXANOL 100'], 'OXYCODONE':['COMBUNOX','DIHYDRONE','DINARCON','ENDOCET','ENDODAN', 'E...

IPC (inter process communication) between python and java

Hello, First, a little explanation of why I'm asking this question in the first place: I'm writing a python program (with a wxPython gui) that needs to call a Java AWT program from python and extract data from it. I have an in-process working solution on Windows. I also have an in-process solution on OSX so long as I run the Java app he...

Arbitrary command line arguments in python

I want to allow arbitrary command line arguments. If the user provides me with a command line that looks like this myscript.py --a valueofa --b valueofb posarg1 posarg2 I know that a was passed with valueofa, b passed with valueofb and that I have these last two positional arguments. I've always used optparse, for which you specify...

How i get the current language in django?

How i can get the current language of my web in a model or in the admin? ...

implementing a basic queue/thread process within python

hi.. looking for some eyeballs to verifiy that the following chunk of psuedo python makes sense. i'm looking to spawn a number of threads to implement some inproc functions as fast as possible. the idea is to spawn the threads in the master loop, so the app will run the threads simultaneously in a parallel/concurrent manner chunk of co...

Django, Borg pattern, API calls, caching results

Hi everyone! I'm using an API from a different site that returns a couple of 'pricepoint URL's that my users use to buy Virtual Goods. I'm supposed to cache those results for at least an hour, since they don't change the price points on their system much. (And we want to save both our's and their bandwidth.) After looking for singleto...

python: exit out of two loops

for row in b: for drug in drug_input: for brand in brand_names[drug]: from the third loop how do i exit the current loop and go to the next value of for row in b: ? ...

I'm using pyAMF in my app, but I want to set smart service like explained here:

In a normal application i set services services = { 'users.login': login, 'test': router } but I would like to do like this: services = [ 'users.login', 'test' ] and every request goes to router function. this takes 2 params: service name (can be "users.login" or "test" in this case) and input (that is the object se...

maximum of 2 numbers

How to find the maximum of 2 numbers? value = -9999 run = problem.getscore() I need to compare the 2 values i.e value and run and find the maximum of 2. I need some python function to operate it? ...

using Python/Pexpect to crawl a network

Hi. This is more a logical thinking issue rather than coding. I already have some working code blocks - one which telnets to a device, one which parses results of a command, one which populates a dictionary etc etc Now lets say I want to analyse a network with unknown nodes, a,b,c etc (but I only know about 1) I give my code block node...

How can I make a dashboard with all pending tasks using Celery?

I want to have some place where I can watch all the pendings tasks. I'm not talking about the registered functions/classes as tasks, but the actual scheduled jobs for which I could display: name, task_id, eta, worker, etc. Using Celery 2.0.2 and djcelery, I found `inspect' in the documentation. I tried: from celery.task.control import...