226 Posted Topics
Re: 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] | |
Re: 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 … | |
| |
Re: You need to run the text-to-speech on a different thread. [icode]import threading #go from there[/icode] | |
Re: [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, … | |
| |
Re: Here's a general idea of what's happening: [CODE] abc = ['a','b','c'] print(abc[3]) #IndexOutOfRange exception [/CODE] | |
Re: To start, you need to figure out and list/prioritize what you want this program to do. | |
![]() | Re: [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. |
![]() | Re: Any code so we can see exactly what's working so far? (I personally don't like recursive functions) |
Re: 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 | |
Re: [CODE] if x in mylist: mylist[mylist.index(x)] #do something to it [/CODE] | |
Re: What you are trying to do is called syntax highlighting. | |
Re: Good, but shouldn't this have been posted as a code snippet? For permutations, you could have used [I]itertools.permutations[/I]. | |
Re: You should realize in floating point numbers, .1 equals .100000000000000000001 or so. So if you want exact, you can use Decimal | |
Re: Is it secure to store the password as an environment variable? | |
Re: 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 … | |
Re: 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 … | |
Re: [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] | |
Re: 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): … | |
Re: What do you mean by "build"... because Python doesn't have much of a concept of "build." | |
Re: [CODE]import sys sys.path.append("..\\log") #(windows style) path to the module import log[/CODE] | |
Re: In Python 2, the input() builtin function was simply [icode]eval(raw_input())[/icode]. You should do something like [icode]int(input())[/icode] | |
Re: [URL="http://pyxml.sourceforge.net/topics/download.html"]http://pyxml.sourceforge.net/topics/download.html[/URL] | |
Re: 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] ?? | |
Re: [icode]print("Hello World")[/icode] You are probably using Python 3. | |
Re: 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 … | |
Re: [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? | |
Re: 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 … | |
Re: 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] | |
| |
Re: 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__ | |
Re: [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 … | |
Re: 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] | |
![]() | Re: 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 … ![]() |
Re: [icode]from bsddb.db import DBError[/icode] add that to your code. | |
Re: [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 … | |
Re: 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. | |
Re: [CODE]if 'key1' in mydict.values(): do something[/CODE] that should do it. | |
Re: 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] | |
Re: 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. | |
Re: 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. | |
Re: 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] | |
Re: 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] | |
Re: How about json? [URL="http://docs.python.org/library/json.html"]http://docs.python.org/library/json.html[/URL] | |
Re: Change last line to: [CODE] print list(fringe.keys())[0] [/CODE] | |
![]() | Re: 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] |
Re: :) 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. | |
Re: 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] |
The End.