Re: [Tutor] Uniform 'for' behavior for strings and files

2008-06-09 Thread Shrutarshi Basu
Thanks for your suggestions, I've decided to go with the smart iterator solution, it's given me the results that I need. The generator solution also seems interesting and I might try it out at a later point. -- The ByteBaker : http://www.bytebaker.com ___

Re: [Tutor] Writing a script to interact with an interactive commandprogram

2008-06-09 Thread Demonic Software
Alan, I have been working with the Popen class, and it hangs when I perform the read on the stdout socket. I am not sure how to read from the file object after I perform the write into the process. When I use "communicate" it closes the PIPE and terminates the process. Below are some configurat

Re: [Tutor] Writing a script to interact with an interactive commandprogram

2008-06-09 Thread Alan Gauld
"Demonic Software" <[EMAIL PROTECTED]> wrote (cin, cout_cerror) = os.popen4("/bin/bash") # write a command on the input pipe of the shell print "writing ls -all!\n\n" cin.write("ls -all") cin.flush() I would have expected that you needed to pass an explicit newline at the end of the command?

Re: [Tutor] Uniform 'for' behavior for strings and files

2008-06-09 Thread Alan Gauld
"Shrutarshi Basu" <[EMAIL PROTECTED]> wrote for item in block: where block is a file, then item becomes each line of the file in turn But if block in a large string (let's say the actual text that was in the file), item becomes each character at a time. Correct because for iterates over a

[Tutor] Writing a script to interact with an interactive command program

2008-06-09 Thread Demonic Software
Hello, I am trying to write an interactive shell that will pipe input from one source to a shell/program, and then return the input to that source. I have been trying to do this with the os.popen*, and I have not had any success in getting this to work. Here is a basic piece of the code that dem

Re: [Tutor] Uniform 'for' behavior for strings and files

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 5:26 PM, Shrutarshi Basu <[EMAIL PROTECTED]> wrote: > If I do the following: > > for item in block: > > where block is a file, then item becomes each line of the file in turn > But if block in a large string (let's say the actual text that was in > the file), item becomes eac

[Tutor] Uniform 'for' behavior for strings and files

2008-06-09 Thread Shrutarshi Basu
If I do the following: for item in block: where block is a file, then item becomes each line of the file in turn But if block in a large string (let's say the actual text that was in the file), item becomes each character at a time. Is there a way to have a uniform iteration irrespective of wheth

Re: [Tutor] Error-handling for a large modular program

2008-06-09 Thread Shrutarshi Basu
Our configuration language has evolved a bit more over the last few days and I've decided to right a recursive descent parser for it. Since this is a learning project for me, I'm writing the parser myself instead of using one of the available packages. I'll see how this affects the error handling.

Re: [Tutor] Controlling applications

2008-06-09 Thread Jeff Younker
On Jun 9, 2008, at 8:51 AM, W W wrote: Originally I was planning to use urllib to post/retrieve the data, but as far as I can tell, the bank uses several variables and some javascript to authenticate everything, and it seems overly complicated to try and manually figure it all out. Raw urllib i

Re: [Tutor] Controlling applications

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 3:26 PM, Michael Langford <[EMAIL PROTECTED]> wrote: > You're looking for mechanize > http://wwwsearch.sourceforge.net/mechanize/ Possibly but mechanize emulates a browser, it doesn't control one, which the OP specifically rejected as an option... Kent >> Originally I was

Re: [Tutor] Controlling applications

2008-06-09 Thread Michael Langford
You're looking for mechanize http://wwwsearch.sourceforge.net/mechanize/ On Mon, Jun 9, 2008 at 11:51 AM, W W <[EMAIL PROTECTED]> wrote: > Hi, > > I've done some cursory searches, and it doesn't appear that what I > want to do is popular, if it's even possible. > > I'm trying to control other appl

Re: [Tutor] Controlling applications

2008-06-09 Thread Alan Gauld
"W W" <[EMAIL PROTECTED]> wrote I'm trying to control other applications via python (specifically my web browser). The webbrowser module will maybe give you a start? My hope is there is some way to emulate a series of keypresses. I know how to do that in Windows but not in Linux! Is the

Re: [Tutor] Why not to use include?

2008-06-09 Thread Dotan Cohen
2008/6/9 Kent Johnson <[EMAIL PROTECTED]>: > On Mon, Jun 9, 2008 at 11:54 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: >> I must learn about these things, I've discovered, in this order: > > I suggest you look at Django, it helps with most of this. Probably > TurboGears does also but I'm not familiar

Re: [Tutor] Why not to use include?

2008-06-09 Thread Dotan Cohen
2008/6/9 W W <[EMAIL PROTECTED]>: > On Mon, Jun 9, 2008 at 11:21 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: >> 2008/6/9 W W <[EMAIL PROTECTED]>: >> I was doing this in PHP: >> $title="Page title"; >> include"/path/to/header.php"; >> > > So in your header.php you had some source: > > echo "$title\n"

Re: [Tutor] Why not to use include?

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 11:54 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > I must learn about these things, I've discovered, in this order: I suggest you look at Django, it helps with most of this. Probably TurboGears does also but I'm not familiar with it. > 1) How to use Python as an apache modu

Re: [Tutor] Adding ctypes to an application with python 2.2

2008-06-09 Thread S. Doron
On Mon, Jun 9, 2008 at 2:02 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: > "S. Doron" <[EMAIL PROTECTED]> wrote > > Hello, I'm new to this list. What I'd like to do is add support for >> pointers >> to an old version of python (2.2) in an existing application (a game). >> > > What do you mean by "ad

Re: [Tutor] Why not to use include?

2008-06-09 Thread W W
On Mon, Jun 9, 2008 at 11:21 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > 2008/6/9 W W <[EMAIL PROTECTED]>: > I was doing this in PHP: > $title="Page title"; > include"/path/to/header.php"; > So in your header.php you had some source: echo "$title\n"; or something to that effect? > In Python I

Re: [Tutor] Empty list validation

2008-06-09 Thread [EMAIL PROTECTED]
Thank you all for the replies. the 'else' is this necessary, surely when you have an: >>> if x: ... print 'x' ...print 'y' is this correct? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why not to use include?

2008-06-09 Thread Dotan Cohen
2008/6/9 W W <[EMAIL PROTECTED]>: >> Thanks, Wayne, I am actually aware of this method. But it seems that >> what I really want _is_ a function, and not a simple include. > > When you say function, exactly what are you referring to? Because > really all a function *is* is a set of statements that >

Re: [Tutor] Why not to use include?

2008-06-09 Thread W W
> Thanks, Wayne, I am actually aware of this method. But it seems that > what I really want _is_ a function, and not a simple include. When you say function, exactly what are you referring to? Because really all a function *is* is a set of statements that takes input* does something* gives output

[Tutor] Controlling applications

2008-06-09 Thread W W
Hi, I've done some cursory searches, and it doesn't appear that what I want to do is popular, if it's even possible. I'm trying to control other applications via python (specifically my web browser). My hope is there is some way to emulate a series of keypresses. My goal is to have a script that

Re: [Tutor] Why not to use include?

2008-06-09 Thread Dotan Cohen
2008/6/9 Jordan Kanter <[EMAIL PROTECTED]>: > Another thing you can do is use django templates. they "work" to be > similarly to php in the browser, and have something called an > "extends" clause (see > http://www.djangoproject.com/documentation/templates/) but in the > background it is completel

Re: [Tutor] Why not to use include?

2008-06-09 Thread Dotan Cohen
2008/6/9 W W <[EMAIL PROTECTED]>: > Python can *too* import from a txt file (even if it contains HTML): > > f = open("myfile.html", "r") > x = f.read() > print x > f.close() > > It even retains formatting (as far as I can tell)... > > HTH, > Wayne > Thanks, Wayne, I am actually aware of this metho

Re: [Tutor] Empty list validation

2008-06-09 Thread simone
[EMAIL PROTECTED] ha scritto: Sorry if this is a basic question, but how do I check if list is empty or not and return True or False ;) Normally, in Python, there are these evaluation: 1) True == 1 2) False == 0 3) Empty or have not value == False == 0 4) Not empty or have value == True == 1

Re: [Tutor] Empty list validation

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 10:25 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello > Sorry if this is a basic question, but how do I check if list is empty > or not and return True or False ;) You can test the list directly, if it is empty it will evaluate to False: if (myList): print 'Somet

Re: [Tutor] Why not to use include?

2008-06-09 Thread Hansen, Mike
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Michael Langford > Sent: Sunday, June 08, 2008 2:39 PM > To: Dotan Cohen > Cc: tutor@python.org > Subject: Re: [Tutor] Why not to use include? > > Python makes web pages just fine. There are both embed

Re: [Tutor] Empty list validation

2008-06-09 Thread C S Shyam Sundar
One another simple method is to check its count using the *len *method. eg: if len(mylist) == 0: print "empty list" This is particularly useful in situations where checking emptiness alone is not enough. On Mon, Jun 9, 2008 at 8:24 PM, W W <[EMAIL PROTECTED]> wrote: > >>> def empty_or_not

Re: [Tutor] Why not to use include?

2008-06-09 Thread Jordan Kanter
sorry about the spelling. that second sentence should be "the work out to be similar to php in the browser". On Mon, Jun 9, 2008 at 9:57 AM, Jordan Kanter <[EMAIL PROTECTED]> wrote: > Another thing you can do is use django templates. they "work" to be > similarly to php in the browser, and have so

