Re: Putting a lock on file.

2005-09-18 Thread tiissa
Harlin Seritt wrote: > I have a file that a few different running scripts will need to access. [...] > This may seem nice on paper but I hate to run a while for an > indeterminate amount of time. Is there anything else that can be done > that would be better? On posix systems, there is a fcntl mod

Re: execute commands and return output

2005-09-10 Thread tiissa
billiejoex wrote: > Hi all. I'm searching for a portable (working on *nix and win32) function > that executes a system command and encapsulate its output into a string. > Searching for the web I found this: > > os.popen('command').read() > > It is perfect but when che command return an error the

Re: sys.stdout

2005-09-09 Thread tiissa
Sébastien Boisgérault a écrit : > The sys.stdout stream behaves strangely in my > Python2.4 shell: > > >>> import sys > >>> sys.stdout.write("") > >>> sys.stdout.write("\n") > > >>> sys.stdout.write("\n") > > >>> sys.stdout.flush() > [...not

Re: Replacing large number of substrings

2005-09-04 Thread tiissa
Will McGugan wrote: > Hi, > > Is there a simple way of replacing a large number of substrings in a > string? I was hoping that str.replace could take a dictionary and use it > to replace the occurrences of the keys with the dict values, but that > doesnt seem to be the case. You can look at th

Re: documentation error

2005-09-04 Thread tiissa
bill wrote: >>From 3.2 in the Reference Manual "The Standard Type Hierarchy": > > "Integers > These represent elements from the mathematical set of whole > numbers." > > The generally recognized definition of a 'whole number' is zero and the > positive integers. This term is ambiguous as it

Re: Proposal: add sys to __builtins__

2005-09-03 Thread tiissa
Michael Hoffman wrote: > To the contrary, I agree with Larry Wall that laziness is one of the > cardinal virtues of a programmer. There's lazy and too lazy. You don't want to be too lazy to even get out of bed to code in Python. Of course, with Perl, that's entirely another mattress^Wmatter. >

Re: Proposal: add sys to __builtins__

2005-09-02 Thread tiissa
Michael Hoffman a écrit : > MrJbQ7 wrote: > > > Besides, a better way is to use your ~/.pythonrc file for customizing > > according to your needs. > > > > A simple: > > > > echo "import sys, os" >> ~./pythonrc > > > > will do the job. > > Until someone else tries to use your script or module. A

Re: random seed

2005-08-16 Thread tiissa
[EMAIL PROTECTED] wrote: > By default, randomm module uses the timestamp to generate the seed > value. Is it possible to know what that seed value is? From a (very) quick glance at the doc [1], I'm not sure you can get it. But if you want to reuse it later (for a deterministic behaviour), you

Re: how to append semicolon to a variable

2005-08-13 Thread tiissa
Grant Edwards wrote: > On 2005-08-13, yaffa <[EMAIL PROTECTED]> wrote: > >>i have the following lines of python code: >> >> couch = incident.findNextSibling('td') >> price = couch.findNextSibling('td') >> sdate = price.findNextSibling('td') >> city = sdate.findNextSibling('td')

Re: Putting function references in a Queue

2005-08-06 Thread tiissa
Richard Townsend wrote: > I've been experimenting putting a reference to a function into a Queue > object and was wondering what actually gets put in the Queue - is it the > function's code object? It would simply be the entire function object (unless you choose it otherwise). > If I read from t

Re: why no arg, abs methods for comlex type?

2005-08-06 Thread tiissa
Daniel Schüle wrote: >> Okay. Write a patch. Personally, I would prefer that it be a >> function in cmath rather than a method because then it could be made >> to work on integers and regular floats, too. > > Ok, but what semantic should angle/arg have, say for 3 respectively > for 3.0? > the s

Re: Comparison of functions

2005-07-30 Thread tiissa
Steven D'Aprano wrote: > It was easy. I never once asked myself whether some complex number was > greater or less than another, I just asked "which one comes first in a > lexicographic sort?" > > The two questions are NOT the same, and it is an ugliness in an otherwise > beautiful language that Py

Re: showing help(M) when running module M standalone

2005-07-30 Thread tiissa
Chris wrote: > hello, > I have a small module which only contains some utility functions. when > running this standalone I would like to show the module docs and each > function docs, as if doing > > import M > help(M) > > I came up with the following but I reckon there is a much simple

Re: string methods

2005-07-30 Thread tiissa
anthonyberet wrote: > I know this touches on immutability etc, but I can't find string methods > to return the first 3 characters, and then the last 2 characters, which > I could concatenate with newchar to make a new string. > > I know the string methods are there, but can't find it in any docs

Re: Comparison of functions

2005-07-30 Thread tiissa
Steven D'Aprano wrote: > Playing around with comparisons of functions (don't ask), I discovered an > interesting bit of unintuitive behaviour: > a = lambda y: y b = lambda y: y a > at 0xf70598ec> b > at 0xf7059844> a < b > False > > So I'm puzzled about how Python compares t

