Re: [Tutor] Need to be able to accept Page Down or CTRL-E

2013-02-01 Thread Alan Gauld
On 01/02/13 03:19, Dave Wilder wrote: So how are you taking this input in? I am using a terminal application and an application called pexpect OK, We need to get the terminology a lot more exact. I'm guessing that what you mean is that you have an application that somebody else wrote runni

Re: [Tutor] Need to be able to accept Page Down or CTRL-E

2013-02-01 Thread Dave Angel
On 02/01/2013 03:34 AM, Alan Gauld wrote: OTOH if you mean you want to send the page up/down/arrows as the "something" then its a different game and you can do it. In that case you need todo what you did with ESC. The character set your external app uses will determine the codes you send. As

Re: [Tutor] Need to be able to accept Page Down or CTRL-E

2013-02-01 Thread Dave Wilder
-Original Message- From: Tutor [mailto:tutor-bounces+d.wilder=f5@python.org] On Behalf Of Dave Angel Sent: Friday, February 01, 2013 7:38 AM To: tutor@python.org Subject: Re: [Tutor] Need to be able to accept Page Down or CTRL-E On 02/01/2013 03:34 AM, Alan Gauld wrote: >> >> >>

Re: [Tutor] First Python Test

2013-02-01 Thread Simon Yan
On Fri, Feb 1, 2013 at 9:18 PM, Dustin Guerri wrote: > Thanks for replying, Simon. I have no particular reason to use Xcode - > what would you recommend instead ? > I would recommend start off from a simple text editor that has basic syntax highlighting features. There are a number of options out

[Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
Hey all how're things? I'm hoping for some guidance on a problem I'm trying to work through. I know this has been previously covered on this list but I'm hoping it won't bother you guys to run through it again. My basic program I'm attempting to create is like this.. I want to read from a large,

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Nick W
quite easy to do; just use enumerate - as so: myString = "The String" with open('largeFile', 'r') as inF: for index, line in enumerate(inF): #myString = "The String" ##Not here because otherwise this gets run for every single line of the large file (which is nasty waste of resources)

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Dave Angel
On 02/01/2013 03:09 PM, Scurvy Scott wrote: Hey all how're things? I'm hoping for some guidance on a problem I'm trying to work through. I know this has been previously covered on this list but I'm hoping it won't bother you guys to run through it again. My basic program I'm attempting to creat

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
> > Why not just use grep ? > Honestly this seemed like a good excuse to write some code and learn some stuff, secondly, it honestly just didn't dawn on me. Also, the code y'all both showed me was exactly what I was looking for and I'm planning on using Nicks code as a template to improve upon. A

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
One last question on this topic.. I'd like to call the files and the string form the command line like Python whatever.py STRINGTOSEARCH NEWFILE FILETOOPEN My understanding is that it would be accomplished as such import sys myString = sys.argv[1] filetoopen = sys.argv[2] newfile = sys.argv[3]

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Dave Angel
On 02/01/2013 04:24 PM, Scurvy Scott wrote: One last question on this topic.. I'd like to call the files and the string form the command line like Python whatever.py STRINGTOSEARCH NEWFILE FILETOOPEN My understanding is that it would be accomplished as such import sys myString = sys.argv[1]

Re: [Tutor] First Python Test

2013-02-01 Thread Simon Yan
On Thu, Jan 17, 2013 at 6:47 AM, Dustin Guerri wrote: > Hi there, > > I'm trying to create a plain text file called "hello.py" with the > following text : > > print('hello world') > raw_input('Press any key to continue') > > I'd then like to run this program with Python Launcher on a Mac.

Re: [Tutor] Need to be able to accept Page Down or CTRL-E

2013-02-01 Thread Alan Gauld
On 01/02/13 12:38, Dave Angel wrote: your local setup you can use the following program(untested!) to read the codes from your keyboard (assuming you are on Windows): import msvcrt The OP is running Python 2.73 on Linux. OK, I didn't notice that. In that case the Linux variant on my tutor

Re: [Tutor] Need to be able to accept Page Down or CTRL-E

2013-02-01 Thread Steven D'Aprano
On 01/02/13 23:38, Dave Angel wrote: On 02/01/2013 03:34 AM, Alan Gauld wrote: OTOH if you mean you want to send the page up/down/arrows as the "something" then its a different game and you can do it. In that case you need todo what you did with ESC. The character set your external app uses w

Re: [Tutor] First Python Test

2013-02-01 Thread Alan Gauld
On 01/02/13 12:05, Simon Yan wrote: I'd lke to use Xcode as my text editor. Once I have Xcode open, which template should I use to input the text ? I don;t know about templates but there are instructions on the MacPython pages that tell you how to set up XCode. I used it for some ex

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Steven D'Aprano
On 02/02/13 08:24, Scurvy Scott wrote: One last question on this topic.. I'd like to call the files and the string form the command line like Python whatever.py STRINGTOSEARCH NEWFILE FILETOOPEN My understanding is that it would be accomplished as such import sys myString = sys.argv[1] filet

[Tutor] Help

2013-02-01 Thread Jack Little
I get this error Traceback (most recent call last):   File "C:\Users\Jack\Desktop\python\g.py", line 56, in     path1pt1() NameError: name 'path1pt1' is not defined With this amount of code: def simpstart():   global ammo1   global ammo2   global ammo3   global health   global tech_parts   glo

Re: [Tutor] Help

2013-02-01 Thread Brandon
You get the error because you call path1pt1() before it is defined. Define your path1pt1() method at the top of your code before simpstart(). Brandon On Fri, Feb 1, 2013 at 5:47 PM, Jack Little wrote: > I get this error > > Traceback (most recent call last): > File "C:\Users\Jack\Desktop\pyt

Re: [Tutor] Help

2013-02-01 Thread Dave Angel
On 02/01/2013 08:47 PM, Jack Little wrote: I get this error Traceback (most recent call last): File "C:\Users\Jack\Desktop\python\g.py", line 56, in path1pt1() NameError: name 'path1pt1' is not defined With this amount of code: def simpstart(): global ammo1 global ammo2 glob

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
> Best practice is to check if your program is being run as a script before > doing anything. That way you can still import the module for testing or > similar: > > > def main(mystring, infile, outfile): ># do stuff here > > > if __name__ == '__main__': ># Running as a script. >import s

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Mitya Sirenef
On 02/01/2013 11:31 PM, Scurvy Scott wrote: > Steve- > thanks a lot for showing me the if __name__ = main part > I've often wondered how it was used and it didn't make sense until I > saw it in my own code if that makes any sense. > Also appreciate the help on the "instructional" side of things

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
And just for the records sake, this is what I've gotten and you guys should see obviously that you helped a lot and I learned a thing or two so I won't have to ask the same silly questions next time: def main(mystring, infile, outfile): with open('infile', 'r') as inF: for i

Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Steven D'Aprano
On 02/02/13 15:31, Scurvy Scott wrote: One question related to the instruction aspect- does this make sense to you? If len(sys.argv) == 0: print "usage: etc etc etc" Right idea, but not quite correct. sys.argv always includes at least one item, the name of the script being called. This