404 Posted Topics
Re: OK, so I got this message: Error line 23: can't assign to function call. What this means is that you have called self.ent.get(), and then tried to take the contents of solution and assign it to the result of the function call. As you can see, that's definitely not what … | |
Re: The problem is a little unclear. What should the contents of the dictionary look like? Jeff | |
Re: Have you tried inserting a print statement into your function? | |
Re: The indentation problem is frustrating, but is solved by use of the [ code="Python"] and [/code] tags. The problem with the original TextMenu was that `__str__` methods are not supposed to *print* things, but instead *return a printable string*. Like this: class Thingy(object): def __init__(self): self.items = [0,1,2,3] def __str__(self): … | |
Re: Well, the code above appears to be intended to schedule an event within an already running program. As it is, the scheduler itself has to be running in order for it to know to call something. Once you quit, the created threads die. So unless you could hook that code … | |
Re: There might be a better algorithm. Why do you need to precompute all of those distances? Could you use lazy evaluation? Or, could you compute distance *squared* for your purpose, which eliminates the expensive sqrt call? Also, I may be being dense, but what does this line do: [sum + … | |
Re: The square brackets are part of a construction called a 'list comprehension'. The basic syntax is [x for blah in yourlist] The idea is to create a list quickly in one line. And as StrikerX11 noted, it's exactly the same as [code="Python"] tmp = [] for blah in yourlist: tmp.append(x) … | |
Re: I'm mostly ignorant of these matters, but it looks to me like your string is just a dictionary. So: [code="Python"] >>> s = "{'params': ['123', 3], 'methodName': 'function'}" >>> result = eval(s) >>> result {'methodName': 'function', 'params': "('123', 3)"} >>> print result['params'] ['123', 3] >>> print result['methodName'] function [/code] So … | |
Re: If I understand, you want something like this: [code="Python"] class SubDevice(object): def __init__(self, action): self.action = action def action1(): print "Hello!" def action2(): print "Goodbye!" sd1 = SubDevice(action1) sd2 = SubDevice(action2) sd1.action() sd2.action() >>> Hello! Goodbye! [/code] Now, I'm not sure where the variable parameter list would come into play. … | |
Re: Oh... this is a confusing feature of GUI programming, and especially with Tkinter. Making root the parent of input_text does *not* automatically make input_text the child of root. Weird, huh? Think of it like this: Tkinter is a Python interface to Tk. Thus, there are two systems going on at … | |
Re: Yeah, you're asking a parsing question: how do take a string representation of a chemical formula and represent it in memory? I might do something like this, but there are smarter ways of doing it: [code="Python"] Z = 0 MASS = 1 NAME = 2 ELEMENTS = {'H': (1,1.00794,'hydrogen'), 'O': … | |
Re: or create a class that looks like a string: [code="Python"] class MyString(object): def __init__(self, string): self.value = string def __str__(self): return self.value # I think strings ought to support index assignment. So my strings will. def __setitem__(self, index, item): self.value = self.value[:index] + item + self.value[index+1:] def __getitem__(self, index): return … | |
So today was the first day of class, and I started it as I did last year: by logging in all students as admin temporarily, then having them drag over the installer from the network and running it, then logging off. It's slightly insecure, but the class is for beginners, … | |
Re: I take it this is an assignment for an undergrad Compilers class? What sort of progress have you made so far? | |
Re: Well, I would probably contact the company and just ask them if you could have an archive. I'm guessing "No", based on their use policy: [quote="www.eventid.net/eventid.asp"] 2.3 You may view or print the Content only for your own personal use, provided that you maintain and include all copyright and other … | |
Re: It's the error that gets thrown in C (and other languages with direct memory access) when you try to write to or read from a piece of memory you don't own. As vega said, you should never see this error in Python, since Python doesn't allow you direct access to … | |
Re: >>> sum([1,0,2]) 3 sum() works on lists, tuples, numeric dictionary keys, but not strings. Jeff P.S. The old-fashioned way would be [code="Python"] counter = 0 for item in [1,0,2]: counter += item print counter [/code] | |
Re: Interesting. A couple of things: * You don't have an "__init__" method. That's not strictly necessary for every class, but most classes have them in order to initialize their data members. So this raises the question, "What kind of object is this class?" * Another way of asking the same … | |
Re: Good analogy, Vega. As a C fan, I would say that Python is definitely a better first language than C. (1) Safety: Python protects you from writing code that can actually mangle your system, whereas C allows you free reign, up to the limits of your OS permissions. So running … | |
Re: This question intrigued me and sent me into the details of [URL="http://www.amazon.com/exec/obidos/ASIN/1590593715"]Foundations of Python Network Programming[/URL]. Think about it like this: (1) You need to authenticate. (2) You need to read the data. (3) You need to find some way to display and manipulate the data. I assume that your … | |
Re: You can also use read(size) or readlines(size). In both cases, size is the number of bytes to read (approximate for readlines). Jeff | |
Re: shadwickman is right; you needed the indent. I'm guessing that your function hung in an endless loop except when name == ""? Also, I'm guessing that your intent is that numero will return the total value of the name, counting 'a' as 1, 'b' as 2, etc.? Python often -- … | |
Re: Yeah, the best approach is to post code (or even pseudo-code) and then we can refer to line numbers. Technically, the objects 'calcMileage', 'range', and 'cost' in the car.py module will be functions rather than methods. Anyways, show us what you got and we can go from there. Jeff | |
Re: It looks like your problem is on the Windows end rather than the Python end. Apparently, a 'user' object's CreateMailbox() method requires something different from what you are supplying. As a result, Server 2k is choking but (as usual) isn't telling you exactly why. If the error were Python-related, you … | |
Re: Just FYI, the link recommended by the first Google hit, "high-levelcert dot com", is bogus. The post itself appears to be a clever version of spam. Jeff | |
Re: That site has a good clean solution. The outline of your code would be something like: [code="pseudo"] def intersects(circle0, circle1): """Returns pair of points of intersection, or None if circles are coincident or too far apart.""" P0 = center(circle0) P1 = center(circle1) r0 = radius(circle0) r1 = radius(circle1) d = … | |
Re: It's acceptable in OOP to have multiple, related classes in one file. What you want to avoid is a garbage-dump file that has unrelated classes in it. You might take a look at the source code in the Lib directory. audiodev.py, for example, contains multiple classes along with other functions. … | |
Re: Learned something! Thanks, vega. Fredzic: have you discovered the online Tkinter manual yet? It's a real life-saver: [URL]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/URL] [URL]http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf[/URL] (pdf) It explains how to use and configure a Text widget, an Entry widget, and the place() method. Jeff | |
Re: Cool program! The inner [B]for[/B] loop can test up to math.sqrt(counter) (== counter**(0.5)), because any factor [B]f[/B] of counter has to be paired with counter/f, and either f or counter/f is guaranteed to be <= sqrt(counter). That can save you some time. Also, the [URL="http://www.math.utah.edu/classes/216/assignment-07.html"]Sieve of Eristothanes[/URL] is worth checking … | |
![]() | Re: Absolutely! I was a C coder for years, then learned Python so that I could teach a programming course. Python has, IMO, the triple virtues of being (1) powerful, (2) readable, and (3) well-supported by add-on modules. Consider: [code="Python"] phone_numbers = {"Jake":"301-555-1212", "Bud":"410-555-3434", "Jen":"800-867-5309"} for name in phone_numbers: print name, … |
Re: Different books will give different advice on the use of input and raw_input. I agree with ghostdog: it's safer to do this: [code=Python] another_num = int(raw_input("Enter another number: ")) [/code] BECAUSE input() allows the user to type in any expression whatsoever, including function calls, and Python will dutifully evaluate it … | |
Re: LOL. Net administration is like cat-herding. Here's a possibility for you: Starcraft won't run if the user doesn't have admin rights... Just a thought. :) Anyways, consider these two methods: [code] for file in file_list: if file somewhere in file_system: delete it. [/code] vs. [code] for file in entire_file_system: if … | |
Re: Hmm ... I don't think the problem is there. Could you post more of the code? | |
Re: When I have these kinds of maddening bugs, I use print statements to see if my assumptions are correct. In this case, we are assuming that x and y will take on values of keys and values, respectively. But now: [code] >>> print pair(dic) ([1, 2], ['Slackware', 'Windows XP SP2']) … | |
Re: You probably want a dictionary: [code=Python] import random all = {"rock":"scissors", "scissors":"paper", "paper":"rock"} user = raw_input("What is your choice? ") comp = random.choice(all.keys()) print "Computer's choice:",comp if all[user] == comp: print "You win!" elif all[comp] == user: print "Comp wins!" else: print "tie!" [/code] The reasoning here is this: you … | |
Re: heehee ... it took me a while, too. In the end, of course, [b]return [/b]was working perfectly. The trick was that the recursion stack was 6 levels deep, and only the top level returned anything. This works now: [code=Python] def increasex(num,b2,x): print "num, b2, x", num, b2, x if num%(b2**x) … | |
Re: Hmm... It's possible that exercise 1 might be looking for something different. Notice that in your second program, you pre-define the numbers in [B]list[/B]. But it seems like the directions want you to solicit the user for the numbers ... am I reading it right? I fact, that seems to … | |
Re: [quote] if i move the mouse, i will see coordinates of mouse not in canvas but in window. [/quote] Do you mean that you want the logical coordinates instead of the device coordinates? If I'm reading you right, when the window is scrolled either vertically or horizontally, you want the … | |
Re: Of the three layout managers, I find grid() to be the most user-friendly. Jeff (But Vega's advice is always sound, so go with place ... :)) | |
Re: Nifty use of recursion! If you *don't* need to have a recursive function, then you could simply use a 'for' loop: [code=Python] def triangle(n): for i in range(1,n+1): print '*' * i [/code] Working backwards, we remember the basic rule: anything doable with iteration can be done with recursion, and … | |
Re: This was old, but I was searching for wxPython stuff and found this ... The code is 'fixed' wrt displaying windows. Still To-Do for anyone who wants, (1) get the sql code to work (2) get the callbacks to work. Jeff [code=Python] import wx #import MySQLdb #db = MySQLdb.connect(host="localhost", user="root", … | |
Re: A very useful project. :) (1) You might want to check out the Python docs for the file and string objects. In particular, you could look at the following functions: file.open file.readline file.readlines string.replace string.startswith (2) You might want to build up to the final project in pieces: write a … | |
Re: Well, Tkinter can certainly do this. Just a user suggestion, then a coding suggestion, then down to business. The user has no clue whether he is supposed to enter the index of the answer starting at 1, the index of the answer starting at 0, or the actual answer itself. … | |
Re: Overall, this is a great improvement in organization! Let's start by posting the code with the [ code= Python ] [/ code ] tags: [code=Python] import pickle f= open ("pin.pck", "w") pickle.dump(1234, f) pickle.dump([1,2,3,4], f) f.close() #Pin Validation def pin(): f=open("pin.pck", "r") x=pickle.load(f) print print " ***Welcome to the bellco … | |
So it's like this: I want to create an 'activebutton' widget with the following properties. * The button itself is text that changes foreground color when the mouse hovers over it. * If the mouse hovers for more than 200ms, a PopupMenu appears that allows the user to select a … | |
Re: Two things. 1. Your line [code=Python] ("<A href="http://www.python.org",80">http://www.python.org",80) [/code] is malformed because you have nested "" marks. Python always takes the first " to be the start of a string and the next " to be the end. (unless the first " is part of """). So if you need … | |
I wanted to do an image viewer for a photo catalog project. Here is the code: [php] import Image, ImageTk from Tkinter import * filename = "C:/Pictures/2006/2006.07.04/E clarus 1 crop.jpg" class MyFrame(Frame): def __init__(self, master): Frame.__init__(self, master) im = Image.open(filename) # <--- chokes! im.resize(250,150) self.image = Label(self, image=ImageTk.PhotoImage(im)) self.image.grid() self.grid() … | |
Re: Well, you'll want a Frame that holds two widgets: A Label or Text widget on top, and an Entry widget on the bottom. I recommend this manual: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] And you're off and running! Jeff |
The End.