Re: Unix Device File Emulation

2008-04-23 Thread Martin Blume
blaine schrieb # Fake Nokia Screen Emulator import sys, os class nokia_fkscrn: def __init__(self, file): if not os.path.exists(file): os.mkfifo(file) self.fifodev = open(file, 'r') def read(self): while 1: r = self.fifodev.readline() print r

Re: Unix Device File Emulation

2008-04-23 Thread Martin Blume
blaine schrieb while 1: r = self.fifodev.readline() if r: print r According to my docs, readline() returns an empty string at the end of the file. Also, you might want to sleep() between reads a little bit. Oh ok, that makes sense. Hmm. So do I not want to use

Re: Is subprocess.Popen completely broken?

2008-03-27 Thread Martin Blume
Istvan Albert schrieb Is subprocess.Popen completely broken? Your lack of faith in Python is somewhat disturbing ... I have consistently made the experience that when I was about to ask is X completely broken, the error was on my side. Martin --

Re: Strange problem with structs Linux vs. Mac

2008-03-18 Thread Martin Blume
Marc 'BlackJack' Rintsch schrieb I don't think this qualifies as a bug, but I am astonished that the struct module does not tell you whether you are big endian, you have to find out yourself with struct.unpack('@I', s)[0]==struct.unpack(I, s)[0] Maybe a little more compact and

Re: Strange problem with structs Linux vs. Mac

2008-03-16 Thread Martin Blume
jasonwiener schrieb I am having a VERY odd problem with unpacking right now. I'm reading data from a binary file and then using a very simple struct.unpack to get a long. Works fine on my MacBook, but when I push it to a Linux box,it acts differently and ends up pewking. [...] the

Re: Strange problem with structs Linux vs. Mac

2008-03-16 Thread Martin Blume
sturlamolden schrieb This seems to imply that the Mac, although running now on Intel processors, is still big-endian. Or maybe the struct module thinks big-endian is native to all Macs? It could be a bug. Dunno, I'm on thin ice here. Never used a Mac. Maybe the underlying C library

Re: Problem with the strip string method

2008-03-02 Thread Martin Blume
Colin J. Williams schrieb The Library Reference has strip( [chars]) Return a copy of the string with the leading and trailing characters removed. It's leading and trailing, not leading, trailing or embedded. xxxaaaxxx.strip(x) 'aaa' xxxaaaxxxaaaxxx.strip(x)

Re: Any experience with Python on a PDA ?

2008-02-22 Thread Martin Blume
Stef Mientki schrieb hello, I wonder if anyone has (good ;-) experiences with Python on a PDA ? And if so, - what OS - what GUI Python runs here on: - Sharp Zaurus SL-C3100 (with the exception of Tkinter) (Linux 2.4) - Mio A701 (Windows Mobile) But I only do small stuff on

Re: how to finish a while loop...

2008-02-20 Thread Martin Blume
richie schrieb That code works. Maybe you fixed it while you were mailing it =) This is weird mate. I'm using eclipse 3.2 with the pydev plugin. There it loops forever - from the eclipse console. Two hours of trying, changing the code...finally gave up. Then I got your

Re: Filtering two files with uncommon column

2008-01-18 Thread Martin Blume
Madhur schrieb I would like to know the best way of generating filter of two files based upon the following condition [...] Sounds like homework. Here some suggestions: - for each file, create a dictionary (see help(dict) in the python shell for details) and populate it with the values, so

Re: Bug in __init__?

2008-01-18 Thread Martin Blume
Zbigniew Braniecki schrieb I found a bug in my code today, and spent an hour trying to locate it and then minimize the testcase. [...] def __init__ (self, val=[]): [...] Any clue on what's going on here, and/if where I should report it? I think this has to do with

Re: Compiler or stg. to get exe!

2007-12-28 Thread Martin Blume
SMALLp schrieb I have question. After short goggling, I haven't found anything good. So my question is: I wrote a program in python and i Get .py files and some .pyc in working folder. Now i want program tu run under windows, so i need to get exe files or something. If python is

Re: making all letters Caps/Small Letters

