Re: [Tutor] What web framework?
Yes, CherryPy is an excellent, and uniquely straightforward tool for writing a database-driven web application. I'd start looking into things like Django for larger sites where you also want templating, and client-side interactivity through JavaScript etc. In my simple CherryPy apps, I use Python's own (%) string substitution instead of a templating language, so a simple CherryPy app can consist of pure Python code, SQL queries and nothing else needed. > -Original Message- > From: [EMAIL PROTECTED] > Sent: Tue, 29 Jan 2008 01:00:22 - > To: tutor@python.org > Subject: Re: [Tutor] What web framework? > > "Terry Carroll" <[EMAIL PROTECTED]> wrote > >> But querying's different. I'd initially planed on making this a >> wxPython >> application, but I think it might be simpler to have it as a web >> app, even >> though I'll be the only user, and the db will be resident on the >> same >> program I'm querying from. >> >> This calls for using a web framework, > > Not really, a simple CGI app would be suffficient. > A framework is really only needed where you have lots of pages > all with the same look n feel and lots of interaction between them. > If all you need is a query screen and a results screen then basic > CGI should be more than adequate. > > If you really want more then look at basic CherryPy rather than > TurboGears/Django. It takes the CGI pains away while keeping > the code simple and direct. > > TurboGears and Django are both excellent but the learning curve > for a simple app is more than the gain IMHO. OTOH If you want > to build knowledge for the future then pick one and go with it. > It doesn't much matter which they all use the same principles > its only syntax differences really. > > IMHO at least, > > Alan G. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What web framework?
On Jan 28, 2008 7:35 PM, Terry Carroll <[EMAIL PROTECTED]> wrote: > It looks like the leading candidates here are Turbogears and Django. This s a results of trying and sometimes using these frameworks over 3 years now. I sometimes thoughtfully evaluate all my options before choosing, other times, I just pick what I can ape off of quickly as possible then get to work. Please don't firebomb my house because I misspoke or put down your favorite web framework. I know this is a tender subject for some of you. I guarantee the below is factually inaccurate in some ways. Then again, it wouldn't be written if I had to do more research to write it. I talk about Magic and Configuration below. Configuration is what you do in Java frameworks, where you make 2^23 xml files to make hello world work. Magic is what happens in Ruby on Rails, where things work and sometimes don't work, but they do it with very little specification required by the user. This makes it hard to tell how something isn't working, or why it is working but slowly. Then again, it makes all initial work fast fast fast. Which frankly, will get you to actually finish your application a lot faster. The new standard for python web applications is WSGI. If you write your apps to be WSGI compliant, you can integrate them with each other and with different webservers within minutes. Yes. Minutes. It's really quite cool. And it's really not that hard. (Look into Paste to get that "minutes" thing down). This question is sort of like asking what is the best text editor. Here is a good screencast to see one guy doing this comparison: http://plone.org/about/movies/better-web-app-development.png Here are your choices of full frameworks, what they bring, and why you might want them: Pylons: Infinite customizablity. Plays well with other frameworks.It's the python analog to Ruby on Rails. If you like lots of magic (i.e. Little configuration), you'll like this. Pylons is WSGI compliant. http://pylonshq.com/ Zope/Plone. The framework really is Zope, but cutting down and turning off parts of Plone if it already does most of what you want is often faster than writing it all yourself. They have awesome screencasts to get you going, and you can quickly get a GUI for free with this system. I think these guys are the ones who dreamt up WSGI IIRC. These guys have lots of cross platform apps you can use for Zope and Plone Sites: http://plone.org/about/movies http://www.zope.org/WhatIsZope You can build anything on Zope. It is becoming less of a ghetto (i.e. all the code is walled off in zope) every day, especially with tools such as Repoze http://radio.weblogs.com/0116506/2007/10/26.html#a441 Plone (and therefore Zope) comes with an easy installer for all platforms. Django: You can run a newspaper off this. A number of people do, as a matter of fact, the framework came out of newspapers. If you need to do something other than running a newspaper, this probably isn't for you. Its a little configuration file heavy for my tastes, and the installable apps aren't as cross platform as the Zope ones in my experience http://www.djangoproject.com/ I feel the documentation is light years behind zope and pylons (then again, that's because pylons needs so little documentation). Is compliant with WSGI according to them. Turbogears: Ahh Turbogears. Your tutorial screencast turned everyone on to you, then they tried it, and it didn't work for them because they had the wrong version of something installed or they were on a different flavor of linux, or etc etc etc. Frankly, this has worked sometimes for me, sometimes not. I don't like that. I like being able to make it work no matter where I am. When it does work though, you pop out a site pretty quickly. You also have a good mix of magic and configuration, that way you can just get a site out there, then you can redo it to be higher performance the night after your server melts from being posted on a busy site like slashdot or the python tutor archives. Appears to be on WSGI now. Paste. This is Ian Bicking showing us how we're all inferior human beings. http://pythonpaste.org/ It's the lightest possible weight framework. It's so light weight, half of the above frameworks use it internally. You should probably use this one from what you've said. Then you can go for something I'd call a microframework: Web.py and mod_python and cherrypy all fit that bill. These are often tied to a given webserver, which may be just fine for you. Or you can write a WSGI compliant app on top of one of those, then upgrade when/if you need it. I don't see a single one that beats Paste for what you need. In short: Do WSGI if you can: http://wsgi.org/wsgi/Frameworks Pick according to your comfort level/motivation level when choosing between Configuration and Magic Probably use Paste(http://pythonpaste.org/), but maybe use a more involved framework too. --Michael -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com _
Re: [Tutor] Serious N00b question.
"Damian Archer" <[EMAIL PROTECTED]> wrote > Now when i write something in Notepad, how do i then open that so it > runs in > IDLE?? Just use File->Open and then Run->Run Module But better still don't use Notepad. The editor in IDLE is far better than Notepad for editing Python code! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Serious N00b question.
Guys, Thanks for your help on my last question, got a few projects in mind now. I usually work on Linux(Fedora) enviroment, i have no trouble with running scripts/programs i write. But i have now got IDLE on my Windows build. Now when i write something in Notepad, how do i then open that so it runs in IDLE?? Sorry for the terrible question! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What web framework?
On Mon, 2008-01-28 at 16:35 -0800, Terry Carroll wrote: > - this application will be query-only; no updating, adding or deleting. > - the database is SQLite. > - security and authentication are not important; there's no private data > here, I'm the only user, and I'm firewalled. If a particular framework > has security features, I'll use them, but I don't see them as important. > (Famous last words.) > > I'd like something that doesn't take forever to get up to speed on, but > that isn't short on features. Although this is the only framework project > I see in the immediate future, I can imagine I might want to do another > project sometime in the future. I really want to be framework-monogamous > here: I don't program for a living, and getting up to speed on a framework > seems like work to me. Try: http://webpy.org/ About WebPy: web.py is a web framework for python that is as simple as it is powerful. web.py is in the public domain; you can use it for whatever purpose with absolutely no restrictions. Tutorial: http://webpy.org/tutorial2 Hope this will help you. Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What web framework?
Michael Langford wrote: > Django: You can run a newspaper off this. A number of people do, as a > matter of fact, the framework came out of newspapers. If you need to > do something other than running a newspaper, this probably isn't for > you. Not for you, perhaps, but certainly many people find Django suitable for web sites that are not newspapers. For example: http://www.djangosites.org/ > I feel the documentation is > light years behind zope and pylons (then again, that's because pylons > needs so little documentation). I guess the Zope and Pylons docs must be truly magnificent then, because the Django docs are IMO very good: http://www.djangoproject.com/documentation/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about a number and bytes.
Use pyserial: http://pyserial.sourceforge.net/ Use struct.pack: http://docs.python.org/lib/module-struct.html The format string will depend whether you need little or big endian. --Michael On Jan 29, 2008 4:13 PM, shawn bright <[EMAIL PROTECTED]> wrote: > Thanks for your reply. > i need to do this in python because python is what scripting language > our data I/O system is written in. > i am writing a command out over a serial port that tells an RTU to > change part of it's program. I am not sure what you mean by using it > in any other python context, this is about the only thing we will need > to be able to do this for, at least, that is the case for right now. > thanks > sk > > > On Jan 29, 2008 2:55 PM, Tiger12506 <[EMAIL PROTECTED]> wrote: > > > Hello there all. > > > > > > I have a need to make a hi byte and lo byte out of a number. > > > > > > so, lets say i have a number 300, and need this number to be > > > represented in two bytes, how do i go about that? > > > > First question. Why would you need to do this in python? Second question. If > > you could do that, how would you use it in any other python context? > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about a number and bytes.
Thanks for your reply. i need to do this in python because python is what scripting language our data I/O system is written in. i am writing a command out over a serial port that tells an RTU to change part of it's program. I am not sure what you mean by using it in any other python context, this is about the only thing we will need to be able to do this for, at least, that is the case for right now. thanks sk On Jan 29, 2008 2:55 PM, Tiger12506 <[EMAIL PROTECTED]> wrote: > > Hello there all. > > > > I have a need to make a hi byte and lo byte out of a number. > > > > so, lets say i have a number 300, and need this number to be > > represented in two bytes, how do i go about that? > > First question. Why would you need to do this in python? Second question. If > you could do that, how would you use it in any other python context? > > ___ > 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] question about a number and bytes.
> Hello there all. > > I have a need to make a hi byte and lo byte out of a number. > > so, lets say i have a number 300, and need this number to be > represented in two bytes, how do i go about that? First question. Why would you need to do this in python? Second question. If you could do that, how would you use it in any other python context? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about a number and bytes.
Hello there all. I have a need to make a hi byte and lo byte out of a number. so, lets say i have a number 300, and need this number to be represented in two bytes, how do i go about that? thanks for any tips, sk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about a number and bytes.
ok, was using pyserial, but was not using struct.pack. thanks sk On Jan 29, 2008 3:16 PM, Michael Langford <[EMAIL PROTECTED]> wrote: > Use pyserial: > > http://pyserial.sourceforge.net/ > > Use struct.pack: > > http://docs.python.org/lib/module-struct.html > > The format string will depend whether you need little or big endian. > >--Michael > > > > On Jan 29, 2008 4:13 PM, shawn bright <[EMAIL PROTECTED]> wrote: > > Thanks for your reply. > > i need to do this in python because python is what scripting language > > our data I/O system is written in. > > i am writing a command out over a serial port that tells an RTU to > > change part of it's program. I am not sure what you mean by using it > > in any other python context, this is about the only thing we will need > > to be able to do this for, at least, that is the case for right now. > > thanks > > sk > > > > > > On Jan 29, 2008 2:55 PM, Tiger12506 <[EMAIL PROTECTED]> wrote: > > > > Hello there all. > > > > > > > > I have a need to make a hi byte and lo byte out of a number. > > > > > > > > so, lets say i have a number 300, and need this number to be > > > > represented in two bytes, how do i go about that? > > > > > > First question. Why would you need to do this in python? Second question. > > > If > > > you could do that, how would you use it in any other python context? > > > > > > ___ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor > > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > -- > Michael Langford > Phone: 404-386-0495 > Consulting: http://www.RowdyLabs.com > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] results not quite 100 percent yet
Greetings, I'm having a problem with the following test. I make a dictionary with 19 keys (1 to 19). Each key has a list of 7 numbers (A to G) # Set up the table #key# A B C D E F G tablE= {1:[ 0, 2, 0, 0, 0, 0, 0],# 1 2:[ 1, 3, 3, 0, 0, 0, 0],# 2 3:[ 2, 0, 5, 2, 0, 0, 0],# 3 4:[ 0, 5, 0, 0, 0, 0, 0],# 4 5:[ 4, 0, 0, 3,15,13, 0],# 5 6:[ 0, 0, 1, 0, 0, 0, 0],# 6 7:[ 0, 8, 0, 0, 0, 0, 0],# 7 8:[ 7,10, 0, 0, 0, 0, 0],# 8 9:[ 0,19, 0, 0, 0, 8, 0],# 9 10:[ 8, 0,11, 0, 0, 0, 0], # 10 11:[ 0, 0,10, 0, 0, 0, 0], # 11 12:[ 0, 0, 0,13, 0, 0, 0], # 12 13:[ 0, 0,12, 0, 5, 0, 0], # 13 14:[ 0,15,17, 0, 0, 0, 0], # 14 15:[14, 0, 0, 0, 0, 5, 0], # 15 16:[17, 0,19, 0, 0, 0, 0], # 16 17:[18,16, 0,14, 0, 0, 0], # 17 18:[ 0,17, 0, 0, 0, 0, 0], # 18 19:[ 9, 0, 0,16, 0, 0, 0]} # 19 #key# A B C D E F G The first loop is supposed to populate G with a random range of 4 integers 10 to 109 in random keys 1-19 that have a zero (except keY 6 and keY 11) So keY 6 and keY 11 should both have a zero in G after the four integers have been sown. # populate G column with range of 4 integers 10 to 109 # in random keys that have a zero [except keYs 6 and 11] print "%"*69 cnt=0 while cnt <= 3: print "CNT111=",cnt #debug-remove when done a = range(1,20) # 1 to 19 keY = random.choice(a) if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0: tablE.values()[5][6] = 0 tablE.values()[10][6] = 0 cnt -= 1 keY = random.choice(a) if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0: b = range(10,110) # 10 to 109 integer = random.choice(b) tablE.values()[keY-1][6] = integer cnt += 1 The second loop is supposed to populate G with numbers -4 to -1 in random keys 1-19 that have a zero (except keY 6 and keY11). So once again, 6 and 11 should have a zero in G after the loop is finished. # populate G with range of integers -1 to -4 # in random keYs that have a zero [except keYs 6 and 11] cnt=4 while cnt > 0: print "CNT222=",cnt a = range(1,20) if keY != 6 or keY != 11 and tablE.values()[keY-1][6] == 0: keY = random.choice(a) tablE.values()[keY-1][6] = -cnt cnt -= 1 if keY == 6 or keY == 11: tablE.values()[5][6] = 0 tablE.values()[10][6] = 0 cnt += 1 The last thing is that two integers are placed in specific keys 4 and 16, overwriting anything that may be in G whether a negative number or a number > 9. # Put an integer in G at two specific keys: 4 & 16 # These will overwrite anything placed there previously #a = range(1,99) #tablE.values()[3][6]= 100 + random.choice(a) #tablE.values()[15][6]= 100 + random.choice(a) The above has been commented out so I see if the two loops are each distributing four numbers each, without putting anything in G of keys 6 and 11. I've approached the problem by trying to get the loop to repeat if a number ends up in G at key 6 or key 11. I've done this changing the loop count. This seems to work about 97% of the time, or so. I'm looking for 100%. I know I can always just set those keys to zero before the table is written, but I'd rather have the table as fully populated by the two loops and just not have anything get in G in keys 6 & 11. Anyway, this is just a short test, part of a larger program. Here's the test code: #!/usr/bin/python import random print "\n"*30 # Set up the table #key# A B C D E F G tablE= {1:[ 0, 2, 0, 0, 0, 0, 0],# 1 2:[ 1, 3, 3, 0, 0, 0, 0],# 2 3:[ 2, 0, 5, 2, 0, 0, 0],# 3 4:[ 0, 5, 0, 0, 0, 0, 0],# 4 5:[ 4, 0, 0, 3,15,13, 0],# 5 6:[ 0, 0, 1, 0, 0, 0, 0],# 6 7:[ 0, 8, 0, 0, 0, 0, 0],# 7 8:[ 7,10, 0, 0, 0, 0, 0],# 8 9:[ 0,19, 0, 0, 0, 8, 0],# 9 10:[ 8, 0,11, 0, 0, 0, 0], # 10 11:[ 0, 0,10, 0, 0, 0, 0], # 11 12:[ 0, 0, 0,13, 0, 0, 0], # 12 13:[ 0, 0,12, 0, 5, 0, 0], # 13 14:[ 0,15,17, 0, 0, 0, 0], # 14 15:[14, 0, 0, 0, 0, 5, 0], # 15 16:[17, 0,19, 0, 0, 0, 0], # 16 17:[18,16, 0,14, 0, 0, 0], # 17 18:[ 0,17, 0, 0, 0, 0, 0], # 18 19:[ 9, 0, 0,16, 0, 0, 0]} # 19 #key# A B C D E F G # populate G column with range of 4 integers 10 to 109 # in random keys that have a zero [except keYs 6 and 11] print "%"*69 cnt=0 while cnt <= 3: print "CNT111=",cnt a = range(1,20) # 1 to 19 keY = random.choice(a) if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0: tablE.values()[5][6] = 0 tablE.values()[10][6] = 0 cnt -= 1 keY = random.choice(a) if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0: b = range(10,110) # 10 to 109 integer = random.choice(b)
Re: [Tutor] results not quite 100 percent yet
bhaaluu wrote: > if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0: > tablE.values()[5][6] = 0 > tablE.values()[10][6] = 0 This is not the right way to access the values of a dict. tablE.values() is a list of the values in tablE, but it is not in the order you expect; it is easiest to think that it is in a random or indeterminate order. Try if keY == 6 or keY == 11 or tablE[keY-1][6] != 0: tablE[5][6] = 0 tablE[10][6] = 0 etc. Kent PS what's with the strange capitalization of variable names? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [tutor] Question on multithreading
Hello friends, I hve a GUI where i have start button and stop button. When i press start button one thread is created and it is executing some background task and when i press stop button that thread is stopped/killed. These two things are working properly. But i have to implement pause button in my GUI. When i press pause the thread execution should come to a halt and after that it should be resumed when i press pause again or may be i can implement some other button. Does anybody have an example where they have implemented this kind of threading concept ?? any help is apreciated, -- Varsha Purohit, Graduate Student ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] Question on multithreading
On 30/01/2008, Varsha Purohit <[EMAIL PROTECTED]> wrote: > Hello friends, > I hve a GUI where i have start button and stop button. When i press > start button one thread is created and it is executing some background task > and when i press stop button that thread is stopped/killed. These two things > are working properly. But i have to implement pause button in my GUI. When i > press pause the thread execution should come to a halt and after that it > should be resumed when i press pause again or may be i can implement some > other button. > > Does anybody have an example where they have implemented this kind of > threading concept ?? How did you implement your stop button? Can you adapt that solution? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] Question on multithreading
Varsha Purohit wrote: > Hello friends, > I hve a GUI where i have start button and stop button. When i > press start button one thread is created and it is executing some > background task and when i press stop button that thread is > stopped/killed. These two things are working properly. But i have to > implement pause button in my GUI. When i press pause the thread > execution should come to a halt and after that it should be resumed > when i press pause again or may be i can implement some other button. > > Does anybody have an example where they have implemented this kind of > threading concept ?? Take a look at the threading module. The thread should acquire() a condition then wait(). The following is quickly thrown together and not tested. main program: import threading cond = threading.Condition() # create a condition variable with a new RLock thread: while True: # I assume the thread runs in some kind of loop if pause: # pressing Pause should set this variable True cond .acquire() cond .wait() # pauses until notified cond .release() # rest of thread - assumes loop repeats fast enough to give the desired response time code behind the pause/resume button: pause = not pause # toggle if not pause: cond.notify() -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to make python program as executable
hi i am developing a GUI application in python(tkinter) i want to know how to make the python program as a application ie i want to make it executable please guide me ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor