Re: [Tutor] Unpacking lists
On 09/07/14 02:44, Robert Nanney wrote: #!/usr/bin/python #list_test2.py list1 = [1, 8, 15] list2 = [2, 9, 16] list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]] list4 = [7, 14, 21] one_list = zip(list1, list2, list3, list4) first_round = [one_list[x][y] for x in range(len(list3)) for y in range(4)] My first thought is that you are using indexing too much. The above would be clearer using: first_round = [tup[x] for tup in one_list for x in range(4)] second_round = [] for i in first_round: if not isinstance(i, list): second_round.append(i) else: for x in range(len(i)): second_round.append(i[x]) and this loop could be for item in i: second_round.append(item) But I think list addition would do the job more easily. Something like (untested) second_round += i While this seems to do the trick, I feel there is probably a better/more pythonic way to accomplish the same thing. I agree but I don;t have time right now to figure it out! But it seems there should be a more straightforward method. I'm thinking something like result = [] for L in (list1,list2,list3): if isinstance(L,list) result += L else: result.append(L) mebbe... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unpacking lists
On 09/07/14 06:58, Alan Gauld wrote: list1 = [1, 8, 15] list2 = [2, 9, 16] list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]] list4 = [7, 14, 21] I'm thinking something like result = [] for L in (list1,list2,list3): if isinstance(L,list) result += L else: result.append(L) mebbe... Too early in the morning... There needs to be another loop around that. for L in (list1,list2,list3): for index in len(list1): #??? if isinstance(L[index],list) result += L[index] else: result.append(L[index]) double mebbe. Anyway I'm off to work... :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
Hi Jim, On 8 July 2014 21:45, Jim Byrnes jf_byr...@comcast.net wrote: I would like to automate running virtualenv with a python script by: opening gnome-terminal cd to proper directory run source /bin/activate I found some examples of using os.system() to get gnome-terminal to open but I can't figure out how then cd to the proper directory in the new terminal. My biggest frustration right now is that I can't find any documentation on how to use os.system(). Looking at the docs on the Python site I don't see system() under the os module. Googling hasn't helped. Could you explain what you're trying to achieve? Virtualenv is about setting up an OS/Unix shell environment (For Windows there's a Powershell variant of virtualenv...) so that a custom Python installation is used by default instead of the system wide on (including possibly using a custom Python executable.) It therefore seems that trying to automate activating a virtualenv with python (which presumably would use the system wide python) is not adding much value? Hence my question: What are you actually trying to achieve? Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A beginner having problems with inheritance
On 06/07/2014 23:06, Danny Yoo wrote: My apologies to the tutors. I have identified my error, which was predictably elementary. With many thanks, By the way, can you say what your conceptual error was or give an example? It might help the other folks here who are learning and who may be making a similar mistake. (And I'm curious!) But if you don't want to say, that's ok too. Good luck! Thanks Danny, My error was simply that I inadvertently used the same name for a method (function) in the derived class that I had already used in the parent class. The result was then a very obscure error because the wrong calculation was performed and later on an array was empty. Fortunately, thanks to you very generous tutors I have learned to read the error trace very carefully indeed. Thanks a lot. Sydney -- Sydney Shall ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
On 07/09/2014 04:27 AM, Walter Prins wrote: Hi Jim, On 8 July 2014 21:45, Jim Byrnes jf_byr...@comcast.net wrote: I would like to automate running virtualenv with a python script by: opening gnome-terminal cd to proper directory run source /bin/activate I found some examples of using os.system() to get gnome-terminal to open but I can't figure out how then cd to the proper directory in the new terminal. My biggest frustration right now is that I can't find any documentation on how to use os.system(). Looking at the docs on the Python site I don't see system() under the os module. Googling hasn't helped. Could you explain what you're trying to achieve? Virtualenv is about setting up an OS/Unix shell environment (For Windows there's a Powershell variant of virtualenv...) so that a custom Python installation is used by default instead of the system wide on (including possibly using a custom Python executable.) It therefore seems that trying to automate activating a virtualenv with python (which presumably would use the system wide python) is not adding much value? Hence my question: What are you actually trying to achieve? Walter I forgot to mention I am using Linux (Ubuntu 12.04). I am working my way through a book about breezypythongui which uses Python 3, hence virtualenv. I found that each time I started to work with it I did the above 3 steps, I was just looking to automatic that repetitive task. Regards, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
On 07/08/2014 06:39 PM, Alan Gauld wrote: On 08/07/14 21:45, Jim Byrnes wrote: I would like to automate running virtualenv with a python script by: opening gnome-terminal cd to proper directory run source /bin/activate Thats almost certainly the wrong approach. Instead of trying to automate what the user does in the terminal replace the terminal with Python. Run the cd command from within Python (os.chdir()) Run Activate from within Python (this is where os.system() could be used, but subprocess.call() is considered better practice. I found some examples of using os.system() to get gnome-terminal to open but I can't figure out how then cd to the proper directory in the new terminal. You can't. os.system() just runs a command it has no way to interaxct5 with the command, you do that manually. Its perfectly fine for displaying a directory listing (although os.listdir() would be better) or sending a file to a printer, or even opening a terminal/editor for the user to interact with. But its no good for your program interacting with it. Thats what subprocess is for. Alan and the others that offered advice, thanks. I see that I have taken the wrong approach. My intent was to automate something I was doing manually time after time and learn a little more Python as well. My biggest frustration right now is that I can't find any documentation on how to use os.system(). Looking at the docs on the Python site I don't see system() under the os module. You should, although they don;t have a lot to say... snip Googling hasn't helped. When you know the module use the browser search tools on the page itself - that's how I found it. I searched for os.system and it was the 3rd occurence. My mistake. I went to the Docs page and clicked on modules and then os. For some reason as I was scrolling down the page I thought the subject had changed and stopped reading. Now I see I stopped reading to soon as it is much further down the page. Thanks, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How does this work (iterating over a function)?
Greetings, I've been learning Python concepts for about 6 months now and was doing okay with most of these. However, I ran into a fairly simple program developed by Mark Pilgrim in his Dive Into Python text that puzzles me and am hoping some of you can explain how this works. He is creating the Fibonoci sequence by iterating over a function that has a generator in it (i.e. no return statement). The code is as follows: def fibonacci(max): #using a generator a, b = 0, 1 while a max: yield a a, b = b, a+b for n in fibonacci(1000): print n, -- The program works beautifully buy I can't figure out what we are actually iterating with. When the function is called it 'yields' the value a which is then updated to b, etc. But what is the value of 'n' as it iterates through the function? I can understand iterating through lists, strings, range(), etc. but how this iterates through a function is puzzling me. Obviously the answer, n, is the Fibonocci series but by what mechanism does this work? What is the iterable component of a function? BTW, this is one of the many things that fascinates me about Python. It's easy to learn but also has some unique (at least to me) ways of doing things. Thanks, Steve Tenbrink Los Alamos, NM ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
Hi, Let's see what happens iteration by iteration. First iteration: def fibonacci(max): #using a generator a, b = 0, 1 # The value of a is 0 and b is 1, easy :) while a max: yield a # yield a (0) (yield is a keyword that is used like return but returns a generator). This value will be sent to the for iteration on the first iteration. On the second iteration: a, b = b, a+b # a is 1 now and b is 1 (1+0) And then yield a which now is 1 On the third iteration: a, b = b, a+b # a is 1 now and b is 2 (1+1) And then yield a which now is 1 On the forth iteration: a, b = b, a+b # a is 2 now and b is 3 (2+1) And then yield a which now is 2 for n in fibonacci(1000): print n, -- n is the value for each iteration that the yield statement is returning. You can read the response on this thread if you want to understand more about yield, generators and iterators. Thanks, Raúl ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
Hi, A little bit more on this :) Python iterator protocol will call the next() method on the iterator on each iteration and receive the values from your iterator until a StopIteration Exception is raised. This is how the for clause knows to iterate. In your example below you can see this with the next example: gen = fibonacci(3) gen.next() 0 gen.next() 1 gen.next() 1 gen.next() 2 gen.next() Traceback (most recent call last): File stdin, line 1, in module StopIteration Thanks, Raúl On Wed, Jul 9, 2014 at 4:18 PM, Raúl Cumplido raulcumpl...@gmail.com wrote: Hi, Let's see what happens iteration by iteration. First iteration: def fibonacci(max): #using a generator a, b = 0, 1 # The value of a is 0 and b is 1, easy :) while a max: yield a # yield a (0) (yield is a keyword that is used like return but returns a generator). This value will be sent to the for iteration on the first iteration. On the second iteration: a, b = b, a+b # a is 1 now and b is 1 (1+0) And then yield a which now is 1 On the third iteration: a, b = b, a+b # a is 1 now and b is 2 (1+1) And then yield a which now is 1 On the forth iteration: a, b = b, a+b # a is 2 now and b is 3 (2+1) And then yield a which now is 2 for n in fibonacci(1000): print n, -- n is the value for each iteration that the yield statement is returning. You can read the response on this thread if you want to understand more about yield, generators and iterators. Thanks, Raúl -- Raúl Cumplido ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter resizable menu??
- Original Message - From: Alan Gauld alan.ga...@btinternet.com To: tutor@python.org Cc: Sent: Tuesday, July 8, 2014 8:56 PM Subject: Re: [Tutor] Tkinter resizable menu?? On 08/07/14 16:46, Albert-Jan Roskam wrote: I pasted the code here because it is a bit much (sorry): Too much for me, I gave up without spotting the problem. Hi Peter, Alan, Yes, that was too much code indeed. Peter's suggestion helped though --thanks! After I added the row/columnfigure commands it was resizable. What a lot of work for a small menu! One thing that did strike me though was that you spend quite a lot of code setting up scrollbars etc on your list boxes. The Tix module has a scrollable listbox widget which is quite easy to use and does all that stuff for you. Simply replace import Tkinter as tk with import Tix as tk Ahh, I will certainly look into that. Today somebody recommanded Python Megawidgets to me (http://pmw.sourceforge.net/). Might be something similar. I gets much more problem-oriented without all the 'mandatory' stuff like scrollbars. Thanks again! Albert-Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
Greetings, I've been learning Python concepts for about 6 months now and was doing okay with most of these. However, I ran into a fairly simple program developed by Mark Pilgrim in his Dive Into Python text that puzzles me and am hoping some of you can explain how this works. He is creating the Fibonoci sequence by iterating over a function that has a generator in it (i.e. no return statement). The code is as follows: def fibonacci(max): #using a generator a, b = 0, 1 while a max: yield a a, b = b, a+b for n in fibonacci(1000): print n, -- Thanks, Steve Tenbrink Los Alamos, NM I am pretty new to Python myself, so I don't know all that much, but you can get a visualization of how the code works at the following website. It is a highly useful tool. just copy/paste and step through. http://www.pythontutor.com/visualize.html#mode=edit Deb in WA, USA FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter resizable menu??
On 09/07/14 16:54, Albert-Jan Roskam wrote: The Tix module has a scrollable listbox widget which is quite easy to use and does all that stuff for you. Ahh, I will certainly look into that. Today somebody recommanded Python Megawidgets to me The PMW are fine too but Tix comes as part of the standard library. Documentation isn't great though - you often find better examples on the Tcl/Tk Tix site. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A beginner having problems with inheritance
My error was simply that I inadvertently used the same name for a method (function) in the derived class that I had already used in the parent class. The result was then a very obscure error because the wrong calculation was performed and later on an array was empty. Fortunately, thanks to you very generous tutors I have learned to read the error trace very carefully indeed. Ah, yes, that one. It's happened to me too. It's one of the reasons why inheritance makes me nervous sometimes. It's a problem that's fairly language-independent. (If you'd like to know the details, the example that I was involved in is described in the comments on: https://github.com/bootstrapworld/js-numbers/pull/5. Essentially, we subclassed some base class, and wrote a method called BigNumber.exp() to do exponentiation. Unfortunately, we didn't realize that our superclass already had defined an exp() method. It ended up showing up as a very strange, obscure error. Same class of problem.) Side note, Python does have a hack called name mangling that can be used to try to avoid this problem: https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references Good luck! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
- Original Message - I guess my higher level question is: what makes this function iterable? and the answer appears to be the fact that it uses a generator instead of a return function. Is that correct? -Steve Tenbrink -- Message: 1 Date: Wed, 9 Jul 2014 16:24:46 +0100 From: Ra?l Cumplido raulcumpl...@gmail.com To: steve10br...@comcast.net Cc: tutor tutor@python.org Subject: Re: [Tutor] How does this work (iterating over a function)? Message-ID: CAD1Rbrou1hDfxkBeJcB97361uwyNYq8tW7REk=mhuavjenn...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Hi, A little bit more on this :) Python iterator protocol will call the next() method on the iterator on each iteration and receive the values from your iterator until a StopIteration Exception is raised. This is how the for clause knows to iterate. In your example below you can see this with the next example: gen = fibonacci(3) gen.next() 0 gen.next() 1 gen.next() 1 gen.next() 2 gen.next() Traceback (most recent call last): File stdin, line 1, in module StopIteration Thanks, Ra?l -- Ra?l Cumplido -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20140709/ccbbee12/attachment-0001.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
Yes, every generator is an iterator (but not viceversa) and you can iterate over an iterator. An iterator is one object that implements the Python iterator protocol. Thanks, Raúl On Wed, Jul 9, 2014 at 7:59 PM, steve10br...@comcast.net wrote: -- I guess my higher level question is: what makes this function iterable? and the answer appears to be the fact that it uses a generator instead of a return function. Is that correct? -Steve Tenbrink -- Message: 1 Date: Wed, 9 Jul 2014 16:24:46 +0100 From: Ra?l Cumplido raulcumpl...@gmail.com To: steve10br...@comcast.net Cc: tutor tutor@python.org Subject: Re: [Tutor] How does this work (iterating over a function)? Message-ID: CAD1Rbrou1hDfxkBeJcB97361uwyNYq8tW7REk= mhuavjenn...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Hi, A little bit more on this :) Python iterator protocol will call the next() method on the iterator on each iteration and receive the values from your iterator until a StopIteration Exception is raised. This is how the for clause knows to iterate. In your example below you can see this with the next example: gen = fibonacci(3) gen.next() 0 gen.next() 1 gen.next() 1 gen.next() 2 gen.next() Traceback (most recent call last): File stdin, line 1, in module StopIteration Thanks, Ra?l -- Ra?l Cumplido -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20140709/ccbbee12/attachment-0001.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- Raúl Cumplido ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
By the way, it may be really instructive to read the article when generators were officially introduced into Python 2.2: https://docs.python.org/3/whatsnew/2.2.html#pep-255-simple-generators It's written for the perspective of someone who doesn't know what generators are. Because of that, it should be fairly approachable. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
It might also be useful to see what an equivalent version of that fib() iterator looks like if we don't take advantage of generators ourselves. Here's an attempt at it: ### def fib1(max): a, b, = 0, 1 while a max: yield a a, b, = b, a+b class fib2(object): def __init__(self, max): self.max = max self.a, self.b = 0, 1 def __iter__(self): return self def next(self): if self.a = self.max: raise StopIteration result = self.a self.a, self.b = self.b, self.a + self.b return result ## We should see the same output between this: for n in fib1(10): print n, print ## and this: for n in fib2(10): print n, ### fib1 is the original iterator of this thread. fib2 is an iterator that manages its state by itself. The difference is that when we're writing a generator, we can depend on the resuming part to restore our state when we want to pick up the next value. In contrast, in the version without generators, we have to manage all that state ourselves. For this example, it's not necessarily hard, but it's slightly tedious. That's why generators are so closely tied to iterators: generators make it really easy to write an iterator. You can write an iterator without using the generator feature, but it can be a hassle. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unpacking lists
On 09.07.2014 08:16, Alan Gauld wrote: On 09/07/14 06:58, Alan Gauld wrote: list1 = [1, 8, 15] list2 = [2, 9, 16] list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]] list4 = [7, 14, 21] I'm thinking something like result = [] for L in (list1,list2,list3): if isinstance(L,list) result += L else: result.append(L) mebbe... Too early in the morning... There needs to be another loop around that. for L in (list1,list2,list3): for index in len(list1): #??? if isinstance(L[index],list) result += L[index] else: result.append(L[index]) double mebbe. Anyway I'm off to work... :-) The working solution closest to Alan's attempt appears to be: list1 = [1, 8, 15] list2 = [2, 9, 16] list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]] list4 = [7, 14, 21] final = [] for outer in zip(list1, list2, list3, list4): for inner in outer: if isinstance(inner, list): final.extend(inner) else: final.append(inner) print (final) but his general idea is right. Best, Wolfgang ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How to Create Webpage with Python
First, please forgive any ignorance in my post here as I am not good with HTML and new to python. I have a bunch of excel spreadsheets (all in the same format) that I am writing a python script to go through and pick out some information and post to a wiki page. I'm new to python and have gone through some basic tutorials. I feel confident that I can figure out how to read an excel spreadsheet in python. However, I am feeling a bit overwhelmed with figuring out how to do the web stuff in python. The webpage doesn't exist yet and I have envisioned that the wiki webpage is created once and then simply update it every time the script is run. However, I don't know much about how persistence works with webpages. I have two main questions: 1) Considering the webpage doesn't exist yet, do I need to 'serve' or 'post' a webpage (as was brought up below)? 2) How do I create this wiki webpage? and does this happen in python every time the script is run? 3) How do I send my data to this webpage? I don't have to have full blown answers here, just a link or advice or anything to help me with navigating all of the information out there on Google. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
Hi Jim, On 9 July 2014 14:43, Jim Byrnes jf_byr...@comcast.net wrote: On 07/09/2014 04:27 AM, Walter Prins wrote: I forgot to mention I am using Linux (Ubuntu 12.04). I am working my way through a book about breezypythongui which uses Python 3, hence virtualenv. I found that each time I started to work with it I did the above 3 steps, I was just looking to automatic that repetitive task. In that case you should put these commands in your .bashrc file so it gets set up as your user's default. (The .bashrc file is somewhat like DOS's autoexec.bat file, if you're familiar with this, except each user has their own .bashrc.) You can also create a shell script that does this for you. (You can install virtualenv wrapper which gives you some further commands to make working with virtualenvs easier.) Regards Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to Create Webpage with Python
Hi John, Welcome you to the Python tutor mailing list. On 9 July 2014 19:26, John Cast jdc...@stanford.edu wrote: First, please forgive any ignorance in my post here as I am not good with HTML and new to python. Not a problem. Although the list if formally about learning the basics of Python, there's many people on here with both diverse and deep knowledge so people often get lucky with what would be formally off-topic questions. I have a bunch of excel spreadsheets (all in the same format) that I am writing a python script to go through and pick out some information and post to a wiki page. I'm new to python and have gone through some basic tutorials. I feel confident that I can figure out how to read an excel spreadsheet in python. I imagine you're referring to using the xlrd module? However, I am feeling a bit overwhelmed with figuring out how to do the web stuff in python. The webpage doesn't exist yet and I have envisioned that the wiki webpage is created once and then simply update it every time the script is run. However, I don't know much about how persistence works with webpages. OK... I have two main questions: 1) Considering the webpage doesn't exist yet, do I need to 'serve' or 'post' a webpage (as was brought up below)? That depends. Actually both approaches are feasible but to make a choice either way would depend really on what you're actually trying to achieve and what constraints you operate under in terms of web server/hosting. 2) How do I create this wiki webpage? and does this happen in python every time the script is run? 3) How do I send my data to this webpage? Again, that depends. You need to decide what approach would suit your context better: 1) Generating a static HTML website from your data == Pros: - Hosts anywhere, not backend Python required - Setup, Management and generation is relatively straightforward, and web pages themselves can be written up in e.g. simple text formats (Markdown etc) - Light, fast - Easy to version control Cons: - No DB backend so site is less interactive than it would otherwise be. Example: Pelican web framework for Python. See here: http://pelican.readthedocs.org/en/3.4.0/ and here: http://blog.getpelican.com/ 2) Build a website with Python on the back-end == Pros: - Much more flexible. - You can pretty much do anything - Setup and management is more involved/complex. Cons - Usually not quite as fast as a static site - Requires hosting that can comply with your backend needs (Python + whatever framework you want to use.) Examples: - Django web framework: https://www.djangoproject.com/ - Web2py web framework: http://www.web2py.com/ There's of course a myriad of related and alternatives to what I've mentioned above which may or may not be applicable to what you're doing but without knowing more about your operational and other requirements it's impossible to make further suggestions. I just want to address one other point -- you mention the term wiki, note that the items I've mentioned aren't wiki's in their own right, however if you really do want wiki functionality then just to note that there are Python powered CMS's and wiki's as well (some powered by the framework's I've mentioned). Hope that helps, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to Create Webpage with Python
On 09/07/14 19:26, John Cast wrote: I have a bunch of excel spreadsheets (all in the same format) that I am writing a python script to go through and pick out some information and post to a wiki page. I'm new to python and have gone through some basic tutorials. I feel confident that I can figure out how to read an excel spreadsheet in python. Its trickier than you might think. But there are a couple of third party modules you can download. Google is your friend. figuring out how to do the web stuff in python. Python has lots of web frameworks and to be honest there isn't much to choose between them IMHO. They are all fairly easy to use and offer the same kind of things. The webpage doesn't exist yet and I have envisioned that the wiki webpage is created once and then simply update it every time the script is run. Thats OK. whats not clear is where you intend to host this 'wiki'? Is it a traditional hosting company? If so you need to create the new html file and copy it to the hosting site (maybe using ftp - Python has an ftp module). But if you are hosting the site on your own server then you can create the HTML file directly on the host server. However, I don't know much about how persistence works with webpages. I'm not sure what you mean by persistence? You could do it in several ways but the easiest way is to just recreate the page each time from a template but substituting the latest data. But another way is to have a dynamic web page that reads the data from a database either on the server or via JSON (requires some minimal JavaScripting) 1) Considering the webpage doesn't exist yet, do I need to 'serve' or 'post' a webpage (as was brought up below)? where below? You need a web server somewhere. Either you provide it yourself or you hire space on a web providers estate. 2) How do I create this wiki webpage? and does this happen in python every time the script is run? Lots of options. It depends on how you want it to run, how often it gets updated, which web framework you choose etc. 3) How do I send my data to this webpage? See my comments above, but again it depends a lot on where the web site lives... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to Create Webpage with Python
On 09/07/2014 19:26, John Cast wrote: First, please forgive any ignorance in my post here as I am not good with HTML and new to python. I have a bunch of excel spreadsheets (all in the same format) that I am writing a python script to go through and pick out some information and post to a wiki page. I'm new to python and have gone through some basic tutorials. I feel confident that I can figure out how to read an excel spreadsheet in python. However, I am feeling a bit overwhelmed with figuring out how to do the web stuff in python. The webpage doesn't exist yet and I have envisioned that the wiki webpage is created once and then simply update it every time the script is run. However, I don't know much about how persistence works with webpages. I have two main questions: 1) Considering the webpage doesn't exist yet, do I need to 'serve' or 'post' a webpage (as was brought up below)? 2) How do I create this wiki webpage? and does this happen in python every time the script is run? 3) How do I send my data to this webpage? I don't have to have full blown answers here, just a link or advice or anything to help me with navigating all of the information out there on Google. Thanks For the excel side see http://www.python-excel.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Off topic - Ruby similar list?
Just curious if there's a similar list like this one for Ruby-ists. Anyone know of one or two? TIA -- ~MEN ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Off topic - Ruby similar list?
On Wed, Jul 9, 2014 at 3:40 PM, Mike Nickey mnic...@gmail.com wrote: Just curious if there's a similar list like this one for Ruby-ists. Anyone know of one or two? Hi Mike, I believe the general ruby-talk mailing list is what you're looking for. See: https://www.ruby-lang.org/en/community/mailing-lists/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
On 09Jul2014 09:00, Jim Byrnes jf_byr...@comcast.net wrote: My mistake. I went to the Docs page and clicked on modules and then os. For some reason as I was scrolling down the page I thought the subject had changed and stopped reading. Now I see I stopped reading to soon as it is much further down the page. When searching for doco on particular functions I find the Index is a good place. Go to the S section and find system; there should be a link directly to the relevant doc section. Cheers, Cameron Simpson c...@zip.com.au In theory, there is no difference between theory and practice. In practice, there is. - Yogi Berra ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can I open and use gnome-terminal from a Python script?
On 09Jul2014 22:16, Walter Prins wpr...@gmail.com wrote: On 9 July 2014 14:43, Jim Byrnes jf_byr...@comcast.net wrote: On 07/09/2014 04:27 AM, Walter Prins wrote: I forgot to mention I am using Linux (Ubuntu 12.04). I am working my way through a book about breezypythongui which uses Python 3, hence virtualenv. I found that each time I started to work with it I did the above 3 steps, I was just looking to automatic that repetitive task. In that case you should put these commands in your .bashrc file so it gets set up as your user's default. (The .bashrc file is somewhat like DOS's autoexec.bat file, if you're familiar with this, except each user has their own .bashrc.) I am aginst this. It makes _every_ one of your interactive bash instances (assuming you're even using bash, though that is probable) use that virtualenv. You can also create a shell script that does this for you. (You can install virtualenv wrapper which gives you some further commands to make working with virtualenvs easier.) I think this is a better approach. Even a tiny shell script that sources activate and then execs $SHELL (your shell, whatever one it is) will ease your pain. Eg: #!/bin/sh . /path/to/venv/bin/activate exec ${SHELL:-/bin/sh} Cheers, Cameron Simpson c...@zip.com.au Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal. - Friedrich Nietzsche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How does this work (iterating over a function)?
On 09Jul2014 15:00, steve10br...@comcast.net steve10br...@comcast.net wrote: I've been learning Python concepts for about 6 months now and was doing okay with most of these. However, I ran into a fairly simple program developed by Mark Pilgrim in his Dive Into Python text that puzzles me and am hoping some of you can explain how this works. He is creating the Fibonoci sequence by iterating over a function that has a generator in it (i.e. no return statement). The code is as follows: def fibonacci(max): #using a generator a, b = 0, 1 while a max: yield a a, b = b, a+b Please post in plain text, not HTML. Something is eating your code indentation. Returning to your question: for n in fibonacci(1000): print n, The program works beautifully buy I can't figure out what we are actually iterating with. When the function is called it 'yields' the value a which is then updated to b, etc. But what is the value of 'n' as it iterates through the function? I can understand iterating through lists, strings, range(), etc. but how this iterates through a function is puzzling me. Obviously the answer, n, is the Fibonocci series but by what mechanism does this work? What is the iterable component of a function? Other have tried to explain, but let me try a different metaphor. Pretend (or actually try) the fibonacci() function says: print a instead of yield a. You can see then that it will print the sequence directly. When you write a generator function (a function with yield statements), what you get back when you call it is an iterator which iterates over the values the yields produce. It is a little like a pipeline: the for loop acts as though it is reading the values from the yields (or prints). What happens is that when you call fibonacci, it sets up the function in memory and _does not run it_. When the for loop iterates, the function runs until it hits a uyield statement. And stalls. The for loop gets the yielded value and does whatever. Next time the for loop iterates the fibonacci function runs again, briefly, until the next yield. I hope this helps you visualise the process. Cheers, Cameron Simpson c...@zip.com.au ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor