[Tutor] passing unknown no of arguments
How do you pass arguments of unknown no. of arguments to a function. Also how can i run my python scripts in a web browser. -- A-M-I-T S|S ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] inheriting different builtin types
Hi, http://objectmix.com/python/710201-dynamically-changing-base-class.html may be of interest. wr On Mittwoch, 4. Februar 2009 14:27:17 spir wrote: > Hello, > > I have a strange problem and cannot see a clear method to solve it. > I would like to build a custom type that is able to add some informational > attributes and a bunch attribute to a main "value". The outline is then: > > class Custom(X): > def __init__(self, value, more): > X.__init__(self) > > > > The base class is here to inherit value's behaviour and to avoid writing > obj.value all the time. For this type will be heavily used by client code. > The point is, this value may actually be of several builtin types. > Logically, X is value.__class__. I imagine there are solutions using a > factory, or __new__, or maybe metaclass (never done yet)? I cannot find a > working method myself. > > Denis > > -- > la vida e estranya > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 1:37 PM, amit sethi wrote: > How do you pass arguments of unknown no. of arguments to a function. You use * operator ( indirection) in the function definition for arguments and you pass the variable number of number arguments as a list. For e.g. >>> def foo(*args): ... print args ... >>> foo(1,2,3,4,5,6) (1, 2, 3, 4, 5, 6) >>> foo(1,2,3) (1, 2, 3) >>> > Also how can i run my python scripts in a web browser. What you are asking for is Python CGI programming. Look out for chapters for Alan's book. I think he has covered from the basics. Or just start here: pytute.blogspot.com/2007/05/python-cgi-howto.html You will write a simple script like #!/usr/bin/env python print "Content-Type: text/html\n" print "Hello, World" Give permissions chmod +rw to the script and put it in your web-server's cgi-bin/ directory and invoke the python file. The result will be displayed in the browser. -- Senthil http://uthcode.sarovar.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
"amit sethi" wrote How do you pass arguments of unknown no. of arguments to a function. search the docs for *args and *kwargs Also how can i run my python scripts in a web browser. In general you can't. You would need to have a Python interpreter in your browser. The only reliable way to run code in a browser is to use JavaScript. That having been said there are some options. The pythonwin extensions include a script to enable Python as an ActiveScripting language and in that case you can run Python inside IE on a PC with WSH enabled. Also there are some tools around that will embed an interpreter into a web page. But in my experience they are not suitable for running any significant amount of code they are really intended for tutorial type applications. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 2:27 PM, Alan Gauld wrote: > In general you can't. You would need to have a Python interpreter > in your browser. Alan, I think he was referring to CGI programming. Given the nature of his first question. Well continuing the discussion further, I saw a post by Bret Cannon on the possibility of Firefox 4 supporting Python. -- Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
"Senthil Kumaran" wrote Also how can i run my python scripts in a web browser. What you are asking for is Python CGI programming. Look out for chapters for Alan's book. I think he has covered from the basics. If you mean how do you write dynamic web pages using Python then indeed it is CGI or some other web framework (Django, TurboGears, Pylons etc). If you mean running a python script actually in the browser itself then see my previous mail. Sadly my tutor does not contain stuff on web programming because freenet removed update access as I was writing that topic. That will be fixed after I finish the update of the tutor to v3 on my new web site -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/l2p/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] named list
Hello, python world! I'm looking for a way to implement a kind of "named" list, or named tree, with the following requirements: * Each item is named (or key-ed), like in a dict. * Each item (node) can be either a terminal item (leaf) or a sub-list (branch). * There may be items with the same name, unlike in a dict. * The item entering order is preserved, unlike in a dict. * A non-requirement: may be useful that items can be retrieved by name (in case several items have the same name, it's allright to return first one -- it's up to the client code to manage that) A structural representation of such an object looks like that: obj n1:val n2:val n3 n31:val n32 n321:val n322:val n33 n4 Which is exactly the same as for a list, except that each item gets a name in addition to its value. I ask for advices before doing bull as I suspect there may be a data structure in language theory that matches that needs. Some questions: * Do you know of such a structure? * What is the difference between a tree and a python list? a tree and an array that allows nesting? * Are items in a tree, as defined in theory, supposed to be of homogeneous type? I cannot implement that simply by giving items an additional attribute, for items can be of an type and can even change. They also need a whole bunch of custom methods. This would require sub-typing averu possible type, including custom ones (this was the cause of a previous, in which I asked if it was possible to sub-type at a type known at runtime). So I plan instead to implement the whole load of necessary behaviour in a container, thus letting the items unchanged. A possible design (?) would be to subtype list in order to add such a container object a parallel list of names. So that direct access still directly reaches values, while matching names are accessed by indexing a parallel list: obj[n] <-- item obj.names[n] <-- name And maybe: obj.link[n] <-- (name,item) obj[name] <-- item obj.name(item) <-- name Denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Visualpython-users] tkinter and visual with objects
The following works to produce a window with nothing displayed in it: ball = sphere() ball.visible = 0 Another scheme would be this: scene.range = 1 ball = sphere(radius=1e-6) The point is that Visual doesn't create a window unless there is something to display. Bruce Sherwood Mr Gerard Kelly wrote: I'm trying to make this very simple program, where the idea is that you click a tkinter button named "Ball" and then a ball will appear in the visual window. Problem is that the window itself doesn't pop up until the button is pressed and the ball is created. I would like it to start out blank, and then have the ball appear in it when the button is pressed. I thought that having "self.display=display()" in the __init__ of the Application would do this, but it doesn't seem to. What do I need to add to this code to make it start out with a blank window? from visual import * from Tkinter import * import sys class Ball: def __init__(self): sphere(pos=(0,0,0)) class Application: def __init__(self, root): self.frame = Frame(root) self.frame.pack() self.display=display() self.button=Button(self.frame, text="Ball", command=self.ball) self.button.pack() def ball(self): self.ball=Ball() root=Tk() app=Application(root) root.mainloop() -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Visualpython-users mailing list visualpython-us...@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/visualpython-users ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 3:57 AM, Alan Gauld wrote: > In general you can't. You would need to have a Python interpreter > in your browser. The only reliable way to run code in a browser is > to use JavaScript. AFAIK MS Silverlight allows you to run .NET languages in your browser, including IronPython. Flash runs ActionScript. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] named list
On Thu, Feb 5, 2009 at 5:09 AM, spir wrote: > Hello, python world! > > I'm looking for a way to implement a kind of "named" list, or named tree, > with the following requirements: > > * Each item is named (or key-ed), like in a dict. > * Each item (node) can be either a terminal item (leaf) or a sub-list > (branch). > * There may be items with the same name, unlike in a dict. > * The item entering order is preserved, unlike in a dict. > > * A non-requirement: may be useful that items can be retrieved by name (in > case several items have the same name, it's allright to return first one -- > it's up to the client code to manage that) > > A structural representation of such an object looks like that: > > obj >n1:val >n2:val >n3 >n31:val >n32 >n321:val >n322:val >n33 >n4 > > Which is exactly the same as for a list, except that each item gets a name in > addition to its value. > I ask for advices before doing bull as I suspect there may be a data > structure in language theory that matches that needs. Some questions: > > * Do you know of such a structure? > * What is the difference between a tree and a python list? a tree and an > array that allows nesting? > * Are items in a tree, as defined in theory, supposed to be of homogeneous > type? > > I cannot implement that simply by giving items an additional attribute, for > items can be of an type and can even change. They also need a whole bunch of > custom methods. This would require sub-typing averu possible type, including > custom ones (this was the cause of a previous, in which I asked if it was > possible to sub-type at a type known at runtime). So I plan instead to > implement the whole load of necessary behaviour in a container, thus letting > the items unchanged. > A possible design (?) would be to subtype list in order to add such a > container object a parallel list of names. So that direct access still > directly reaches values, while matching names are accessed by indexing a > parallel list: > >obj[n] <-- item >obj.names[n] <-- name > > And maybe: > >obj.link[n] <-- (name,item) >obj[name] <-- item >obj.name(item) <-- name Perhaps a list of (name, value) pairs, where the value could be a leaf node or another list? Or the nodes could be instances of namedtuple, so they have .name and .value attributes. You could subclass list or UserList. UserList gives you bottleneck methods which make it easy to customize all behaviour. You could also make your own wrapper class which would implement the above API. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] inheriting different builtin types
On Wed, Feb 4, 2009 at 8:27 AM, spir wrote: > Hello, > > I have a strange problem and cannot see a clear method to solve it. > I would like to build a custom type that is able to add some informational > attributes and a bunch attribute to a main "value". The outline is then: > > class Custom(X): >def __init__(self, value, more): >X.__init__(self) > > > > The base class is here to inherit value's behaviour and to avoid writing > obj.value all the time. For this type will be heavily used by client code. > The point is, this value may actually be of several builtin types. Logically, > X is value.__class__. I imagine there are solutions using a factory, or > __new__, or maybe metaclass (never done yet)? I cannot find a working method > myself. If I understand correctly, you have two problems: - creating a class with a dynamic base type - creating a subclass of a built-in value type such as int The first is easily solved with a factory method to create the classes: def make_value_class(base_): class Derived(base_): # etc return Derived IntValue = make_value_class(int) Subclassing builtin types is tricky because the value has to be assigned in the __new__() method, not in __init__(). See for example http://www.python.org/download/releases/2.2.3/descrintro/#__new__ or search the tutor archives for __new__. Note that subclasses of builtin types are not as useful as you might hope because they are not preserved by binary operations. For example given a working IntValue class, if you did x = IntValue(3) y = IntValue(5) z = x+y type(z) is int, not IntValue, so all the special sauce is lost. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Killing a socketserver
Geeting, my masters. How do I kill/shutdown a socket server running in its own thread either from handle() or from outside of the tread? Any thing will do. It's python version 2.5.2, so the newer shutdown method in version 2.6 does not work here. Thanks in advance. -- Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmer / BOFH ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
Le Thu, 5 Feb 2009 08:57:15 -, "Alan Gauld" a écrit : > > "amit sethi" wrote > > > How do you pass arguments of unknown no. of arguments to a function. > > search the docs for *args and *kwargs > Or simply pass a tuple: def myPrint(thing): print thing thing_of_things = (1,'a',[True]) myPrint(thing_of_things) ==> (1,'a',[True]) Denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sort of database & "family tree" question
Le Wed, 4 Feb 2009 22:33:45 -, "Alan Gauld" a écrit : > > "Timo" wrote > > class Person: > def __init__(self, parser): > self.first = parser.get(person, 'firstName') > > > > Hey Alan, thanks for that explanation! > > > > But the class you gave, does almost the same thing as my function. > > That was my point. Its just a prettier way of handling it and slightly > easier to use sionce you don;t need to quote the field names, > just use the dot notation. > > > both store the info in a dic, so to retrieve info for a certain > > person, we both have to do the same thing. Or am I missing something > > here? > > The class is less typing. Youcreate a dictionary of dictionaries, > I create a dictionary of objects - which are easier to access. > However the class can also have methods added to do searches, > follow the tree etc. You could also add the people dictionary as a > class variable which would add to the conceptual consistency of > the solution.. [... lots of sensible words comparing dict way to object way ...] A note on implementing all the features needed for actual use (at least, a nice output format): using a dict of dicts will tend mixing up things related to persons with other, indirectly related things. Unless you keep a very strict design and coding discipline. Many things get uselessly dependant so that minor changes become difficult. Using objects does not guarantee preventing that (especially in python where it is always possible to access any object attribute from anywhere), but it helps much. Actually, it helps both at design and coding levels. But you are still free to write an unreadable mess... Denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 3:57 AM, Alan Gauld wrote: > > In general you can't. You would need to have a Python interpreter > > in your browser. The only reliable way to run code in a browser is > > to use JavaScript. I'm very new to Python, but I've also been wondering about this. It would seem to me that with Jython you could write Python code that you convert to Java applets to run in the web browser. After a little bit of googling around, it seems that it all comes down to importing Applet from java.applet and then, of course, learning the applet interface. I didn't immediately see anything about performance issues, reliability, gotchas, or any other significant drawbacks, but if the original poster really did mean Python code that runs in the browser instead of on the server, maybe this approach would help them. -Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Install/upgrade question
Hello, I am very new to programming and have been using Python on my Mac mini 1.66. I'm a bit confused by the install procedure as I have two different versions on my machine. I didn't know that it came pre-installed on my mac (version 2.3) and went to the DL site for 2.61. Well it downloaded just fine but I seem to have a few situations. My main question is "How do I get the downloaded version to replace what's on my system? As it is, I can open the IDLE and it verifies I have installed version 2.61. But when I run a dir() request it spouts the version is 2.3. Confusing... Further I DL'ed the .tar which decompressed to a .dmg file. The 2.61 folder is currently on my Desktop, where I process most of my downloads. Thanks! And finally, this is amazing stuff. I've dreamed about being able to write software for years and feel I have found something quite useful. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Install/upgrade question
On Thu, Feb 5, 2009 at 12:06 PM, wrote: > My main question is "How do I get the downloaded version to replace what's > on my system? Don't; leave the system copy alone, there are system components that use it. > As it is, I can open the IDLE and it verifies I have installed version 2.61. > But when I run a dir() request it spouts the version is 2.3. Confusing... I don't understand that; what is a dir() request? What is spouting? Please be more specific and show the actual text. > Further I DL'ed the .tar which decompressed to a .dmg file. The 2.61 folder > is currently on my Desktop, where I process most of my downloads. Do you mean the installed Python in on your desktop, or the .dmg file, or what? It should not install to the desktop. > And finally, this is amazing stuff. Yes :-) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
"Kent Johnson" wrote in your browser. The only reliable way to run code in a browser is to use JavaScript. AFAIK MS Silverlight allows you to run .NET languages in your browser, But how many browsers currently support Silverlight? After all IE supports VBScript too but its the only one. Eventually Silverlight may become ubiquitous but for now the only *reliable* way to write client code is JavaScript. Flash runs ActionScript. Flash is a valid point although somewhat limited in practice - I wouldn't want to write a general purpose app in Actionscript! Also the point made about a Jython applet is good too. That might in fact be the best route to Python in a browser. Although Java applets seem to have fallen out of favour lately... -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Killing a socketserver
"Michael Bernhard Arp Sørensen" wrote How do I kill/shutdown a socket server running in its own thread either from handle() or from outside of the tread? Any thing will do. kill -9 pid if you are on *nix? Or do you need to do it from code? Or is it only the thread you want to kill? Are you killing from inside the same process? Or from an external process? Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
On Thu, Feb 5, 2009 at 1:02 PM, Alan Gauld wrote: > > "Kent Johnson" wrote >> AFAIK MS Silverlight allows you to run .NET languages in your browser, > > But how many browsers currently support Silverlight? >From the Silverlight FAQ: Silverlight will support all major browsers on both Mac OS X, Linux and on Windows. Particular care is being taken to account for differences in platform and browser capabilities to ensure a consistent experience including experiences on Firefox, Safari, and Internet Explorer. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Killing a socketserver
On Thu, Feb 5, 2009 at 7:26 AM, Michael Bernhard Arp Sørensen wrote: > Geeting, my masters. > > How do I kill/shutdown a socket server running in its own thread either from > handle() or from outside of the tread? Any thing will do. > > It's python version 2.5.2, so the newer shutdown method in version 2.6 does > not work here. > Subclass the server class adding shutdown() and supporting infrastructure from 2.6. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passing unknown no of arguments
"Kent Johnson" wrote From the Silverlight FAQ: Silverlight will support all major browsers on both Mac OS X, Linux and on Windows. I briefly tried and failed to get it working on MacOS X and lost interest. Looks like I might be a bit premature in ignoring it. I'll have another go... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] confusing enumerate behavior
Hi Tutors, I'm a little, actually a lot confused by the behavior of the enumerate function here. I have a text and I want to get each word within the context of the three preceding and the three following words. I tried this: #BEGIN my_input = "one two three four five six seven eight nine ten" text = my_input.split() for i,v in enumerate(text): line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], text[i+3] print line # END The ouput was not as I expected. It did not start from the beginning (actually I had expected it to throw and exception immediately) ('eight', 'nine', 'ten', 'one', 'two', 'three', 'four') ('nine', 'ten', 'one', 'two', 'three', 'four', 'five') ('ten', 'one', 'two', 'three', 'four', 'five', 'six') ('one', 'two', 'three', 'four', 'five', 'six', 'seven') ('two', 'three', 'four', 'five', 'six', 'seven', 'eight') ('three', 'four', 'five', 'six', 'seven', 'eight', 'nine') ('four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') Traceback (most recent call last): File "enumerate.py", line 13, in line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], text[i+3] IndexError: list index out of range e...@emad-laptop:~/Desktop$ I then though of adding dummy words to the beginning and the end and exclude them later like this: #BEGIN my_input = "one two three four five six seven eight nine ten" text2 = " nothing " *6 + my_input + " nothing "* 6 text2 = text2.split() for i,v in enumerate(text2[6:-6]): line = text2[i-3], text2[i-2], text2[i-1], v, text2[i+1], text2[i+2], text2[i+3] print line #END The output this time was even more confusing: e...@emad-laptop:~/Desktop$ python enumerate.py ('nothing', 'nothing', 'nothing', 'one', 'nothing', 'nothing', 'nothing') ('nothing', 'nothing', 'nothing', 'two', 'nothing', 'nothing', 'nothing') ('nothing', 'nothing', 'nothing', 'three', 'nothing', 'nothing', 'nothing') ('nothing', 'nothing', 'nothing', 'four', 'nothing', 'nothing', 'one') ('nothing', 'nothing', 'nothing', 'five', 'nothing', 'one', 'two') ('nothing', 'nothing', 'nothing', 'six', 'one', 'two', 'three') ('nothing', 'nothing', 'nothing', 'seven', 'two', 'three', 'four') ('nothing', 'nothing', 'one', 'eight', 'three', 'four', 'five') ('nothing', 'one', 'two', 'nine', 'four', 'five', 'six') ('one', 'two', 'three', 'ten', 'five', 'six', 'seven') Can somebody please explain what is going on here? Have I done something wrong? How can this be fixed? Thanks in anticipation, Emad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python 2.6.1 + Linux Ubuntu (Gutsy Gibbon)
I am trying to teach myself Linux, and so I'm running Ubuntu (Gutsy Gibbon) as a virtual machine. I went to terminal, started up Python and realized it was version 2.5 so I thought I'd just upgrade to 2.6.1 After doing some Googling around, it seems that Ubuntu is highly reliant on Python 2.5, so upgrading isn't so simple after all. Is this just Ubuntu that is so integrated with Python, or all flavors of Linux? Doesn't this hinder developers who use Ubuntu (and Linux?) as their primary OS when new versions of Python come out? I have been using Windows forever, but everyone says Linux is the development environment. Thoughts? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] confusing enumerate behavior
"Emad Nawfal (عماد نوفل)" wrote I'm a little, actually a lot confused by the behavior of the enumerate Its not enumerate thats confusing you its indexing. my_input = "one two three four five six seven eight nine ten" text = my_input.split() for i,v in enumerate(text): line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], for i=0 the first index is -3 but an index of -3 in Python is the third item from the end. Its a little bit like the list was circular, so, instead of falling off the end with -1, you wrap around to the last item. ('eight', 'nine', 'ten', 'one', 'two', 'three', 'four') So eight is text[-3] because its 3 from the end. I then though of adding dummy words text2 = " nothing " *6 + my_input + " nothing "* 6 text2 = text2.split() for i,v in enumerate(text2[6:-6]): line = text2[i-3], text2[i-2], text2[i-1], v, text2[i+1], text2[i+2], by using the slice you extracted your old list and got the same set of indexes! Instead of subtracting 3 you would need to add six minus the offset: line = text2[i+6-3], text2[i+6-2] by the way doesn't this look like it could be in a loop? The other way is to simply test the index and if its beyond the range of your list add 'nothing'. Something like: my_input = "one two three four five six seven eight nine ten" text = my_input.split() for i,v in enumerate(text): for n in range(3,0,-1) if i-n < 0: print 'nothing', print text[i], for n in range(1,4) if i+n >= len(text) print 'nothing, Its late and this is untested but it should give a starting point. My brain is saying something about list comprehensions but I'm too tired to care :-) Or another waty might be to use your text2 approach and just print using indexes starting at the offset of your frst entry. Actually that sounds like it might be the best way... text2 = 'nil'*3+text+'niil*3 for i in range(3,len(text)): print text2[i-3:i+3] or somesuch... HTH Alan G. Zz ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python 2.6.1 + Linux Ubuntu (Gutsy Gibbon)
On Thu, Feb 5, 2009 at 8:24 PM, Eric Dorsey wrote: > I am trying to teach myself Linux, and so I'm running Ubuntu (Gutsy Gibbon) > as a virtual machine. I went to terminal, started up Python and realized it > was version 2.5 so I thought I'd just upgrade to 2.6.1 After doing some > Googling around, it seems that Ubuntu is highly reliant on Python 2.5, so > upgrading isn't so simple after all. > Is this just Ubuntu that is so integrated with Python, or all flavors of > Linux? Doesn't this hinder developers who use Ubuntu (and Linux?) as their > primary OS when new versions of Python come out? > > I have been using Windows forever, but everyone says Linux is the > development environment. Thoughts? > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > Just a quick reply until you get a better answer: I'm using Ubuntu Linux and I have Python 2.5.2 is the default version. I have recently downloaded and installed python3.0 without any problems. All I have to do is to specify that I want to use python3.0 >From the terminal type python and you get python2.5 Type python3.0 and you get python3.0. You can have multiple python versions on your machine. -- لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد الغزالي "No victim has ever been more repressed and alienated than the truth" Emad Soliman Nawfal Indiana University, Bloomington http://emnawfal.googlepages.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Install/upgrade question
On Thu, Feb 5, 2009 at 9:29 PM, wrote: > Hi Kent, > Thanks for your very quick reply. I'll be as succinct as possible. > On Feb 5, 2009, at 10:48 AM, Kent Johnson wrote: > Last login: Thu Feb 5 18:55:15 on console > Welcome to Darwin! > p-ws-computer:~ pw$ python > Python 2.3.5 (#1, Nov 26 2007, 09:16:55) > [GCC 4.0.1 (Apple Computer, Inc. build 5363) (+4864187)] on darwin > Using IDLE I get a different version listing: > Python 2.6.1 (r261:67515, Dec 6 2008, 16:42:21) > [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin OK, so IDLE is using the 2.6.1 you installed but the command line still sees 2.3. > Further I DL'ed the .tar which decompressed to a .dmg file. The 2.61 folder > is currently on my Desktop, where I process most of my downloads. > > Do you mean the installed Python in on your desktop, or the .dmg file, > or what? It should not install to the desktop. > > This is what happened. I have 2.61 on the desktop. Before I move it I wanted > to be sure of several other things: > 1. You already answered that Q, "don't remove the older version 2.35." > 2. Is there a hack to get my 2.61 off the desktop and into the System? I > still have the .tar file. I'm still confused by this. The download from Python.org is a dmg file, not a tar file. The standard installers don't install to the desktop, and they put the new Python into your path. Where did you get your installer? Maybe you should just install the version from Python.org. What is the console output of these commands? echo $PATH which python which python2.6 python2.6 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Designing a Dialog in Python
Title: Signature.html When I used VBasic many years ago, it had the ability to design a dialog and then attach it to the code. Is there something like this available for Python? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Q: What do you do when your resistors get to hot? A: Open the switch and coulomb they off. -- Anon. (fortunately!) Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] confusing enumerate behavior
On Fri, Feb 6, 2009 at 5:43 AM, Emad Nawfal (عماد نوفل) wrote: > Hi Tutors, > I'm a little, actually a lot confused by the behavior of the enumerate > function here. I have a text and I want to get each word within the context > of the three preceding and the three following words. I tried this: > #BEGIN > my_input = "one two three four five six seven eight nine ten" > text = my_input.split() > for i,v in enumerate(text): > line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], > text[i+3] > print line > # END > The ouput was not as I expected. It did not start from the beginning > (actually I had expected it to throw and exception immediately) > ('eight', 'nine', 'ten', 'one', 'two', 'three', 'four') > ('nine', 'ten', 'one', 'two', 'three', 'four', 'five') > ('ten', 'one', 'two', 'three', 'four', 'five', 'six') > ('one', 'two', 'three', 'four', 'five', 'six', 'seven') > ('two', 'three', 'four', 'five', 'six', 'seven', 'eight') > ('three', 'four', 'five', 'six', 'seven', 'eight', 'nine') > ('four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') > Traceback (most recent call last): > File "enumerate.py", line 13, in > line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], > text[i+3] > IndexError: list index out of range > e...@emad-laptop:~/Desktop$ > > I then though of adding dummy words to the beginning and the end and exclude > them later like this: > #BEGIN > my_input = "one two three four five six seven eight nine ten" > > text2 = " nothing " *6 + my_input + " nothing "* 6 > > text2 = text2.split() > for i,v in enumerate(text2[6:-6]): > line = text2[i-3], text2[i-2], text2[i-1], v, text2[i+1], text2[i+2], > text2[i+3] > print line > #END > > The output this time was even more confusing: > e...@emad-laptop:~/Desktop$ python enumerate.py > ('nothing', 'nothing', 'nothing', 'one', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'two', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'three', 'nothing', 'nothing', 'nothing') > ('nothing', 'nothing', 'nothing', 'four', 'nothing', 'nothing', 'one') > ('nothing', 'nothing', 'nothing', 'five', 'nothing', 'one', 'two') > ('nothing', 'nothing', 'nothing', 'six', 'one', 'two', 'three') > ('nothing', 'nothing', 'nothing', 'seven', 'two', 'three', 'four') > ('nothing', 'nothing', 'one', 'eight', 'three', 'four', 'five') > ('nothing', 'one', 'two', 'nine', 'four', 'five', 'six') > ('one', 'two', 'three', 'ten', 'five', 'six', 'seven') > > Can somebody please explain what is going on here? Have I done something > wrong? How can this be fixed? > > Thanks in anticipation, > Emad > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > hello Emad Try this if u r looking for this kind of solution >>>my_input = "one two three four five six seven eight nine ten" >>>text = my_input.split() >>>for i in range(len(text)): if i+3>=len(text): print text[i-3:len(text):1] elif i<=2: print text[0:i+4] else: print text[i-3:i+4] Output is... ['one', 'two', 'three', 'four'] ['one', 'two', 'three', 'four', 'five'] ['one', 'two', 'three', 'four', 'five', 'six'] ['one', 'two', 'three', 'four', 'five', 'six', 'seven'] ['two', 'three', 'four', 'five', 'six', 'seven', 'eight'] ['three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] ['four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'] ['five', 'six', 'seven', 'eight', 'nine', 'ten'] ['six', 'seven', 'eight', 'nine', 'ten'] ['seven', 'eight', 'nine', 'ten'] Jitendra Kumar Hyderabad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor