226 Posted Topics

Member Avatar for Kacoo

Since I have no knowledge of Python GUI libraries whatsoever (only .NET's WPF and WinForms), I searched "Toplevel" on google and got this: [URL="http://effbot.org/tkinterbook/toplevel.htm"]http://effbot.org/tkinterbook/toplevel.htm[/URL] So will this work? [CODE]logedInPage = Toplevel() logedInPage.minsize(width=30,height=50) logedInPage.title("Message to You!") msg = Message(logedInPage, text="Logged is misspelled.") msg.pack()[/CODE]

Member Avatar for jcao219
0
180
Member Avatar for Aeronobe

Well, if you are going to add more to the list of things it can't start or end with, you can do something like this: [CODE]nostart = ("javascript","mailto") #you can add more noend = ("pdf","ppt") if not ([item for item in nostart if link.startswith(item)] + [item for item in noend …

Member Avatar for vegaseat
1
169
Member Avatar for ShinyDean
Member Avatar for Seagull One

You need to run the text-to-speech on a different thread. [icode]import threading #go from there[/icode]

Member Avatar for jcao219
0
139
Member Avatar for ultimatebuster

[QUOTE=ultimatebuster;1214796]Is this needed? [CODE] class Test: def __init__(self, f): self.f = open(f) def __del__(self): try: self.f.close() except: pass [/CODE] [/quote] Not absolutely needed, but that's a way to do things, with [b]magic methods[/b]. This way, you can do: [CODE]a = Test("myfile.txt") del a[/CODE] Or of course you can do this, …

Member Avatar for HiHe
0
132
Member Avatar for Qwazil
Member Avatar for shyami

Here's a general idea of what's happening: [CODE] abc = ['a','b','c'] print(abc[3]) #IndexOutOfRange exception [/CODE]

Member Avatar for TrustyTony
0
88
Member Avatar for sabiut

To start, you need to figure out and list/prioritize what you want this program to do.

Member Avatar for snippsat
0
125
Member Avatar for ChargrO

[QUOTE=ultimatebuster;1208790]oh wow i didn;t know you can't do that in python. I was taught saying that's bad practise..[/QUOTE] It's not anti-idiomatic, I think.

Member Avatar for TrustyTony
0
472
Member Avatar for lam-chop

Any code so we can see exactly what's working so far? (I personally don't like recursive functions)

Member Avatar for justaguy101
0
850
Member Avatar for cahram

For future reference, You can do something like this for multi-level lists [CODE]def find_item(iterable,obj): if hasattr(iterable,"__iter__"): for item in iterable: if item == obj or find_item(item,obj): return True return False find_item([1,2,["a",["b",2,[3,"asdf"]],3]],"asdf") #returns True [/CODE] or you can just flatten the list

Member Avatar for TrustyTony
0
202
Member Avatar for linuxoidoz
Member Avatar for Kruptein
Member Avatar for giri.pankaj

Good, but shouldn't this have been posted as a code snippet? For permutations, you could have used [I]itertools.permutations[/I].

Member Avatar for TrustyTony
0
4K
Member Avatar for naktos

You should realize in floating point numbers, .1 equals .100000000000000000001 or so. So if you want exact, you can use Decimal

Member Avatar for TrustyTony
0
115
Member Avatar for giri.pankaj
Member Avatar for TrustyTony
Member Avatar for jagopy

Make his own video games, at twelve? I don't think it's possible, unless if he is a genius who understands trigonometry for 3d vector transformations and game logic. I really think he is too young to start programming games, but he isn't too young to start programming, in general. Games …

Member Avatar for jagopy
0
120
Member Avatar for TrustyTony

Man, object-oriented in my opinion is one of Python's best features. It's not just for creating GUI. So if you aren't familiar with the object oriented features of Python, you should really play around with them. They make programming very fun. I don't think you should be using Tkinter with …

Member Avatar for vegaseat
0
594
Member Avatar for linuxoidoz

[QUOTE=tonyjv;1205551]I do not know other things than that property is one builtin class dealing with decorators.[/QUOTE] Yea, that's right. [code] class Apple(object): def __init__(self): self._seeds = 5 @property def seeds(self): return self._seeds myapple = Apple() print myapple.seeds myapple.seeds = 4 #raises exception: #AttributeError: can't set attribute [/code]

