Re: Import module with non-standard file name

2006-08-07 Thread Simon Forman
Ben Finney wrote: Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to be run as commands to a file with no extension. This allows other programs to use

Re: using python at the bash shell?

2006-08-07 Thread Simon Forman
[EMAIL PROTECTED] wrote: John Aside from the normal commands you can use, I was wondering if John it's possible to use Python from the terminal instead of the John normal bash commands (e.g. print instead of echo). Take a look at ipython http://ipython.scipy.org/. It's not precisely

Re: subprocesses and deadlocks

2006-08-06 Thread Simon Forman
[EMAIL PROTECTED] wrote: Hi, there are many ways of solving the problem of finite buffer sizes when talking to a subprocess. I'd usually suggest using select() but today I was looking for a more readable/understandable way of doing this. Back in 1997 Guido himself posted a very nice

Re: current recursion level

2006-08-06 Thread Simon Forman
Cameron Laird wrote: In article [EMAIL PROTECTED], Simon Forman [EMAIL PROTECTED] wrote: David Bear wrote: Is there an easy way to get the current level of recursion? I don't mean . . . import sys def getStackDepth

Re: Backup GMAIL Messages with Python

2006-08-05 Thread Simon Forman
Gregory PiƱero wrote: I was wondering what methods you experts would reccomend for this task? Here are the options I have come up with so far: 1. Build something with the poblib library (http://docs.python.org/lib/module-poplib.html) --Any pointers on doing this? How to I get poplib to

Re: testing array of logicals

2006-08-05 Thread Simon Forman
Janto Dreijer wrote: Janto Dreijer wrote: John Henry wrote: Simon Forman wrote: False not in logflags Or, if your values aren't already bools False not in (bool(n) for n in logflags) Very intriguing use of not in... Is there a reason why you didn't

Re: Thread Question

2006-08-05 Thread Simon Forman
Ritesh Raj Sarraf wrote: Bryan Olson on Saturday 05 Aug 2006 23:56 wrote: You don't want ziplock = threading.Lock() in the body of the function. It creates a new and different lock on every execution. Your threads are all acquiring different locks. To coordinate your threads, they need

Re: Need help building boost python on mac os x.

2006-08-04 Thread Simon Forman
KraftDiner wrote: Could someone point me to step by step instructions on building boost python on mac os x? I have bjam running.. I have the boost source... but the tests are failing.. Probably something to do with environement variables... Anyone with time? You might also ask on the boost

Re: What is the best way to print the usage string ?

2006-08-03 Thread Simon Forman
Leonel Gayard wrote: Hi all, I had to write a small script, and I did it in python instead of shell-script. My script takes some arguments from the command line, like this. import sys args = sys.argv[1:] if args == []: print Concat: concatenates the arguments with a colon (:)

Re: Hiding Console Output

2006-08-03 Thread Simon Forman
Kkaa wrote: This seems like the right thing to do, but it runs the program in the background, and I need my program to wait until the x.exe has finished. I tried using this code: p = subprocess.Popen(x.exe,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE, stderr=subprocess.PIPE)

Re: OS independent files

2006-08-03 Thread Simon Forman
crystalattice wrote: I'm sure this has been addressed before but it's difficult to search through several thousand postings for exactly what I need, so I apologize if this a redundant question. Google groups has a very good search. I've figured out how to use os.path.join to make a file or

Re: help - iter dict

2006-08-03 Thread Simon Forman
[EMAIL PROTECTED] wrote: Dear Python people, im a newbie to python and here...so hello! Hi Ali, and welcome. Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that valuewhat ive done so far: def pcloop(dictionary,

Re: current recursion level

2006-08-03 Thread Simon Forman
David Bear wrote: Is there an easy way to get the current level of recursion? I don't mean sys.getrecursionlimit. I want to know during a live run of a script how many times the functions has recursed -- curses, I don't know how to say it better. -- David Bear -- let me buy your

Re: Problem reading/writing files

2006-08-03 Thread Simon Forman
[EMAIL PROTECTED] wrote: This is a bit of a peculiar problem. First off, this relates to Python Challenge #12, so if you are attempting those and have yet to finish #12, as there are potential spoilers here. I have five different image files shuffled up in one big binary file. In order to

Re: Zipping files/zipfile module

2006-08-02 Thread Simon Forman
Brian Beck wrote: OriginalBrownster wrote: I want to zip all the files within a directory called temp and have the zip archive saved in a directory with temp called ziptemp I was trying to read up on how to use the zipfile module python provides, but I cannot seem to find adequate

Re: Is there an obvious way to do this in python?

2006-08-02 Thread Simon Forman
H J van Rooyen wrote: Hi, I want to write a small system that is transaction based. I want to split the GUI front end data entry away from the file handling and record keeping. Now it seems almost trivially easy using the sockets module to communicate between machines on the same LAN, so

Re: Thread Question

2006-08-02 Thread Simon Forman
Ritesh Raj Sarraf wrote: Hi, I have this following situation: #INFO: Thread Support # Will require more design thoughts from Queue import Queue from threading import Thread, currentThread NUMTHREADS = variables.options.num_of_threads def

Re: cleaner way to write this try/except statement?

2006-08-01 Thread Simon Forman
John Salerno wrote: John Salerno wrote: The code to look at is the try statement in the NumbersValidator class, just a few lines down. Is this a clean way to write it? i.e. is it okay to have all those return statements? Is this a good use of try? Etc. I cleaned it up a little and did

Re: cleaner way to write this try/except statement?

2006-08-01 Thread Simon Forman
Simon Forman wrote: John Salerno wrote: John Salerno wrote: The code to look at is the try statement in the NumbersValidator class, just a few lines down. Is this a clean way to write it? i.e. is it okay to have all those return statements? Is this a good use of try? Etc. I cleaned

Re: cleaner way to write this try/except statement?

2006-08-01 Thread Simon Forman
John Salerno wrote: John Salerno wrote: The code to look at is the try statement in the NumbersValidator class, just a few lines down. Is this a clean way to write it? i.e. is it okay to have all those return statements? Is this a good use of try? Etc. I cleaned it up a little and did

Re: cleaner way to write this try/except statement?

2006-08-01 Thread Simon Forman
Boris Borcic wrote: John Salerno wrote: The code to look at is the try statement in the NumbersValidator class, just a few lines down. Is this a clean way to write it? i.e. is it okay to have all those return statements? Is this a good use of try? Etc. Thanks.

Re: Get age of a file/dir

2006-08-01 Thread Simon Forman
url81-1 wrote: Actually this has nothing to do with datetime.datetime -- he's asking how to find the created time of the directory. Python has a builtin module called stat (afer sys/stat.h) which includes ST_ATIME, ST_MTIME, ST_CTIME members which are times accessed, modified, and created,

Re: trouble understanding super()

2006-07-31 Thread Simon Forman
John Salerno wrote: Here's some code from Python in a Nutshell. The comments are lines from a previous example that the calls to super replace in the new example: class A(object): def met(self): print 'A.met' class B(A): def met(self): print 'B.met'

Re: FTP (ftplib) output capture

2006-07-31 Thread Simon Forman
ChaosKCW wrote: Hi Has anyone caputerd the output from the std ftp lib? It seems a bit annoying that everything is printed to stdout. It means incorporating this into any real program is a problem. It would have been much better if they used the std logging module and hooked up a console

Re: import error

2006-07-31 Thread Simon Forman
cheeky wrote: Hi, all. I now really like to program with Python, even though I'm a newbie. I have difficulty in solving the following problem. $ python Traceback (most recent call last): File x.py, line 6, in ? import calendar, time File time.py, line 5, in ? now =

Re: running an app as user foo

2006-07-31 Thread Simon Forman
bruce wrote: hi. within python, what's the best way to automatically spawn an app as a given user/group. i'm testing an app, and i'm going to need to assign the app to a given user/group, as well as assign it certain access rights/modes (rwx) i then want to copy the test app to a given

Re: Pickle vs XML for file I/O

2006-07-31 Thread Simon Forman
crystalattice wrote: I'm creating an RPG for experience and practice. I've finished a character creation module and I'm trying to figure out how to get the file I/O to work. I've read through the python newsgroup and it appears that shelve probably isn't the best option for various reasons.

Re: BCD List to HEX List

2006-07-31 Thread Simon Forman
Philippe, please! The suspense is killing me. What's the cpu!? For the love of God, what's the CPU? I-can't-take-it-anymore-it's-such-a-simple-question-ingly yours, ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with arrays of strings

2006-07-31 Thread Simon Forman
Jon Smirl wrote: I only have a passing acquaintance with Python and I need to modify some existing code. This code is going to get called with 10GB of data so it needs to be fairly fast. http://cvs2svn.tigris.org/ is code for converting a CVS repository to Subversion. I'm working on changing

Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Simon Forman
Chaos wrote: Simon Forman wrote: Chaos wrote: As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes 450

Re: non-blocking PIPE read on Windows

2006-07-28 Thread Simon Forman
placid wrote: Hi all, I have been looking into non-blocking read (readline) operations on PIPES on windows XP and there seems to be no way of doing this. Ive read that you could use a Thread to read from the pipe, but if you still use readline() wouldnt the Thread block too? Yes it will,

Re: SocketServer and timers

2006-07-28 Thread Simon Forman
alf wrote: Hi, I have one thread app using SocketServer and use server_forever() as a main loop. All works fine, but now I need certain timer checking let's say every 1 second something and stopping the main loop. So questions are: -how to stop serve_forever -how to implement

Re: locked file

2006-07-28 Thread Simon Forman
Kirt wrote: By locked files i mean Outlook PST file while Outlook has it open Simon Forman wrote: Kirt wrote: i have a code that backsup file from src to dest. Now if some of the files are locked , i need to skip those files.. I was trying to use fctl module but it can be used only

Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread Simon Forman
Simon Forman wrote: Chaos wrote: Simon Forman wrote: Chaos wrote: As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX

Re: replacing single line of text

2006-07-28 Thread Simon Forman
[EMAIL PROTECTED] wrote: I want to be able to replace a single line in a large text file (several hundred MB). Using the cookbook's method (below) works but I think the replace fxn chokes on such a large chunk of text. For now, I simply want to replace the 1st line (CSV header) in the file but

Re: SocketServer and timers

2006-07-28 Thread Simon Forman
[EMAIL PROTECTED] wrote: ... That alone does not work. If server.handle_request() blocks, you don't get to the check(). You need some kind of timeout in handle_request(). -- --Bryan Ach! You're right. I didn't consider that handle_request() might block.. --

Re: Functions and code objects

2006-07-27 Thread Simon Forman
Fuzzyman wrote: Fuzzyman wrote: Fuzzyman wrote: Hello all, I'm trying to extract the code object from a function, and exec it without explicitly passing parameters. The code object 'knows' it expects to receive paramaters. It's 'arg_count' attribute is readonly. How

Re: Thread Question

2006-07-27 Thread Simon Forman
Ritesh Raj Sarraf wrote: Duncan, I couldn't make out much from the code. Please, try again to understand Duncan's code. It's much better than what you did. Instead this is what I did. threads = [] nloops = range(len(lRawData)) for i in nloops: (sUrl, sFile,

Re: locked file

2006-07-27 Thread Simon Forman
Kirt wrote: i have a code that backsup file from src to dest. Now if some of the files are locked , i need to skip those files.. I was trying to use fctl module but it can be used only in unix i suppose. is there anyother way? i am using windows os. What does locked mean in this case? No

Re: Thread Question

2006-07-27 Thread Simon Forman
Duncan Booth wrote: Simon Forman wrote: If you need help understanding it please ask questions. I, for one, would be happy to comment it for you to explain how it works. It's so nice and elegant that I've already cut-and-pasted it into my own notebook of cool useful python patterns

Re: iter(callable, sentinel)

2006-07-27 Thread Simon Forman
Will McGugan wrote: Hi, I've been using Python for years, but I recently encountered something in the docs I wasnt familar with. That is, using two arguements for iter(). Could someone elaborate on the docs and maybe show a typical use case for it? Thanks, Will McGugan -- work:

Re: iter(callable, sentinel)

2006-07-27 Thread Simon Forman
Will McGugan wrote: Hi, I've been using Python for years, but I recently encountered something in the docs I wasnt familar with. That is, using two arguements for iter(). Could someone elaborate on the docs and maybe show a typical use case for it? Thanks, Will McGugan -- work:

Re: iter(callable, sentinel)

2006-07-27 Thread Simon Forman
Will McGugan wrote: Hi, I've been using Python for years, but I recently encountered something in the docs I wasnt familar with. That is, using two arguements for iter(). Could someone elaborate on the docs and maybe show a typical use case for it? Thanks, Will McGugan -- work:

Re: help: output arrays into file as column

2006-07-27 Thread Simon Forman
bei wrote: Hi, I am trying to write several arrays into one file, with one arrays in one column. Each array (column) is seperated by space. ie. a=[1,2,3, 4] b=[5,6,7,8] c=[9,10,11,12] 1 5 9 2 6 10 3 7 11 4 8 12 Now I use the function file.writelines(a), file.writelines(b),

Re: Fastest Way To Loop Through Every Pixel

2006-07-27 Thread Simon Forman
Chaos wrote: As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes 450-1000 milliseconds I want speeds less than 10

Re: list problem

2006-07-26 Thread Simon Forman
placid wrote: But there may be other characters before XXX (which XXX is constant). A better example would be, that string s is like a file name and the characters before it are the absolute path, where the strings in the first list can have a different absolute path then the second list

Re: import from containing folder

2006-07-26 Thread Simon Forman
David Isaac wrote: Suppose I have inherited the structure PackageFolder/ __init__.py mod1.py mod2.py SubPackageFolder/ __init__.py mod3.py and mod3.py should really use a function in mod2.py. *Prior* to Python 2.5, what is the best

Re: Tkinter pack Problem

2006-07-26 Thread Simon Forman
I find the Tkinter reference: a GUI for Python under Local links on this page http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html to be very helpful. It has a decent discussion of the grid layout manager. HTH, ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: extender method

2006-07-26 Thread Simon Forman
[EMAIL PROTECTED] wrote: 'Learning Python' by Lutz and Ascher (excellent book by the way) explains that a subclass can call its superclass constructor as follows: class Super: def method(self): # do stuff class Extender(Super): def method(self): Super.method(self) # call

Re: Changing a value for each folder while traversing a file system

2006-07-26 Thread Simon Forman
PipedreamerGrey wrote: I'm using the script below (originally from http://effbot.org, given to me here) to open all of the text files in a directory and its subdirectories and combine them into one Rich text file (index.rtf). Now I'm adapting the script to convert all the text files into

Re: subprocess problem on WinXP

2006-07-26 Thread Simon Forman
Wolfgang wrote: Hi, I want to compress all files (also in subfolder). The code is working more or less, but I get a black popup window (command line window) for every file to compress. How do I cave to change my system call that nothing pops up? Wolfgang import os import subprocess

Re: import from containing folder

2006-07-26 Thread Simon Forman
David Isaac wrote: Alan wrote: I do not want to make any assumptions about this particular package being on sys.path. (I want a relative import, but cannot assume 2.5.) I should mention that to get around this I have been using sys.path.append(os.path.split(sys.argv[0])[0]) in the

Re: subprocess problem on WinXP

2006-07-26 Thread Simon Forman
Wolfgang wrote: Hi Simon, I did not know that library! I'm still new to python and I still have problems to find the right commands. Welcome. : ) Python comes with batteries included. I'm always finding cool new modules myself, and I've been using it for years. In fact, I didn't notice the

Re: Splitting a float into bytes:

2006-07-26 Thread Simon Forman
Michael Yanowitz wrote: Hello: For some reason I can't figure out how to split a 4-byte (for instance) float number (such as 3.14159265359) into its 4-bytes so I can send it via a socket to another computer. For integers, it is easy, I can get the 4 bytes by anding like: byte1 =

Re: Splitting a float into bytes:

2006-07-26 Thread Simon Forman
Michael Yanowitz wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Simon Forman Sent: Wednesday, July 26, 2006 2:56 PM To: python-list@python.org Subject: Re: Splitting a float into bytes: Michael Yanowitz wrote: Hello: For some reason

Re: splitting words with brackets

2006-07-26 Thread Simon Forman
Qiangning Hong wrote: faulkner wrote: re.findall('\([^\)]*\)|\[[^\]]*|\S+', s) sorry i forgot to give a limitation: if a letter is next to a bracket, they should be considered as one word. i.e.: a(b c) d becomes [a(b c), d] because there is no blank between a and (. This variation seems

Re: splitting words with brackets

2006-07-26 Thread Simon Forman
Qiangning Hong wrote: Tim Chase wrote: import re s ='a (b c) d [e f g] h ia abcd(b c)xyz d [e f g] h i' r = re.compile(r'(?:\S*(?:\([^\)]*\)|\[[^\]]*\])\S*)|\S+') r.findall(s) ['a', '(b c)', 'd', '[e f g]', 'h', 'ia', 'abcd(b c)xyz', 'd', '[e f g]', 'h', 'i'] [...]

Re: removing duplicates, or, converting Set() to string

2006-07-26 Thread Simon Forman
[EMAIL PROTECTED] wrote: Hello, I have some lists for which I need to remove duplicates. I found the sets.Sets() module which does exactly this, but how do I get the set back out again? # existing input: A,B,B,C,D # desired result: A,B,C,D import sets dupes = ['A','B','B','C','D']

Re: dicts vs classes

2006-07-25 Thread Simon Forman
Simon Hibbs wrote: I'm wondering about whether to use objects in this way or dictionaries for a program I'm writing at the moment. It seems to me that unless you need some of the functionality supplied with dictionaries (len(a), has_key, etc) then simple objects are a syntacticaly cleaner and

Re: Help in string.digits functions

2006-07-25 Thread Simon Forman
John McMonagle wrote: On Mon, 2006-07-24 at 22:19 -0700, Anoop wrote: Hi All I am getting two different outputs when i do an operation using string.digits and test.isdigit(). Is there any difference between the two. I have given the sample program and the output Thanks for ur inputs

Re: print function question

2006-07-25 Thread Simon Forman
Bertrand-Xavier M. wrote: On Tuesday 25 July 2006 05:52, Eric Bishop wrote: Why does this work: # start a = 5 print a, 'is the number' #end, prints out 5 is the number But not this: # start a = 5 print a 'is the number' #end, errors out The difference here

Re: cStringIO.StringIO has no write method?

2006-07-25 Thread Simon Forman
Laszlo Nagy wrote: Nope. StringI is an input-only object, StringO is an output object. You got a StringI because you gave a string argument to the creator. f1 = cStringIO.StringIO() f1 cStringIO.StringO object at 0x186c9c00 dir(f1) ['__class__', '__delattr__', '__doc__',

Re: building an index for large text files for fast access

2006-07-25 Thread Simon Forman
Yi Xing wrote: Hi, I need to read specific lines of huge text files. Each time, I know exactly which line(s) I want to read. readlines() or readline() in a loop is just too slow. Since different lines have different size, I cannot use seek(). So I am thinking of building an index for the

Re: list problem

2006-07-25 Thread Simon Forman
placid wrote: Hi all, I have two lists that contain strings in the form string + number for example list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] the second list contains strings that are identical to the first list, so lets say the second list contains the following list1 = [ ' XXX1',

Re: list problem

2006-07-25 Thread Simon Forman
Simon Forman wrote: Finally, you can say: for i in xrange(1,10): s = XXX1%04i % i if s not in list1 and s not in list2: print s HTH, ~Simon D'oh! Forgot to break. for i in xrange(1,10): s = XXX1%04i % i if s not in list1 and s not in list2: print s

Re: list problem

2006-07-25 Thread Simon Forman
placid wrote: Simon Forman wrote: placid wrote: Hi all, I have two lists that contain strings in the form string + number for example list1 = [ ' XXX1', 'XXX2', 'XXX3', 'XXX5'] the second list contains strings that are identical to the first list, so lets say

Re: Search within running python scripts

2006-07-24 Thread Simon Forman
gmax2006 wrote: Hi, Is it possible that a python script finds out whether another instance of it is currently running or not? Thank you, Max Yes, there are several ways. What OS are you using? ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: Search within running python scripts

2006-07-24 Thread Simon Forman
gmax2006 wrote: Simon Forman wrote: gmax2006 wrote: Hi, Is it possible that a python script finds out whether another instance of it is currently running or not? Thank you, Max Yes, there are several ways. What OS are you using? ~Simon I have to use an os

Re: Search within running python scripts

2006-07-24 Thread Simon Forman
Cameron Laird wrote: ... Particularly when I hear os-independent, I think first of binding to a socket. While URL: http://wiki.tcl.tk/1558 is written for a Tcl-based crowd, the commentary there ap- plies quite well to Python. I was going to suggest something like this, as I have noticed

Re: Which Pyton Book For Newbies?

2006-07-23 Thread Simon Forman
W. D. Allen wrote: I want to write a retirement financial estimating program. Python was suggested as the easiest language to use on Linux. I have some experience programming in Basic but not in Python. I have two questions: 1. What do I need to be able to make user GUIs for the program,

Re: Track keyboard and mouse usage

2006-07-23 Thread Simon Forman
Dennis Lee Bieber wrote: On 17 Jul 2006 21:00:09 -0700, dfaber [EMAIL PROTECTED] declaimed the following in comp.lang.python: Is there no clean method of accessing the keyboard device or the mouse on linux? It seems that looking at /proc/interrupts might prove to be useful for keyboard

Re: regular expression - matches

2006-07-21 Thread Simon Forman
abcd wrote: how can i determine if a given character sequence matches my regex, completely? in java for example I can do, Pattern.compile(regex).matcher(input).matches() this returns True/False whether or not input matches the regex completely. is there a matches in python? Yes. It's

Re: regular expression - matches

2006-07-21 Thread Simon Forman
John Salerno wrote: Simon Forman wrote: Python's re.match() matches from the start of the string, so if you want to ensure that the whole string matches completely you'll probably want to end your re pattern with the $ character (depending on what the rest of your pattern matches

Re: An optparse question

2006-07-21 Thread Simon Forman
T wrote: fuzzylollipop wrote: you can make the usage line anything you want. ... usage = 'This is a line before the usage line\nusage %prog [options] input_file' parser = OptionsParser(usage=usage) parser.print_help() ... No, that affects the string printed only *after* the

Re: An optparse question

2006-07-21 Thread Simon Forman
[EMAIL PROTECTED] wrote: No, that affects the string printed only *after* the usage = string. What I would like to do is insert some string *before* the usage = string, which is right after the command I type at the command prompt. So I would like to make it look like this: The

Re: regular expression - matches

2006-07-21 Thread Simon Forman
John Salerno wrote: Thanks guys! A pleasure. : ) -- http://mail.python.org/mailman/listinfo/python-list

Re: Nested function scope problem

2006-07-21 Thread Simon Forman
Gerhard Fiedler wrote: On 2006-07-21 21:05:22, Josiah Manson wrote: I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my

Re: Depricated String Functions in Python

2006-07-20 Thread Simon Forman
Anoop wrote: Thanks Stefen let me be more specific how would i have to write the following function in the deprecated format map(string.lower,list) Thanks Anoop Ah. This is easy enough: lower_list = [s.lower() for s in str_list] Or, if you really like map() (or really don't like list

Re: Text Summarization

2006-07-19 Thread Simon Forman
[EMAIL PROTECTED] wrote: Jim Jones wrote: Is there a Python library that would allow me to take a paragraph of text, and generate a one or two sentence summary of that paragraph? There is a OTS wrapper. http://libots.sourceforge.net/ as for the wrapper, this was all I could find (in

Re: Authentication

2006-07-19 Thread Simon Forman
bigodines wrote: Hello guys, I'm trying to learn python by making some small programs that could be useful for some bigger propouses. In fact, i've made a small check latest-modified for webpages and it's working great. The next step I would like to do is to check if I have new e-mails (I

Re: Simple file writing techiques ...

2006-07-19 Thread Simon Forman
cdecarlo wrote: Hello, I've often found that I am writing little scripts at the interpretor to read a text file, perform some conversion, and then write the converted data back out to a file. I normally accomplish the above task by snip Any suggestions, Colin You should check out the

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Dan Bishop wrote: [EMAIL PROTECTED] wrote: it seems that range() can be really slow: ... if i in range (0, 1): This creates a 10,000-element list and sequentially searches it. Of course that's gonna be slow. And you're doing it 3 times. --

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Nick Craig-Wood wrote: Sets are pretty fast too, and have the advantage of flexibility in that you can put any numbers in you like I know this is self-evident to most of the people reading this, but I thought it worth pointing out that this is a great way to test membership in range(lo, hi,

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Diez B. Roggisch wrote: Simon Forman wrote: Nick Craig-Wood wrote: Sets are pretty fast too, and have the advantage of flexibility in that you can put any numbers in you like I know this is self-evident to most of the people reading this, but I thought it worth pointing out

Re: Piping external commands

2006-07-18 Thread Simon Forman
[EMAIL PROTECTED] wrote: What is the Python translation for this Bash statement: tar cf - [EMAIL PROTECTED] | bzip2 $file.tar.bz2 (Ignoring the fact that tar cjf also exists...) In other words, how does one pipe together arbitrary commands? For piping subcommands check out the

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
K.S.Sreeram wrote: Simon Forman wrote: Nick Craig-Wood wrote: Sets are pretty fast too, and have the advantage of flexibility in that you can put any numbers in you like I know this is self-evident to most of the people reading this, but I thought it worth pointing out

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
tac-tics wrote: Simon Forman wrote: To me, and perhaps others, T = set(xrange(0, 1, 23)) and n in T are somewhat easier to read and write than not n % 23 and 0 = n 1, YMMV. Eh? How is the first easier to read than the second?? You have a nested function call in the first! I

Re: execute a shell script from a python script

2006-07-17 Thread Simon Forman
spec wrote: Thanks, actually there are no args, is there something even simpler? Thanks Frank you could try os.system() From the docs: system(command) Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same

Re: instantiate all subclasses of a class

2006-07-16 Thread Simon Forman
Daniel Nogradi wrote: What is the simplest way to instantiate all classes that are subclasses of a given class in a module? More precisely I have a module m with some content: # m.py class A: pass class x( A ): pass class y( A ): pass # all kinds of other objects follow #

Re: instantiate all subclasses of a class

2006-07-16 Thread Simon Forman
Daniel Nogradi wrote: What is the simplest way to instantiate all classes that are subclasses of a given class in a module? More precisely I have a module m with some content: # m.py class A: pass class x( A ): pass class y( A ): pass # all kinds

Re: reading specific lines of a file

2006-07-15 Thread Simon Forman
Yi Xing wrote: Hi All, I want to read specific lines of a huge txt file (I know the line #). Each line might have different sizes. Is there a convenient and fast way of doing this in Python? Thanks. Yi Xing I once had to do a lot of random access of lines in a multi gigabyte log file. I

Re: searching for strings (in a tuple) in a string

2006-07-14 Thread Simon Forman
Simon Forman wrote: ... I usually use this with assert statements when I need to check a sequence. Rather than: for something in something_else: assert expression I say assert False not in (expression for something in something_else) This way the whole assert statement will be removed

Re: instances

2006-07-14 Thread Simon Forman
Quenton Bonds wrote: Hello I am trying to understand the abilities and limitation of creating an instance. First I will give you my understanding then please steer me in the right direction. Wow, you've got it nearly completely comprehensively backwards. Abiities 1. The two ways to

Re: String handling and the percent operator

2006-07-13 Thread Simon Forman
Tom Plunket wrote: I have some code to autogenerate some boilerplate code so that I don't need to do the tedious setup stuff when I want to create a new module. So, my script prompts the user for the module name, then opens two files and those files each get the contents of one of these

Re: String handling and the percent operator

2006-07-13 Thread Simon Forman
Tom Plunket wrote: Simon Forman wrote: strings have a count() method. thanks! For enrichment purposes, is there a way to do this sort of thing with a generator? E.g. something like: def SentenceGenerator(): words = ['I', 'have', 'been', 'to', 'the', 'fair'] for w in words

Re: testing array of logicals

2006-07-13 Thread Simon Forman
John Henry wrote: Hi list, Is there a more elagant way of doing this? # logflags is an array of logicals test=True for x in logflags: test = test and x print test -- Thanks, So many ways *drool* How about: False not in logflags (Anybody gonna run all these through timeit?

Re: testing array of logicals

2006-07-13 Thread Simon Forman
False not in logflags Or, if your values aren't already bools False not in (bool(n) for n in logflags) Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: Identifying apparently unused globals

2006-07-11 Thread Simon Forman
[EMAIL PROTECTED] wrote: At work we have a fairly large application (about 20 packages, 300+ modules) that looks like we might be heading into a bit of a plateau stage. Now seems like a good time to identify and delete old, unused code that's flown under the radar screen for awhile simply

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Simon Forman
horizon5 wrote: Hi, my collegues and I recently held a coding style review. All of the code we produced is used in house on a commerical project. One of the minor issues I raised was the common idiom of specifing: pre if len(x) 0: do_something() /pre Instead of using the

Re: Abuse of the object-nature of functions?

2006-07-11 Thread Simon Forman
Carl J. Van Arsdall wrote: Hrmms, well, here's an interesting situation. So say we wanna catch most exceptions but we don't necessarily know what they are going to be. For example, I have a framework that executes modules (python functions), the framework wraps each function execution in a

<    1   2   3   4   5   >