404 Posted Topics

Member Avatar for karenmaye

Well, here's the basic idea. You have a button in your GUI. The button has a callback function. That function can then call your program. Here's a typical instance: [code="Python"] def mycallback(self, event): os.system("C:\Program Files\Myprog.exe") [/code] Jeff

Member Avatar for karenmaye
0
184
Member Avatar for breatheasier

Lists of lists work fine as container arrays (not mathematical arrays, but you don't seem to be wanting that). So: [code="Python"] nlat=10 mylist = [] for x in range(0,nlat): tmp = [] for y in range(0,nlat): disk=sphere(pos=(x*s,y*s), radius = r, color=(0,1,9)) tmp.append(disk) mylist.append(tmp) [/code] et voila! An array of spheres. …

Member Avatar for breatheasier
0
687
Member Avatar for leegeorg07

For the file choosing, you should check out the filedialog module. Google for references on it. For the endless looping, take a look at the code and think about how to remove the element of choice from it. Jeff

Member Avatar for woooee
0
107
Member Avatar for lcc_551

As well he should :) Here's what wooee means: [code="Python"] def SD(): b = [] for n in range(r-1): if r[n] > a: b.append((r[n] - a)**2) if r[n] < m: b.append((a - r[n])**2) SD = (float(b)/r)**0.5 #float because the data includes decimal values return SD print "The standard deviation is", …

Member Avatar for jrcagle
0
189
Member Avatar for artmansoft

Yeah, that's interesting ... None in Python is a special type, whereas Nothing is equivalent to NULL of whatever datatype one is working with: Dim b as Integer: b = Nothing -- this makes b a Nothing value of type Integer (as opposed to a None type). In short, Nothing …

Member Avatar for jrcagle
0
1K
Member Avatar for orangie

Well, if you think about it, the problem does not have a unique solution. [code="Python"] x = Class() x.name = 'the_name' x.value = 10 y = Class() y.name = 'the_name' y.value = 20 [/code] So now ... do you want x.value or y.value? Maybe both? Jeff

Member Avatar for paddy3118
0
119
Member Avatar for drew7py

Two thoughts. (1) You're writing code as if it were C or Pascal. A better way is to write a class: [code="Python"] class Bird(object): def __init__(self, nID=0, ter=0, year=0, fled=0, age=0.0): self.nID = nID self.ter = ter self.year = year self.fled = fled self.age = age def from_line(self, string): items …

Member Avatar for drew7py
0
113
Member Avatar for RMartins

Well, start with a thought. How can you explain the process to someone else in English? Make it general: given data in rows of [i]n[/i], how would you rewrite it in rows of [i]m[/i]? Once you have that explanation in English, it will lead to the thought that gives the …

Member Avatar for woooee
0
93
Member Avatar for karthik.c

I really like the text we used for my high-school level class: Python Programming for the Absolute Beginner. Two caveats -- it's game-oriented, and it doesn't use Python 3.0. That said, it contains clear explanations and models reasonably good programming practices. Jeff

Member Avatar for scru
0
20K
Member Avatar for scoob_m

[quote]My question is what is the order in which instantiations and allocations occur in python when instantiating a class? The author's code below is under the assumption that 'DefaultDomainName' will exist when an instance of the class is created (e.g. __init__() is called), but this does not seem to be …

Member Avatar for jrcagle
0
103
Member Avatar for mahela007

I'm confused. Here's the help on shutil.copy: [quote="TFM"] >>> help(shutil.copy) Help on function copy in module shutil: copy(src, dst) Copy data and mode bits ("cp src dst"). The destination may be a directory. [/quote] Can you be specific with your question? Thanks, Jeff

Member Avatar for Ene Uran
0
210
Member Avatar for karthik.c

One more thought: lists of lists in Python function reasonably well as arrays: [code="Python"] mylist = [[1,2,3],[4,5,6],[7,8,9]] print mylist[0][2] 3 [/code] I say "reasonably well" -- there aren't any linear algebra methods that can be used on lists of lists (like det(), inv(), or eigenvalues()), but the LinearAlgebra module covers …

Member Avatar for karthik.c
0
185
Member Avatar for mahela007

Just to add to scru's point: Being able to re-use code is an extremely important but sometimes overlooked feature of programming. Its main value is not saving time, but eliminating bugs. That is, if the code for CD works provably correctly (or testably correct even), then a DVD class built …

Member Avatar for lllllIllIlllI
0
652
Member Avatar for eyewirejets

I fully agree, Vega. The coding purists frown on while True loops, but I find them really useful. Glad to know someone else out there shares my guilty secret. :lol: Jeff

Member Avatar for jrcagle
0
118
Member Avatar for mahela007

Without contradicting the posters above, I would add that Python makes OOP really easy. And in the end, coding with objects is easier to wrap one's mind around than coding without objects -- once OOP is learned, of course. So ... yes, you could ... but you probably shouldn't. ;) …

