404 Posted Topics

Member Avatar for RaDeuX

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 …

Member Avatar for vegaseat
0
434
Member Avatar for axn
Member Avatar for ghostdog74
0
119
Member Avatar for Bmarkusrowe
Member Avatar for bumsfeld
0
75
Member Avatar for zagrijs

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): …

Member Avatar for zagrijs
0
111
Member Avatar for AnjaliThukral
Member Avatar for City one

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 …

Member Avatar for City one
0
89
Member Avatar for grahhh

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 + …

Member Avatar for grahhh
0
149
Member Avatar for jobs

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) …

Member Avatar for vegaseat
0
363
Member Avatar for spinaltoad

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 …

Member Avatar for spinaltoad
0
179
Member Avatar for jonamasa

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. …

Member Avatar for jrcagle
0
265
Member Avatar for Haze

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 …

Member Avatar for jrcagle
0
2K
Member Avatar for rjmiller

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': …

Member Avatar for rjmiller
0
191
Member Avatar for StrikerX11

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 …

Member Avatar for jrcagle
0
112
Member Avatar for jrcagle

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, …

Member Avatar for vegaseat
0
124
Member Avatar for coolmo

I take it this is an assignment for an undergrad Compilers class? What sort of progress have you made so far?

Member Avatar for jrcagle
0
162
Member Avatar for bsdixon21222

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 …

Member Avatar for jrcagle
0
97
Member Avatar for kaze139

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 …

Member Avatar for jrcagle
0
137
Member Avatar for CelestialDog

>>> 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]

Member Avatar for ffao
0
139
Member Avatar for CelestialDog

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 …

Member Avatar for CelestialDog
0
215
Member Avatar for php111

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 …

Member Avatar for vegaseat
0
182
Member Avatar for galbi

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 …

Member Avatar for N317V
0
108
Member Avatar for bergy_nj

You can also use read(size) or readlines(size). In both cases, size is the number of bytes to read (approximate for readlines). Jeff

Member Avatar for jrcagle
0
348
Member Avatar for CelestialDog

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 -- …

Member Avatar for CelestialDog
0
104
Member Avatar for irotsenmar

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

Member Avatar for jrcagle
0
113
Member Avatar for drexlus

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 …

Member Avatar for katharnakh
0
1K
Member Avatar for StrikerX11

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

Member Avatar for jrcagle
0
92
Member Avatar for flaerpen

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 = …

Member Avatar for flaerpen
0
129
Member Avatar for freddypyther

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. …

Member Avatar for jrcagle
0
137
Member Avatar for fredzik

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

Member Avatar for fredzik
0
305
Member Avatar for Matt Tacular

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 …

Member Avatar for vegaseat
0
288
Member Avatar for iamthwee

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, …

Member Avatar for Ene Uran
0
697
Member Avatar for Zorbie

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 …

Member Avatar for jrcagle
0
273
Member Avatar for Matt Tacular

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 …

Member Avatar for jrcagle
0
111
Member Avatar for wandie

Hmm ... I don't think the problem is there. Could you post more of the code?

Member Avatar for LouLouLou
0
166
Member Avatar for StrikerX

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']) …

Member Avatar for StrikerX
0
152
Member Avatar for Gumster

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 …

Member Avatar for jrcagle
0
104
Member Avatar for jwjazz

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) …

Member Avatar for jrcagle
0
137
Member Avatar for olufunkky

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 …

Member Avatar for olufunkky
0
291
Member Avatar for Blujacker

[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 …

Member Avatar for Blujacker
0
243
Member Avatar for fredzik

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 ... :))

Member Avatar for fredzik
0
140
Member Avatar for Python23

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 …

Member Avatar for Python23
0
453
Member Avatar for Jellomaster

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", …

Member Avatar for jrcagle
0
83
Member Avatar for atetrault

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 …

Member Avatar for jrcagle
0
327
Member Avatar for fredzik

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. …

Member Avatar for fredzik
0
888
Member Avatar for muddpigeon

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 …

Member Avatar for muddpigeon
0
124
Member Avatar for Blujacker
Member Avatar for jrcagle

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 …

0
79
Member Avatar for newharvar

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 …

Member Avatar for jrcagle
0
154
Member Avatar for jrcagle

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() …

Member Avatar for aot
0
6K
Member Avatar for Prahaai

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

Member Avatar for leeqiang
0
88

The End.