Re: FAQ?

2005-07-24 Thread tiissa
Michael Hoffman wrote: > Keith P. Boruff wrote: > >> Michael Hoffman wrote: >> >>> Keith P. Boruff wrote: >>> Is there an FAQ available specific to this NG as I'm sure some of the list slicing questions I have have been asked before. > > Therefore I asked a question on why you want a *

Re: Printing a variable's name not its value

2005-07-20 Thread tiissa
Simon Dahlbacka wrote: > as you have been told, there is no way to get a variable's name Well, if you really want to, you can get all the names bound to a given object: def get_names(obj): g = globals() names = [] for name in g: if g[name] is obj: names.appe

Re: Existance of of variable

2005-07-04 Thread tiissa
Josiah Manson wrote: > Hello. I am very new to Python, and have been unable to figure out how > to check if a variable exists or not. In the following code I have made > a kludge that works, but I think that it would be clearer to check if > closest exists and not have to initialize it in the first

Re: a question

2005-07-03 Thread tiissa
Xinyue Ye wrote: > when I type sys.ps2 after import sys, > I got the message like: > Traceback (most recent call last): > File "", line 1, in -toplevel- > sys.ps2 > AttributeError: 'module' object has no attribute 'ps2' > why does it happen? sys.ps2 is defined in an interactive session only as

Re: How to get/set class attributes in Python

2005-06-12 Thread tiissa
Kalle Anke wrote: > I'm coming to Python from other programming languages. I like to > hide all attributes of a class and to only provide access to them > via methods. Some of these languages allows me to write something > similar to this > > int age( ) > { > return theAge > } > > void age( x :

Re: Dynamic Lists, or...?

2005-06-11 Thread tiissa
Lorn wrote: > I'm trying to figure out a way to create dynamic lists or possibly > antother solution for the following problem. I have multiple lines in a > text file (every line is the same format) that are iterated over and > which need to be compared to previous lines in the file in order to > p

Re: If - Or statements

2005-06-11 Thread tiissa
Patrick Down wrote: > What about: > > if True in [thefile.endswith(x) for x in > ('mp3','mp4','ogg','aac','wma')]: That will catch (widely used) file names such as 'tmp3' or 'i_cant_spell_frogg'. ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: If - Or statements

2005-06-04 Thread tiissa
Ognjen Bezanov wrote: > ext = thefile.split('.') #get the file extension > ext[1] = ext[1].lower() #convert to lowercase As a side note, ext[1] will be the first extension: >>> 'foo.bar.ogg'.split('.')[1] 'bar' I'd advise ext[-1], the last element of the spli

Re: finding indices in a sequence of parentheses