Member Avatar for jcao219
0
134
Member Avatar for jacob07

Something like this: [CODE]#Filters: def get_FF(entry): return entry[0].startswith("FF") def get_N2_biggerthan_25(entry): return int(entry[2]) > 25 def get_file_data(f): '''Gets the data from the input file name f''' fs = open(f,"r") #opens the input file filedat = [line.split() for line in fs.readlines()] fs.close() return filedat #file as a list of lists def format_line(lst): …

Member Avatar for jcao219
0
220
Member Avatar for d.devendran
Member Avatar for jcao219
0
161
Member Avatar for ultimatebuster

[CODE]import sys sys.path.append("..\\log") #(windows style) path to the module import log[/CODE]

Member Avatar for TrustyTony
0
98
Member Avatar for HiHe

In Python 2, the input() builtin function was simply [icode]eval(raw_input())[/icode]. You should do something like [icode]int(input())[/icode]

Member Avatar for TrustyTony
0
4K
Member Avatar for ultimatebuster

[URL="http://pyxml.sourceforge.net/topics/download.html"]http://pyxml.sourceforge.net/topics/download.html[/URL]

Member Avatar for ultimatebuster
0
197
Member Avatar for NPDA

Something like [code] DialogResult result = MessageBox.Show("Are you Sure?","collection", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if(result == DialogResult.Yes) { this.Hide(); MessageBox.Show(M, "collection", MessageBoxButtons.OK); }[/code] ??

Member Avatar for mirfan00
0
164
Member Avatar for carpenoctem
Member Avatar for carpenoctem
0
101
Member Avatar for nsutton

I encourage a two-spaced indent. [CODE]class MyContact(object): def __init__(self,fn = "", ln = "", ph = "", em = "", ad = ""): self.firstName=fn self.lastName=ln self.Phone=ph self.Email=em self.Address=ad #what to do action=raw_input("Are you [1]Creating entrys or [2]Searching for existing entrys? ") # IF Creating or editing if action=='1': action2=raw_input("Would you …

Member Avatar for nsutton
0
2K
Member Avatar for SgtMe

[QUOTE=SgtMe;1200903] Thanks for your time![/QUOTE] You're welcome! First you should have a constant long hand length, and a constant short hand length. Are you confident in math, particularly trigonometry?

Member Avatar for SgtMe
0
970
Member Avatar for Danthier

You're right, you need return. Python has local and global scopes, functions have their own local scope, so a local variable is changed inside of the function, it doesn't affect a variable outside the function's scope. Add [icode]return mode[/icode] to switchMode(), and then whenever you call switchMode, do this: [icode]mode …

Member Avatar for Danthier
0
293
Member Avatar for joshua91

This should get you started. [CODE] def numbergen(): randomnumber = random.randint(0,100) #randrange is better return randomnumber def main(): while True: question = raw_input("Do you wish to play the Guess a Number Game?(Y/N)") #variables tend to be lowercase, and classes are uppercase if question.lower() == "n": break else: print numbergen() main()[/CODE]

Member Avatar for Hummdis
0
158
Member Avatar for camigirl4k3
Member Avatar for tkpanther

In my opinion, that assignment is a terrible assignment. I would rather use magic methods to make such a set class, i.e. __iter__, __setitem__, __eq__, __add__, __getitem__

Member Avatar for TrustyTony
0
182
Member Avatar for pythonnewbie10

[QUOTE=Hummdis;1191942]That is true and I've used that method, however, I find it to be better used in longer, more complex programs, not in the short ones such as this.[/QUOTE] I would have to agree to that. I think much of the code commonly put in a main function should be …

Member Avatar for TrustyTony
0
156
Member Avatar for kekela

Somethin like this? [CODE] private void pictureBox1_Click(object sender, EventArgs e) { if(pictureBox1.Image == Image.FromFile(@"IMAGEPATH\test1.jpg")){ pictureBox1.Image = Image.FromFile(@"IMAGEPATH\test2.jpg"); }else{ pictureBox1.Image = Image.FromFile(@"IMAGEPATH\test1.jpg"); } }[/CODE]

Member Avatar for jcao219
0
106
Member Avatar for cyon

You are trying to inherit an instance attribute, but you need a class attribute. This code below fixes your problem, but your code structure is strange, and I think you have a wrong concept about inheritance. Also, I fixed the indentation for you, don't use tabs, use spaces. [CODE]#!/usr/bin/env python …

Member Avatar for cyon
0
156
Member Avatar for cyberparadox
Member Avatar for cyberparadox
0
147
Member Avatar for vskumar19

[QUOTE=vskumar19;1196699]I want to open the file in an editor .. jst like whn u give $ gedit file.txt in terminal .. i want the same to be done using python.. is it possible ???[/QUOTE] well, there is os.system, so you can do [icode]os.system("gedit file.txt")[/icode], and you can also make it …

Member Avatar for hondros
0
11K
Member Avatar for StratmanPereida

Using the words array and pointer in your code make me think that this is C++ or something. Anyways, what is this Table1Builder? I'm not understanding the question.

Member Avatar for StratmanPereida
0
185
Member Avatar for kadvar
Member Avatar for kadvar
0
152
Member Avatar for LucyX

I would first tackle easier problems. A google search yielded this: [URL="http://svn.python.org/projects/python/trunk/Demo/turtle/tdemo_fractalcurves.py"]http://svn.python.org/projects/python/trunk/Demo/turtle/tdemo_fractalcurves.py[/URL]

Member Avatar for ultimatebuster
0
300
Member Avatar for ihatehippies

Well, I can't think of a way, other than: [CODE]>>> p = property(lambda self: self.__p) >>> p = property(lambda self: 10) #reassigning p to a new property[/CODE] I think its actually read-only, maybe with no ways to work around it.

Member Avatar for jcao219
0
111
Member Avatar for toll_booth

Maybe the image file you are trying to load doesn't exist. Other than, that, I have no clue what is wrong since I have never worked with PIL or cpython imaging.

Member Avatar for vegaseat
0
176
Member Avatar for toll_booth

You gotta download the tar.gz source and then build it if you want to use it under mac (I don't know how to do that, ask a mac person). Here's the version for Windows and python 2.5: [URL="http://effbot.org/downloads/PIL-1.1.7.win32-py2.5.exe"]http://effbot.org/downloads/PIL-1.1.7.win32-py2.5.exe[/URL]

Member Avatar for toll_booth
0
206
Member Avatar for R3k

I think you should have something like: [CODE=c#]using System.Net; using System.Net.Sockets;[/CODE] And then: [CODE=c#]IPAddress localAddr = IPAddress.Parse("127.0.0.1"); TcpListener tcpListener = new TcpListener(localAddr,111);[/CODE]

Member Avatar for R3k
0
207
Member Avatar for elmaami

How about json? [URL="http://docs.python.org/library/json.html"]http://docs.python.org/library/json.html[/URL]

Member Avatar for jcao219
0
50
Member Avatar for theweirdone
Member Avatar for theweirdone
0
129
Member Avatar for cyon

Here's a functional solution: [CODE]def list_disp(lst,num = -1,lname = "L"): i = 0 result = "" try: while num: num -= 1 result += "{0}[{1}] = {2}\n".format(lname, i, lst[i]) i += 1 return result except: return result print list_disp([1,2,3,4,5],9) print list_disp([1,2,3,4,5],3,"LIST") [/CODE]

Member Avatar for TrustyTony
0
127
Member Avatar for vegaseat

:) I think they used this code to test the abilities of Python before they got serious about working on IronPython and the DLR as an open source project.

Member Avatar for TrustyTony
4
110
Member Avatar for Dan08

Something like this? [code] def uniquelines(lineslist): unique = {} result = [] for item in lineslist: if item.strip() in unique: continue unique[item.strip()] = 1 result.append(item) return result file1 = open("wordlist.txt","r") filelines = file1.readlines() file1.close() output = open("wordlist_unique.txt","w") output.writelines(uniquelines(filelines)) output.close() [/code]

Member Avatar for TrustyTony
0
4K

The End.