python

Sending data received in one Twisted factory to second factory

Howdy! I am trying to write a simple program using Twisted framework and I am struggling with resolving (or even with imaging how to write it) issue I couldnt find any relevant documentation for: The main reactor uses two factories, one custom, listening for TCP connections on given port (say, 8000) and second one, to log into given IR...

How do you convert a stringed dictionary to a Python dictionary?

I have the following string which is a Python dictionary stringified: some_string = '{123: False, 456: True, 789: False}' How do I get the Python dictionary out of the above string? ...

How to quit the running python program to python prompt?

Hi everyone, I wrote a implementation of conway's game of life. I set up two modes, one is auto and the other is manual, which I mean the way to ouput the result of the game. For the auto mode, I cannot stop the running progran without ctrl + q or ctrl + c (which prints out the error message). So is there any way which can allow me to s...

[python] i got this error: "ImportError: cannot import name python" How do I fix it?

File "G:\Python25\Lib\site-packages\PyAMF-0.6b2-py2.5-win32.egg\pyamf\util\__init__.py", line 15, in <module> ImportError: cannot import name python How do I fix it? If you need any info to know how to fix this problem, I can explain, just ask. Thanks Code: from google.appengine.ext.webapp.util import run_wsgi_app from google.appeng...

Why does PyUSB / libusb require root (sudo) permissions on Linux?

I have been toying around with PyUSB lately, and found that it works beautifully on Linux (Ubuntu has libusb 0.1 and 1.0, as well as OpenUSB)... but only if I run the program with root privileges (with sudo, of course). Can anyone tell me why it requires elevated privileges and, more importantly, if I can change the permissions somehow ...

Generating parser in Python language from JavaCC source???

I do mean the ??? in the title because I'm not exactly sure. Let me explain the situation. I'm not a computer science student & I never did any compilers course. Till now I used to think that compiler writers or students who did compilers course are outstanding because they had to write Parser component of the compiler in whatever langu...

How to insert arrays into a database?

In my previous question a lot of users wanted me to give some more data to toy with. So I got working on exporting all my data and processing it with Python, but then I realized: where do I leave all this data? Well I decided the best thing would be to stick them in a database, so at least I don't have to parse the raw files every time...

What do I do when I need a self referential dictionary?

I'm new to Python, and am sort of surprised I cannot do this. dictionary = { 'a' : '123', 'b' : dictionary['a'] + '456' } I'm wondering what the Pythonic way to correctly do this in my script, because I feel like I'm not the only one that has tried to do this. EDIT: Enough people were wondering what I'm doing with this, so ...

Calling cxfreezed exe of a python script as an independent process in windows

In windows i m trying to create new process and got stuck while spawning an independent process using win32process.CreateProcess I have freeze my python script using cxfreeze to make .exe. By using following command i tried to create a new process which would do some tasks. si = win32process.STARTUPINFO() details = win32process.Create...

Django trying to set up a project and find out which Django I have

I'm on a Mac OS X Snow Leopard with Python 2.6.5, I'm trying to get django working but I keep getting this error. Do I need to add it to the path? I'm not sure where django is installed is there any way that I can find it? james:~/home/james → python Python 2.6.5 (r265:79063, Aug 8 2010, 21:45:26) [GCC 4.2.1 (Apple Inc. build 5659)]...

Streaming the state of a Python script to a website

Hello: I have a simple workflow [Step 0]->[1]->[2]->...->[Step N]. The master program knows the step (state) it is currently at. I want to stream this in real time to a website (in the local area network) so that when my colleagues open, say, http://thecomputer:8000, they can see a real time rendering of the current state of our workfl...

Django, unable to import validators in form class, getting "name 'validatorname' is not defined"

I am trying to use validators in my form fields but am getting an error: from django import forms from django.db import models from django.core.exceptions import ValidationError class Register(forms.Form): username = forms.CharField(max_length=100,label="Username",validators=[validate_email]) >>>> name 'validate_email' is not def...

Python circular dependency import

Say I have three files like this: testimports module: #import moduleTwo import moduleOne hiString = "Hi!" moduleOne.sayHi() moduleOne: import moduleTwo class sayHi(): moduleTwo.printHi() moduleTwo: import testimports def printHi(): print(testimports.hiString) If I run testimports, I get the following: Traceback (mo...

Need help with an assignment from the MIT opencourse. Calculating prime numbers.

So, I have a very shotty background in programing and I have, for a very long time, attempted to learn through various lessons, though, no matter how good the lesson or tutorial is said to be, it always loses me at some point. For example the CarlH lectures lost me at around unit 5 part 1 and 2 where it jumped the shark and neglected to ...

is there a compatible TCL environment variable for cygwin and python idle

Idle stopped working after installing cygwin and after some troubleshooting (on windows if its not obvious), it looks like the issue is with a TCL library. They both use an environment variable to locate tcl. when I installed cygwin, it overwrote the variable to a different (and incompatible to python) version. Now I figure I can just ch...

How to strip all whitespace from string

How do I strip all the spaces in a python string? For example, I want a string like strip my spaces to be turned into stripmyspaces, but I cannot seem to accomplish that with strip(): >>> 'strip my spaces'.strip() 'strip my spaces' ...

Trying to find all the combinations of values inside N lists.

I am trying to compare all combinations of the values in N lists. Each list is identical holding values 1 through 9 in order. I am having a very hard time figuring out how to code this because I cannot create N nested loops beforehand. N is user defined and won't be known until run time. The place I always get stuck on is trying to itera...

design for continuation based python web appliction framework

There are many continuation based framework for java, ruby etc but none in python. Nagare framework somewhat solves the problem but it do not use standard python and uses stackless python to solve continuation problem. I was wondering, what part of standard python constraint to create such continuation web framework in standard python...

How can I call a inner function from the Python shell?

I have some code (that I can't easily modify), of the following form: def foo(x): do_other_stuff_that_I_do_not_want_to_do() def bar(): "do something" str(x) bar() I would like to call bar(), directly, from the Python shell. I don't mind using co_globals, or other internal bits. I have the feeling that this may b...

List sorted by categories in Tkinter?

I'm building a graphical program that will need to show files on both the user's computer and on a remote server. I'm using Tkinter, and I'm definitely a novice with this toolkit. I want to have the files displayed in a box similar to what you would get from a "Details" view in Windows, so that each file has several categories of info(th...