python

how to make a Command Line Interface from a given data model used for GUI

HI, guys. I am developing a GUI to configure and call several external programs with Python and I use wxPython for the GUI toolkits. Basically, instead of typing commands and parameters in each shell for each application (one application via one shell), the GUI is visualizing these parameters and call them as subprocesses. I have built t...

How do I abort object instance creation in Python?

I want to set up a class that will abort during instance creation based on the value of the the argument passed to the class. I've tried a few things, one of them being raising an error in the __new__ method: class a(): def __new__(cls, x): if x == True: return cls else: raise ValueError Thi...

How save a binary file in Python3

I am trying to create a binary file in Python3 but i don 't know how to save it, the manual doesn 't say anything about that. i create a code but i don 't catch the mistake: s = open('/home/hidura/test.jpeg', 'wb') s.write(str.encode(formFields[5])) s.close() ...

Python - English translator

What is the best way to approach writing a program in Python to translate English words and/or phrases into other languages? ...

Trouble with Emacs pdb and breakpoints in multi-threaded Python code

I am running Emacs 23.2 with python.el and debugging some Python code with pdb. My code spawns a sibling thread using the threading module and I set a breakpoint at the start of the run() method, but the break is never handled by pdb even though the code definitely runs and works for all intents and purposes. I was under the impressi...

Is there a design pattern for this: hide certain methods from certain classes.

I'm writing a simulation in Python for a dice game, and am trying to find the best way to handle the following situation in an Object Oriented manner. I have a Dice class that handles rolling the dice and reporting things about the dice. This class's methods include a roll() method which modifies the dice values, and various reporting ...

Python: 2.6 and 3.1 string matching inconsistencies

I wrote my module in Python 3.1.2, but now I have to validate it for 2.6.4. I'm not going to post all my code since it may cause confusion. Brief explanation: I'm writing a XML parser (my first interaction with XML) that creates objects from the XML file. There are a lot of objects, so I have a 'unit test' that manually scans the XML ...

Newbie Confusion regarding classes

I have been trying, without success, to control an object within a class from without such class. These are the important bits (not the whole thing!) def GOGO(): ################################################ VFrame.SetStatusText("Ok") # ----> THIS IS WHAT I AM TRYING TO FIX # ...

How do I modify variables in the SocketServer server instance from within a RequestHandler handler instance in Python?

Here's the code in question: class Server(SocketServer.ForkingMixIn, SocketServer.TCPServer): __slots__ = ("loaded") class Handler(SocketServer.StreamRequestHandler): def handle(self): print self.server.loaded # Prints "False" at every call, why? self.server.loaded = True print self.server.loaded #...

Is it possible to generate variables from a list ??

Is it possible to generate variables on the fly from a list? In my program I am using the following instruction: for i in re.findall(r"...(?=-)", str(vr_ctrs.getNodeNames())): tmp_obj = vr_ctrs.getChild(i+"-GEODE") TMP.append([tmp_obj.getPosition(viz.ABS_GLOBAL)[0], tmp_obj.getPosition(viz.ABS_GLOBAL)[1], ...

programmatically find and replace content dynamically in a string in python

hi, i need to find and replace patterns in a string with a dynamically generated content. lets say i want to find all strings within '' in the string and double the string. a string like: my 'cat' is 'white' should become my 'catcat' is 'whitewhite' all matches could also appear twice in the string. thank you ...

Creating User Profiles In Python

I'm making a small python game with pygame. I'd like to be able to have multiple profiles with different stats, upgrades, etc. My biggest problem is storing this information persistently. I've already thought about MySql but I don't know how I could connect to it and I would prefer some way to be able to distribute it without requirin...

Alternate ways of saving a list into a file in Python

Hi, I am trying to a save a list into a file in a way that when I load and read the file again I get my lists as they are. In other words,the datatype doesn't change while saving and loading. Because right now, I use "write" to save my list into a file, and when I try to load it back into memory I get strings rather than real lists. is t...

Google App Engine-Ajax refresh from datastore using python

Hi, I have an application(developed in python) that requires a refreshed view from the datastore after every 5 seconds. I have came out with an javascript function and handle the refresh using ajax. Ajax function <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"&gt;&lt;/script&gt; ...

Strip whitespace from Mako template output (Pylons)

Hi guys, I'm using Mako + Pylons and I've noticed a horrendous amount of whitespace in my HTML output. How would I go about getting rid of it? Reddit manage to do it. ...

Omit iterator in list comprehension?

Is there a more elegant way to write the following piece of Python? [foo() for i in range(10)] I want to accumulate the results of foo() in a list, but I don't need the iterator i. ...

Find phone numbers in python script

Hello, the following python script allows me to scrape email addresses from a given file using regular expressions. How could I add to this so that I can also get phone numbers? Say, if it was either the 7 digit or 10 digit (with area code), and also account for parenthesis? My current script can be found below: # filename variables...

Grepping for Python processes

I'm running a script that executes either: ./ide.py # or python ./ide.py After that I use pstree -p | grep ide.py to check, but I only found a Python process. If I have many Python scripts running, how can I distinguish them from each other? ...

Parse large RDF in Python

I'd like to parse a very large (about 200MB) RDF file in python. Should I be using sax or some other library? I'd appreciate some very basic code that I can build on, say to retrieve a tag. Thanks in advance. ...

Passing variables between modules

I'm wonder why this simple code doesn't work. In main.py I have def foo(): HTTPHelper.setHost("foo") host = HTTPHelper.host() and in HTTPHelper.py: _host = None def setHost(host): _host = host def host(): return _host But when I step through foo() host becomes NoneType, even though I set it on the line before. Very...