how to stop a loop with ESC key? [newbie]
Can somebody explain how to stop a WHILE loop in running program by pressing ESC key? mo -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop a loop with ESC key? [newbie]
Thanks, I tryed your example: import msvcrt while 1: print '.' if msvcrt.kbhit() and msvcrt.getch() == chr(27): break but it doesn't work. It is running (Win2000), there is no messages about errors but there is no effect when pressing ESC key. What I am doing wrong? mo -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop a loop with ESC key? [newbie]
"Fredrik Lundh" wrote: > works for me, when running it from a stock CPython interpreter in a windows > console window, with focus set to that window. > what environment are you using? I use IDLE 1.0.3, Python 2.3.4 The same problem is when running in a win console. mo -- http://mail.python.org/mailman/listinfo/python-list
Name 'NewAxis' is not defined
I found such a script - a gas model. http://des.memphis.edu/lurbano/vpython/gas/Temp_KE_07.py Can anybody help and find a mistake. There is a message: Name 'NewAxis' is not defined. I tried Python 25 with numpy 121 and Python 26 with scipy 071. (Win Vista). -- mo (not proffessional programmer ;) -- http://mail.python.org/mailman/listinfo/python-list
python app development
an anyone recommend a resource (book,tutorial,etc.) that focuses on application development in python? something similar to Practical Django Projects, but for stand alone applications instead of web apps (for now). i'm in a bit of a funny place, i have a decent/good grasp of python syntax and my logic isn't bad, but i have no clue on how to assemble an application, i seem to be stuck on writing scripts. i've looked at the source of a few projects but the flow is way over my head, i understand the syntax but not the logic, which is why i'm looking for a project-cenetered learning resource, instead of a reference or language-feature resource. also, it seems that a lot of app programming is 90% gui bindings, with very little actual code, or am i totally way off mark? i recently picked up the django practical projects book, and in a few days i re-wrote a website i did with django. i feel it was the book's project-centric approach that made this possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: python app development
On Jul 3, 9:59 pm, Terry Reedy wrote: > On 7/3/2010 1:48 PM,mo reinawrote: > > > an anyone recommend a resource (book,tutorial,etc.) that focuses on > > application development in python? something similar to Practical > > Django Projects, but for stand alone applications instead of web apps > > (for now). > > > i'm in a bit of a funny place, i have a decent/good grasp of python > > syntax and my logic isn't bad, but i have no clue on how to assemble > > an application, i seem to be stuck on writing scripts. > > > i've looked at the source of a few projects but the flow is way over > > my head, i understand the syntax but not the logic, which is why i'm > > looking for a project-cenetered learning resource, instead of a > > reference or language-feature resource. also, it seems that a lot of > > app programming is 90% gui bindings, with very little actual code, or > > am i totally way off mark? > > If the app is a gui app and if logic is overly intermixed with gui > stuff, I am sure it can seem like that. Many recommend the MVC > model-view-controller model for app design. Even that can be confusing; > to me it should be model-controller-view, even though that is harder to > say. What are the data (values and objects) and how are they stored? > What are the rules for manipulating the data and objects? And then, and > only then, how to communicate with the user? > > > > > i recently picked up the django practical projects book, and in a few > > days i re-wrote a website i did with django. i feel it was the book's > > project-centric approach that made this possible. > > Another issue is who controls the flow of interactions, the user or the > code. For instance, a gui form used for input tends to direct the user > along a linear path. The same form, used for edit, presents existing > data and allows the user to pick and choose the fields to edit. This > distinction, along with MVC ideas, is important for reading source code. > > I have mostly seen this issue discussed in game reviews and game design > writing. In computer games, there is the same general difference between > a linear obstacle course game and a world to be explored in whatever > order one wants. (And there are some with both an explorable world *and* > a (somewhat optional) linear main quest line.) > > I am not familiar with any general app design books, but I have seen > game design articles and books that are on a par with writing about web > design. There are other books on business apps. > > -- > Terry Jan Reedy so you're suggesting: -write core algorithm(model) -link algorithm(s) with each other and a central menu, if applicable(controller) -write views for gui or cli(view) this is actually the path that i follow when writing django apps, and is the sequence that is being used in "Practical Django Projects", where first the different classes/data structures are written, then linked together through the url file, and finally html is written for each "view". -- http://mail.python.org/mailman/listinfo/python-list
Personal archive tool, looking for suggestions on improving the code
0 down vote favorite i've written a tool in python where you enter a title, content, then tags, and the entry is then saved in a pickle file. it was mainly designed for copy-paste functionality (you spot a piece of code you like on the net, copy it, and paste it into the program), not really for handwritten content, though it does that with no problem. i mainly did it because i'm always scanning through my pdf files, books, or the net for some coding example of solution that i'd already seen before, and it just seemed logical to have something where you could just put the content in, give it a title and tags, and just look it up whenever you needed to. i realize there are sites online that handle this ex. http://snippets.dzone.com, but i'm not always online when i code. i also admit that i didn't really look to see if anyone had written a desktop app, the project seemed like a fun thing to do so here i am. it wasn't designed with millions of entries in mind, so i just use a pickle file to serialize the data instead of one of the database APIs. the query is also very basic, only title and tags and no ranking based on the query. there is an issue that i can't figure out, when you are at the list of entries there's a try, except clause where it tries to catch a valid index (integer). if you enter an inavlid integer, it will ask you to enter a valid one, but it doesn't seem to be able to assign it to the variable. if you enter a valid integer straightaway, there are no problems and the entry will display. anyway let me know what you guys think. this is coded for python3. main file: #!usr/bin/python from archive_functions import Entry, choices, print_choice, entry_query import os def main(): choice = '' while choice != "5": os.system('clear') print("Mo's Archive, please select an option") print('') print('1. Enter an entry') print('2. Lookup an entry') print('3. Display all entries') print('4. Delete an entry') print('5. Quit') print('') choice = input(':') if choice == "1": entry = Entry() entry.get_data() entry.save_data() elif choice == "2": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "3": queryset = 'all' result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) elif choice == "4": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: entry = result[choices(result)] entry.del_data() else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "5": break else: input('please enter a valid choice...') main() if __name__ == "__main__": main() archive_functions.py: #!/bin/usr/python import sys import pickle import os import re class Entry(): def get_data(self): self.title = input('enter a title: ') print('enter the code, press ctrl-d to end: ') self.code = sys.stdin.readlines() self.tags = input('enter tags: ') def save_data(self): with open('entry.pickle', 'ab') as f: pickle.dump(self, f) def del_data(self): with open('entry.pickle', 'rb') as f: data_list = [] while True: try: entry = pickle.load(f) if self.title == entry.title: continue data_list.append(entry) except: break with open('entry.pickle', 'wb') as f: pass with open('entry.pickle', 'ab') as f: for data in data_list: data.save_data() def entry_query(file, queryset): '''returns a list of objects matching the query''' result = [] try: with open(file, 'rb') as f: entry = pickle.load(f) os.system('clear') if queryset == "all": while True: try: result.append(entry) entry = pickle.load(f) except: return result break while True: try: if re.search(queryset, entry.title) or re.search(queryset,
Re: Personal archive tool, looking for suggestions on improving the code
On 27 Lug, 10:23, Peter Otten <__pete...@web.de> wrote: > mo reina wrote: > > i've written a tool in python where you enter a title, content, then > > tags, and the entry is then saved in a pickle file. it was mainly > > designed for copy-paste functionality (you spot a piece of code you > > like on the net, copy it, and paste it into the program), not really > > for handwritten content, though it does that with no problem. > > > i mainly did it because i'm always scanning through my pdf files, > > books, or the net for some coding example of solution that i'd already > > seen before, and it just seemed logical to have something where you > > could just put the content in, give it a title and tags, and just look > > it up whenever you needed to. > > > i realize there are sites online that handle this ex. > >http://snippets.dzone.com, but i'm not always online when i code. i also > > admit that i didn't really look to see if anyone had written a desktop > > app, the project seemed like a fun thing to do so here i am. > > > it wasn't designed with millions of entries in mind, so i just use a > > pickle file to serialize the data instead of one of the database APIs. > > the query is also very basic, only title and tags and no ranking based > > on the query. > > > there is an issue that i can't figure out, when you are at the list of > > entries there's a try, except clause where it tries to catch a valid > > index (integer). if you enter an inavlid integer, it will ask you to > > enter a valid one, but it doesn't seem to be able to assign it to the > > variable. if you enter a valid integer straightaway, there are no > > problems and the entry will display. > > > anyway let me know what you guys think. this is coded for python3. > > def choices(list_result): > > '''takes a list of objects and returns the index of the selected > > object''' > > os.system('clear') > > index = 0 > > for entry in list_result: > > print('{}. {}'.format(index, entry.title)) > > index += 1 > > try: > > choice = int(input('\nEnter choice: ')) > > return choice > > except: > > pause = input('\nplease enter a valid choice') > > choices(list_result) > > When the exception is triggered you call choices() recursively but discard > the result. Therefore you get Python's default, None, which is not a valid > index. Change the last line to > > return choices(list_result) > > for a minimal fix. However, I suggest that you use a while loop instead of > the recursion: > > def choices(list_result): > while True: > os.system('clear') > for index, entry in enumerate(list_result): > print('{}. {}'.format(index, entry.title)) > try: > choice = int(input('\nEnter choice: ')) > if 0 <= choice < len(list_result): > return choice > except ValueError: > pass > input('\nplease enter a valid choice') > > I've also added a test for the integer range and replaced the bare except > with a more specific one. I recommend that you never use bare excepts > because they can hide unexpected exceptions and lead to nasty bugs. > > You should also remove the recursive call of main(). Its only effect is that > when you enter an invalid choice twice you will have to enter "5" twice to > really exit your script. > > Peter hi peter, i noticed the issue you mentioned but don't understand why they happen. for example, when the function is called in the case of an exception, the variable choice is re-assigned to whatever the next input is, so why is the default None assigned instead? and what' s the difference between just calling the function again (the variable list_result remains unchanged) and using a return statement? i also don' t understand what happens when main is called recursively, the variable choice should be re-assigned to whatever the next input is, and yet it seems that in the first call, after an invalid choice, it doesn't assign the input to the variable. thanks for taking the time to post and review the code by the way, i really appreciate it -- http://mail.python.org/mailman/listinfo/python-list
Re: Personal archive tool, looking for suggestions on improving the code
On Jul 27, 2:06 pm, Peter Otten <__pete...@web.de> wrote: > mo reina wrote: > > On 27 Lug, 10:23, Peter Otten <__pete...@web.de> wrote: > >> mo reina wrote: > >> > i've written a tool in python where you enter a title, content, then > >> > tags, and the entry is then saved in a pickle file. it was mainly > >> > designed for copy-paste functionality (you spot a piece of code you > >> > like on the net, copy it, and paste it into the program), not really > >> > for handwritten content, though it does that with no problem. > > >> > i mainly did it because i'm always scanning through my pdf files, > >> > books, or the net for some coding example of solution that i'd already > >> > seen before, and it just seemed logical to have something where you > >> > could just put the content in, give it a title and tags, and just look > >> > it up whenever you needed to. > > >> > i realize there are sites online that handle this ex. > >> >http://snippets.dzone.com, but i'm not always online when i code. i also > >> > admit that i didn't really look to see if anyone had written a desktop > >> > app, the project seemed like a fun thing to do so here i am. > > >> > it wasn't designed with millions of entries in mind, so i just use a > >> > pickle file to serialize the data instead of one of the database APIs. > >> > the query is also very basic, only title and tags and no ranking based > >> > on the query. > > >> > there is an issue that i can't figure out, when you are at the list of > >> > entries there's a try, except clause where it tries to catch a valid > >> > index (integer). if you enter an inavlid integer, it will ask you to > >> > enter a valid one, but it doesn't seem to be able to assign it to the > >> > variable. if you enter a valid integer straightaway, there are no > >> > problems and the entry will display. > > >> > anyway let me know what you guys think. this is coded for python3. > >> > def choices(list_result): > >> > '''takes a list of objects and returns the index of the selected > >> > object''' > >> > os.system('clear') > >> > index = 0 > >> > for entry in list_result: > >> > print('{}. {}'.format(index, entry.title)) > >> > index += 1 > >> > try: > >> > choice = int(input('\nEnter choice: ')) > >> > return choice > >> > except: > >> > pause = input('\nplease enter a valid choice') > >> > choices(list_result) > > >> When the exception is triggered you call choices() recursively but > >> discard the result. Therefore you get Python's default, None, which is > >> not a valid index. Change the last line to > > >> return choices(list_result) > > >> for a minimal fix. However, I suggest that you use a while loop instead > >> of the recursion: > > >> def choices(list_result): > >> while True: > >> os.system('clear') > >> for index, entry in enumerate(list_result): > >> print('{}. {}'.format(index, entry.title)) > >> try: > >> choice = int(input('\nEnter choice: ')) > >> if 0 <= choice < len(list_result): > >> return choice > >> except ValueError: > >> pass > >> input('\nplease enter a valid choice') > > >> I've also added a test for the integer range and replaced the bare except > >> with a more specific one. I recommend that you never use bare excepts > >> because they can hide unexpected exceptions and lead to nasty bugs. > > >> You should also remove the recursive call of main(). Its only effect is > >> that when you enter an invalid choice twice you will have to enter "5" > >> twice to really exit your script. > > >> Peter > > > hi peter, i noticed the issue you mentioned but don't understand why > > they happen. > > > for example, when the function is called in the case of an exception, > > the variable choice is re-assigned to whatever the next input is, so > > why is the default None assigned instead? and what' s the difference > > between just calling the function again (the variable list_result > > remains unchanged) and using a return statement? > > If you have a function > > def f(): > re
looking for open source python project
looking for a python project (preferably something a bit small) that is looking for contributors. the small bit is because i've never worked in a team before and haven't really read source code that's 1000s of lines long, so i'm not too sure i can keep up. my python fu is decent (i think), i recently wrote a small archive/ grimoire program (command line only) that can store multiline text with title, tags, and basic search functionality (not using curses so the entry, once entered, can't be modified), entries are stored in a pickle file. anybody have any suggestions? i'm keen to work on something with others, both for learning and i'd like to do something a bit meaningful, plus i'm sure it's fun. -- http://mail.python.org/mailman/listinfo/python-list