904 Posted Topics
Re: The two functions num = input("Enter a number: ") and name = raw_input("Enter a name: ") are for the user to enter number or name from the console. Please use code blocks. import string def main(): #data = raw_input("H:\harry.txt") # use data = raw_input("Enter file name: ") # what you … | |
Re: You could save important details of player (player, hitpoints, treasures, weapons etc.) to a file before you exit the game. Now you have to also write your code to accept any saved game as option when you start. Tkinter that comes with Python allows graphics, another one is PIL also … | |
Re: If you have Windoze machine you can use MSvfw32.lib for Dev_Cpp code example see: "An AVI Media Player (Dev-C++)" [url]http://www.daniweb.com/code/snippet95.html[/url] | |
Re: One solution to fix problem is to have MakePanel2 inherit MakePanel1, then you only need to create instance of MakePanel1 in MakePanel2. For some odd reason wx.BoxSizer() gets confused with the label location. Look the code over. [code]#!/usr/bin/python import wx import time class MakePanel1(wx.Panel): def __init__(self, Parent, *args, **kwargs): wx.Panel.__init__(self, … | |
Re: I have used Python and I am learning C++. Programs that are just a few lines of code in Python are nightmares in C++, like splitting sentence into words and loading them into array of strings dynamically. | |
Re: Here are some corrections: [code]// blah blah blah code cout << "Please enter initial balance: "; cin >> acctbalance; // add the do for the while!!! do { cout << "What do you wish to do?" << endl; cout << "D Deposit Money" << endl; cout << "W Withdraw Money" … | |
Re: I have used pygtk one little and have found these good resources: [QUOTE]Recommended reading for Python+GTK users PyGTK 2.0 Tutorial by John Finlay download from: [url]http://www.pygtk.org/dist/pygtk2-tut.pdf[/url] also: PyGTK FAQ Index at: [url]http://www.async.com.br/faq/pygtk/index.py?req=index[/url][/QUOTE] | |
Re: Looks like whatever is item in hand[i] is not an integer. I also fail to see how hand[i] can be 1, 2, 3 , 4, ... all at the same time? | |
Re: Maybe it's something like this: [code]// simple to do with copy and paste #include <iostream> using namespace std; void hour_glass() { cout << "*******" << endl; cout << " ***** " << endl; cout << " *** " << endl; cout << " * " << endl; cout << " … | |
I read in the news that Python in going from version 2.4 to version 2.5 fixed 450 bugs. That seems to be lots of bugs! I used Python a lot and never found a single one of those bugs. What is your experience? | |
Re: Looks like you have somewhat incomplete code: [code]#include<stdio.h> float x[4] = {1.2,2.4,3.6,4.8}; float f[4] = {0.1,0.2,0.3,0.4}; float xave = 0.0; float ftotal = 0.0; int main() { int i; float weights[4] = {0}; char buf[80]; for(i = 0; i < 4; ++i) { printf("Enter weight #%d", i+1); fgets(buf,sizeof(buf),stdin); weights[i] = … | |
I wrote this little code to test a 2 dimensional array. Given the array array[row][col] I can find total_columns, but I am at loss to figure out total_rows. [code]// 2 D array #include <iostream> using namespace std; int main() { int row, col, total_columns; // two dimensional array in the … | |
Re: Make sure you test this out thoroughly! There are few things that might need to be changed. | |
Re: If the lines you want start with number, other than header, here is easy solution: [code]# this would be rawfile.txt str1 = """ NAME:XXXXXXXXXXXX SURNAME:XXXXXXXXXXXX DATE:23.09.2006 A B C D E F G H (column names) 40 250 300 01.01.2006 13:43:21 250 12345678 KENTBANK 31 123 455 02.02.2006 11:22:43 450 … | |
Re: There are modules like numpy, that do high speed array and matrix manipulations. Google for numpy, its free. | |
Re: Just for learning purposes: [code]# one alternative to random.sample(range(0,50), 6) import random print "show 6 random unique integers from 1 to 50:" numbers=[] while len(numbers) < 6: ri = random.randint(1,50) if ri not in numbers: numbers.append(ri) print numbers [/code] | |
Re: Nice little song! This is how you make things wait for a few seconds: [code]# by Christopher O'Leary # The death of Charlie! import time def print_charlieVerse(): print "Charlie was a pidgeon, a pidgeon, a pidgeon." print "Charlie was a pidgeon, a pidgeon that flew." print "He flew in the … | |
Re: Wonder why you did that: [code]noun1 = noun verb1 = verb adjective1 = adjective moan = sound_disgust [/code] You had perfectly good variable names already. | |
Re: A while ago our friend "a1eio" suggested the Python tutorial at [url]http://bembry.org/technology/python/index.php[/url] I liked that one! Very good for Python starters! | |
Re: A more foolproof way would be to loop each data entry like this: [code]# let's say your attacking army can be from 1 tp 100 # keeps looping until entry is acceptable aArmy = 0 while aArmy < 1 or aArmy > 100: try: aArmy = input("Enter the size of … | |
Re: [QUOTE=Ene Uran]Is there a way to verify an exit, if you click on the exit symbol on a wxPython frame?[/QUOTE] I left a short example in code snippet area: [url]http://www.daniweb.com/code/snippet526.html[/url] | |
Re: Looks like first thing you need to add is menu loop to add, edit, search data, also exit program should be in loop. Took the liberty to put your code into code tags, added some remarks: [code]import shelve import string UNKNOWN = 0 HOME = 1 WORK = 2 FAX … | |
Re: Usually memory is saved by keeping data in files. In your case, you would have to keep data in memory using module StringIO. That is swimming upstream. You could compress your datafile with methods in module zipfile or better tarfile. That will speed up loading time. | |
Re: For image files I would stick with binary file operation, it can handle text too. Here is example: [code]# typical image header str1 = \ """BANDS = 1 BAND_STORAGE_TYPE = BAND_SEQUENTIAL BAND_NAME = "N/A" LINES = 2240 LINE_SAMPLES = 3840 SAMPLE_TYPE = UNSIGNED_INTEGER SAMPLE_BITS = 8 END ~~now starts binary … | |
Re: Which version of wxPython did you install? Here is site that seems to have many difficult install questions/answers for wxPython: [url]http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi/11[/url] | |
Re: For learning about Python and XML see this website: [url]http://pyxml.sourceforge.net/topics/howto/xml-howto.html[/url] For GUI package for Python I would use wxPython. It is much more powerful than Tkinter. Python is useful for just about anything you are interested in. Things like scientific calculations, problem solving, working with databases, networking, WEB programming, audiovisual … | |
Re: "Beautiful Soup" is an HTML/XML parser for Python that can turn even poorly written markup code into a parse tree, so you can extract information. Download the free program and documentation from: [url]http://www.crummy.com/software/BeautifulSoup/[/url] | |
Re: If you insist writing your own destructor for class Tree, change it to this: [code]class Tree: def __init__(self): self.Root = None def __del__(self): if self.Root != None: del self.Root def LNR(self): ... ... [/code] Note: Destructors are optional thing in Python. | |
Re: Please show your code. It makes it tough to help without it. Others too can learn from your code and the answers. This would be one way to bind Entry box enter1 to return key: [code]enter1.bind('<Return>', func=my_function) [/code] The data is then in enter1.get() as a string. | |
Why is there a tuple and list in Python. They seemed to perform similar things. | |
Re: Go to directory where idle.py is located. On my Windows XP computer this was C:\Python24\Lib\idlelib Now bring up file config-main.def in editor like NotePad. It explains a lot of your questions. | |
Re: A kbyte is 1024 bytes. This would be more correct: [code]fsize = os.path.getsize(fname) print "size = %0.1f kb" % float(fsize/1024.0) [/code] | |
Re: I assume you want to sum numeric values. Here is slight modification, also removing return statement out of the loop: [code]def three2one(prot): code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4", "R" : "2", "K" : "3", "M" : "5", "C" : "8", "Y" : … | |
Re: If you have two lists like list1 = [1, 2, 3] list2 = [1, 2, 3] then list1 == list2 is True, they have equal content but list1 is list2 would give False, they are not the same object. | |
Re: Well, I can help with the startButton text: [code]def dieSimulator(): startButton.configure(text="Restart") # rest of your code ....... [/code] | |
Re: Have you checked into function reload(my_module)? What happened to your indentations? | |
Re: Which Python GUI kit are you using? What is your operating system? | |
Re: Give me an example of your list. Also, wouldn't use list as variable name since list() is built-in function, just as len(). | |
Re: Could you enlighten me, what is this all used for? | |
Re: I would just cancel the tread. | |
Re: You have to set widget for name to come up. At the moment I don't quite know how, I don't have my notes along. | |
Re: What operating system do you have? Did you install proper version of wxPython? I have Windows XP and my wx package is in C:\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\__init__.py Here is a simple sample of wxPython code: [code]import wx class MyFrame(wx.Frame): def __init__(self): # create a frame/window, no parent, default to wxID_ANY wx.Frame.__init__(self, None, wx.ID_ANY, … | |
Re: Given featureList = ['a','b','c','d'] what do you expect as result? Please give complete result. | |
Re: I started playing with code from you and came to this conclusion: [code]# want 'abc' to generate a list [['a','bc'],['bc','a'],['c','ab'],['ab','c'],['b','ac'],['ac','b']] def gensubset(colocation): rulesList= [] length = len(colocation) for i in range(0,length): rule1 = [colocation[i:i+1],colocation[i+1:length]] rule2 = [colocation[i+1:length],colocation[i:i+1]] rulesList.append(rule1) rulesList.append(rule2) return rulesList colocation = 'abc' sublist = gensubset(colocation) # not quite … | |
Re: Can you give sample of the first ten lines of each file? If the lines match (word and number), then you can read in one line from each file at a time, process and write/append back out. | |
Re: You put program code in a loop and designate one key to break out of loop: [code]while True: # this is an example of your program: print print "My program! Really!" print choice = raw_input("Enter r (repeat) or q (quit): ") if 'q' in choice: break # exits the while … | |
Re: This is cool, so initially list1[0] is zero to start the count! How can you wrap that into a normal bread and butter function? | |
Re: ['a': 1,'b': 2] is an invalid construct and gives a syntax error! Do you mean dictionary {'a': 1,'b': 2} ? If you want the same data/info in a tuple you could use (('a', 1),('b', 2)) and later on ... [code]# convert tuple of tuples to dictionary print dict((('a', 1),('b', 2))) … | |
Re: Dictionary keys have to be immutable objects. Lists are mutable objects. Comvert all the lists to tuples. |
The End.