Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Roel Schroeven
Alan Gauld schreef: if line == "3": line.next this then becomes f.next() # next is a method not an attribute so needs the () to call it Shouldn't it even be 'line = f.next()'? -- The saddest aspect of life right now is that science gathers knowledge faster than society gathe

Re: [Tutor] put? and files

2008-05-02 Thread Alan Gauld
"Ross Glover" <[EMAIL PROTECTED]> wrote That said, it would seem that I do need to understand files better. Does anyone have a suggestion for a solid and detailed explanation? Either online or a book? Reading the Python tutorial section might be enough. If you understand the books you mention

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 3:55 AM, Roel Schroeven <[EMAIL PROTECTED]> wrote: > Shouldn't it even be 'line = f.next()'? Wow, I think Brain Stormer should get a prize. I'm not sure what the prize is, but his short program has elicited incomplete and inaccurate answers from three of the top posters to

Re: [Tutor] put? and files

2008-05-02 Thread Kent Johnson
On Thu, May 1, 2008 at 11:42 PM, Ross Glover <[EMAIL PROTECTED]> wrote: > Thanks all for your in[put]. It did take me a minute to figure out that 2 > variables could get assigned using this method. Thanks to your help, I > managed to cobble together a fully functional GUI based dictionary program

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Brain Stormer
Well, I was somewhat confused with all of the answers so I decided to go with my/following method. Kent's method has 4 fewer lines of code than mine and cleaner. Please correct me if I am fundamentally wrong. f=open('file.txt',r) for line in f.read().split(): if line == "3" positi

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread bob gailer
Brain Stormer wrote: Well, I was somewhat confused with all of the answers so I decided to go with my/following method. Kent's method has 4 fewer lines of code than mine and cleaner. Please correct me if I am fundamentally wrong. f=open('file.txt',r) for line in f.read().split(): if l

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Brain Stormer
You are correct. It is missing the ":" and it will print "3" On Fri, May 2, 2008 at 10:18 AM, bob gailer <[EMAIL PROTECTED]> wrote: > Brain Stormer wrote: > > > Well, > > I was somewhat confused with all of the answers so I decided to go with > > my/following method. Kent's method has 4 fewer

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Brain Stormer
f=open('file.txt',r) position =False for line in f.read().split(): if position == True print line position = False if line == "3": position = True else: position = False f.close() On Fri, May 2, 2008 at 10:28 AM, Brain Stormer <[EMAIL PROTECTED]> wrot

[Tutor] best way to get external data

2008-05-02 Thread Bryan Fodness
I am trying to figure out the best way to get external data. Using the following data in a file 1 2 3 I have used, fi = open(infile, 'r') s = fi.readlines() fi.close() a = s[0] b = s[1] c = s[2] but, if I have, x = 1 y = 2 z = 3 I h

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 10:34 AM, Brain Stormer <[EMAIL PROTECTED]> wrote: > f=open('file.txt',r) > position =False > > for line in f.read().split(): Note that split() splits on any whitespace, not just line endings. In your case it doesn't much matter I guess. Kent _

Re: [Tutor] best way to get external data

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 11:12 AM, Bryan Fodness <[EMAIL PROTECTED]> wrote: > I am trying to figure out the best way to get external data. 1. Put the data in a Python module and import it 2. Put the data in a .ini file and read it with the ConfigParser module http://docs.python.org/lib/module-Config

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Paul McGuire
Augghh! I can't stand it!!! If position is a boolean, then *why* must we test if it is equal to True?!!! It's a boolean! Just test it! For that matter, let's rename "position" to something a little more direct, "print_line" perhaps? Did you know that files are now iterators? If going through

[Tutor] python -v command

2008-05-02 Thread Stephanie
Hi, I'm at a very beginning level of Python knowledge, but I use several Python programs via the Macintosh Unix Terminal. I was trying to quickly see which version of Python I am running and typed in the command "python -v". That was obviously not the correct command to use. It installed several

[Tutor] Regular expressions...

2008-05-02 Thread Spencer Parker
I need to use a regular expression to get a couple of items for my python script. So far the script is running an 'ls' command to get a few items that I need I run an 'ls -sk /xen/domains2/machinename/disk.img' Output 2454112 /xen/domains2/machinename/disk.img Then I have it running an 'ls -lk

Re: [Tutor] python -v command

2008-05-02 Thread Jerry Hill
On Fri, May 2, 2008 at 11:33 AM, Stephanie <[EMAIL PROTECTED]> wrote: > Hi, > I'm at a very beginning level of Python knowledge, but I use several Python > programs via the Macintosh Unix Terminal. I was trying to quickly see which > version of Python I am running and typed in the command "python

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 11:42 AM, Paul McGuire <[EMAIL PROTECTED]> wrote: > f=open('file.txt',r) > print_line = False > for line in f: >if print_line: > print line > print_line = False >if line == "3": Don't forget about the newline...(that makes four!) Kent _

Re: [Tutor] python -v command

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 11:33 AM, Stephanie <[EMAIL PROTECTED]> wrote: > Hi, > I'm at a very beginning level of Python knowledge, but I use several Python > programs via the Macintosh Unix Terminal. I was trying to quickly see which > version of Python I am running and typed in the command "python

Re: [Tutor] Regular expressions...

2008-05-02 Thread Jerry Hill
On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > I need to use a regular expression to get a couple of items for my python > script. So far the script is running an 'ls' command to get a few items > that I need Why do you need to use regular expressions? This problem

Re: [Tutor] python -v command

2008-05-02 Thread Stephanie
Thank you to everyone for your help. I'm sorry to waste your time with such a silly question. I am now back up and running! I really appreciate your responses. On Fri, May 2, 2008 at 11:16 AM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Fri, May 2, 2008 at 11:33 AM, Stephanie <[EMAIL PROTECTE

Re: [Tutor] Regular expressions...

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > I need to use a regular expression to get a couple of items for my python > script. So far the script is running an 'ls' command to get a few items > that I need > > I run an 'ls -sk /xen/domains2/machinename/disk.img' >

[Tutor] Method question?

2008-05-02 Thread W W
I'm playing around with pyGTK, and I have a question to see if I'm understanding things correctly. Is a method just a function inside a class? i.e. def myFunction(): print "This is a function" class myClass: def myMethod(): print "This is a method" and to call: myFunction() I

Re: [Tutor] Method question?

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 12:55 PM, W W <[EMAIL PROTECTED]> wrote: > I'm playing around with pyGTK, and I have a question to see if I'm > understanding things correctly. > > Is a method just a function inside a class? Pretty much. It also has a required 'self' parameter which gets the value of the

Re: [Tutor] Regular expressions...

2008-05-02 Thread Spencer Parker
Well...it gives me the entire path...I am not running this script from the actual directory...I am running it from a secure user directory that only has certain access rights. During the os.path.dirname gives me the entire directory path...I just need to last part of it is all. out of '/xen/domain

Re: [Tutor] Regular expressions...

2008-05-02 Thread jay
dir = '/xen/domains2/machinename/disk.img' a = dir.split('/')[3] is what I would use... On Fri, May 2, 2008 at 12:38 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > Well...it gives me the entire path...I am not running this script from the > actual directory...I am running it from a secure user

Re: [Tutor] Regular expressions...

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 1:38 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > Well...it gives me the entire path...I am not running this script from the > actual directory...I am running it from a secure user directory that only > has certain access rights. During the os.path.dirname gives me the en

Re: [Tutor] Method question?

2008-05-02 Thread W W
On Fri, May 2, 2008 at 12:17 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > This just makes x an alias for the class object. Should be > x = myClass() > > > x.myMethod() > > then this will work. Ah! Thank you! I knew/guessed the alias bit from my experience with C++, but I couldn't figure o

Re: [Tutor] Method question?

2008-05-02 Thread Arthur
i had tough time understanding classes ... hope this helps : http://www2.lib.uchicago.edu/keith/courses/python/class/5/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Method question?

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 2:20 PM, W W <[EMAIL PROTECTED]> wrote: > I knew/guessed the alias bit from my experience with C++, but I > couldn't figure out exactly what I needed. I've seen the "self" > reference before, but I never really understood it. 'self' is roughly like 'this' in C++. Unlike

Re: [Tutor] How to skip to next line in for loop

2008-05-02 Thread bob gailer
bob gailer wrote: Or even simplre f = open('file.txt',r).readlines() print [f[x+1] for x, line in enumerate(f) if line.rstrip() == "3"][0] -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/ma

Re: [Tutor] Method question?

2008-05-02 Thread W W
I think I'm beginning to understand how classes/methods work now, I'm sure further understanding will come with practice. Thanks for the help and suggestions! -Wayne On Fri, May 2, 2008 at 1:42 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Fri, May 2, 2008 at 2:20 PM, W W <[EMAIL PROTECTED]>

Re: [Tutor] put? and files

2008-05-02 Thread Ross Glover
If you give some examples of what you want to parse we can give more specific advice. Kent I'm assuming this falls under the rubric of text parsing. Here's what I want to make: A way to create a set of user defined tags or markers that can be applied to any section of a text document.

Re: [Tutor] put? and files

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 3:08 PM, Ross Glover <[EMAIL PROTECTED]> wrote: > I'm assuming this falls under the rubric of text parsing. Here's what I > want to make: > A way to create a set of user defined tags or markers that can be applied > to any section of a text document. Then I want a functio

[Tutor] Starting a .py file from Idle

2008-05-02 Thread Mihai Iacob
Hello, Can anyone tell me how to start a program directly from the interpreter (i'm using IDLE). Usually i open a new window , write the lines of code and press F5 to run the program in the interpreter. The problem is that i need to to that directly from the interpreter. (I'm running windows).

Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread Arthur
i guess : START > RUN then type : python your_script.py arg_1 arg_2 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread Arthur
> On Fri, May 2, 2008 at 7:11 PM, Mihai Iacob <[EMAIL PROTECTED]> wrote: > Hello, > > Can anyone tell me how to start a program directly > from the interpreter (i'm using IDLE). Usually i open > a new window , write the lines of code and press F5 to > run the program in the interpreter. > The pro

Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread Alan Gauld
"Mihai Iacob" <[EMAIL PROTECTED]> wrote Can anyone tell me how to start a program directly from the interpreter (i'm using IDLE). Usually i open a new window , write the lines of code and press F5 to run the program in the interpreter. You mean the results show up in the interactive shell w

Re: [Tutor] python -v command

2008-05-02 Thread Alan Gauld
"Stephanie" <[EMAIL PROTECTED]> wrote programs via the Macintosh Unix Terminal. I was trying to quickly see which version of Python I am running and typed in the command "python -v". uppercase: python -V Alan G. ___ Tutor maillist - Tutor@

Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread bob gailer
Mihai Iacob wrote: Hello, Can anyone tell me how to start a program directly from the interpreter (i'm using IDLE). Usually i open a new window , write the lines of code and press F5 to run the program in the interpreter. The problem is that i need to to that directly from the interpreter.

Re: [Tutor] best way to get external data

2008-05-02 Thread rui
PyYaml is an option too. [1] [1] - http://pyyaml.org/ It´s very readable and is converted to a Python native structure/object. On Fri, May 2, 2008 at 12:12 PM, Bryan Fodness <[EMAIL PROTECTED]> wrote: > I am trying to figure out the best way to get external data. > > Using the following data in