Member Avatar for jrcagle
0
80
Member Avatar for scru

[code="Python"] >>> class Thing(object): pass >>> t = Thing() >>> dir(t) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] >>> print t.__class__ <class '__main__.Thing'> >>> print t.__module__ __main__ [/code] Jeff

Member Avatar for Ene Uran
0
135
Member Avatar for scru

[QUOTE=scru;798764]Now I want to take it a step further and make myself a small GUI library for python 3. What I'm interested in is how I could go about designing the object hierarchy among other things. As a community of python users, this would be an ideal place to start …

Member Avatar for lllllIllIlllI
0
215
Member Avatar for leegeorg07

In Python < 3.0, [b]print[/b] is a keyword and as such cannot be deleted or clobbered, as far as I can tell. So for example, it's not a part of __builtins__ because it isn't a function. Interesting that on this point, Python is bowing to the wisdom of C. Jeff

Member Avatar for leegeorg07
0
88
Member Avatar for eyewirejets

The style is good too. In general, functions should do one thing and do it well. Yours pass that criterion. Although ... I don't usually have a "main()" for the simple reason that I like to examine variables if the program crashes, and stuffing the main code into main() makes …

Member Avatar for jrcagle
0
330
Member Avatar for Haze

I'm not getting your results: [code="Python"] class test(object): a = 55 def dispmenu(self): print self.a >>> >>> instance = test() >>> >>> instance.dispmenu() 55 >>> action1 = instance.dispmenu() 55 >>> print action1 None [/code] Here's what I think you want to do: [code="Python"] >>> action1 = instance.dispmenu >>> action1() 55 …

Member Avatar for jrcagle
0
132
Member Avatar for juzzy

If you have two genuinely separate programs, then they will have to signal each other. This would likely be accomplished with a pipe, and you'll need some kind of signal handling. How badly do you want to pursue this solution? What are you trying to accomplish? Jeff

Member Avatar for Stefano Mtangoo
0
139
Member Avatar for mruane

The newline character is '\n' (including the quotes), not \n\. Hope it helps, Jeff

Member Avatar for mruane
0
70
Member Avatar for lllllIllIlllI

This appears to work: >>> im = Image.open("24bit test.bmp") >>> im2 = im.convert("P") >>> im2.save("256bit test.bmp") The bit-depth of the output file is 8, so I assume that's what you were after? Jeff

Member Avatar for lllllIllIlllI
0
143
Member Avatar for nitinloml

Ah. Here's a stab: [code=Python] def change_time(record, new_time): name,id,time = record.split('|') time = str(new_time) record = '|'.join((name,id,time)) + '|' return record [/code] Jeff

Member Avatar for woooee
0
203
Member Avatar for ich1

Nice code! Line 19 in the second file is (one of?) your troubles: def __init__(self, filename = "", NodeList = [], ModelInfo = [""], EdgeList = []) This is tricky, and it gets even experienced Python users several times until they learn by banging their heads against walls. Here's what …

Member Avatar for gaunle
0
458
Member Avatar for gusbear

Yeah, that's a challenging newbie project. Start by solving your problem in English -- write a plan that closely imitates how you would do this by hand. Then we can help turn your plan into code. Jeff

Member Avatar for hobbz86
0
139
Member Avatar for Dekudude

Search this forum for posts by Seagull One. She has gotten a lot of this code working. Jeff

Member Avatar for Dekudude
0
221
Member Avatar for Seagull One

It's good code, seagull (or should I say "Lore-enn"?). You're asking a question that has more to do with the speech recognition module than Python, so I can't directly help. But when I'm stuck on such, I usually try out the help files. In this case, it looks as if …

Member Avatar for Seagull One
0
1K
Member Avatar for Matt Tacular

Surely this is too hard? What are you trying to do, Matt? Also, Vega ... how old is 'too old', exactly? :) Jeff

Member Avatar for mchen10
0
474
Member Avatar for mayapower

I would probably take a completely different approach: [code="Python"] class MyFloat(float): def __new__(self, name, value): return float.__new__(self, value) def __init__(self, name, value): self._name = name name = property(lambda self: self._name) x=MyFloat("name", 1.5) print x print x._name print x.name [/code] The call to __new__ is necessary when subclassing immutable types like …

Member Avatar for jrcagle
0
1K
Member Avatar for linkrulesx10

Or this: [code="Python"] try: val = int(item) if val > 0: do stuff for positive numbers elif val < 0: do stuff for negative numbers else: # don't omit zero! do stuff for zero except: pass [/code] If you want to allow floating point numbers, you can change the int() …

Member Avatar for linkrulesx10
0
5K
Member Avatar for jobs

The function "unpack" is not a built-in function. Does your code import some module at the top? Jeff

Member Avatar for jrcagle
0
60
Member Avatar for Edwards8

Well, a quick tangential note: your method for extracting the extension name[-4:] is buggy. What if the file extension is ".jpeg"? Better: [code="Python"] filename, ext = os.path.splitext(name) if ext == ".tif": do stuff ... savedfile = filename+".jpg" do more stuff... [/code]

Member Avatar for woooee
0
436
Member Avatar for Scuppery

Good news: the convention for scientific notation 2.72e-2 (which is the correct rendering) is so well-recognized that superscripting is not required. Jeff

Member Avatar for jrcagle
0
5K
Member Avatar for ymf

Just to jlm's good points above, the getter and setter functions allow the object to control access to its own data members. For instance, suppose you have a sprite that can rotate. Clearly, if the rotation is greater than 360 degrees, then you want to reduce the rotation to its …

Member Avatar for jrcagle
0
148
Member Avatar for adarshvp

There are a couple of bugs that jump out at me. First, notice that you remove the "serverlist.txt" file each time a server message is received. So naturally, only the last server that broadcasts will be in your list -- which I don't think was the desired behavior. Second, your …

Member Avatar for jrcagle
0
9K
Member Avatar for leegeorg07

Well, that depends. Do you want to end up coding games? If so, then start! [url]http://www.pygame.org/news.html[/url] The "tutorials" link on the left should be helpful Jeff

Member Avatar for jrcagle
0
76
Member Avatar for mharter

I would try to contact Tim Golden. At first glance, it looks like his AD module doesn't handle Unicode properly (though I might be mistaken about this) Jeff

Member Avatar for ldk
0
95
Member Avatar for elhallouf

Absolutely. You need ... dictionaries. [code="Python"] store_dict = {} f1 = open("ITEMS.txt") for line in f1: store, item = line.strip("/n").split(" ") store_dict[store] = item f1.close() items_dict = {} f2 = open("IDs.txt") for line in f2: item, ID = line.strip("\n").strip() items_dict[item] = ID f2.close() [/code] At this point, you now have …

Member Avatar for elhallouf
0
162
Member Avatar for cdub

It worked for me. What result are you getting? Jeff P.S. eliminate the spaces between "code = Python" to get your tag to work.

Member Avatar for Fuse
0
4K
Member Avatar for caribedude

Is there a chance that the sound is playing on the wrong sound device? I have two sound cards (built in and recording equipment), and sometimes my software gets confused. Jeff

Member Avatar for vegaseat
0
126
Member Avatar for eibwen

Well, that question may not have an answer if the values are not unique; for example, if book['key1'] = {'keya':valuea, 'keyb':valueb} and book['key2'] = {'keya':valuec, 'keyd':valued} then 'keya' cannot be mapped backwards. But suppose that your values [b]are[/b] unique. Then you could do this: [code="Python"] >>> import shelve ## set …

Member Avatar for eibwen
0
140
Member Avatar for Potty391

Well, the usual procedure here is to start with your code. Post it here and then we can give pointers and such. Jeff

Member Avatar for woooee
0
100
Member Avatar for FreezeBlink

If you are determined to iterate through the original list ... and there are times when that's appropriate ... then you must iterate through a [b]copy[/b] of the list: [code="Python"] >>> nums = [1.0,2.0,3.0,4.0,5.0] >>> for n in nums[:]: if n % 2 == 1: # better way to say …

Member Avatar for jrcagle
0
118
Member Avatar for sarabhjeet

What do you mean by "increasing the look"? If you just want to make it more visible, you could set border colors to hot pink or something... Jeff

Member Avatar for sarabhjeet
0
89
Member Avatar for msaenz

Seems to me that this line ought to be an error... [code="Python"] c=Cursor() [/code] because you then try to execute commands on it ... but it's not assigned to any database, right? Maybe I'm misunderstanding. Jeff

Member Avatar for jrcagle
0
2K
Member Avatar for bf2loser

I would recommend re-ordering your class a bit, if you have the freedom to do so: [code="Python"] class Temperature(object): def __init__(self, temp): def toCelcius(self): def toRankine(self): def toFahrenheit(self): [/code] That way, all of your temperatures can be stored as objects of the same class and you can access the value …

Member Avatar for jrcagle
0
1K
Member Avatar for joshuabraham

The appropriate code tags are [noparse][code="Python"] ## code here [/code][/noparse] What's happening? I'm guessing that the sound plays, but then the code hangs after that? Jeff

Member Avatar for joshuabraham
0
177
Member Avatar for tondeuse34

Yes, the standard way of writing a shell (which is what you are doing) is like this: [code="pseudo"] while True: inputline = raw_input(myprompt) parse inputline into command, operands if command == "quit": break else: execute command using operands [/code]

Member Avatar for jrcagle
0
119
Member Avatar for ivy47469

What you've done is to make the game itself into your main code. If you think about it, that's not what you want. The main loop here is [code="pseudo"] playerscore = housescore = 0 while user wants to play: winner = CrapsGame() # note the 's' -- a Crap Game …

Member Avatar for jrcagle
0
102

The End.