2005-05-30 Thread tiissa
Peter Otten wrote: > I think no amount of testing will give these strange people confidence. > "Proof" is the magic word here. Some would maybe be satisfied if your tests cover the whole set of input. When that's possible, that may be useless. But that's not a matter to bother them with. ;) (An

Re: finding indices in a sequence of parentheses

2005-05-30 Thread tiissa
Peter Otten wrote: > tiissa wrote: >>Disclaimer: not tested further than example above (but confident). > > Not tested but confident should be an oxymoron for a programmer. Not tested but confident is an oxymoron for mathemtaticians. Programmers know better than that, they leav

Re: finding indices in a sequence of parentheses

2005-05-29 Thread tiissa
Steven Bethard wrote: > (2) Does anyone see an easier/clearer/simpler[1] way of doing this? I'd personnally extract the parenthesis then zip the lists of indices. In short: >>> def indices(mylist): ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in enumerate(mylist)],[]) ...

Re: need help of RE

2005-05-29 Thread tiissa
cheng wrote: > im sorry, my engilsh is not vell well, That's alright, you could have been french. ;) > the string not only contain '&' and '|' and it can be anyting > > i just want to split out the "whole word" inside the string Look at the example for split function of re module in the doc [1]

Re: __call__

2005-05-28 Thread tiissa
TK wrote: > Sorry but it does not work. It _does_ work. It just don't do what you expect. That's different till you know how to do it. Let's see: > >>> class Test(object): > ... def __call__(self): > ... print 'Hi' > ... You first define a class whose members can be called.

Re: Parsing a Python dictionary inside a Python extension

2005-05-28 Thread tiissa
[EMAIL PROTECTED] wrote: > I tried something like this and it has not worked. Oh! What did you ask of it, what did you expect and what did you get? > if ( (item = PyDict_GetItemString( vdict , "atab1")) != NULL ) > PyArg_ParseTuple( item , "i" , &atab1 ); This code expects a dictionary

Re: Markov chain with extras?

2005-05-18 Thread tiissa
[EMAIL PROTECTED] wrote: > I want to use it for music. So given list 1 (melody), list 2 (chords) > could be generated by a Markov chain. Also, given the chords the melody > could be generated again by a chain. So, at each time step you want: - chord(t) given melody(t-1), chord(t-1) and chord(t-2

Re: Markov chain with extras?

2005-05-17 Thread tiissa
[EMAIL PROTECTED] wrote: > I think is more easy explained as two linked markov chains. So given > one list the other can be generated. 'Given one list sounds' like an observation (and this sound like an order 2 hmm). But I'm not sure what exactly you want to do with your markov chain. Do you wan

Re: Precision?

2005-05-15 Thread tiissa
Steffen Glückselig wrote: 1.0 + 3.0 + 4.6 > > 8.5996 > > Ehm, how could I get the intuitively 'correct' result of - say - 8.6? > ;-) You may find annex B of the python tutorial an interesting read: http://docs.python.org/tut/node16.html -- http://mail.python.org/mailman/listinfo

Re: function with variable arguments

2005-05-14 Thread tiissa
Xah Lee wrote: > on a related topic, > I think it would be a improvement for the built-in range() so that step > needs not be an integer. There are easy workarounds but I'd find it useful as well. > Further, it'd be better to support decreasing range. e.g. > > Range( 5, 7, 0.3); # returns [5, 5.

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote: In article <[EMAIL PROTECTED]>, tiissa <[EMAIL PROTECTED]> wrote: So far, the OP is proposed the choice to either use the event/bind mecanism or use different callbacks for his different buttons (either with the method I proposed or not). Is there general unders

Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote: In article <[EMAIL PROTECTED]>, Eric Brunel <[EMAIL PROTECTED]> wrote: Unfortunately, making a binding to on Button widgets does not have the same behavior as setting their 'command' option. Without unraveling my own confusion about who has said what to whom, does everyone rea

Re: Getting the sender widget's name in function (Tkinter)

2005-04-26 Thread tiissa
Harlin Seritt wrote: I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: As far as I know you can't (but I can be proven wrong). You may try to define a class to solve this (not tested): class say_hello: def

Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread tiissa
[EMAIL PROTECTED] wrote: i wonder if there is an automatic way to make that without calling a function. You mean without _explicitely_ calling a function. May I inquire why you need to write f instead of f(x)? an automatic way that depends on changing the value of x. as each time x=something used t

Re: __del__ and reference count problem

2005-04-21 Thread tiissa
[EMAIL PROTECTED] wrote: Your problem can be simplified : class A: pop = 11 def __del__(self): print A.pop if __name__ == '__main__': objA = A() I got the same error message, and I don't know why ? it looks like the class variable can't be accessed from __del__? It's interesting to note t

Re: inner sublist positions ?

2005-04-21 Thread tiissa
Bernard A. wrote: > maybe have you some better / faster ideas / implementations ? or even > a more pythonic to help me learning that You may want to look at string matches algorithm (a good review: [1]). In particular there are classics like Boyer-Moore and some involving minimal automatons simila

Re: pyGTK on Mouse over event ?

2005-04-20 Thread tiissa
[EMAIL PROTECTED] wrote: def __init__(self): xml = gtk.glade.XML("/home/domenique/project1.glade") self.window = xml.get_widget("window1") self.img = xml.get_widget("image1") self.img.set_from_file("./test.svg") self.img.show() self.img.add_events(gtk.gdk.BUTTON_MOTION_MASK)

Re: pyGTK on Mouse over event ?

2005-04-20 Thread tiissa
[EMAIL PROTECTED] wrote: def __init__(self): xml = gtk.glade.XML("/home/domenique/project1.glade") self.window = xml.get_widget("window1") self.img = xml.get_widget("image1") self.img.set_from_file("./test.svg") self.img.show() self.img.add_events(gtk.gdk.BUTTON_MOTION_MASK)

Re: What's the difference between these 2 statements?

2005-04-20 Thread tiissa
Peter Otten wrote: Still, for practical purposes you have to test for slicelen >= stringlen, so whether you choose None, -len(s)-1, or -sys.maxint as the second slice parameter doesn't matter much. Sure, for practical purposes you don't bother to write extra characters and leave it void. But we kn

Re: pyGTK on Mouse over event ?

2005-04-20 Thread tiissa
[EMAIL PROTECTED] wrote: if i add a motion_notify or even a butten_press event to an image object it does absolutly nothing :s I have tried coding a simple application in pyGTK and I remember I had trouble getting button_press event in a DrawingArea. I was using glade and despite having declared a

Re: What's the difference between these 2 statements?

2005-04-20 Thread tiissa
Peter Otten wrote: [EMAIL PROTECTED] wrote: so if I want to reverse it fully using s[len(s)-1:x:-1] what would x be or is it impossible to express it in this way ? This does not work for integers, because the theoretically correct value x = -1 already has another interpretation as the gap betwee

Re: What's the difference between these 2 statements?

2005-04-20 Thread tiissa
[EMAIL PROTECTED] wrote: I'm sorry, I'm not really following your logic. Can you supply the statement with the three parameters ? so if I want to reverse it fully using s[len(s)-1:x:-1] what would x be or is it impossible to express it in this way ? Contrary to what I said above x should be _strict

Re: pyGTK on Mouse over event ?

2005-04-20 Thread tiissa
[EMAIL PROTECTED] wrote: hello, Is there an event simular to the java event onMouseOver ? I want to get the coordinates of the mouse pointer when it is over an image ( GTKImage widget) I've tried using the EventBox with the motion_notify but that only seems to work when the mouse is pressed ? Why d

Re: What's the difference between these 2 statements?

2005-04-20 Thread tiissa
Reinhold Birkenfeld wrote: ATSkyWalker wrote: What's the difference between these 2 statements? If you have a String s="12345" s[len(s)::-1] = "54321" But s[len(s):0:-1] = "5432" Why? What's the difference? What number then can I use as the end of the slice if I were to supply all 3 parameters? -1

Re: The value of the entry widget doesn't get updated

2005-04-19 Thread tiissa
Clara wrote: self.loginButton = Button(self, text='Login', command = VerifyProcessor(self.x.get(), self.y.get()) ) class VerifyProcessor: def __init__(self, thename, thepass): self.username = thename self.password = thepass def __cal

Re: Tkinter Event Types

2005-04-18 Thread tiissa
codecraig wrote: Hi, When I do something like. s = Scale(master) s.bind("", callback) def callback(self, event): print event.type I see "7" printed out. Where are these constants defined for various event types? Basically i want to do something like... 7 must be for KeyPressed. That's the t

Re: Tkinter & Tkconstants

2005-04-18 Thread tiissa
codecraig wrote: from Tkinter import * you have access to the constants in Tkconstants, since Tkinter imports it automatically. Yes However, in the shell if I do.. from Tkinter import * print Tkinter.HORIZONTAL I get an error..NameError: Tkinter is not defined Sure, you ask for Tkinter.HORIZONTAL.

Re: fpectl

2005-04-18 Thread tiissa
Matt wrote: Sébastien Boisgérault wrote: My platform is Linux (Mandrake 10.x) I'm assuming that means you can't use it on a Windows platform It's harsh to say Mandrake is a Windows platform. ;o) -- http://mail.python.org/mailman/listinfo/python-list

Re: packages

2005-04-18 Thread tiissa
Jaime Wyant wrote: What I *dont* like about the example is the PascalStyleCasing used for the package names. Is their not some *suggested* standard on naming conventions? There is: see PEP 8. http://www.python.org/peps/pep-0008.html However, I understood there was no definitive convention hence va

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-18 Thread tiissa
Synonymous wrote: tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(s1[i]!=s2[i]) for i in range(min(len(s1), len(s2)))] : diff_index=''.join(dif

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know the number of cha

Re:

2005-04-16 Thread tiissa
[EMAIL PROTECTED] wrote: I have been going through the manuals and not having much luck with the following code. This is basically an issue of giving 'split' multiple patterns to split a string. If it had an ignore case switch, the problem would be solved. Instead, I have to code the following,