2007-12-14 Thread Martin Blume
Merrigan schrieb im I'm sure I have done this before, but cannot remember how, or find out how to do it quickly - but is there a way/function/something in python to make all the letters of a raw_input() string small/capital letters? upper might help.upper() OR LOWER.lower() HTH Martin

Re: pprinting objects

2007-12-08 Thread Martin Blume
Donn Ingle schrieb Is there a way to get a dump of the insides of an object? I thought pprint would do it. print would actually like to do it if you told it how to do it. print actually does it, but takes a default implementation if you do not override __repr__ or __str__. If I had a class

Re: reading raw variables from file

2007-12-02 Thread Martin Blume
MonkeeSage schrieb If I have understood python naming scoping correctly, doing my_var=hello import stuff print my_var is not the same as my_var=hello exec open(stuff.py).read() print my_var with stuff.py containing my_var=bye It's not the same...

Re: reading raw variables from file

2007-11-30 Thread Martin Blume
Bruno Desthuilliers schrieb I have a file that might contain literal python variable statements at every line. For example the file info.dat looks like this: users = [Bob, Jane] status = {1:ok,2:users[0]} the problem is I want to read this file and load whatever variables

Re: reading raw variables from file

2007-11-30 Thread Martin Blume
Astan Chee schrieb I have a file that might contain literal python variable statements at every line. For example the file info.dat looks like this: users = [Bob, Jane] status = {1:ok,2:users[0]} the problem is I want to read this file and load whatever variables written in it as normal

Re: where is help file?

2007-09-14 Thread Martin Blume
Carsten Haese schrieb new to Fedora7, typed python in interactive interpreter, then help(). Then modules to get a list of modules. Then module name to get info on a module but no help file. What is the help file name? Is there an environmental variable I have to set? There is no help

Re: strftime in python 2.2

2007-08-13 Thread Martin Blume
Flyzoneschrieb I'm trying to make work this code in python 2.2.3: check=datetime.datetime.today().strftime(%H%M) but datetime is not supported in that version but just in the later. I can't upgrade python, too many dependencies in a critical system. How can i convert that string to

Re: Need a Little Help on Tkinter and Python

2007-06-06 Thread Martin Blume
W. Watson schrieb I have about a 1600 line Pythron program I'd like to make some simple mods to, but have really just a nodding acquaintance with Python and Tkinter. [...] Let's change that. The book Learning Python from O'Reilly is excellent. If you are into scientific programming,

Re: Execute commands from file

2007-05-19 Thread Martin Blume
Steve Holden schrieb [ difference between exec open(fname).read() and for line in open(fname): exec line ] So it seems to depend on the way the file is read. It depends on the way the lines of the file are executed, not how they are read. Could you elaborate a little bit

Re: Execute commands from file

2007-05-19 Thread Martin Blume
Steve Holden schrieb I simply meant that the whole source has to be presented to the exec statement and not chunked into lines. That's what I meant: With exec open(f).read() it is not broken into several exec invocations. I was probably just a little over-zealous in pursuing correct

Re: Execute commands from file

2007-05-17 Thread Martin Blume
Steve Holden schrieb Try it on a file that reads something like xxx = 42 print xxx and you will see NameError raised because the assignment hasn't affected the environment for the print statement. [...] No, because there isn't one. Now try adding a function definition

Re: Execute commands from file

2007-05-16 Thread Martin Blume
tmp123 schrieb We have very big files with python commands (more or less, 50 commands each file). It is possible to execute them command by command, inp = open(cmd_file) for line in inp: exec line might help. You don't get quite the same feeling as like if the commands was typed

Re: Finding the insertion point in a list

2007-03-17 Thread Martin Blume
7stud schrieb How about: --- x = [0, 100, 200, 1000] y = -1 inserted = False for i in range(len(x)): if(y = x[i]): x.insert(i, y) inserted = True break if(not inserted): x.append(y) print x You can

Re: How to call a function defined in another py file

2007-02-19 Thread Martin Blume
[EMAIL PROTECTED] schrieb I have a function called 'test' defined in A.py. How can I call that function test in my another file B.py? In B.py: import A A.test() HTH Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: How to call a function defined in another py file

