Re: [Tutor] module import problems
On Mon, 26 Apr 2010 11:56:06 am Rayon wrote: > I have a module with the name _table > in the same directory I have another by the name of _module > > I would like to import _table into _module > > can someone tall me how. At the beginning of the _module module (what a name! yuck! don't you have a more descriptive name you can use?), put this line: import _table Then whenever you need something from _table, you write something like this: print _table.my_function("something") > from tables.report_db_engine import * Two comments: What is "tables"? Is that the same as _table? Generally you shouldn't use the "from module import *" form. You should consider it advanced usage, or at least discouraged. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] module import problems
On 4/25/2010 9:56 PM, Rayon wrote: I have a module with the name _table in the same directory I have another by the name of _module I would like to import _table into _module What exactly does that mean? The import statement, when executed, imports a module into the module containing the import statement. And what is the purpose of the following line? from tables.report_db_engine import * -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] module import problems
I have a module with the name _table in the same directory I have another by the name of _module I would like to import _table into _module can someone tall me how. from tables.report_db_engine import * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which Designer
On Mon, Apr 26, 2010 at 01:48:24AM +0100, Sharon wrote: > I think you are probably right. The only other sort of programming I did > before I started on python was really 'VBA' and everything was done with > GUI. I think that is what was in my mind. I have started using Tkinter > and it isn't so bad. I just like the idea of having the visual side of Tkinter is really not a bad way to quickly hack together a GUI application which will run on pretty much anything. In my experience, I started with more primitive toolkits for X and they were a real pain until I discovered Tcl/Tk, which was truly wonderful to move to. However, there are some real disadvantages to Tk(inter) as well, chiefly that it is a least-common denominator which does a passable job of running GUIs but they don't look consistent with the native look of Windows or OS/X or whatever. And there is a lot of missing functionality. I'm getting into wxPython at the moment, and I have to say it's at least worth a look. It's also available for every platform (but doesn't come with Python), and is far more complete, and just about as easy to use as Tk, but looks a lot more polished. There are other toolkits with their advocates as well, of course, but if someone were just starting out with Python GUI programming, I'd recommend looking around at your options before starting with Tk. -- Steve Willoughby| Using billion-dollar satellites st...@alchemy.com | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which Designer
I think you are probably right. The only other sort of programming I did before I started on python was really 'VBA' and everything was done with GUI. I think that is what was in my mind. I have started using Tkinter and it isn't so bad. I just like the idea of having the visual side of actually seeing the buttons and whistles on the form ready. I have looked at QT, GTK and wxGlade but it is all more complicated than 'visual basic' and not at all rad like. So, for now I'll stick with my book and use Tkinter to get to grips with binding the widgets to the event handlers. Thank you for your advice, Sharon Alan Gauld wrote: "Sharon" wrote I am a newbie to python but would like to use a designer for simplicity. Which would be the easiest to use: WxGlade Qt 4 Designer Glade Interface Designer (Gtk) These are all GUI builders so I assume you want to write GUIs? If so which GUI toolkit are you intending to use because the GUI builders all tend to be specific to one particular tookit, which limits your options. Choose your toolkit and the GUI builder is chosen for you... At this point in time I would be looking at the simplest for a newbie until my programming skills in Python improve. Appreciate a few opinions on this. The simplest toolkit or the simplest tool? Picking the simplest tool may leave you writing code for a complex toolkit? OPne of the simplest GUI tookits is the standard Tkinter that comes with Python. But the tools for building GUIs for Tkinter are not great! But toolkits like Gtk and Qt have better tools but tend to be much more complex than Tkinter (more powerful too of course - it tends to be the case in programming that power and complexity are closely linked!) Maybe you should stick to simple programming first and worry about the GUI stuff later? Or are you already comfortable with command line/console programs and its only the GUI stuff that is new? To really help we need to know more. HTH, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which Designer
"Sharon" wrote I am a newbie to python but would like to use a designer for simplicity. Which would be the easiest to use: WxGlade Qt 4 Designer Glade Interface Designer (Gtk) These are all GUI builders so I assume you want to write GUIs? If so which GUI toolkit are you intending to use because the GUI builders all tend to be specific to one particular tookit, which limits your options. Choose your toolkit and the GUI builder is chosen for you... At this point in time I would be looking at the simplest for a newbie until my programming skills in Python improve. Appreciate a few opinions on this. The simplest toolkit or the simplest tool? Picking the simplest tool may leave you writing code for a complex toolkit? OPne of the simplest GUI tookits is the standard Tkinter that comes with Python. But the tools for building GUIs for Tkinter are not great! But toolkits like Gtk and Qt have better tools but tend to be much more complex than Tkinter (more powerful too of course - it tends to be the case in programming that power and complexity are closely linked!) Maybe you should stick to simple programming first and worry about the GUI stuff later? Or are you already comfortable with command line/console programs and its only the GUI stuff that is new? To really help we need to know more. HTH, -- Alan Gauld 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] Binary search question
Lie Ryan wrote: On 04/24/10 23:39, Robert Berman wrote: -Original Message- From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor- bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld Sent: Friday, April 23, 2010 7:41 PM To: tutor@python.org Subject: Re: [Tutor] Binary search question "Emile van Sebille" wrote BIG SNIP And even at 1000 entries, the list creation slowed right down - about 10 seconds, but the searches even for "-5" were still around a second. So 'in' looks pretty effective to me! Now that is most impressive. But that is with the assumption that comparison is very cheap. If you're searching inside an object with more complex comparison, say, 0.01 second per comparison, then with a list of 10 000 000 items, with 'in' you will need on *average* 5 000 000 comparisons which is 50 000 seconds compared to *worst-case* 24 comparisons with bisect which is 0.24 seconds. Now, I say that's 208333 times difference, most impressive indeed. The ratio doesn't change with a slow comparison, only the magnitude. And if you have ten million objects that are complex enough to take .01 secs per comparison, chances are it took a day or two to load them up into your list. Most likely you won't be using a list anyway, but a database, so you don't have to reload them each time you start the program. It's easy to come up with situations in which each of these solutions is better than the other. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqrt?
From: bob gailer To: tutor@python.org Sent: Sun, April 25, 2010 12:52:10 PM Subject: Re: [Tutor] sqrt? On 4/24/2010 11:00 PM, Kirk Z Bailey wrote: > ok gang, My desktop runs 2.5, and for my college algebra I needed to do som > quadratic equation work. This involves squareroots. So I fired uop the > interactive idle and imported math. I then tried to play with sqrt. > > Nothing. As Hugo pointed out - asking good questions is important. That includes being really specific. "play" and "nothing" are not specific. We can guess - we might even be right - but that is costly for all of us in time. Python rarely gives "nothing". You usually get some result (perhaps you don't agree with it) or some error (traceback). Sometimes there is no visible result, as the case with import. So if I were willing to spend some time guessing I'd guess that you did and got something like: >>> import math >>> sqrt Traceback (most recent call last): File "", line 1, in NameError: name 'sqrt' is not defined >>> Please either confirm or alter the above. IOW show us what you entered and what you got. Did you read the Python Manual's explanation of import? > > Importing math does not import a sqrt function. Not under that name, as a global variable. It did create a global name math. Math has attributes, one of which is sqrt. > > Now riddle me this: if string.foo makes it do a function FOO on a string Wow - so many assumptions, errors and generalities. Where would I even begin? > , whyfore and howcome does math.sqrt not do square roots on a simple number > like 4??? O but it does, as others have pointed out >>> math.sqrt(4) 2.0 > > I am now officiciously pissed. > > Help? > I am a newbie but after typing "import math" you can do a dir(math) to get the available first level methods available to you. >>> import math >>> dir(math) ['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'] Eric ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqrt?
On 4/24/2010 11:00 PM, Kirk Z Bailey wrote: ok gang, My desktop runs 2.5, and for my college algebra I needed to do som quadratic equation work. This involves squareroots. So I fired uop the interactive idle and imported math. I then tried to play with sqrt. Nothing. As Hugo pointed out - asking good questions is important. That includes being really specific. "play" and "nothing" are not specific. We can guess - we might even be right - but that is costly for all of us in time. Python rarely gives "nothing". You usually get some result (perhaps you don't agree with it) or some error (traceback). Sometimes there is no visible result, as the case with import. So if I were willing to spend some time guessing I'd guess that you did and got something like: >>> import math >>> sqrt Traceback (most recent call last): File "", line 1, in NameError: name 'sqrt' is not defined >>> Please either confirm or alter the above. IOW show us what you entered and what you got. Did you read the Python Manual's explanation of import? Importing math does not import a sqrt function. Not under that name, as a global variable. It did create a global name math. Math has attributes, one of which is sqrt. Now riddle me this: if string.foo makes it do a function FOO on a string Wow - so many assumptions, errors and generalities. Where would I even begin? , whyfore and howcome does math.sqrt not do square roots on a simple number like 4??? O but it does, as others have pointed out >>> math.sqrt(4) 2.0 I am now officiciously pissed. Help? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] the binary math "wall"
>From the virtual desk of Lowell Tackett --- On Tue, 4/20/10, Steven D'Aprano wrote: > From: Steven D'Aprano > Subject: Re: [Tutor] the binary math "wall" > To: tutor@python.org > Date: Tuesday, April 20, 2010, 7:39 PM > On Wed, 21 Apr 2010 02:58:06 am > Lowell Tackett wrote: > > I'm running headlong into the dilemma of binary math > representation, > with game-ending consequences, e.g.: > > >>> 0.15 > But if you really need D.MMSS floats, then something like > this should be > a good start.: > > def dms2deg(f): > """Convert a floating point number formatted > as D.MMSS > into degrees. > """ > mmss, d = math.modf(f) > assert d == int(f) > if mmss >= 0.60: > raise ValueError( > 'bad fractional part, expected > < .60 but got %f' % mmss) > mmss *= 100 > m = round(mmss) > if m >= 60: > raise ValueError('bad minutes, > expected < 60 but got %d' % m) > s = round((mmss - m)*100, 8) > if not 0 <= s < 60.0: > raise ValueError('bad seconds, > expected < 60.0 but got %f' % s) > return d + m/60.0 + s/3600.0 > > > >>> dms2deg(18.15) > 18.25 > >>> dms2deg(18.1515) > 18.2541666 > > Haven't gone away...I'm having a blast dissecting (parsing[?]-is that the right word?) your script snippet! Got a big pot of coffee fueling the effort. > > Note though that this still fails with some valid input. I > will leave > fixing it as an exercise (or I might work on it later, time > > permitting). Got the hint...I'm gonna pick up this challenge. This effort is taking me in endless tangents (all productive)-I'll be back sometime [soon] with my efforts and results. Thanks for your [own] time and effort. > > > -- > Steven D'Aprano > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] sqrt?
Forwarding for the benefit of the list. There I go again, ranting for nothing ;-) Hugo -- Forwarded message -- From: Kirk Z Bailey Date: Sun, Apr 25, 2010 at 4:44 PM Subject: Re: [Tutor] sqrt? To: Hugo Arts I have solved the problem; the . key has keybounce and needs cleaning. Going back and deleting one solves it. Sorry to bother the list ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqrt?
On Sun, Apr 25, 2010 at 5:00 AM, Kirk Z Bailey wrote: > ok gang, My desktop runs 2.5, and for my college algebra I needed to do som > quadratic equation work. This involves squareroots. So I fired uop the > interactive idle and imported math. I then tried to play with sqrt. > > Nothing. > > Importing math does not import a sqrt function. > I know it seems like the members of this list work magic sometimes, but contrary to popular belief we don't actually have the power to remotely see what is happening on someone's computer. Furthermore, we are all busy people and we don't have time to guess at what your problem may be, so until we get some more information, most people will just assume that you're doing it wrong. > Now riddle me this: if string.foo makes it do a function FOO on a string, > whyfore and howcome does math.sqrt not do square roots on a simple number > like 4??? It does. How did you come to the conclusion that it doesn't? What did you try? did you read help(math)? help(math.sqrt)? did you google something like "python sqrt?" Is the math file you're importing the one you think you're importing? > > I am now officiciously pissed. > > Help? We can't properly help you with the information you are providing us. Asking good questions is not hard, really, and the more you help us the more likely we are to help you. I recommend everyone posting on any mailing list to read Eric S. Raymond's guide to asking smart questions: http://catb.org/~esr/faqs/smart-questions.html Yours truly, Hugo Arts (please excuse the rant) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which Designer
Sent from my Verizon Wireless BlackBerry -Original Message- From: Sharon Date: Sun, 25 Apr 2010 14:34:56 To: Tutor Python Subject: [Tutor] Which Designer Hi, I am a newbie to python but would like to use a designer for simplicity. Which would be the easiest to use: WxGlade Qt 4 Designer Glade Interface Designer (Gtk) At this point in time I would be looking at the simplest for a newbie until my programming skills in Python improve. Appreciate a few opinions on this. Regards Sharon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Which Designer
Hi, I am a newbie to python but would like to use a designer for simplicity. Which would be the easiest to use: WxGlade Qt 4 Designer Glade Interface Designer (Gtk) At this point in time I would be looking at the simplest for a newbie until my programming skills in Python improve. Appreciate a few opinions on this. Regards Sharon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqrt?
"Kirk Z Bailey" wrote som quadratic equation work. This involves squareroots. So I fired uop the interactive idle and imported math. I then tried to play with sqrt. Nothing. Importing math does not import a sqrt function. So what error do you get? Please post it. Did you try dir(math) to see the list of names? Does it include sqrt? If the list is not as you expect have you perhaps inadvertantly created a file called math.py that it is importing instead? Now riddle me this: if string.foo makes it do a function FOO on a string, whyfore and howcome does math.sqrt not do square roots on a simple number like 4??? It does on my system. -- Alan Gauld 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] sqrt?
On 4/24/2010 9:00 PM Steven D'Aprano said... On Sun, 25 Apr 2010 01:00:50 pm Kirk Z Bailey wrote: Importing math does not import a sqrt function. Hmm... mine's there, but hey, it's easy to roll your own: ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def sqrt(x): return x**.5 ... >>> sqrt(4) 2.0 >>> sqrt(12) 3.4641016151377544 Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor