988 Posted Topics
Re: Soemthing like that? [code=python]s = "c:/hello/scot" if s.endswith("scot"): s = s.replace("scot", "bob") print s # c:/hello/bob [/code] | |
Re: You have to add a newline character to the end of each line in the string: [code=python]mylist = [[2934110, 'B1', 'D4', '7C7C7C7C804040404040F140404000'], [2934110, 5, 1, 1, '01', 'Actes Sud '], [2934110, 4, 1, 2, '8C00Dubbelganger (motief)'], [2934110, 3, 1, 1, '01', '01', '03', 'Les amants imparfaits', ' : roman'], [2934110, … | |
Re: First of all, take the second line out, vegaseat did not write your program! Note that print is used in console programs and will not work in a GUI. You have to use a label. Also line [code=python]label25=tk.Label(root, text="Enter your number here:") [/code]asks for an input, so you need an … | |
Re: [QUOTE=ONELA;348550]I M A Girl Reading A Degree At A Local University , I M Having A Assignment To Do Please Help Me On That Fact[/QUOTE] Very funny, but a little late for an April first joke! | |
Re: Don't forget to take a look at the Python module BioPython. More info, free download and docs at: [url]http://biopython.org/wiki/Main_Page[/url] | |
Illustrates the close relationship of the hard-software industry to April first: [CODE=c]#include <nonsense.h> #include <lies.h> #include <spyware.h> /* Microsoft Network Connectivity library */ #include <process.h> /* For the court of law */ #define say(x) lie(x) #define computeruser ALL_WANT_TO_BUY_OUR_BUGWARE #define soon next_year #define the_product_is_ready_to_ship another_beta_version void main() { if (latest_window_version>one_month_old) { … | |
Re: First of all, welcome to the forum! To preserve the code's indentations, please use the [b][noparse][code=python][/noparse][/b] and [b][noparse][/code][/noparse][/b] tag pair to enclose your python code. | |
Re: Somethin along this line: [code=python]# get the IP address of the machine the program is running on import socket print socket.getaddrinfo(socket.gethostname(), None)[0][4][0] [/code] | |
Re: The advantage of BF is that it allows you to use the f-word in an academic setting. | |
Re: If you just want to remove the first 'n' use: [code=python]old = "open sesame nnnn" # replace first occurance of 'n' new = old.replace('n', '', 1) print new # 'ope sesame nnnn' [/code] | |
Re: You have to let us know a little more, like what operating system are we talking about? | |
Re: You define method __str__() within the class: [code=python]class Book: def __init__(self, author, title, price): self.author = author self.title = title self.price = price def __str__(self): # overrides print for the instance text = "%s by %s" % (self.title, self.author) return text abook = Book(author = "Amy Doe", title = "Sun … | |
Re: I modified mawe's code so you don't have to worry about the date of the day: [code=python]# using just time and not date ... import datetime lunch_start = datetime.time(11, 30) lunch_end = datetime.time(12, 45) now = datetime.datetime.now().time() # testing print lunch_start # 11:30:00 print lunch_end # 12:45:00 print now # … | |
Re: Several things: Try to give Tkinter and Calendar a namespace, so you know where the functions come from. Give variables names that don't confuse, like 'l1' looks a lot like '11' in many editors, switching to 'lb1' helps readability. Please use the [b][noparse][code=python][/noparse][/b] and [b][noparse][/code][/noparse][/b] tag pair to enclose your … | |
Re: No need to blush, we all have made that mistake. Python allows functions to be passed to and from other functions, so all you have to remember is to use the function object and not the function call for the argument. Makes more sense once you look at it that … | |
Re: Tkinter does not have a fancy spreadsheet like widget like wxPython. However, you could create a matrix of Entry widgets and go from there. | |
Re: I took mawe's code and Jeff's ideas and came up with this: [php]# analyze a chemical recipe to create a chemical data list rcp = """23 g chemicalA is dissolved in 250 ml methanol. The solution is cooled to 0 - 5 degC and 18 ml compoundB is added dropwise … | |
Re: A couple of things wrong with your countdown timer. 1 - don't limit the size of your root window, widgets won't fit 2 - labels take strings 3 - root.update() is needed Look this over: [php]#Gamal Crichton #Teje's Counter #04/02/07 from Tkinter import * import time class Application(Frame): def __init__(self,master,act_name,time_): … | |
Re: Frigg, I posted it and it got swallowed up. An array of unions might do. | |
Re: The IT did not use C++ or she would still be working on it! | |
Re: VB.NET followed by VC.NET and possibly VD.NET? My soothing condolence! | |
Re: Unless you have a huge amount of events in your loop, it could very well be your mouse. | |
Re: Well, this one is tough because the code is frankly a nightmare! Here are some hints (look at !!!!!!! comments): [php]#Role Playing Form.py from Tkinter import * #Create the Start window class character(object): def __init__(self, master): # \Images is a subfolder of current folder torch=PhotoImage(file=r".\Images\Title Screen Flames.gif") #!!!!! grave=PhotoImage(file=r".\Images\TitleScreenGraves.gif") #!!!!! … | |
Re: [QUOTE=Aia;311655]I have learn more with you that almost six month going through several books on C programming. Again. Thank you.[/QUOTE]Reading the books might help. | |
Re: Here is something very simple that you can fancy up with a +/- year and a +/- month button: [php]# as simple monthly calendar with Tkinter # give calendar and Tkinter abbreviated namespaces import calendar as cd import Tkinter as tk # supply year and month year = 2007 month … | |
Re: I have used this info on Tkinter: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] A liitle dry with few examples however! This one has a nice Tkinter section and more examples: [url]http://bembry.org/technology/python/index.php[/url] | |
Re: I am a little lost here. I assume your data comes from a file? Well, anyway, using assumptions here is some code: [code=python]def strip_brackets(txt): if txt[0] == "[": # remove leading '[' txt = txt[1:] if txt[-1] == "]": # remove trailing ']' txt = txt[:-1] return txt # assume … | |
Re: Sharky, DrPython is not a compiler nor an interpreter, it is simply an fancy editor that allows you to run code from. I assume from your question that you want to retain the previous outputs in your output window, so you can compare them? | |
Re: "Data Mining" is an increasingly popular field and Python is pretty good at it. To data-mine HTML pages on the Web you can use an HTML Scraper like "Beautiful Soup" from: [url]http://www.crummy.com/software/BeautifulSoup/[/url] More involved are data scrapers like Orange from: [url]http://www.ailab.si/orange[/url] | |
Re: I have used SPE for quite a while. No, it's not the "Society of Petroleum Engineers", but "Stani's Python Editor". For some odd reason it has vanished on the net. Now I am starting to use DrPython, that one seems to be still quite active and just released a new … | |
Re: Similar to Jeff's code: [php]# write this as a list of lists ... matrix = [[9,8,12,15], [0,11,15,18], [0,0,10,13], [0,0,0,5]] # find the minimum value above val in each list val = 0 for n in matrix: print n # test mv = min([v for v in n if v > … | |
Re: I find counter4 to be a very interesting function, thanks for putting it up vegaseat. | |
Re: In case of the capital:state pair I did it this way: [php]def swap_dictionary(original_dict): temp_dict = {} dict_list = original_dict.items() for i in dict_list: temp_dict[i[1]] = i[0] return temp_dict cs = {"indianapolis":"indiana", "columbus":"ohio", "jackson":"mississippi", "phoenix":"arizona", "honolulu":"hawaii", "richmond":"virginia", "springfield":"illnois", "lincoln":"nebraska", "boston":"massachuettes", "lansing":"michigan", "desmoines": "iowa", "salem": "oregon"} dic = swap_dictionary(cs) print dic """ … | |
Re: Your initial problem is right here: [code]def main(): print "This program sorts student grade information" filename = raw_input("Enter the name of the data file: ") dfield = raw_input("Enter gpa, name, or credits to sort: ") filename = raw_input("Enter a name for the output file: ") data = readStudents(filename) ... [/code]You … | |
Re: I played wit it for a little while and came up with these obvious shortcuts: [php]# changed playerInitialList to pL to save on typing # changed pL1 etc. to pL[1] etc. # What do you do if initials of the two players match? import random def continents(): #<--- Visual Display … | |
Re: Method curselection() returns a tuple of the selections in case you selected more than one line, in your case pick tuple item zero. Change the your code line to reflect that: [code] passType=self.listPass.curselection()[0] [/code] | |
Re: Could be your editor/IDE. Also, a Unicode string literal is preceded with a 'u'. | |
Re: I would use the state as the key just in case there could be two capitol cities with the same name: [php]dic = {'mississippi': 'jackson', 'arizona': 'phoenix', 'iowa': 'desmoines', 'massachuettes': 'boston', 'michigan': 'lansing', 'virginia': 'richmond', 'oregon': 'salem', 'hawaii': 'honolulu', 'nebraska': 'lincoln', 'indiana': 'indianapolis', 'ohio': 'columbus', 'illnois': 'springfield'} while True: state … | |
Re: Not knowing Tkinter that well, here is a somewhat simple minded approach: from Tkinter import * def center_window(w=300, h=200): # get screen width and height ws = root.winfo_screenwidth() hs = root.winfo_screenheight() # calculate position x, y x = (ws/2) - (w/2) y = (hs/2) - (h/2) root.geometry('%dx%d+%d+%d' % (w, h, … | |
Re: You most likely get the error because you haven't selected anything on the listbox yet. You need to bind the listbox to the mouseclick that does the selection and to a function that contains your get(index) code. Something like this: [php]from Tkinter import * musicfolder = [ ["CollegeRock/"], ['RnB/'], ['HipHop/'], … | |
Re: 1) Py2Exe is not easy to use! 2) Have you looked at the Py2Exe snippet at Daniweb? That should make it easier to use! 3) Have you been able to package any Python code into an exe? 4) Your program might be small, but there are some 'outhouse' modules that … | |
Re: Always check you statement blocks! After you program with Python for a short while, these kind of things stick out like a sore thumb. | |
Re: Your error trapping in the letter grades can be mildly improved: [php]s = 'A,A-,A+,B,B-,B+,C,C-,C+,D,D-,D+,F' ps = """ Enter grade letters A through F, you can also postfix A through D with + or - (press just Enter to exit the loop when done): """ while True: x = raw_input(ps).upper() print … | |
Re: Ah, the old Turbo C bad habit clrscr() function. First try to make your program without it, it is rarely needed! You can replace one bad habit with another and use: [code]#include <stdlib.h> void clrscr(void) { system ("cls"); //system ("clear"); // for Unix } [/code]A more official version of a … | |
Re: I think that Dev C++ follows the standard better, since it really uses a very common open source compiler. A program should close unless you make it wait within the code. Anything else is added by the IDE and is not standard. Your version of Borland C++ is very old. … | |
Re: This if statment logic will not work for you [INLINECODE]if letter == "A" or "A-" or "A+": [/INLINECODE]. You have to break it up, here is an example: [php]ps = """ Enter grade letters A through F, you can also postfix A through D with + or - (press just … | |
Re: Actually the Python25 version of wxPython has a flash player component. Here is the demo they give: [CODE]import os import wx if wx.Platform == '__WXMSW__': from wx.lib.flashwin import FlashWindow from Main import opj #---------------------------------------------------------------------- class TestPanel(wx.Panel): def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.pdf = None sizer = wx.BoxSizer(wx.VERTICAL) btnSizer … | |
Re: I looked at some of your questions. [CODE]#I AM CONFUSED RIGHT HERE. SHOULD IT BE: self.letter = letter[/CODE]Since you only going to use the variable 'letter' in this particular method, you can keep it local, no need to add the 'self.' prefix. [CODE] for ch in letter: print ord(ch)[/CODE]The function … | |
Re: There are 4,017,010 characters in the authorized version of the Bible. War and Peace shouldn't be much larger. Can you put the entire text of the Bible in one string and save it? You can test it with this simple program, gives no problems on my PC: [PHP]# create a … |
The End.