Re: [Tutor] how to see a terminal window showing progress of os.system
On 2009-12-17 20:02:03 -0500, "Alan Gauld" said: "pedro" wrote Hi I am sending commands to the command line using python's os.system. Is there a way to see a terminal window showing the progress of os.system as if you had just run the command from a normal terminal window? As it is now it runs completely in the background You can sometimes launch a terminal with your program running in it but thats usually not the best way to do it. Normally you would use the subprocess module and the Popen class to capture the output of the command and either monitor it for some event or display it within your own program. That looks more professional and gives you much more control You will find examples of using subprocess in the Using the OS topic of my tutorial. HTH, Thanks I'll check out your site. Pete ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] running function program
On 12/20/2009 11:53 PM, Richard Hultgren wrote: Hello, when i try to run this (see below) i get message: socket error: no connection could be made because the target maching actively refused it, and, idle subprocess didn't make connection. either idle can't start a subprocess or personal firewall software is blocking the connection. It's not the problem with the program. It's a problem with IDLE. You've got a software firewall or some other programs blocking IDLE to make connection with the python subprocess: The workarounds are either (from best to worst): - create a rule to allow python to connect to localhost in your firewall - don't start more than one instance of IDLE, it could messes things up sometimes - restart your machine, it might be some previous IDLE stuck and messing things up - start your program from the command line (without IDLE) - start IDLE without subprocess, be warned that this means your program runs in the same python instance as IDLE itself and if your program pokes around too much it will messes IDLE up. Run this in command line or make a shortcut: C:\Python26\python.exe -m idlelib.idle -n (adjust path and version appropriately) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] running function program
Hello, when i try to run this (see below) i get message: socket error: no connection could be made because the target maching actively refused it, and, idle subprocess didn't make connection. either idle can't start a subprocess or personal firewall software is blocking the connection. def mult(a, b): if b == 0: return 0 rest = mult(a, b - 1) value = a + rest return value print "3 * 2 = ", mult(3, 2) i used idle window(gui) and new window and it works sometimes. Help!? Richard ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A Python Pastebin where scripts can be run
On Sun, Dec 20, 2009 at 02:45, Rich Lovely wrote: > python.codepad.org is the one I prefer. That's it! Thank you. Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A Python Pastebin where scripts can be run
python.codepad.org is the one I prefer. 2009/12/20 Richard D. Moores : > A couple of days ago I had a link to a Python Pastebin where scripts > can be run, but I failed to bookmark it. Of course, I've Googled for > it, and searched my Firefox history, but have failed to find it. I'm > hoping some Tutor could post the link. > > Thanks, > > Dick Moores > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] A Python Pastebin where scripts can be run
A couple of days ago I had a link to a Python Pastebin where scripts can be run, but I failed to bookmark it. Of course, I've Googled for it, and searched my Firefox history, but have failed to find it. I'm hoping some Tutor could post the link. Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] subclass question
2009/12/20 David Perlman : > If I make a subclass of a built-in class, like this: > > class mylist(list): > def __init__(self): > list.__init__(self) > > Then it is valid for me to do this: > x=mylist() x.hello=3 > > But I can't do this: > y=list() y.hello=3 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'list' object has no attribute 'hello' > > What is it that is special about built-in classes that prevents you from > adding methods or, uh, whatever the generic term is for sub-variables? Is > there a way to make your own classes restricted like that? > > OK thanks! > > > -- > -dave > Unfortunately, as soon as they graduate, our people return > to a world driven by a tool that is the antithesis of thinking: > PowerPoint. Make no mistake, PowerPoint is not a neutral tool — > it is actively hostile to thoughtful decision-making. It has > fundamentally changed our culture by altering the expectations > of who makes decisions, what decisions they make and how > they make them. -Colonel T. X. Hammes, USMC > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > You can use the __slots__ attribute to get the same behaviour: >>> class Demo(object): ... __slots__ = [] ... >>> d = Demo() >>> d.a=1 Traceback (most recent call last): File "", line 1, in AttributeError: 'Demo' object has no attribute 'a' But beware: You need to add every attribute you want your class to have to __slots__, if they're not defined on the class (i.e. instance variables, defined within methods): >>> class Demo(object): ...def __init__(self): ...self.a = 1 ...__slots__ = [] ... >>> d = Demo() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ AttributeError: 'Demo' object has no attribute 'a' >>> class Demo(object): ...def __init__(self): ...self.a = 1 ...__slots__ = ['a'] ... >>> d = Demo() >>> d.a 1 This will need updating every time you add a new instance variable to a class, but it does help detect typos. There is also the option of using __getattr__, __setattr__ and so on, but that's a little more complicated. I will however say, that the original behaviour is entirely intentional. Python was designed to be a language used by consenting adults who should know better than doing things that are likely to break stuff. For instance, there is nothing to stop you from overwriting any of the builtin functions or types. See http://docs.python.org/reference/datamodel.html#slots for some of the other side effects. -- Rich "Roadie Rich" Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor