Re: How to lock files (the easiest/best way)?

2006-07-16 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Jim Segrave <[EMAIL PROTECTED]> wrote: >except OSError, e: >if e.errno != errno.EEXIST: this should read: if e.errno != errno.ENOENT: (it was left with EEXIST from testing this code by forcing an error, as

Re: How to lock files (the easiest/best way)?

2006-07-16 Thread Jim Segrave
quot; % (lockfile, max_wait, pid)) # it's not been locked too long, wait a while and retry f.close() time.sleep(1) # if we get here. we have the lockfile. Convert the os.open file # descriptor into a Python file object and record our PID

Re: stderr, stdout, and errno 24

2006-07-12 Thread Jim Segrave
that they are all properly closed (or, in the case of Python, if you don't explicitly close them, that any references to the files cease to exist after the script runs). I'd personally recommend explicit closing here. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: re question

2006-07-10 Thread Jim Segrave
^^^ entire regular expression. This is useful if you wish to include ^ the flags as part of the regular expression, instead of passing a flag argument to the compile() function. Some regex packages, but not Python's, support (?-) and this allows turning the flag off and on for parts of the regex. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Augument assignment versus regular assignment

2006-07-10 Thread Jim Segrave
ugmented version. $ cat x.py def getindex(ind = 0): print 'getindex() called' return ind a = [0, 1, 2, 3, 4, 5] a[getindex(0)] = a[getindex(0)] + 17 print a a[getindex(1)] += 22 print a $ python x.py getindex() called getindex() called [17, 1, 2, 3, 4, 5] getindex() called [17

Re: Detecting 64bit vs. 32bit Linux

2006-07-08 Thread Jim Segrave
on of Python, then you'll need to figure out how to build and incorporate a Python extension which can detect this situation -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: how can I avoid abusing lists?

2006-07-08 Thread Jim Segrave
eyz = counters.keys() keyz.sort() for k in keyz: print k, counters[k] Takes care of IndexError and ValueError. It does not report keys that don't get incremented. If that's important, then initalise counters as in the quoted posting. For Python 2.4 and later, you can replace the keyz =

Re: socket buffer flush question

2006-07-05 Thread Jim Segrave
until the previous command has been processed. Once you transfer data to your machine's network stack, there's no way to stop it being sent to the remote end - in fact there's no practical way to determine if it's been put in a packet, sent to the remote end and lost or put in

Re: Can I do it using python?? about xterm and telnet

2006-07-02 Thread Jim Segrave
p of a machine (OS installation or whatever), our solution was to have a post-install CD or floppy which fetched standard server configuration data. This included an ssh public key for our ssh-key distribution, so after running the post-install disc, we could push out staff ssh-keys and logins were

Re: Regular Expression - old regex module vs. re module

2006-07-01 Thread Jim Segrave
either literals or lists > if type(item) == ListType: Might you be better off asking if item has a __getitem__? It would then work with tuples and Extending to dictionaries would then be easier >def isReportTemplate(obj): >"""Return 1 if obj is an instance of class ReportTemplate. >""" >if type(obj) == InstanceType and \ >string.find(`obj.__class__` , ' ReportTemplate ') > -1: >return 1 >else: >return 0 Why not just use isinstance(obj, classname)? >### ># ColumnReportTemplate # >### > >class ColumnReportTemplate: >"""This class allows one to specify column oriented output formats. > -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression - old regex module vs. re module

2006-06-30 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paul McGuire <[EMAIL PROTECTED]> wrote: >"Jim Segrave" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] > >I can see that the OP omitted the concept of "@|||" centering, since the >Python string int

Re: Regular Expression - old regex module vs. re module

2006-06-30 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paul McGuire <[EMAIL PROTECTED]> wrote: >"Jim Segrave" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> In article <[EMAIL PROTECTED]>, >> Paul McGuire <[EMAIL PROTECTED]> wrote: >> &

Re: Regular Expression - old regex module vs. re module

2006-06-30 Thread Jim Segrave
e definition of the >formatters variable. > >Pyparsing's project wiki is at http://pyparsing.wikispaces.com. If fails for floats specified as ###. or .###, it outputs an integer format and the decimal point separately. It also ignores \# which should prevent the '#' from being inc

Re: string replace

2006-06-30 Thread Jim Segrave
vowel uppercase: import string trans_table = string.maketrans('aeiou', 'AEIOU') "I don't know, but can be this feature included into".translate(trans_table) prints: "I dOn't knOw, bUt cAn bE thIs fEAtUrE InclUdEd IntO" That more than addresses y

Re: Regular Expression - old regex module vs. re module

2006-06-30 Thread Jim Segrave
: , integer # integer at end # Result: integer: %4d, integer %1d integer at end %1d Testing: float .## no decimals ###. no int .### at end ###. Result: float %7.2f no decimals %4.0f no int %4.3f at end %4.0f Testing: Left string <<<<<< short left string < Result: Left string %-6s short left string %-1s Testing: right string >>>>>> short right string > Result: right string %6s short right string %1s Testing: escaped chars \ \.## \<\<<<< \>\><<< Result: escaped chars \#%3d \#%6.2f \<\<%-3s \>\>%-3s -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: locating strings approximately

2006-06-29 Thread Jim Segrave
Useless Python <http://www.uselesspython.com/download.php?script_id=108>. *Apse* An extension module (written in C): Apse <http://www.personal.psu.edu/staff/i/u/iua1/python/apse/>. Requires python, SWIG, and a C compiler *Java* SecondString <http://sourceforge.net/projects/secondstring/> is an open source package with Java implementations of a large number of string comparision algorithms. They should not be too difficult to port to Python. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Large Dictionaries

2006-06-05 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Tim Peters <[EMAIL PROTECTED]> wrote: >[Jim Segrave] >> Actually, presorted lists are not a bad case for heapsort - it's quite >> immune to any existing order or lack thereof, > >Write a heapsort and time it. It's not a d

Re: Large Dictionaries

2006-06-05 Thread Jim Segrave
27;s quite immune to any existing order or lack thereof, whereas some other sorts, quicksort being a prime example, require great care to avoid pathological cases. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: wxpython wxgrid question

2006-06-03 Thread Jim Segrave
xt = "Row: %d\nCol: %d" % (row, col), bg = "#%02x%02x%02x" % ((row * 4 + col) * 16, (row * 4 + col) * 16, (row * 4 + col) * 16), fg = "#ff" ).grid(row =

Re: grouping a flat list of number by range

2006-06-02 Thread Jim Segrave
didn't see the right way to iterate over the supplied list inside the function, wheras he did. It's short, simple and correct. If you really wanted to return 'spam' or an exception in his solution, it's a simple if statement at the start of the function. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
, 9], [12, 14], [15, 16]] Fails on an empty list, as tmp is not defined when it hits the yield -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
tmp, valinc]; >tmp = val >valinc = val+1 >yield [tmp, valinc] Still fails when passed an empty list, the initial assignment to tmp is an IndexError -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
t now works, but returns [0, 0] when passed an empty list, when it should return nothing at all -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
tinue if __name__ == '__main__': for l in [[3, 6, 7, 8, 12, 13, 15], [2], []]: print l, "=>", [lst for lst in IterInterval(l)] /usr/home/jes% python interval.py [3, 6, 7, 8, 12, 13, 15] => [[3, 4], [6, 9], [12, 14], [15, 16]] [3] => [[3, 4]] [] => [] -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: An oddity in list comparison and element assignment