Re: [Tutor] Why not to use include?

2008-06-09 Thread Jordan Kanter
Another thing you can do is use django templates. they "work" to be similarly to php in the browser, and have something called an "extends" clause (see http://www.djangoproject.com/documentation/templates/) but in the background it is completely python (i.e. the template compiler), so it is not as

Re: [Tutor] Empty list validation

2008-06-09 Thread W W
>>> def empty_or_not(mylist): ... if mylist: ... print "Not empty" ... elif not mylist: ... print "Empty!" ... >>> empty_or_not([]) Empty! >>> foo = [] >>> empty_or_not(foo) Empty! >>> foo.append('hi') >>> empty_or_not(foo) Not empty My guess is that if any object is empty,

[Tutor] Empty list validation

2008-06-09 Thread [EMAIL PROTECTED]
Hello Sorry if this is a basic question, but how do I check if list is empty or not and return True or False ;) Thanks David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] clipping file to size ?

2008-06-09 Thread Kent Johnson
On Mon, Jun 9, 2008 at 9:04 AM, dave selby <[EMAIL PROTECTED]> wrote: > writing smaller file... > > and I end up with the remnants of the old larger file at the end. > any idea how to clip the file to the newer smaller size without > closing it and reopening it as a 'w' ? f.truncate() ? Why not r

[Tutor] (no subject)

2008-06-09 Thread amit sethi
Hi , Are there any python bindings for sox(sound Exchange). -- A-M-I-T S|S ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] clipping file to size ?

2008-06-09 Thread dave selby
Hi All, I need to read parse and re-write the parsed file. I am opening with f = open(file_rc, 'r+') reading file f.seek(0) resetting file pointer ... print >> f, section writing smaller file... and I end up with the remnants of the old larger file at the end. any idea how to clip the

Re: [Tutor] Why not to use include?

2008-06-09 Thread W W
Python can *too* import from a txt file (even if it contains HTML): f = open("myfile.html", "r") x = f.read() print x f.close() It even retains formatting (as far as I can tell)... HTH, Wayne On Sun, Jun 8, 2008 at 4:25 PM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > 2008/6/8 Kent Johnson <[EMAIL