python

How do I get the time a file was last modified in Python?

Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference. ...

Non-blocking read on a stream in python.

Hi, I'm using the subprocess module to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-bloking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Window...

Forum software written in python

Most of the forum software out there is in php and some in .net but are there any written in python? I would like to go full python with my site and a forum would be the only thing missing. ...

Prevent ftplib from Downloading a File in Progress?

We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file and add it to the lis...

How do I create a wx.Image object from in-memory data?

I'm writing a GUI application in Python using wxPython and I want to display an image in a static control (wx.StaticBitmap). I can use wx.ImageFromStream to load an image from a file, and this works OK: static_bitmap = wx.StaticBitmap(parent, wx.ID_ANY) f = open("test.jpg", "rb") image = wx.ImageFromStream(f) bitmap = wx.BitmapFromImag...

How do you override vim options via comments in a python source code file?

I would like to set some vim options in one file in the comments section. For example, I would like to set this option in one file set syntax=python The file does not have a .py extension and I am not interested in making my vim installation recognise all files with this extension as python files. I know this can be done because I h...

Is there a python library for editing msword doc files?

I know there are some libraries for editing excel files but is there anything for editing msword 97/2000/2003 .doc files in python? Ideally I'd like to make some minor changes to the formatting of the text based on the contents of the text. A really trivial example would be highlighting every word starting with a capital. ...

Programmatic mail-merge style data injection into existing Excel spreadsheets?

I'd like to automate data entry into Excel spreadsheets. User data will exist on a web site, and when the user requests it, that data will need to be injected into an Excel spreadsheet. The complication is that the format of the Excel spreadsheet can vary significantly between users - it'll be user defined. I've been thinking of this as...

String concatenation vs. string substitution in Python

In Python, the where and when of using string concatenation versus string substitution eludes me. As the string concatenation has seen large boosts in performance, is this (becoming more) a stylistic decision rather than a practical one? For a concrete example, how should one handle construction of flexible URIs: DOMAIN = 'http://stack...

IntelliJ Python plug-in

I've been using IntelliJ IDEA at the day job for Java development for a few weeks now. I'm really impressed with it and I'm looking to extend it for other programming languages that I tinker with, starting with Python. I found this plug-in, pythonid. I figured I would look for some input on the Stack before proceeding. First, has anyone...

need help-variable creation in Python (continuation)

That was helpful kgiannakakis. I'm facing a problem as below: a = ['zbc','2.3'] for i in range(0,5): exec('E%d=%s' %(i,a[i])) This results in: Traceback (most recent call last): File "", line 2, in exec('E%d=%s' %(i,a[i])) File "", line 1, in NameError: name 'zbc' is not defined ...

Test if executable exists in Python?

In python, is there a portable and simple way to test if an executable program exists? By simple I mean something like the 'which' command which would be just perfect. I don't want to search PATH manually or something involving trying to execute it with Popen & al and see if it fails (that's what I'm doing now, but imagine it's launchmi...

How to set and preserve minimal width?

I use some wx.ListCtrl classes in wx.LC_REPORT mode, augmented with ListCtrlAutoWidthMixin. The problem is: When user double clicks the column divider (to auto resize column), column width is set to match the width of contents. This is done by the wx library and resizes column to just few pixels when the control is empty. I tried calli...

Stackless python and multicores?

So, I'm toying around with Stackless Python and a question popped up in my head, maybe this is "assumed" or "common" knowledge, but I couldn't find it actually written anywhere on the stackless site. Does Stackless Python take advantage of multicore CPUs? In normal Python you have the GIL being constantly present and to make (true) use ...

OOP and MVC programming style

I'm writing some data analysis software and decided to use such approach: epn: model/data.py <- Model definition model/reader.py <- How to read data into model view/gui.py <- main gui frame (wx) view/dialogs.py <- different dialogs (wx) epn.py <- controller For communication between gui and data I used wx.lib.pubsub. So when button 'Mo...

Code not waiting for class initialization!

I have a block of code that basically intializes several classes, but they are placed in a sequential order, as later ones reference early ones. For some reason the last one initializes before the first one...it seems to me there is some sort of threading going on. What I need to know is how can I stop it from doing this? Is there som...

How do I get my python program to sleep for 50 msec?

See title .. ! ...

Best Practice: network communication

Hi stackers, I'm programming a simple network chat with a Python server and a Java client. But one question came into my mind: Which "network protocol" should I use for communication? There are some possibilities for me: YAML: Nice to parse, problem: parsed objects contain language specific parts XML: Easy to parse, big overhead for ...

pyc to py files

hello, I wrote a lot of important python code for my project. unfortunately, I ran sed with wrong options and lost my files :( In repo these files are very old, but I have the pyc files. How can I convert pyc files to py? Thanks! ...

Python, Regular Expression Postcode search

Hi Guys, I am trying to use regular expressions to find a UK postcode within a string. I have got the regular expression working inside RegexBuddy, see below: \b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\b I have a bunch of addresses and want to grab the postcode from them, example below: 123 Some Road Name Town, City County...