2006-06-01 Thread Jim Segrave
which works at the moment of comaprision is already there - that's what == does. If you really think there's a need for a comparision which includes dealing with aliasing, then it seems to me a python module with a set of functions for comparisions would make more sense. --

Re: An oddity in list comparison and element assignment

2006-06-01 Thread Jim Segrave
f analysiing nested structures - if you have a tuple, containing tuples which contain lists, then are those top level tuples 'equal' if there are aliases in the lists? How many levels deep should an equality test go? Does the more common test, to see if the elements of a sequence a

Re: iterator? way of generating all possible combinations?

2006-05-31 Thread Jim Segrave
er the file object, as follows, works - it now generates a a ... a z b a ... z z class FileReIterable2(object): def __init__(self, file): self.file = open(file, 'rU') def __iter__(self): self.file.seek(0) while True: line = self.f

Re: hi,everyone. a problem with shelve Module

2006-05-26 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, softwindow <[EMAIL PROTECTED]> wrote: [some context restored] >> Sometimes you add records but the size of the database does not >> change... :-) >really > >in which case? whenever the database is big enough to add them without i

Re: regex in python

2006-05-25 Thread Jim Segrave
ope/geocoord/32.32,42,12 > >By using \1\2\4 as replace. I'm open for other suggestions to achieve >this! But you're looking for a string followed by two floats and your sample input is a string, a float, an integer, a comma and another integer. If you actually mean the input i

Re: buffers readlines and general popen2 confusion...

2006-05-20 Thread Jim Segrave
est practice. Suggestions >welcomed. I'm puzzled - a daemonised program normally closes stdin/stdout/stderr and disconnects from its controlling terminal, so where is its output going? -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: 'error reading datastream' -- loading file only when transfer is complete?

2006-05-20 Thread Jim Segrave
size after a delay period, assume all the data is there. This isn't a good method, but it's simple to implement and will reduce the occurrence of attempts to process a file which is still in transit/ -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create a tear off menu in TKinter. Help Needed

2006-04-06 Thread Jim Segrave
t the code itself works to create cascading auto-pop-up menus, or any other widget you want to pop-up as part of a menu. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Server.sendmail with no "to_addrs" parameter.

