Re: [Tutor] Process problem
On Wed, 15 Jun 2005 22:04:48 + "Alberto Troiano" <[EMAIL PROTECTED]> wrote: Hi Alberto, > Hey > > Let me make you understand > > I need that levantamuertos.py run cotascamon.py (every script with it > differents arguments that are passed) and then die letting the cotascamon.py > scripts running independently > > Now, I don't know if my code is right, and thinking now you're right, > levantamuertos.py waits until cotascamon.py finish. > What can I do since cotascamon will never die (and it doesn't have to die)? > > Maybe a different approach will be the solution but I can't find a way to do > it > > Best Regards > > Alberto > I didn't follow the thread completely, so maybe I missed something, but if the problem is that python waits until the os.system() calls are finished, I think adding a "&" to the command to make it run in the background should do the trick. Best regards Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Process problem
Thanks for the reply That was one of the problems Now the other problem is that when the script finishes all processes (runing in the background or not) finishes with him. levantamuertos.py is supoosed to be a process manager for cotascamon.py I need levantamuertos.py run, start the cotascamons.py that are dead, let them running and then die letting the others alive How can I do this? Best Regards Alberto >From: Michael Lange <[EMAIL PROTECTED]> >To: tutor@python.org >Subject: Re: [Tutor] Process problem >Date: Thu, 16 Jun 2005 12:19:12 +0200 > >On Wed, 15 Jun 2005 22:04:48 + >"Alberto Troiano" <[EMAIL PROTECTED]> wrote: > >Hi Alberto, > > > Hey > > > > Let me make you understand > > > > I need that levantamuertos.py run cotascamon.py (every script with it > > differents arguments that are passed) and then die letting the >cotascamon.py > > scripts running independently > > > > Now, I don't know if my code is right, and thinking now you're right, > > levantamuertos.py waits until cotascamon.py finish. > > What can I do since cotascamon will never die (and it doesn't have to >die)? > > > > Maybe a different approach will be the solution but I can't find a way >to do > > it > > > > Best Regards > > > > Alberto > > > >I didn't follow the thread completely, so maybe I missed something, but if >the problem >is that python waits until the os.system() calls are finished, I think >adding a "&" to >the command to make it run in the background should do the trick. > >Best regards > >Michael > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor Gaucho ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Process problem
Hey all Nevermind, it worked with the & trick. I just posted because the first 2 times didn't do anything but there was an error in the crontab so... Thanks to all who helped Best regards Alberto >Thanks for the reply > >That was one of the problems >Now the other problem is that when the script finishes all processes >(runing in the background or >not) finishes with him. levantamuertos.py is >supoosed to be a process manager for cotascamon.py > >I need levantamuertos.py run, start the cotascamons.py that are dead, let >them running and then >die letting the others alive > >How can I do this? > >Best Regards > >Alberto >From: Michael Lange <[EMAIL PROTECTED]> >To: tutor@python.org >Subject: Re: [Tutor] Process problem >Date: Thu, 16 Jun 2005 12:19:12 +0200 > >On Wed, 15 Jun 2005 22:04:48 + >"Alberto Troiano" <[EMAIL PROTECTED]> wrote: > >Hi Alberto, > > > Hey > > > > Let me make you understand > > > > I need that levantamuertos.py run cotascamon.py (every script with it > > differents arguments that are passed) and then die letting the >cotascamon.py > > scripts running independently > > > > Now, I don't know if my code is right, and thinking now you're right, > > levantamuertos.py waits until cotascamon.py finish. > > What can I do since cotascamon will never die (and it doesn't have to >die)? > > > > Maybe a different approach will be the solution but I can't find a way >to do > > it > > > > Best Regards > > > > Alberto > > > >I didn't follow the thread completely, so maybe I missed something, but if >the problem >is that python waits until the os.system() calls are finished, I think >adding a "&" to >the command to make it run in the background should do the trick. > >Best regards > >Michael > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor Gaucho ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Process problem
On 6/16/05, Alberto Troiano <[EMAIL PROTECTED]> wrote: Hey allNevermind, it worked with the & trick.I just posted because the first 2 times didn't do anything but there was anerror in the crontab so... Alberto, If you are going to use put the processes in the background with the ampersand ('&'), then you probably want to use 'nohup' as well in the os.system() call: os.system("nohup %s >/dev/null 2>&1 &" % cmd) This may save some headaches later. -Arcege-- There's so many different worlds,So many different suns.And we have just one world,But we live in different ones. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Clearing the Console Screen
With the console-based menu system I'm building, I'd like to clear the screen for each menu call - something like: def main_menu(): clear #start with a fresh console screen, menu at top print menuitems This way, the users won't have to get too confused by all the previous screens. I haven't found the correct way to do this so far. You can point me to the documentation, and I'll play with that. Thanks, Don -- evangelinuxGNU Evangelist http://matheteuo.org/ http://chaddb.sourceforge.net/ "Free software is like God's love - you can share it with anyone anytime anywhere." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A newbie question about running python scripts
On Thu, 2005-06-16 at 07:23 -0700, typetext wrote: > Thank you for responding. Here is what happens when I type python > helloworld.py without any quotation marks into the command line:1. > The prompt line reads > 1.C:\Documents and Settings\Micky > 2. I type "python" > 3. the python prompt comes up Active Python 2.4.1 > 4. then I type "helloworld.py" > 5. Then I get " Traceback (most recent call last) > > > File "", line 1 in ? > > > NameError:name 'helloworld' is not defined" > > Do you have any ideas on this? It looks to me as if that ought to > work, but it doesn't. I would really appreciate some help. Perhaps I > need to put in a file path name, or reinstall Python 2.4.1? > Michael Riggs No. You don't need to go into Python's interactive shell (the one with the ">>> " prompt) to run the script. Just type the following two lines exactly: cd "C:\Documents and Settings\Micky" python helloworld.py And that's all! Tell us what you get. Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
One way is to - print * 25 but that's probably not the best. You could check out Pythoncard for a simple GUI builder - pythoncard.sourceforge.net - but it's a leap into the OO stuff.On 6/17/05, Don Parris < [EMAIL PROTECTED]> wrote:With the console-based menu system I'm building, I'd like to clear the screen for each menu call - something like:def main_menu():clear #start with a fresh console screen, menu at topprint menuitemsThis way, the users won't have to get too confused by all the previous screens.I haven't found the correct way to do this so far. You can point me to thedocumentation, and I'll play with that.Thanks,Don--evangelinuxGNU Evangelist http://matheteuo.org/ http://chaddb.sourceforge.net/"Free software is like God's love - you can share it with anyone anytimeanywhere."___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor -- 'There is only one basic human right, and that is to do as you damn well please.And with it comes the only basic human duty, to take the consequences.' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
Don Parris wrote: > With the console-based menu system I'm building, I'd like to clear the > screen for each menu call - something like: > > def main_menu(): > clear #start with a fresh console screen, menu at top > print menuitems There is no nice portable way to do this. On Windows running in a DOS window (not in IDLE or another GUI environment) you can use import os os.system('cls') Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A newbie question about running python scripts
On Thu, 2005-06-16 at 08:08 -0700, typetext wrote: > I get exactly the same error message as below. What could be going on > here? To check that I am not misspelling the name, I also wrote a > script that says print "helloworld" and saved it as hello.py. The same > message comes up then, as well. Any input is appreciated.. > Michael Riggs, Seattle. > There seems to be some miss-understanding on what's going on! It seems to me that you're typing "python", hitting Enter key, then typing "helloworkd.py" *inside* the Python interactive shell and that's *not* what I said! All you need to type is "python helloworld.py", then hit the Enter key. Of course, you need to be inside the directory that holds that file. Just start a command prompt, type "cd C:\Documents and Settings\Micky", hit Enter, type "python helloworld.py", hit Enter and your script should run fine. If you get anything else, just repost here again. Do *not* let this get in your way of learning! If I (or anyone else on this list) didn't want to help you, we wouldn't responded to your questions in the first place. Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A newbie question about running python scripts (Out of the Office June 16)
I will be out of the office on June 16, to return on June 17. I will reply to your message at that time. Catherine Kostyn Transportation Planner Indianapolis MPO 200 E. Washington St., Ste. 1821 Indianapolis, IN 46204 (317)327-5142 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
On Thu, 16 Jun 2005 11:16:37 -0400 Kent Johnson <[EMAIL PROTECTED]> wrote: > Don Parris wrote: > > With the console-based menu system I'm building, I'd like to clear the > > screen for each menu call - something like: > > > > def main_menu(): > > clear #start with a fresh console screen, menu at top > > print menuitems > > There is no nice portable way to do this. On Windows running in a DOS > window (not in IDLE or another GUI environment) you can use import os > os.system('cls') > > Kent > > > ___ Thanks! I thought there had to be a way to call the OS' clear screen command, but was going about it the wrong way. I was trying to use sys.clear instead of os.system. Would it be difficult to test the OS, store the result in a variable, and call the comand based on the variable result? Or would it be simpler to have users edit the script for their OS? Mind you, there may be other areas where I need an OS-specific command. I'm beginning to get an idea of the challenges of portability though. ;) Don -- evangelinuxGNU Evangelist http://matheteuo.org/ http://chaddb.sourceforge.net/ "Free software is like God's love - you can share it with anyone anytime anywhere." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
Don Parris wrote: > Thanks! I thought there had to be a way to call the OS' clear screen > command, but was going about it the wrong way. I was trying to use > sys.clear instead of os.system. Would it be difficult to test the OS, > store the result in a variable, and call the comand based on the variable > result? Or would it be simpler to have users edit the script for their OS? You could try this (from http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3edf6589c533f78e): import os if os.name == "nt": os.system("cls") # Works in w2k else: os.system("clear") # Works in cygwin's Bash > Mind you, there may be other areas where I need an OS-specific command. I'm > beginning to get an idea of the challenges of portability though. ;) Python actually gets a lot of this right, you may find it's easier than you think to write portable Python. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A newbie question about running python scripts
. Here's what happened. I had forgotten to specify the following, and therefore was not inside the proper directory. What worked was cd c:\documents and settings\my documents\ then enter, then python helloworld.py. Success! Onward and upward. I was missing the "my documents" part, and therefore was not inside the proper directory. Michael Riggs On 6/16/05, ZIYAD A. M. AL-BATLY <[EMAIL PROTECTED]> wrote: > On Thu, 2005-06-16 at 08:08 -0700, typetext wrote: > > I get exactly the same error message as below. What could be going on > > here? To check that I am not misspelling the name, I also wrote a > > script that says print "helloworld" and saved it as hello.py. The same > > message comes up then, as well. Any input is appreciated.. > > Michael Riggs, Seattle. > > > There seems to be some miss-understanding on what's going on! It seems > to me that you're typing "python", hitting Enter key, then typing > "helloworkd.py" *inside* the Python interactive shell and that's *not* > what I said! > > All you need to type is "python helloworld.py", then hit the Enter key. > Of course, you need to be inside the directory that holds that file. > > Just start a command prompt, type "cd C:\Documents and Settings\Micky", > hit Enter, type "python helloworld.py", hit Enter and your script should > run fine. > > > If you get anything else, just repost here again. Do *not* let this get > in your way of learning! If I (or anyone else on this list) didn't want > to help you, we wouldn't responded to your questions in the first place. > > Ziyad. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
On 6/16/05, Don Parris <[EMAIL PROTECTED]> wrote: Thanks! I thought there had to be a way to call the OS' clear screencommand, but was going about it the wrong way. I was trying to usesys.clear instead of os.system. Would it be difficult to test the OS, store the result in a variable, and call the comand based on the variableresult? Or would it be simpler to have users edit the script for their OS?Mind you, there may be other areas where I need an OS-specific command. I'm beginning to get an idea of the challenges of portability though. ;)Don You might want to use the tput command. It returns control sequences for the terminal that are used by all programs, e.g. emacs, vi(m). Your could capture the output with the commands module and send it to the terminal with stdout.write (instead of print). import commands clear_str = None def clearscreen(): global clear_str from sys import stdout if not clear_str: clear_str = commands.getoutput('tput clear') stdout.write(clear_str) clearscreen() If you wanted, you could encapsulate this into a module or a class. This would work on just about any UNIX/Linux/BSD system, and might work on Mac OS/X (I don't know if they use terminfo). You can use the other tput subcommands in your program if you wished as well. (Hide the cursor, go to column X row Y, etc.) -Arcege-- There's so many different worlds,So many different suns.And we have just one world,But we live in different ones. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
On Thu, 16 Jun 2005 12:24:32 -0400 Kent Johnson <[EMAIL PROTECTED]> wrote: > > Mind you, there may be other areas where I need an OS-specific command. > > I'm beginning to get an idea of the challenges of portability though. ;) > > Python actually gets a lot of this right, you may find it's easier than > you think to write portable Python. > Hmmm, I'm using Python 2.3 on SUSE Linux 9.2 at home, and the latest Python on WinXP at my job (I get to do some non-work-related stuff during my downtime at work). So far, I haven't had any problems running my script on either box. Frankly, I'm finding Python to be quite easy to learn. With a little help from the standard tutorials, this list, and my co-worker (experienced developer), I've managed to get my menu system functioning rather well, and can even connect to the MySQL database to print off a member roster to the console. All this in less than two weeks. I even found a better way to print the menus to the console. These successes are what makes developing a program exciting. Meanwhile, I'll check out that site/code. Again, I appreciate the help. Don -- evangelinuxGNU Evangelist http://matheteuo.org/ http://chaddb.sourceforge.net/ "Free software is like God's love - you can share it with anyone anytime anywhere." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Process problem
Hey You weren't pedantic at all I needed the explanation 'cause I don't like to make things I don't understand so now I will add the code to mine Thanks Alberto http://graphics.hotmail.com/emvamp.gif"; width=12> Gaucho >From: "Michael P. Reilly" <[EMAIL PROTECTED]> >Reply-To: "Michael P. Reilly" <[EMAIL PROTECTED]> >To: Alberto Troiano <[EMAIL PROTECTED]> >Subject: Re: [Tutor] Process problem >Date: Thu, 16 Jun 2005 10:40:09 -0400 > >On 6/16/05, Alberto Troiano <[EMAIL PROTECTED]> wrote: > > > > Hey > > > > What its that for? > > > > can you explain me what it does? and the way to implementing it here: > > os.system("python2.2 /root/levantamuertos.py &") > > and what headaches are you talking about? > > > >Hi, > >The 'nohup' command is to make sure that the child process sticks around >after the parent (and grandparents) have died. > >When a process creates a child, the child is tied to the parent and when >the >parent exits, all the child processes get sent a specific signal (with >os.kill()) telling them that the parent has died. The default procedure >when >they receive this signal is to exit. > >A little history: back in the days of only modems, you would dial into a >UNIX mainframe from a terminal and if the modem disconnected, the system >(or >you) would not want all your processes hanging around afterward. For this >reason, the UNIX system would send a "hangup" signal (SIGHUP) to the login >shell and all its child processes. Shells added a "nohup" (no hangup) >command so certain processes could survive if the user wanted. > >When you say "nohup" it tells the process to ignore the default procedure >and to ignore the SIGHUP (hangup signal). It does not put the process in >the >background so you still need the "&" and it does not change stdout and >stderr (that is why I put those in my e-mail too). > >In python, you would just say: >os.system("nohup python2.2 /root/levantamuertos.py >/dev/null 2>&1 &") > >This should handle most headaches. The headaches that I mentioned are going >to be very subtle. > >1. One is that sometimes developers have changed shells without >telling users. It has happened in the past that "&" has had an implicit >"nohup" in one version of a shell and in the next release, the implict >"nohup" is no longer there. It is better to be explicit and clear... it >also >helps readability. >2. A second headache comes from the output streams (stdout and >stderr). You want to be running a number of these >levantamuertos.pyprocess at the same time. Did you know that the >output of your cron job is >captured and e-mailed to you? And by default, the output of child >processes >(levantamuertos.py) would be the same as cron job, usually only on >error? So you might get a lot of mixed output from the different >levantamuertos.py processes running at the same time. If you send all >the output to /dev/null. Or to specific log files (based on PID), then >you >may not have this headache. > >I hope this helps and wasn't too pedantic. I get that way sometimes. >-Arcege >-- >There's so many different worlds, >So many different suns. >And we have just one world, >But we live in different ones. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Controlling Where My Program Ends
> >>Never mind. I found it - sys.exit() You can do the same thing by raise SystemExit This avoids the need to import sys... Alan G. > >> > >>Sorry to have wasted the bandwidth/time. > >>-- > > > > > > This was in reference to a post about exiting from a program. I couldn't > > figure out why my program wouldn't let me exit from within a sub-menu of the > > console interface. Since my webmail client goofed up the "from" header, it > > never showed up, and I've cancelled it to avoid wasting everyone's time > > further. I found sys.exit() in the library reference, which allows me to do > > what I want. > > > > Don > > > > If you use the if __name__ == '__main__': idiom, then you can just use return > instead of sys.exit() > > def main(): > lotsa interesting python code > if somethinorother: > # sys.exit() > return > more interesting python code > > if __name__ == '__main__': > main() > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't see emacs timer in action
> buffer/output pane before running my program, so I always do > this to start my program: > ... > ...6 steps listed > ... > This is one cycle of running. > Is that normal ??? I doubt it, I've never user python mode in emacs but I have used SQL and C++ modes and usually you just call C-c C-c from the code window and the rest all happens magically. But even if you do have to do all of that the sionple solution is to record it as a macro C-x ( keys to press here C-x ) You can execute it again with C-x e And you can save it so that it will be available next time you start emacs. You can also bind it to a shortcut of your own - after all this is emacs you can do anything! :-) > I need to make shortcut for starting interpreter do you have any idea. record and save a macro M-x apropos macro is your friend... Alan G. A one time emacs user... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
> I haven't found the correct way to do this so far. There is no correct way. Every console is different so you have to adapt. That having been said Fred Lundh has written a console module that tries to hide the diffeent trminal types in a common set of commands - you can download it from his site. The other ways are: Unix/LInux/MacOS/BSD: os.system('clear') DOS/Windows console: os.system('CLS') Generic: print '\n' * 100 # a 100 line screen... Or you could find the control codes for your screen and print them as octal character codes... HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
> Don Parris wrote: > > Thanks! I thought there had to be a way to call the OS' clear screen > > command, but was going about it the wrong way. I was trying to use > > sys.clear instead of os.system. Would it be difficult to test the OS, > > store the result in a variable, and call the comand based on the variable > > result? Or would it be simpler to have users edit the script for their OS? You can do that and I think thats what Fred Lundh's console program does but its not as simple as that either. Some terminals won't respond to the os clear - for example som Textronic displays only clear in text mode but when in graphics mode (and many folks use them thus to use nicer fonts) they won't clear with 'clear'. The only way to do it is send the graphics control characters... > beginning to get an idea of the challenges of portability though. ;) Portability is a real pain. You can achieve 95% portability with only minimal effort but complete portability (think Palm, Paper teletype, Mainframe 3270 terminal, embedded browser interpreter etc etc) is a very elusive goal indeed. On Unix(*) you do have one other option however which is to use curses. This is a pseudo windowing system which runs on character terminals. It has a default window of the whole screen and allows accurate cursor placement, character deletion, screen clearing, instant character reading etc etc. Its a bit irksome to set up but once initialised not too hard to use. If your app does a lot of screen control - like vim or emacs say, then curses is probably the right approach. (*) There is a DOS curses available for download but I couldn't get it to work properly. The *nix curses module is part of the standard library. (THere is also an O'Reilly book on ncurses - the C version, and several online tutorials for the C version too. The Python module is a pretty straight translation of the C API to Python.) Alan G. > > Python actually gets a lot of this right, you may find it's easier than you think to write portable Python. > > Kent > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clearing the Console Screen
Alan G wrote: >>I haven't found the correct way to do this so far. > > > There is no correct way. Every console is different so you have > to adapt. > That having been said Fred Lundh has written a console module > that tries to hide the diffeent trminal types in a common set > of commands - you can download it from his site. The only one I can find there is for Windows: http://www.effbot.org/zone/console-handbook.htm Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Checking if value exist in a '2D array'
Hi again, I have a '2D array', I mean a list inside a list ([[][],[][],...]) and would need to check if the value exists in it. Of course I could do a for loop, but that just seem to be a little overkill, so is there any other way to do it? I have to check the first cell of every insider list. Here's a little pseudo code if that helps. if list[[x][0]] == 'value': # where x can be anything > 0 print 'found' So, is there a similar method like list.count('value') that I use for 1D lists? Regards, -- Olli Rajala <>< Tampere, Finland http://www.students.tut.fi/~rajala37/ "In theory, Theory and Practice should be the same. But in practice, they aren't." - Murphy's Proverbs ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor