python

How can I package a scrapy project using cxfreeze?

I have a scrapy project that I would like to package all together for a customer using windows without having to manually install dependencies for them. I came across cxfreeze, but I'm not quite sure how it would work with a scrapy project. I'm thinking I would make some sort of interface and run the scrapy crawler with 'from scrapy.cmd...

python list to newline separated value

hi, Im trying to get data in pylon to use in jquery autocomplete, the librarary i'm using for autocomplete it requires this format abc pqr xyz and in python i have data in this format [["abc"], ["pqr"],["xyz"] How do i convert this list to the above one. Edit: I trying to use these for a autocompete and i'm using pylons, in ...

Fastest way to convert an iterator to a list

Having an iterator object, is there something faster, better or more correct than a list comprehension to get a list of the objects returned by the iterator? user_list = [user for user in user_iterator] ...

Piecewise list comprehensions in python

What is the easiest/most elegant way to do the following in python: def piecewiseProperty(aList): result = [] valueTrue = 50 valueFalse = 10 for x in aList: if hasProperty(x): result.append(valueTrue) else result.append(valueFalse) return result where hasProperty is some fu...

If i connect to a python websocket will it start a new script or connect to a daemon

Clue is in the name. When a websocket connects will it connect to run a new script or start a daemon, if it does start a new script is there a way to pass it on to a daemon script ? Thankyou ! Finished I dont know what the answer to my own question is but i just set up a deamon to run on its own port. ...

Building Python libraries on a Mac and experiencing flat namespace errors

As a general rule, I rue the days whenever I have to build Python libraries on a Mac. I've generally had fairly good success using Boost::Python, and if I use distutils, most of the time everything works correctly. However, I've never been able figure out the exact combination of what works/what doesn't work. Specifically, I've often ru...

Python number wrapping?

Consider this Python code: assert(a > 0) assert(b > 0) assert(a + b > 0) Can the third assert ever fail? In C/C++, it can if the sum overflows the maximum integer value. How is this handled in Python? ...

How to stop python from propagating signals to subprocesses?

I'm using python to manage some simulations. I build the parameters and run the program using: pipe = open('/dev/null', 'w') pid = subprocess.Popen(shlex.split(command), stdout=pipe, stderr=pipe) My code handles different signal. Ctrl+C will stop the simulation, ask if I want to save, and exit gracefully. I have other signal handlers ...

How can you select a random element from a list, and have it be removed?

Let's say I have a list of colours, colours = ['red', 'blue', 'green', 'purple']. I then wish to call this python function that I hope exists, random_object = random_choice(colours). Now, if random_object holds 'blue', I hope colours = ['red', 'green', 'purple']. Does such a function exist in python? ...

Python, os.system for command-line call (linux) not returning what it should?

I need to make some command line calls to linux and get the return from this, however doing it as below is just returning 0 when it should return a time value, like 00:08:19, I am testing the exact same call in regular command line and it returns the time value 00:08:19 so I am confused as to what I am doing wrong as I thought this was h...

Is there any other way besides browser extensions that one could have a GUI bar hover over any website a user visits?

Goal I want to create a web app with a horizontal GUI bar that floats with the user as they move from site to site. e.g. A user will sign into the web at the home page and then proceed to say Google to start searching for their topic. Once they are signed in and leave the web app homepage a horizontal GUI bar will appear on each page th...

what constitutes a member of a class? What constitutes a method?

It seems that an acceptable answer to the question What is a method? is A method is a function that's a member of a class. I disagree with this. class Foo(object): pass def func(): pass Foo.func = func f = Foo() print "fine so far" try: f.func() except TypeError: print "whoops! func must not be a metho...

How do I get all instances of VLC on dbus quickly?

basically the problem is, that the only way to get all instances of VLC is to search all non-named instances for the org.freedesktop.MediaPlayer identity function and call it. (alternatively I could use the introspection API, but this wouldn't seem to solve my problem) Unfortunately many programs upon having sent a dbus call, simply do ...

wxPython - wxHtmlWindow, can the scrollbar be kept at the veyr bottom at all times?

I am working on a chatroom client and am using an HTML window to process things like images and html tags and formatting. I am having trouble finding out how to make the scrollbar stay at the bottom as messages are added to the window (every message sends the bar to the top) would anyone know how I would go about doing this? ...

Modifying The Template For New Pylons Controllers

I'm at a point in my Pylons projects where I end up creating and deleting controllers often (probably more often than I should). I grow tired of adding my own imports and tweaks to the top of every controller. There was a recent question about modifying the new controller template that got me part-way to not having to do that - but I do...

which python version need from __future__ import with_statement ?

Currently i'm using python 2.6.5, I didn't use from __ future __ import with_statement,it can use with statement all right. I want to know in which version we need use from __ future __ import with_statement,which not? ...

Output a python script to text file

I'm using a script that someone else wrote in python. It's executed from the command line with 3 arguments. example: "python script.py 1111 2222 3333" It does it's thing and works perfectly. The results are NOT saved though, and I would really like to pipe the output to a text file. Can I simply use similar dos commands to accomplis...

How do you stream data into the STDIN of a program from different local/remote processes in Python?

Standard streams are associated with a program. So, suppose there is a program already running in some way (I don't care how or in what way). The goal is to create pipes to the STDIN of the program from different processes (or programs) that run either locally or remotely and stream data into it asynchronously. Available information is ...

when i reload supervisord the process under it control will stop or not?

I try to figure out when i use reload command to supervisord,dose it will stop the processing currently executing under it? so i use bellow steps: mlzboy@mlzboy-mac:~/my/ide/test$ pstree -p|grep super |-supervisord(6763) mlzboy@mlzboy-mac:~/my/ide/test$ supervisorctl daemon STARTING supervisor> relo...

Storing dynamic form in a model

I want to build a system using Django that will allow users to build forms, store them and have their customers use them. I know how I can go about creating the forms dynamically but I'm looking for a good way to still use the form classes and handle many different user's dynamic forms in an elegant way. I'm thinking of storing the for...