Re: [Tutor] database app
> database and display customer information on web. ok, easy enough. > heres the trick. the database is MS Access. - ick. ick indeed, but maybe for different reasons... There is an ODBC database driver that you can use to access Access. But you will have to be careful about locking if the traffic is high. Access was designed as a single uuser desktop database and that legacy still shows through. The very latest versions are better but if you have more than 1 simultaneous update going on at a time I'd consider moving the database or using snapshot technology or similar, Access locks by pages (default 2K?) which can mean a lot of data rows being locked by a single update. Make sure as a minimum that you are not locking on reads! HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about comma delineated text
Hey there, i have some log files that i want to be able to work with. the lines of the log files are comma - delineated. i want to put those into a database where each piece of info (comma delineated) would be the fields of the database. ok, so the first obstacle is learning how to make a list or dictionary (prefer dictionary) out of each line of the log. any suggestions of where to start? thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about comma delineated text
nephish wrote: > Hey there, > i have some log files that i want to be able to work with. > the lines of the log files are comma - delineated. > i want to put those into a database where each piece of info (comma > delineated) > would be the fields of the database. > > ok, so the first obstacle is learning how to make a list or dictionary > (prefer dictionary) out of > each line of the log. > > any suggestions of where to start? See the DictReader class in the csv library module. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Layering Canvas widgets with Tkinter
Greetings again helpful friends, I've written a series of Python/Tkinter programs, each of which will represent a different menu/screen in a simple Tkinter game I'm making. Now, my trouble is linking them together through layered menus with buttons. So far, I've tried using a single Tk window, creating a series of canvas widgets, each containing a series of buttons. When pressed, each button calls a function which uses .grid_remove() on the current canvas and creates a new canvas with new buttons in its place (a new menu). My trouble is the menu layers are not covering each other up correctly. menu1 and menu2 functions fail to create a canvas of their designated size and .grid_remove() does not seem to remove the main canvas, thus creating the appearance of jumbled, stacked buttons. Oddly, the menu3 function will create its designated canvas to cover up the main menu, but only seems to work because it has no buttons. Likewise, the mainmenu function will return the menu cleanly to its normal state. I've also fiddled with .grid_forget() and .destroy() and had the same results. I'm still very inexperienced. Can someone give me a hand here? Thanks, -Phil # from Tkinter import * def menu(y): main.grid_remove () root.update() if y ==1: menu1() if y==2: menu2() if y==3: menu3() def menu1(): X=Canvas(root, width=200, height=200, bg="blue") X.grid(row=0,column=0) but2=Button(X,text="back",command=mainmenu) but2.grid() def menu2(): Y=Canvas(root, width=200, height=200, bg="red") Y.grid(row=0,column=0) but1=Button(Y,text="back",command=mainmenu) but1.grid() def menu3(): Z=Canvas(root, width=200, height=200, bg="green") Z.grid(row=0,column=0) def mainmenu(): main=Canvas(root,width=200,height=200,bg="grey") main.grid(row=0,column=0) men1=Button(main,text="menu 1",command=lambda y=1:menu(y)) men1.grid() men2=Button(main,text="menu 2",command=lambda y=2:menu(y)) men2.grid() men3=Button(main,text="menu 3",command=lambda y=3:menu(y)) men3.grid() root= Tk() root.geometry('200x200') main=Canvas(root,width=200,height=200,bg="grey") main.grid(row=0,column=0) men1=Button(main,text="menu 1",command=menu1) men1.grid() men2=Button(main,text="menu 2",command=menu2) men2.grid() men3=Button(main,text="menu 3",command=menu3) men3.grid() root.mainloop() # ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Numbers & Characters As Dictionary Keys
I have a dictionary called Menu_Main: Menu_Main = { 1: ['People', Call_Fam], 2: ['Groups', Call_Group], 3: ['Events', nullfunc], 4: ['Attendance', nullfunc], 5: ['Visitation', nullfunc], 6: ['Finances', nullfunc], 7: ['Administration', nullfunc], 10: ['Help', nullfunc], # I would like to make the "10" an "h" 12: ['Quit', 'return']} # and the "12" a "q". I assume the keys can be of mixed types. However, I'm not sure how to adjust my code below that actually drives the menu system. I changed "input" to "raw_input", but I get "H is not defined" when I run the script. Essentially, I'd like the user to enter a number for most items, but use letters for "Help", "Quit", and "Back to Main". def RunMenu(MenuList): '''This is the function that drives the menu system. We place the "clear screen" command twice to provide a fresh screen for each menu level. We then call the menus above to display them. There is a special value for MenuList[sel][1] of 'return' which is the exit condition for the loop. look at the entry for 9 of Menu_Main, or item 8 of Menu_Fam. ''' while True: for opts in MenuList.keys():# print menu list print opts, ': ', MenuList[opts][0] # sel = input('Enter Selection:') # get input if sel in MenuList.keys(): #verify user input is a valid key if MenuList[sel][1] == 'return': return MenuList[sel][0] else: MenuList[sel][1]() Thanks, Don -- DC Parris Matheteuo Christian Fellowship [EMAIL PROTECTED] http://matheteuo.org/ Free software is like God's love - you can share it with anyone anywhere anytime! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Every Other
Hello Tutors, What would be the most Pythonic way of printing (or extracting) every other element of a list? Thanks in advance. -- Chuck Allison ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Layering Canvas widgets with Tkinter
Quoting Phillip Hart <[EMAIL PROTECTED]>: > So far, I've tried using a single Tk window, creating a series of canvas > widgets, each containing a series of buttons. When pressed, each button > calls a function which uses .grid_remove() on the current canvas and > creates a new canvas with new buttons in its place (a new menu). Your logic is a bit confused, I think. What you are aiming for, I think, is something like this: Display Main Menu "menu 1" pushed --> hide main menu, display menu1 "back" pushed --> hide menu1, display main menu "menu 2" pushed --> hide main menu, display menu2 "back" pushed --> hide menu2, display main menu "menu 3" pushed --> hide main menu, display menu3. One way you could do this is to create all four menus, and then use callbacks that simply show/hide as appropriate. For example: Note that I have replaced leading spaces with underscores # You will need to undo this to run the program # from Tkinter import * def switch(hide, show): hide.grid_forget() show.grid(sticky=N+S+E+W) tk = Tk() # This is necessary, otherwise the canvas shrinks to the size of the button(s) it contains. # You could also use width= and height= to give the canvases a specific size. tk.grid_rowconfigure(0, weight=1) tk.grid_columnconfigure(0, weight=1) main = Canvas(tk) menu1 = Canvas(tk, background='green') menu2 = Canvas(tk, background='pink') menu3 = Canvas(tk, background='yellow') for i, m in enumerate((menu1, menu2, menu3)): Button(main, text='Menu %d' % i, command=lambda m=m: switch(main, m)).grid() Button(m, text='Back', command=lambda m=m: switch(m, main)).grid() main.grid() tk.mainloop() ## I am only creating the canvases once, and then just using grid() and grid_forget() to hide/show them as appropriate. In your code, you created a new canvas with every call to menu1/menu2/menu3. Also, you never called grid_forget on any of those canvases (so they never disappeared). Finally, I made all the canvases children of tk, rather than making menu1/menu2/menu3 children of main. If menu1 were a child of main, then to display menu1, you would have to hide the buttons (because menu1 would display inside main). Additional comments: - grid_forget is, I think, exactly the same as grid_remove. - Are you sure you want to be using canvases at all? Geometry managers like grid are normally used with Frames. If you want to display widgets on a canvas, the normal way to do it is to use canvas.create_window. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Every Other
Quoting Chuck Allison <[EMAIL PROTECTED]>: > Hello Tutors, > > What would be the most Pythonic way of printing (or extracting) every > other element of a list? Thanks in advance. This is probably it: >>> arr = range(20) >>> arr[::2] [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] >>> arr[1::2] [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Numbers & Characters As Dictionary Keys
DC Parris said unto the world upon 20/06/2005 01:13: > I have a dictionary called Menu_Main: > > Menu_Main = { 1: ['People', Call_Fam], > 2: ['Groups', Call_Group], > 3: ['Events', nullfunc], > 4: ['Attendance', nullfunc], > 5: ['Visitation', nullfunc], > 6: ['Finances', nullfunc], > 7: ['Administration', nullfunc], > 10: ['Help', nullfunc], # I would like to make the > "10" an "h" > 12: ['Quit', 'return']} # and the "12" a "q". > > > I assume the keys can be of mixed types. However, I'm not sure how > to adjust my code below that actually drives the menu system. I > changed "input" to "raw_input", but I get "H is not defined" when I > run the script. Essentially, I'd like the user to enter a number > for most items, but use letters for "Help", "Quit", and "Back to > Main". > > def RunMenu(MenuList): > '''This is the function that drives the menu system. > > We place the "clear screen" command twice to provide a fresh screen for > each menu level. We then call the menus above to display them. There is > a > special value for MenuList[sel][1] of 'return' which is the exit condition > for the loop. look at the entry for 9 of Menu_Main, or item 8 of Menu_Fam. > ''' > while True: > for opts in MenuList.keys():# print menu list > print opts, ': ', MenuList[opts][0] # > sel = input('Enter Selection:') # get input > if sel in MenuList.keys(): #verify user input is a valid key > if MenuList[sel][1] == 'return': return MenuList[sel][0] > else: MenuList[sel][1]() > > Thanks, > Don Hi Don, you are better off using raw_input for reasons of security -- input executes the input it receives, which can be dangerous. I'd probably just go with all dict keys being strings, be they '1', 'h', or whatever. If you're set on some being ints rather than strings, here's one approach. (I've simplified the rest of the case to show the idea more clearly. Doubtless someone else could improve upon it.) menu_dict = {1:'Action 1!', 2:'Action 2!', 'h':'Assistance here', 'q':'For quitters'} while True: # Sorted, as else there is no standard order for the keys. # Needs a reasonably recent Python -- I forget when it came in. # And, you can just print key in a_dict, you don't need # a_dict.keys() for key in sorted(menu_dict): print key, menu_dict[key] choice = raw_input('make your choice') try: choice = int(choice) except ValueError: # The ValueError will get raised for cases where choice is a # string not convertible into an int ('h', 'five', etc) pass if choice in menu_dict: print menu_dict[choice] break else: print "Please read the menu" HTH, Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor