[Tutor] advice on an app
hi all, I'm trying to create an app that schedules 3000 to 5000 trainees' practical exams. All the trainees basic info (name, badge, major, etc.) is in excel and i've managed to convert it into a *HUGE *list via a csv.reader object. My question is: is this the right way to go or should i use sqlight3 instead? thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] advice on an app
On Tue, May 1, 2012 at 5:19 AM, Khalid Al-Ghamdi wrote: > hi all, > > I'm trying to create an app that schedules 3000 to 5000 trainees' > practical exams. > > All the trainees basic info (name, badge, major, etc.) is in excel and i've > managed to convert it into a HUGE list via a csv.reader object. > > My question is: is this the right way to go or should i use sqlight3 > instead? > > thanks > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > I would first start with all my fields and understanding how they relate to each other. The student/course situation you may be describing is often used as an example in sql tutorials since it is easy to understand and lends itself to a nice discussion about joins. The size of your data set isn't really a problem. Thousands of records are a lot to look at on a printout, but not a big deal for a computer script (python) or a database endgine (sqlite3). -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
Is there space a between "#!" and "/usr/bin/env python"? I have seen Python manual, it says <#! /usr/bin/env python> But snippet manager of many text editing programs have <#!/usr/bin/env python>. Python is a strongly typed language, which one is correct? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about listing variables defined since session started
> Steven D'Aprano wrote: > Robert Sjoblom wrote: > > On 30 April 2012 23:25, Comer Duncan wrote: > >> Hi, > >> > >> I have a newbie type question. Say I have started a python (or > >> ipython) session and have done some imports and have also defined some > >> new variables since the session started. So, I have in my current > >> namespace a bunch of things. Suppose I want to list just those > >> variable names which have been defined since the session started but > >> not include the names of the objects that who and whos will return. > >> How to do that? > > > > Not entirely sure, but something like this might work (untested): > > for name in dir(): > > myvalue = eval(name) > > print name, "is", type(name), "and is equal to ", myvalue > > Please do not use eval unless you know what you are doing, and certainly > don't > encourage newbies to use it without a word about the risks. > ast.literal_eval(name) is probably safer. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 05/01/2012 09:55 AM, Santosh Kumar wrote: > Is there space a between "#!" and "/usr/bin/env python"? > > I have seen Python manual, it says <#! /usr/bin/env python> > But snippet manager of many text editing programs have <#!/usr/bin/env > python>. Python is a strongly typed language, which one is correct? > That's a comment, so it's irrelevant to Python. That line is called a shebang line, and is used by the various Unix command shells to specify what program shall interpret this particular script. I have no idea whether your shell will ignore a leading space or not. The bash that happens to be on my system will ignore the leading space. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] binding a button to an entry
Hi all, Please can anyone tell me how i bind the activation of a button with input from an entry widget. i know i should be using classes etc. but i don't understand them fully yet.. problem here is that no matter what i enter in the entry window it displays as password incorrect. from Tkinter import * password="trial" def reveal():"""Display message based on password"""contents=sif contents=="trial":print "password correct"else:print "password wrong" #mainroot=Tk()root.title("Password entry box")root.geometry("300x100")app=Frame(root)app.grid() #labelslbl=Label(app, text="Enter your password: ")lbl.grid(row=1, column=0) #create entry widgetse = Entry(root)e.grid(row=1, column=1)s=e.get() #create a submit buttonb=Button(root, text="SUBMIT", command=reveal)b.grid(row=0, column=2) root.mainloop() thanks all,adrian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] binding a button to an entry
On 05/01/2012 10:40 AM, ADRIAN KELLY wrote: > Hi all, Please can anyone tell me how i bind the activation of a button with > input from an entry widget. i know i should be using classes etc. but i don't > understand them fully yet.. problem here is that no matter what i enter in > the entry window it displays as password incorrect. > from Tkinter import * > password="trial" > def reveal():"""Display message based on password"""contents=sif > contents=="trial":print "password correct"else:print > "password wrong" > #mainroot=Tk()root.title("Password entry > box")root.geometry("300x100")app=Frame(root)app.grid() > #labelslbl=Label(app, text="Enter your password: ")lbl.grid(row=1, column=0) > #create entry widgetse = Entry(root)e.grid(row=1, column=1)s=e.get() > #create a submit buttonb=Button(root, text="SUBMIT", > command=reveal)b.grid(row=0, column=2) > > root.mainloop() > > thanks all,adrian > > Please post as text; this program is incomprehensible as viewed in Thunderbird. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
> I have seen Python manual, it says <#! /usr/bin/env python> > But snippet manager of many text editing programs have <#!/usr/bin/env > python>. Python is a strongly typed language, which one is correct? That's not python code - it's interpreted by the shell (on Linux/Unix) to determine what to invoke to process the file - in this case the python interpreter. Whether there's a space there or not doesn't usually matter to the shell, and python doesn't care because it's seen as a comment when the code is compiled. In short - either is fine. This email and any attachment to it are confidential. Unless you are the intended recipient, you may not use, copy or disclose either the message or any information contained in the message. If you are not the intended recipient, you should delete this email and notify the sender immediately. Any views or opinions expressed in this email are those of the sender only, unless otherwise stated. All copyright in any Capita material in this email is reserved. All emails, incoming and outgoing, may be recorded by Capita and monitored for legitimate business purposes. Capita exclude all liability for any loss or damage arising or resulting from the receipt, use or transmission of this email to the fullest extent permitted by law. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about listing variables defined since session started
Prasad, Ramit wrote: Steven D'Aprano wrote: Robert Sjoblom wrote: On 30 April 2012 23:25, Comer Duncan wrote: Hi, I have a newbie type question. Say I have started a python (or ipython) session and have done some imports and have also defined some new variables since the session started. So, I have in my current namespace a bunch of things. Suppose I want to list just those variable names which have been defined since the session started but not include the names of the objects that who and whos will return. How to do that? Not entirely sure, but something like this might work (untested): for name in dir(): myvalue = eval(name) print name, "is", type(name), "and is equal to ", myvalue Please do not use eval unless you know what you are doing, and certainly don't encourage newbies to use it without a word about the risks. ast.literal_eval(name) is probably safer. Safer, but doesn't work: py> import ast py> name = 25 py> ast.literal_eval('name') Traceback (most recent call last): File "", line 1, in File "ast.py", line 87, in literal_eval return _convert(node_or_string) File "ast.py", line 86, in _convert raise ValueError('malformed node or string: ' + repr(node)) ValueError: malformed node or string: <_ast.Name object at 0xb7a9560c> literal_eval is for evaluating literals, not names. py> ast.literal_eval('[123, "ABC", None, {}]') [123, 'ABC', None, {}] It apparently can also do simply arithmetic, but that's *possibly* an implementation detail due to the keyhole optimizer in CPython's compiler. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] binding a button to an entry
> Hi all, > Please can anyone tell me how i bind the activation of a button with input > from an entry widget. i know i should be using classes etc. but i don't > understand them fully yet.. problem here is that no matter what i enter in > the entry window it displays as password incorrect. > > from Tkinter import * > > password="trial" > > def reveal(): > """Display message based on password""" > contents=s > if contents=="trial": > print "password correct" > else: > print "password wrong" > > #main > root=Tk() > root.title("Password entry box") > root.geometry("300x100") > app=Frame(root) > app.grid() > > #labels > lbl=Label(app, text="Enter your password: ") > lbl.grid(row=1, column=0) > > #create entry widgets > e = Entry(root) > e.grid(row=1, column=1) > s=e.get() > > #create a submit button > b=Button(root, text="SUBMIT", command=reveal) > b.grid(row=0, column=2) > > > root.mainloop() That is because the value of s never changes once it gets assigned. Change the following in reveal() contents=s to : contents=e.get() You may want to read Alan Gauld's tutorial (he is contributor to this list). It covers classes and basic GUI programming. http://www.alan-g.me.uk/tutor/index.htm Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about listing variables defined since session started
Steven D'Aprano wrote: > Prasad, Ramit wrote: > >> Steven D'Aprano wrote: > >> Robert Sjoblom wrote: > >>> On 30 April 2012 23:25, Comer Duncan wrote: > Hi, > > I have a newbie type question. Say I have started a python (or > ipython) session and have done some imports and have also defined > some > new variables since the session started. So, I have in my current > namespace a bunch of things. Suppose I want to list just those > variable names which have been defined since the session started but > not include the names of the objects that who and whos will return. > How to do that? > >>> Not entirely sure, but something like this might work (untested): > >>> for name in dir(): > >>> myvalue = eval(name) > >>> print name, "is", type(name), "and is equal to ", myvalue > >> Please do not use eval unless you know what you are doing, and > certainly > >> don't > >> encourage newbies to use it without a word about the risks. > >> > > > > ast.literal_eval(name) is probably safer. > > Safer, but doesn't work: > > > py> import ast > py> name = 25 > py> ast.literal_eval('name') > Traceback (most recent call last): >File "", line 1, in >File "ast.py", line 87, in literal_eval > return _convert(node_or_string) >File "ast.py", line 86, in _convert > raise ValueError('malformed node or string: ' + repr(node)) > ValueError: malformed node or string: <_ast.Name object at 0xb7a9560c> > > > literal_eval is for evaluating literals, not names. > > py> ast.literal_eval('[123, "ABC", None, {}]') > [123, 'ABC', None, {}] > > > It apparently can also do simply arithmetic, but that's *possibly* an > implementation detail due to the keyhole optimizer in CPython's compiler. > What about just using dir / globals / locals? global_variables = globals() for name in dir(): value = globals_variables[ name ] if name in global_variables else locals[ name ] print '{0} is {1} and is equal to {2}'.format( name, type(value), value ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
> and is used by the various Unix command shells to specify what program > shall interpret this particular script. To be precise, the shell does not care about the shebang line either, the shebang is interpreted by the program loader in the kernel. The shell simply execve()-ed a script containing a shebang line just like a binary executable. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] events and popup menus
I have four images in a frame. I want to pop up a menu when the user right clicks on an image, and when they choose an option from the menu, execute the action. I can create the popup menu, and bind it to the image. However, what I can't figure out is how to detect in the popup menu code which image fired the event so I can do the right thing (like display a larger version of the image, etc.) # create a menu self.popup = Menu(self.pictureWindow, tearoff=0) self.popup.add_command(label="Change Picture", command=self.selectPicture) self.popup.add_command(label="Make Primary", command=self.selectPicture) self.popup.add_command(label="Large View", command=self.selectPicture) self.picture1.bind("", self.do_popup) def do_popup(self,event): # display the popup menu try: self.popup.tk_popup(event.x_root, event.y_root, 0) finally: # make sure to release the grab (Tk 8.0a1 only) self.popup.grab_release() Thanks for the advice! Chris ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] events and popup menus
> I have four images in a frame. I want to pop up a menu when the user > right clicks on an image, and when they choose an option from the menu, > execute the action. > > I can create the popup menu, and bind it to the image. However, what I > can't figure out is how to detect in the popup menu code which image fired > the event so I can do the right thing (like display a larger version of > the image, etc.) > > # create a menu > self.popup = Menu(self.pictureWindow, tearoff=0) > self.popup.add_command(label="Change Picture", > command=self.selectPicture) > self.popup.add_command(label="Make Primary", command=self.selectPicture) > self.popup.add_command(label="Large View", command=self.selectPicture) > > self.picture1.bind("", self.do_popup) > > def do_popup(self,event): > # display the popup menu > try: >self.popup.tk_popup(event.x_root, event.y_root, 0) > > finally: > # make sure to release the grab (Tk 8.0a1 only) > self.popup.grab_release() > I would probably use a lambda to pass the picture name (where LARGE_VIEW is a module level unique string identifier). self.popup.add_command(label=LARGE_VIEW, command=lambda event: self.selectPicture( LARGE_VIEW) ) Or if you need the event in selectPicture self.popup.add_command(label=LARGE_VIEW, command=lambda event: self.selectPicture( LARGE_VIEW, event) ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
Its getting complicated now. Will it effect or not? Give me one word answer with one line description. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 05/01/2012 08:02 PM, Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. "Experiment" -- Try it and see... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 02/05/12 01:02, Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. impossible. It depends what OS you are on, but you didn't say. If its Windows the line makes no difference. If it's Unix it depends on the variety, but usually no space is needed. Search shebang on wikipedia. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. No. Either of these are fine: #! /usr/bin/env python #!/usr/bin/env python This is not a Python trick. It will work for Ruby, or Perl, or any other language with an interpreter. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
Alan Gauld wrote: On 02/05/12 01:02, Santosh Kumar wrote: Its getting complicated now. Will it effect or not? Give me one word answer with one line description. impossible. It depends what OS you are on, but you didn't say. If its Windows the line makes no difference. On Windows, the presence or absence of a space will make no difference, because it's just a comment. If it's Unix it depends on the variety, but usually no space is needed. As far as I know, on any Unix, Linux or other POSIX system, the presence or absence of a space between the #! and the path is irrelevant. I suppose it is possible that ancient Unixes from 1970 or something might not like the space, but that would surprise me. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] binding a button to an entry
On 01/05/12 15:40, ADRIAN KELLY wrote: Please can anyone tell me how i bind the activation of a button with input from an entry widget. I don;t know what you mean. Do you want to make the button press when the entry widget changes? Or change the entry widget when the button presses? Or just read the entry widget content in the button event handler - which is what the code below does - kind of... i know i should be using classes etc. but i don't understand them fully yet.. You can write Tkinter code without classes, its just more difficult to avoid complexity... problem here is that no matter what i enter in the entry window it displays as password incorrect. from Tkinter import * password="trial" If you must use global variables (and without classes you probably do) at least bring them all together so we don;t need to scan up/down to find them. def reveal(): """Display message based on password""" contents=s if contents=="trial": You don't need contents here, just use e.get() directly if e.get() == "trial": print "password correct" else: print "password wrong" e = Entry(root) e.grid(row=1, column=1) s=e.get() You get this before starting the mainloop so any changes will not be seen. Thats why its better to do the get in the event handler. And you save another unnecessary variable too... #create a submit button b=Button(root, text="SUBMIT", command=reveal) b.grid(row=0, column=2) root.mainloop() -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] events and popup menus
On 01/05/12 21:59, Chris Hare wrote: ... what I can't figure out is how to detect in the popup menu code > which image fired the event def do_popup(self,event): The event argument has various attributes. For a mouse click it should include the screen coordinates. You can use those to determine which widget was being clicked. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 02/05/12 01:27, Steven D'Aprano wrote: If it's Unix it depends on the variety, but usually no space is needed. As far as I know, on any Unix, Linux or other POSIX system, the presence or absence of a space between the #! and the path is irrelevant. So far as I know you are right. One thing nobody has mentioned is that the presence of a space between the # and ! will usually (always?) not work. I have been caught out by that before... ie #! /bin/sh #!/bin/sh will both work # ! /bin/sh # !/bin/sh will not. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?
On 5/1/12, Santosh Kumar wrote: > Its getting complicated now. Will it effect or not? No. It won't. Spaces between '#!' and '/foo/bar/whatever' are ignored. Long Answer: Don't worry about it. For example, on one of my Ubuntu linux boxes there's 69 rc files shipped with the OS that use the variant: '#! /bin/sh' (with space). And there's 26 that use the variant '#!/bin/sh' without a space; It really doesn't matter. (For the curious, you can find out like this):: grep --ignore-case --regex '^#!/. *' --recursive /etc/rc* | wc And this respectively:: grep --ignore-case --regex '^#!/.*' --recursive /etc/rc* | wc On my FreeBSD server all files shipped with the OS don't uses spaces. They're just '#!/bin/sh'. However, some of my own scripts do, and they work regardless. i.e. It doesn't really matter. On Windows they're ignored entirely. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor