Re: Tkinter widgets into classes.
On Sun, 02 Feb 2014 00:07:00 +0100, Lewis Wood wrote: On Saturday, 1 February 2014 22:26:17 UTC, Dave Angel wrote: Lewis Wood Wrote in message: (snip) DaveA It does, this is the whole code: from tkinter import * root=Tk() root.title("Second Root Testing") def secondwindow(): root2=Tk() root2.mainloop() this may seem to work, but you're starting a new event loop here instead of using the current one. I think you want to create another TopLevel() window here, not a new Tk instance. button1=Button(root,text="Root2",command=secondwindow).grid(row=0,column=0) Note that if you want to be able to actually use the button1 symbol, you have to break this statement up: button1=Button(root,text="Root2",command=secondwindow) button1.grid(row=0,column=0) You can't shortcut this because grid() returns None. root.mainloop() -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Is vars() the most useless Python built-in ever?
On Tue, 01 Dec 2015 22:15:08 +0100, Rick Johnson wrote: On Tuesday, December 1, 2015 at 10:56:27 AM UTC-6, John Gordon wrote: Rick Johnson writes: > Your lament does remind me of a pet peeve i have concerning Python, and > that is, the lie about: "THERE SHOULD BE ONE (AND PREFERABLY ONLY ONE) > WAY TO DO IT!". In fact, in python there is almost always *MANY* ways to > achieve the same output.=20 The koan reads: There should be one-- and preferably only one --obvious way to do it. You left out the rather important word "obvious". Indeed you are correct about the wording, but your interpretation is wrong. Mm, not so much. What you're describing is a statement like "There should be one way and it should be obvious". -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
On Sat, 05 Mar 2016 08:41:39 +0100, wrote: On Saturday, December 12, 2015 at 1:05:29 AM UTC-8, Harbey Leke wrote: Create a class called BankAccount .Create a constructor that takes in an integer and assigns this to a `balance` property. .Create a method called `deposit` that takes in cash deposit amount and updates the balance accordingly. .Create a method called `withdraw` that takes in cash withdrawal amount and updates the balance accordingly. if amount is greater than balance return `"invalid transaction"` .Create a subclass MinimumBalanceAccount of the BankAccount class Please i need help on this i am a beginer into python programming. Also below is a test case given for this project import unittest class AccountBalanceTestCases(unittest.TestCase): def setUp(self): self.my_account = BankAccount(90) def test_balance(self): self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid') def test_deposit(self): self.my_account.deposit(90) self.assertEqual(self.my_account.balance, 180, msg='Deposit method inaccurate') def test_withdraw(self): self.my_account.withdraw(40) self.assertEqual(self.my_account.balance, 50, msg='Withdraw method inaccurate') def test_invalid_operation(self): self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction') def test_sub_class(self): self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No true subclass of BankAccount') my solution is: class BankAccount(object): def __init__(self, initial_balance): self.balance = initial_balance def deposit(self, amount): self.balance +=amount def withdraw(self, amount): if self.balance>= amount: self.balance -= amount else: return invalid transaction a1 = BankAccount (90) a1.deposit(90) a1.withdraw(40) a1.withdraw(1000) class MinimumBalanceAccount(BankAccount): def __init__(self): BankAccount.__init__(self,minimum_balance) self.minimum_balance = minimum_balance my_account = BankAccount(90) my_account.withdraw(40) print my_account.balance It keeps alerting me that,"Error running your script".Where might I have gone wrong?Please help.. Most probably there's extra information available on the "Error running your script" message. You should examine that. Meanwhile, I think the line "return invalid transaction" provides a clue. -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: I am out of trial and error again Lists
On Fri, 24 Oct 2014 19:03:47 +0200, Seymore4Head wrote: http://i.imgur.com/DTc5zoL.jpg The interpreter. I don't know how to use that either. It's what's on the left hand side of your screenshot. You can simply type Python statements following the >>> prompt and hit enter to examine the result, instead of pushing F5 to run your code -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is inspect() located?
On Sun, 16 Nov 2014 05:12:36 +0100, Igor Korot wrote: import lib Traceback (most recent call last): File "", line 1, in ImportError: No module named lib In the https://docs.python.org/2/library/inspect.html, it says it is located in Lib/inspect.py. What am I missing? Or its only for 3.x? Thank you. Windows may not be case-sensitive, but Python is iirc -- Vriendelijke groeten / Kind regards, Albert Visser -- https://mail.python.org/mailman/listinfo/python-list
Re: Tuples and immutability
On Sun, 02 Mar 2014 15:17:11 +0100, Eric Jacoboni wrote: Le 02/03/2014 15:05, Mark Lawrence a écrit : The behaviour is consistent except when you try to modify a tuple. Not in my opinion... li = [10, 30] li = li + "spam" --> TypeError: can only concatenate list (not "str") li += "spam" --> Ok possibly because you expect += to take "spam" as a string, but have you looked at the result? In [1]: mylist = ['1', '2'] In [2]: mylist += 'spam' In [3]: mylist Out[3]: ['1', '2', 's', 'p', 'a', 'm'] consequently, try adding something that can not be interpreted as a sequence: In [4]: mylist += 3 --- TypeError Traceback (most recent call last) in () > 1 mylist += 3 TypeError: 'int' object is not iterable -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: trailing underscores naming convention_
On Fri, 09 May 2014 12:22:56 +0200, Metallicow wrote: On Friday, May 9, 2014 3:10:26 AM UTC-6, Peter Otten wrote: Metallicow wrote: > I guess to be more clear here is a small code snippet that shows what is > happening more readably. Hence the underscores question. Working with multiple names with small differences is error-prone. Definitely. Anyway, the small snippet just shows that this can be done, but the actual question you replied to you left unanswered. It is about the trailing underscores. It's not an "official" convention I think, but a (single) trailing underscore is mainly meant to create something that is close to an original definition without shadowing it. If you subclass an object and bind a thusly underscored method to an event to which the original is already bound in the superclass's __init__ method, they are both getting called on the event unless you do not call the superclass's __init__() in your own __init__(). -- Vriendelijk groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: semicolon at end of python's statements
On Mon, 02 Sep 2013 12:58:23 +0200, Antoon Pardon wrote: Op 02-09-13 12:42, Fábio Santos schreef: On 09/02/2013 10:45 AM, Antoon Pardon wrote: Op 02-09-13 10:05, Steven D'Aprano schreef: [...] for item in seq: if cond: do_this() do_that() else: do_something else() which is still nonsense but won't raise SyntaxError. Why shouldn't this raise a SyntaxError? Because it would be parsed as a valid for .. else construct. Either that or become ambiguous to the programmer, who would not be sure whether he was writing an else clause for the `if`, or for the `for`. [...] I also don't see how this would be that ambigous. The else lines up with the for, so it seems rather obvious for which he was writing an else clause. My first association would be with the for, but someone could also be thinking it's referring to the if on the same line, because there wouldn't be any other way to write it (besides nesting the if). I wouldn't like this syntax anyway, two colons and all. When I first saw the idea of a nested for .. if construct the thing that came to mind was another nesting, namely that of context managers. While I don't mind using with : with : do_stuff I like being able to do e.g. with open('some_file') as _in, open('another_file', 'w') as _out: because it makes it obvious that the context managers are related. Expressing that the for and the if are related also appeals to me. Another parallel might be slicing, where you can specify not only a start and an end value, but also an interval (which could be seen as a kind of filtering condition). I think that if you really want to show the "filtered for" as a somewhat different concept than a for that just happens to have an if in its suite, that should be made visible. Coming back to my first association mentioned above, why not use a comma? for in , : (come to think of it, it has the added bonus that you won't get ambiguity what an else might be about). Somehow this makes sense to me. But then, I also like 'x = y if else z'. Moreover, I'm Dutch (...) Albert Visser -- Using Opera's mail client: http://www.opera.com/mail/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?
On Sun, 12 Jul 2015 19:33:17 +0200, Simon Evans wrote: Dear Peter Otten, I typed in (and did not copy and paste) the code as you suggested just now (6.28 pm, Sunday 12th July 2015), this is the result I got: Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. from bs4 import BeautifulSoup with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: ... soup = BeautifulSoup(f,"lxml") File "", line 2 soup = BeautifulSoup(f,"lxml") ^ IndentationError: expected an indented block soup = BeautifulSoup(f,"lxml") Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined The first time I typed in the second line, I got the "Indentation error" the second time I typed in exactly the same code, I got the: "NameError:name 'f' is not defined" "Expected an indented block" means that the indicated line should have started with at least one whitespace character more than the preceding line. >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: ... soup = BeautifulSoup(f,"lxml") should have been something like >>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r")as f: ... soup = BeautifulSoup(f,"lxml") -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem configuring apache to run python cgi on Ubuntu 14.04
On Mon, 21 Sep 2015 20:41:13 +0200, wrote: Hello everybody, (...) I created index.py: #!/usr/bin/env python # -*- coding: UTF-8 -*-# enable debugging import cgitb cgitb.enable() print("Content-Type: text/html;charset=utf-8") print("Hello World!") But it is still not working. Can anybody help me out? Thanks in advance. Which Python are you running? If it's Python 3, change the shebang accordingly because "python" is assuming Python 2. -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Sequencing images using tkinter?
On Sat, 30 Aug 2014 22:27:01 +0200, wrote: Although getting next_image to run for e.g. 10 times in a for loop is still something I can't get to work. It only displays one image. I think this is because you do all your processing befoe starting the event loop (myGui.mainloop() ). A better way is to bind the function that displays the images to a button callback. Referring to your first post, that could be something like (untested) def rotate(): for i in range(10): myImage = PhotoImage(file="MonsterImages/Converted/" + random.choice(monsters)) myButton1.config(image=myImage, width="100", height="200") sleep(0.2) myButton1=Button(canvas1, text='OK', justify = LEFT, command=rotate) myButton1.place(x=500,y=300) myGui.mainloop() Hope this helps -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list