Thanks, and I'll try those. On Wed, Jun 15, 2011 at 12:47 AM, <tutor-requ...@python.org> wrote:
> Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Communicating Between Programs Using Raw Inputs (Jacob Bender) > 2. Re: Break stament issue (Steven D'Aprano) > 3. Re: Communicating Between Programs Using Raw Inputs > (Steven D'Aprano) > 4. Re: Communicating Between Programs Using Raw Inputs > (Steve Willoughby) > 5. Re: Communicating Between Programs Using Raw Inputs (Alan Gauld) > 6. Re: Communicating Between Programs Using Raw Inputs > (Steve Willoughby) > 7. Already Initialized Object Inheritance? (WolfRage) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 14 Jun 2011 17:39:03 -0400 > From: Jacob Bender <benderjaco...@gmail.com> > To: Python Tutor <tutor@python.org> > Subject: [Tutor] Communicating Between Programs Using Raw Inputs > Message-ID: <BANLkTi=gwb4hrvkj0qdrjpmwep6omzm...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > Dear Python Tutors, > > I was wondering how to break into my one program I made using brute force > methods. Here's the code: > > password = "Helloworld" > try= raw_input("What's the password?") > while try != password: > try = raw_input("Incorrect, what's the password?") > > I know how to do it in the command line, but not through another program. > Generating the random tries for the password isn't the issue, but entering > the password(s) in between the two programs is an issue because I don't > know > how to make programs communicate through raw inputs. > > Thanks! > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20110614/0c5ecf31/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Wed, 15 Jun 2011 08:40:26 +1000 > From: Steven D'Aprano <st...@pearwood.info> > To: tutor@python.org > Subject: Re: [Tutor] Break stament issue > Message-ID: <4df7e35a.1080...@pearwood.info> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Susana Iraiis Delgado Rodriguez wrote: > > Hello members! > > > > I'm doing a script that needs to loop to get some information, in order > to > > do that I'm using modules from OGR and Mapnik. These to get data from > > shapefiles, but some of the files have 0 elements, I wrote a line to > > validate it, but it hasn't worked, so I added a break to keep working. > When > > I run the scipt I got the next error: > > Traceback (most recent call last): > > File "<pyshell#0>", line 1, in <module> > > import mapnik_punto_sin_duda > > File "C:\Python26\mapnik_punto_sin_duda.py", line 23 > > break > > ^ > > IndentationError: unexpected indent > > This error has nothing to do with break. Look at the error message, and > the position of the ^ mark: the error occurs *before* the break > statement, in the indentation. > > I can duplicate the error in Python 2.6 with this: > > > >>> for t in (1, 2, 3): > ... print t # four spaces > ... break # one tab > File "<stdin>", line 3 > break # one tab > ^ > IndentationError: unexpected indent > > > Newer versions of Python give more helpful error messages: Python 3 > reports "TabError: inconsistent use of tabs and spaces in indentation". > > > You can fix this by using the tabnanny script supplied with Python. From > the shell (not Python's interactive interpreter!) or the DOS prompt, run: > > python -m tabnanny -v <path to your file> > > replacing <path to your file> with the actual filename, and see what it > says. > > > -- > Steven > > > ------------------------------ > > Message: 3 > Date: Wed, 15 Jun 2011 08:48:49 +1000 > From: Steven D'Aprano <st...@pearwood.info> > To: Python Tutor <tutor@python.org> > Subject: Re: [Tutor] Communicating Between Programs Using Raw Inputs > Message-ID: <4DF7E <4df7e551.6080...@pearwood.info>551.6080204@ > pearwood.info> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Jacob Bender wrote: > > Dear Python Tutors, > > > > I was wondering how to break into my one program I made using brute force > > methods. Here's the code: > > > > password = "Helloworld" > > try= raw_input("What's the password?") > > while try != password: > > try = raw_input("Incorrect, what's the password?") > > > > I know how to do it in the command line, but not through another program. > > Generating the random tries for the password isn't the issue, but > entering > > the password(s) in between the two programs is an issue because I don't > know > > how to make programs communicate through raw inputs. > > > Normally you would do this by redirecting standard input. What operating > system are you using? In Linux, you would do something like: > > > # run script foo.py taking input from the output of bar.py > foo.py < bar.py > > > at the shell. I don't know how to do it in DOS. > > However, I don't know if this will actually work for raw_input. It may > not. Try it and see. > > Perhaps a better way is to have your program accept a user name and > password on the command line, and only prompt for them if not given. > Then you can say: > > foo.py --user=fred --password="y8Mr3@hzi" > > > Hope this helps, > > > > -- > Steven > > > > ------------------------------ > > Message: 4 > Date: Tue, 14 Jun 2011 15:54:20 -0700 > From: Steve Willoughby <st...@alchemy.com> > To: tutor@python.org > Subject: Re: [Tutor] Communicating Between Programs Using Raw Inputs > Message-ID: <4df7e69c.6000...@alchemy.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 14-Jun-11 15:48, Steven D'Aprano wrote: > > > Normally you would do this by redirecting standard input. What operating > > system are you using? In Linux, you would do something like: > > > > > > # run script foo.py taking input from the output of bar.py > > foo.py < bar.py > > Actually, no, that will send the *source code* of bar.py as the input to > foo.py. I think you mean: > > bar.py | foo.py > > which also should work in DOS as well (although less efficiently). > > > However, I don't know if this will actually work for raw_input. It may > > not. Try it and see. > > It should. > > > > > Perhaps a better way is to have your program accept a user name and > > password on the command line, and only prompt for them if not given. > > Then you can say: > > > > foo.py --user=fred --password="y8Mr3@hzi" > > This is one way. Another would be to use the subprocess module in > Python which will let one program invoke another program, and have a > file-like object on which it can write data, which the child program > will see as its standard input (and read in to raw_input). > > -- > Steve Willoughby / st...@alchemy.com > "A ship in harbor is safe, but that is not what ships are built for." > PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C > > > ------------------------------ > > Message: 5 > Date: Wed, 15 Jun 2011 00:36:13 +0100 > From: "Alan Gauld" <alan.ga...@btinternet.com> > To: tutor@python.org > Subject: Re: [Tutor] Communicating Between Programs Using Raw Inputs > Message-ID: <it8r9f$unn$1...@dough.gmane.org> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "Jacob Bender" <benderjaco...@gmail.com> wrote > > > I know how to do it in the command line, but not through another > > program. > > Generating the random tries for the password isn't the issue, but > > entering > > the password(s) in between the two programs is an issue because I > > don't know > > how to make programs communicate through raw inputs. > > You need to search for stdin and stdout. Try wikipedia. > Then google python stdin > > By linking stdout of one program to stdin of another you can pass > data between them. This is one of the things that makes Unix > such an insanely great programmers OS, its commands are > explicitly designed to do this. But you can make it work with > any command that prints to stdout and reads from stdin. > > If you read the "Talking to the User" topic in my tutorial you > will see a sidebar/box that discusses this and gives an example > of reading from a file. You need to take that one step further and > read from a process. In Unix the easiest way you can do that is > to surround the command with backtick marks: > > python reader.py < `python writer.py` > > notice the *back* quote marks. > > There are other ways of doing it inside Python, seee my > "Using the OS" topic for those. But backtics and stdin should > do what you need. > > HTH, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > > ------------------------------ > > Message: 6 > Date: Tue, 14 Jun 2011 16:46:10 -0700 > From: Steve Willoughby <st...@alchemy.com> > To: tutor@python.org > Subject: Re: [Tutor] Communicating Between Programs Using Raw Inputs > Message-ID: <4df7f2c2.7020...@alchemy.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > As always, Alan has given a lot of great advice and useful information. > There's just one piece at the end I would question, however: > > > On 14-Jun-11 16:36, Alan Gauld wrote: > > python reader.py < `python writer.py` > > Almost, but not quite. The backticks mean the command is executed and > the output substituted back on the command line. The < bracket means to > take what follows it as a file NAME (not a data stream). So unless > writer.py outputs a filename, you really want something like > > python writer.py | python reader.py > > > > -- > Steve Willoughby / st...@alchemy.com > "A ship in harbor is safe, but that is not what ships are built for." > PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C > > > ------------------------------ > > Message: 7 > Date: Tue, 14 Jun 2011 21:47:27 -0700 > From: WolfRage <wolfrage8...@gmail.com> > To: Python Tutor <tutor@python.org> > Subject: [Tutor] Already Initialized Object Inheritance? > Message-ID: <1308113247.1952.45.camel@wolfrage-LE1600> > Content-Type: text/plain; charset="UTF-8" > > I can not get this to behave in the manor that I would like. I am trying > to have an object refereed to as CursesApp.Screen become the already > initialized object "stdscr". To elaborate I would like it to become that > object but to also be able to define additional methods and properties, > so more along the lines of inherit from "stdscr". Is this even possible? > Well I can make it equal to that object I can not add additional methods > and properties to it? Additionally, so that I learn; where has my > thinking been too short sited? Thank you for your help. > -- > Jordan > > ****CODE BELOW**** > > #!/usr/bin/python3 > """With thi method I can make the class "Screen" become "stdscr" but if > I refernce any of the new methods or properties the applications > promptly fails and notifies me that the method or property does not > exist. Another downside of this method is I can not reference > self.Screen.* or it crashes.""" > import curses > class CursesApp: > def __init__(self, stdscr): > self.Screen(stdscr) #This is the stdscr object. > curses.init_pair(1,curses.COLOR_BLUE,curses.COLOR_YELLOW) > #self.Screen.bkgd(' ', curses.color_pair(1)) > #self.mainLoop() > > #def mainLoop(self): > #while 1: > #self.Screen.refresh() > #key=self.Screen.getch() > #if key==ord('q'): break > > class Screen: > def __init__(self,stdscr): > self=stdscr > #self.height, self.width = self.getmaxyx() # any reference > to these crashes > #self.offsety, self.offsetx = -self.height/2, -self.width/2 > # any reference to these crashes > #self.curx, self.cury = 1, 1 # any reference to these > crashes > self.clear() > self.border(0) > while 1: > self.refresh() > key=self.getch() > if key==ord('q'): break > > def main(): > cursesapp = curses.wrapper(setup) > > def setup(stdscr): > CursesApp(stdscr) > > if __name__ == '__main__': > main() > > > > ****CODE BELOW**** > > #!/usr/bin/python3 > """With this method I can make "Screen" become "stdscr" but if I > obviously can not even define any new methods or properties. But atleast > the references can be used through out the class with out crashing.""" > import curses > class CursesApp: > def __init__(self, stdscr): > self.Screen=stdscr #This is the stdscr object. > curses.init_pair(1,curses.COLOR_BLUE,curses.COLOR_YELLOW) > self.Screen.bkgd(' ', curses.color_pair(1)) > self.mainLoop() > > def mainLoop(self): > while 1: > self.Screen.refresh() > key=self.Screen.getch() > if key==ord('q'): break > > def main(): > cursesapp = curses.wrapper(setup) > > def setup(stdscr): > CursesApp(stdscr) > > if __name__ == '__main__': > main() > > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 88, Issue 53 > ************************************* >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor