404 Posted Topics

Member Avatar for ChrisRiv91

Yes, yes, and yes. Welcome to the freedom of Python. :) First of all, as is typical for Python, there is a module called time (and another one, datetime) that does exactly this stuff automagically. Look them up in the Python docs. But if you wanted to do it by …

Member Avatar for Ene Uran
0
864
Member Avatar for shadwickman
Member Avatar for timo_81

Well, there's two problems. First, you have to define the list lbl_addy before you start assigning to it. Second, the name of your newly created Label in line 6 is lbl_addy[k]. So in line 7, you need to pack it like this: lbl_addy[k].pack() Hope that helps, Jeff

Member Avatar for timo_81
0
222
Member Avatar for xRuP7uR3x

Hi. A couple of suggestions. (1) (minor) mydict2 should be generated dynamically from mydict1 so that if you ever decide to change mydict1, it will automagically change along with it. Here's how. Replace the entirety of mydict2 with this line: mydict2 = dict(zip(mydict1.values, mydict1.keys)) This will make a bunch of …

Member Avatar for jrcagle
0
156
Member Avatar for relm86

Hm. The IDLE shell's purpose is for instant code testing. If you want to write a program, then <CTRL>-N gives you a new window to write code to. Is that what you needed? Jeff

Member Avatar for ZZucker
0
111
Member Avatar for aot

Exactly so. Install PIL from the link above, and then [code="Python"] from PIL import Image, ImageTk my_im = Image.open("myjpg.jpg") real_im = ImageTk.PhotoImage(my_im) [/code] and now you can use real_im in your Tkinter code. WARNING!!! There is a bug in Tkinter such that if you do not keep a hard reference …

Member Avatar for woooee
0
235
Member Avatar for nish88

I watched it for a while and didn't see any rectangles being deleted. But you're right; the algorithm doesn't make a rectangle shape. So what's the issue, exactly? Jeff

Member Avatar for nish88
0
86
Member Avatar for 1337455 10534

Yeah, if you think XML is a pain, wait until you try to create the OLE file required for the .doc format. :lol: 300+ pages of documentation, and I gave up in disgust. Jeff

Member Avatar for 1337455 10534
0
140
Member Avatar for papaJ

It looks like you are simply blit-ing from the source to the destination at the same size. You'll need to rescale the image first. When you say you are using Canvas and Image, are you referring to Image from the PIL library? Jeff

Member Avatar for papaJ
0
99
Member Avatar for izzybitsie
Member Avatar for jrcagle
0
44
Member Avatar for alivip

I'm surprised that it hangs rather than giving an error message. Your code references text1 before text1 is ever defined. I recommend this procedure for debugging: First, write a small program that simply creates a text widget and writes something to it. Then, transfer what you've learned back to this …

Member Avatar for jrcagle
0
699
Member Avatar for sigkill9
Member Avatar for sigkill9
0
206
Member Avatar for alivip
Member Avatar for xRuP7uR3x

Sorry, didn't see this thread before. I'm afraid it doesn't work ... :( [code="unittesting"] Enter the real number you would like to convert to binary: 3.1 11.0001100110011 Would you like to continue? y/n : y Enter the real number you would like to convert to binary: 2.5 10. Would you …

Member Avatar for jrcagle
0
544
Member Avatar for raswin

>>> unicode("India is") u'India is' Dunno. What version of Python are you running? Jeff

Member Avatar for jrcagle
0
29
Member Avatar for vagab0nd

Hmm... I'm getting a different set of messages: [code="Error"] Warning (from warnings module): File "C:/Python25/menuapp.py", line 8 from wxPython.wx import * #import the GUI DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible. Traceback (most recent …

Member Avatar for vagab0nd
0
386
Member Avatar for volcs

Well, walk through your code: [code="Python"] class Superlist(list): def __init__(self, list): self.a = list[1][0] self.b = list[2][1] somelist = [[1,2,3],[4,5,6],[7,8,9]] somelist = Superlist(somelist) [/code] At line 8, you create a new Superlist object. This creates a new list [], and then calls __init__. At init, you create two new properties …

Member Avatar for katharnakh
0
105
Member Avatar for LanierWexford

One way to eliminate the "if" clause is like this: chr(ord(c) - 65 + num) % 26 + 65 It subtracts the ord('A') to get the letter number (from 0...25), rotates the letter using %, and then adds the ord('A') back on. Showcasing three favorite Pythonisms: anonymous functions, list generators, …

Member Avatar for jrcagle
0
199
Member Avatar for sarabhjeet

So it turns out that Timer objects don't receive normal callback functions, but event handler objects. If you don't feel like making one, then you can subclass the Timer and make your own Notify() method for it. That's what I did here: [code="Python"] import wx class MyTimer(wx.Timer): def Notify(self): m.frame.MB.Close(True) …

Member Avatar for jrcagle
0
158
Member Avatar for asrekdal

To my inexpert eye, it looks like you have to assign each item a different id number. Then, wx.EVT_LIST_ITEM_SELECTED will tell you which item is selected. That's a non-expert opinion, BTW. Jeff

Member Avatar for asrekdal
0
92
Member Avatar for fonz87

Here's a start: [code="Python"] digits = {0:"zero, 1:"one", 2:"two", etc.} print digits[2] [/code] HTH, Jeff

Member Avatar for jrcagle
0
120
Member Avatar for jrcagle

I'm having an opaque moment. +5 brownie points to anyone who can enlighten. The plan is to write a unit-testing module for the wxCanvas widget (good progress there :) ) So I wanted a row of different objects (similar to MS Paint) on buttons; the behavior of the different buttons …

Member Avatar for jrcagle
0
117
Member Avatar for harshaaithal

Here's a very basic example: [code="Python"] import threading import time def handler(): for i in range(5): time.sleep(5) print "Hi!" t = threading.Thread(target=handler) t.start() for i in range(20): print "hello!" time.sleep(1) [/code] handler() will chime in every 5 seconds. Jeff

Member Avatar for jrcagle
0
4K
Member Avatar for Leonerd

Well, a couple of things come to mind. This is a commendable start. First of all, how would you solve this problem on paper? Suppose I gave you a string "dog" and said "find all of the letters in 'dog' in 'abcdefghijklmnopqrstuvwxyz' and tell me how many compares it takes …

Member Avatar for woooee
0
205
Member Avatar for iamoldest

For a 2D array, a list-of-lists can work: [code="Python"] >>> a = [[1,2,3],[4,5,6],[7,8,9]] >>> a[1][2] 6 >>> [/code] Jeff

Member Avatar for jrcagle
0
94
Member Avatar for wsn

you have to import the module that contains that function first: [code="Python"] >>> import random >>> random.randint(1,3) 1 [/code] Jeff

Member Avatar for jrcagle
0
27
Member Avatar for Raulito
Member Avatar for zclevenger

That's a good function. You did all of the sensible optimizations. But now, notice that your design requirement is to print the factors of your number ... so ... modify your function (same loop, different action at the if n % x == 0: branch) so that it generates a …

Member Avatar for Arob1000
0
344
Member Avatar for GreyInTheLaw

Nice job! Here's a nitpicky critique -- take it as a compliment to your obvious talent at picking up a language in short order. Am I correct in thinking that your background is in C? (1) no '' is needed after ','. Python accepts a comma as a line continuation …

Member Avatar for ZZucker
0
174
Member Avatar for G-Do

Couldn't find anything. Is there a reason you wouldn't want to use Newton's Method to approximate a solution? Jeff

Member Avatar for jrcagle
0
101
Member Avatar for asrekdal

Well, here're a couple of suggestions: [code="Python"] import wx class KeyEvent(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) ## <<< self.panel = wx.Panel(self, -1,size=wx.Size(100,100)) ## <<< self.button = wx.Button(self, -1, label="click me") self.sizer = wx.BoxSizer(orient=wx.VERTICAL) ## basic sizer stuff self.sizer.Add(self.panel) self.sizer.Add(self.button) self.SetSizer(self.sizer) ## I always forget to do …

Member Avatar for asrekdal
0
239
Member Avatar for asrekdal

I've had intermittent problems over the last week. Reloading pages usually solves the problem. Time for a new server at wxpython.org, I think. Jeff

Member Avatar for jrcagle
0
93
Member Avatar for jrcagle