2007-02-19 Thread Martin Blume
[EMAIL PROTECTED] schrieb I have a function called 'test' defined in A.py. How can I call that function test in my another file B.py? In B.py: import A A.test() But Do I need to put A.py and B.py in the same directory? No, but then you have to take certain precautions. (*) if not,

Re: Why does this code crash python?

2006-11-12 Thread Martin Blume
[EMAIL PROTECTED] schrieb I am trying to make a program that will basically simulate a chess clock in python. ... ... it crashes shortly after. Can't help you on why it crashes, but class eventMonitor (Thread): def run ( self ): [snipped] if

Re: Decorator

2006-05-12 Thread Martin Blume
bruno at modulix schrieb What Python 2.4 adds is only syntactic sugar for decorators. You can do the same - somewhat more explicitely - in 2.3. What is the decorator useful for? The whole things looks like this: def deco(func): print decorating %s % func.__name__ def

Re: Decorator

2006-05-12 Thread Martin Blume
Sybren Stuvel schrieb Martin Blume enlightened us with: Don't know if I enlightened anybody ... :-) Another question: Isn't decorating / wrapping usually done at runtime, so that the @deco notation is pretty useless (because you'd have to change the original code)? Please explain

Re: Decorator

2006-05-12 Thread Martin Blume
bruno at modulix schrieb [snip] The use case for @decorator is for wrapping functions or method *in the module/class itself*. That was the question. What's the use of doing it like that in the module *itself* (I mean, you change directly the original function)? It's not for module

Re: Decorator

2006-05-12 Thread Martin Blume
bruno at modulix schrieb Well, if you're changing the original module, Who's talking about changing the original module ? Well, you have to apply @deco in the module where func_to_decorated is placed. Isn't the point of a decorator to change the behavior externally, at runtime,

Re: Decorator

2006-05-12 Thread Martin Blume
bruno at modulix schrieb [lucid introduction into decorators] Thanks for the help in understanding decorators. Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a legal / acceptable statement ?

2006-05-05 Thread Martin Blume
Philippe Martin schrieb Hi, This code works, but is it appropriate ? l_init = False if True == l_init and 1234 = l_value: print 'l_value is initialized' I know I can do this with a try but ... I am a Python newbie, but I think working with l_value = None would be the most

Re: Invoking Unix commands from a Python app

2005-12-16 Thread Martin Blume
Rob Cowie schrieb Excellent... just the thing I was looking for. Thanks. Does anyone know of a unix app that could be used to monitor the duration of processes etc.? man -k account showed me (among others): acct (2) - switch process accounting on or off acct (5) -

Re: finding a number...

2005-10-21 Thread Martin Blume
Enrique Palomo Jiménez After ftp a file from mvs to windows, i find: is an offset, so up to 2GB, a commercial application drives crazy [...] ??? I didn't understand your question, but 2 GB is popular limit for the maximal size of a file for some filesystems (e.g. ext2, FAT [???]). Maybe

Re: eval() in python

2005-06-21 Thread Martin Blume
Xah Lee schrieb perhaps i'm tired, but why can't i run: t='m=3' print eval(t) Perhaps you didn't read the documentation? :-) Perhaps you didn't try hard enough? C:\WINNTc:\programme\python\python Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type help,

Re: oddness in super()

2005-06-19 Thread Martin Blume
Bjrn Lindstrm schrieb A great analysis, but what's a pogo stick and where can I get one? http://search.ebay.com/pogo-stick Yes, that explains the bouncing with the pogo stick; I would have poked around with a stick. ROTFL, thank you. Martin --

Re: continuous plotting with Tkinter

2005-02-04 Thread Martin Blume
Russell E. Owen schrieb I have a number-crunching application that spits out a lot of numbers. Now I'd like to pipe this into a python app and plot them using Tkinter, such as: $ number_cruncher | myplot.py But with Tkinter once I call Tkinter's mainloop() I give up my control of the app

continuous plotting with Tkinter

2005-02-02 Thread Martin Blume
I have a number-crunching application that spits out a lot of numbers. Now I'd like to pipe this into a python app and plot them using Tkinter, such as: $ number_cruncher | myplot.py But with Tkinter once I call Tkinter's mainloop() I give up my control of the app and I can't continue to read in