2006-03-22 Thread Jim Segrave
Max number Notes ... to 0 1 cc 0 1 bcc 0 1 ... So the answere is, that it's not required to have any destinations listed in the headers of the message. It appears that it's not kosher to have an empty

Re: Server.sendmail with no "to_addrs" parameter.

2006-03-22 Thread Jim Segrave
r mail client) Much as it pains me to admit it, Outlook, for all its many faults is correct if it allows sending messages where the To: CC: and or Bcc: headers are empty. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: put multiple condition in if statement

2006-03-12 Thread Jim Segrave
t;".strip() == " ".strip() >True >>>> > > So... Your mixed C/Python simplifies to just... > > if str.strip(): # after removing leading/trailing spaces, > # if not empty, do something str = " " and str = "\t" fail with your substitution - the OP was looking only for strings containing one space or empty strings. Tab characters and multi-spaces would not match. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: time series calculation in list comprehension?

2006-03-12 Thread Jim Segrave
74 49.00 7: 21 50.25 8: 78 51.25 9: 28 50.25 10: 32 39.75 11: 93 57.75 12: 2 38.75 13: 7 33.50 14: 8 27.50 15: 30 11.75 16: 1 11.50 17: 8 11.75 18: 40 19.75 19: 8 14.25 For all but the first 3 rows, the third column is the average of the values in the 2nd column

Re: MySQLdb question... using table name as arg

2006-02-03 Thread Jim Segrave
question but I just can't figure it out. How about interpolating the table name into the string: c.execute("update %s set col1 = %%s, col2 = %%s, col3=%%s" % (sometable), \ ['the', 'cat', 'in the hat']) Note the need to double the %'s for the parameters to be bound. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs C for a mail server

2006-01-29 Thread Jim Segrave
t these days. > >I'm on my second major mail system deployment built around Exim, and >would recommend it to anybody needing a robust, flexible mail server. There is an exim 4 book out, but not via O'Reilly - I gather sales were insufficient to persuade O'Rei

Re: Python vs C for a mail server

2006-01-29 Thread Jim Segrave
hich is ready to be used on the Internet for any but very limited applications. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs C for a mail server

2006-01-28 Thread Jim Segrave
the mistaken belief that they actually have done it correctly. The number of software products which use eail and do so incorrectly is astounding and depressing. There's a reason that the source for sendmail is about 120K lines, exim is nearly 270K lines. Doing it right is _hard_. -- Ji

Re: Detecting problems in a forked process

2005-12-29 Thread Jim Segrave
the same thing at the same time. Thanks in advance :) options: Have the child set it's exit code to indicate success or failure and use one of the various os.wait functions in the parent to retrieve it. or create a pipe before forking and you can pass data back and forth between the parent

Re: how do i use "tkinter.createfilehandler" with a regular c program?

2005-11-14 Thread Jim Segrave
mainFrame = Frame(root) textBox = Text(mainFrame) textBox.pack(fill=BOTH, expand=YES) mainFrame.pack(fill=BOTH, expand=YES) fh = os.popen('/bin/cat /tmp/pipe', 'r', 1) def readfh(filehandle, stateMask): global textBox newText = filehandle.readline() textBox.insert(END, newText) tkinter.createfilehandler(fh, tkinter.READABLE, readfh) root.mainloop() -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: mod_python

2005-11-06 Thread Jim Segrave
g, z_price) ) I hate to ask, but what happens when I enter "a, b, c);DROP DATABASE;" as the entry for z_name? (Or some similar attempt to close the SQL statement and start a new one). I think you want to google for "SQL injection" and think about sanitising user input a bit. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: fcntl.flock() not working when called from a function

2005-11-04 Thread Jim Segrave
keep a reference to f: import fcntl def lock(): f=open('/tmp/lockfile') fcntl.flock(f,fcntl.LOCK_EX) return f saveme = lock() print "OK" while True: pass Under FreeBSD, the first copy prints OK and waits for a SIGINT, the second copy prints nothing. Killing the first copy prints OK on the second one -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter- New Window

2005-11-04 Thread Jim Segrave
f = RIDGE) otherlabel.pack(side = TOP, fill = BOTH, expand = YES) root.mainloop() -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter- checkbutton

2005-11-04 Thread Jim Segrave
ther_stuff_here() else: print "This is impossible, but it happened" b = Checkbutton(root, text = 'Press Me', command = check, variable = v) b.grid(row = 0, column = 0) root.mainloop() -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: strange sockets

2005-11-04 Thread Jim Segrave
ed is how long it takes to transfer the data to the underlying OS socket buffers. The first transfer fills the buffers, subsequent ones have to wait until the data has been put on the wire and acknowledged before there's space for the writes. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list

Re: If Statement Error (Tic Tac Toe)

2005-11-02 Thread Jim Segrave
ocation, fill it in board[loc] = ['X', 'O'][player] for i in range(3): # check for horizontal win if board[3 * i] == board[ 3 * i + 1] == board[3 * i + 2] and \ board[3 * i] != ' ': win =