Hi all, I want to write a function that returns a bounding box for a wxPython polygon as in wx.DC.DrawPolygon. Essentially, the polygon is defined in terms of a list of points [(x0,y0),(x1,y1),...,(xn,yn)]. The bounding rectangle is clearly (xmin, ymin, xmax, ymax), or in terms of the wx.Rect structure, wx.Rect(xmin, …

0
52
Member Avatar for asrekdal

The good folk over in the C++ forum will be happy to, I'm sure. wxWidgets is written in C++, and wxPython sits on top of it. Are you trying to figure out something in wxPython? Jeff

Member Avatar for asrekdal
0
98
Member Avatar for defience

The first goal is met with simple replace: [code="Python"] >>> mystring="""1243#74656453634#6356#56456456#565#1212121#7838483 #457#090#720347###24273#18712#478230478#5711758125671#47464 #74647#46474647#19192938#828##25835#2948284#6010203040#""" >>> mystring2 = mystring.replace("#","!") >>> print mystring2 1243!74656453634!6356!56456456!565!1212121!7838483 !457!090!720347!!!24273!18712!478230478!5711758125671!47464 !74647!46474647!19192938!828!!25835!2948284!6010203040! [/code] The second goal is unclear. Do you want to replace the first three ! with @, or what? Jeff

Member Avatar for woooee
0
8K
Member Avatar for RMartins

Yes, you want to use xrange() instead of range(). xrange() creates an 'iterator' that loops through one at a time, while range() creates the whole list in place. [code="Python"] from math import sqrt f=lambda n: sum([int(i)*int(i) for i in str(n)]) L=[] for n in range(0,10**8): if sqrt(f(n))%1==0:# == float(int(sqrt(f(n)))): L.append(n) …

Member Avatar for G-Do
0
86
Member Avatar for jrcagle

Hi all, This is the beginning of a hopefully useful project: to create a Canvas widget for wxPython that will mimic or improve on the Tkinter Canvas widget. Those of you who have coded with both will probably know what I'm talking about. With Tkinter, you can plop items like …

Member Avatar for BJSH
1
547
Member Avatar for turnerca902

I'm confused about the nature of the problem. Are you asking "When on June 1, 2008 did the sun enter the window @30 and leave the window @45?" 'Cause with the data you have, the sun never leaves that window... Jeff

Member Avatar for turnerca902
0
113
Member Avatar for alexgv14

This wants to be OOP code, I think. The problem you're having is extracting the date meaningfully from the records. The solution is to create a class for the log entries and let the class worry about how to do it. Here's a crude example: [code="Python"] # logreader import datetime …

Member Avatar for jrcagle
0
119
Member Avatar for what_is_that???

Hmm... where'd you get the file? Opening it in IDLE is not likely to work. :lol: Jeff

Member Avatar for Ene Uran
0
47
Member Avatar for nikoasumi

Hi nioasumi, Fine, thanks. The best way to help is to see the offending code. Just post it here, surrounded by [ code ] tags. Jeff

Member Avatar for nikoasumi
0
221
Member Avatar for Carlo Gambino

And don't forget to understand the underlying math. If you're incrementing each value by its own value, then what you get is twice that value: [code] a = [1,2,3,4] b = [2*x for x in a] [/code] OR if you are incrementing each value by its place in the list, …

Member Avatar for jrcagle
0
143
Member Avatar for RMartins

First, the newer Python constructions pretty much eliminate the need for "map()". Try this: [code] squaredigits = lambda x: sum([int(i)*int(i) for i in x]) [/code] Jeff

Member Avatar for Ene Uran
0
169
Member Avatar for implor
Member Avatar for nish88
Member Avatar for jrcagle
0
40
Member Avatar for G-Do

Great game. I've used it with my math students once upon a time. Rumor has it that Bill Gates took a while to figure it out. :) Jeff

Member Avatar for jrcagle
0
198
Member Avatar for zclevenger

1. Usually, you use a counter like this: [code="python"] counter = 0 # initialize counter here for line in infile: if "NAME" in line: continue counter += 1 # increment counter here line = line.rstrip() fields = line.split(',') name, iso, capital, population, area = fields if int(population) >= p: print …

Member Avatar for jrcagle
0
173
Member Avatar for lkk2116

That's a steep learning curve! One day of Python, and *POOF*, file structures. Jeff

Member Avatar for jrcagle
0
101
Member Avatar for StepIre

Your code is broken as it stands. What's the URLLister() class? I don't have it in my urllib. Jeff

Member Avatar for StepIre
0
199
Member Avatar for gusbear

[quote]...where in hell is the tax equation...[/quote] Massachusetts. Seriously, this line: [code] output.setText("%0.1% tax) [/code] should read [code] output.setText("%0.1f" % tax) [/code] I think. Use print statements to figure out where the problem is exactly. Jeff

Member Avatar for jrcagle
0
115

The End.