4,305 Posted Topics
![]() | Re: This will allow you to test your module ... [code]# Function that recieves number of characters and calculate cost # of advertising, save module as costAd.py (case sensitive) def costAd(numChar): if numChar >= 15: cost = 35.00 else: cost = 35.00 + ((numChar - 15) * 3.55) return cost # … ![]() |
Re: WAG, try to give your program a .pyw extension. | |
Re: This may give you a hint ... [code]# a statusbar is an information line at the bottom of a frame # set and clear the info import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) # fill the top part with a panel panel = … | |
Re: Here you go ... [code]# a wxPython general frame template import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) self.SetBackgroundColour("red") # create an input widget # # bind mouse or key event to an action # # create an output widget # def onAction(self, event): … | |
Re: Can you boil that down to just the minimum code required to do what you want to do? | |
![]() | Re: Since hex numbers '87' and 'c4' are not even in your charset, it could take you a very long time to match. :) You could use this little test program ... [code]import random # search for this upper case HexValue string: # use hex digit pairs that are in the … ![]() |
Re: I would approach it this way ... [code]def is_magic(n): """check if n is a perfect (magic) number""" acc = 0 for i in range(1, n): if (n % i == 0): factor = i # these 2 lines could be acc += i acc += factor if (acc == n): … | |
Re: An example of a portion of a typical error text file would help muchly! | |
Re: Writing windows programs in C/C++ can be a bear for even experienced programmers. I started out with the DEV C++ package and quickly switched to BCX. This is a basic to C/C++ translator that uses simple basic code and allows inline asm and C code. If you are familiar with … | |
Re: Hint: If you [B]read[/B] your text file as one complete string (call it [B]text[/B]), then you can do a couple of split() operations ... [B]line_list = text.split('\n')[/B] [B]word_list = text.split()[/B] Now get the length of these lists ... [B]line_count = len(line_list)[/B] [B]word_count = len(word_list)[/B] You are splitting the text string … | |
| |
Re: Adding a toolbar to a panel is somewhat tricky, but can be done. For an example see: [url]http://www.daniweb.com/forums/post1138860.html#post1138860[/url] | |
Re: You could potentially do something like this ... [code]line = "10810 'AHANE 10' 110.00 1 0.00 0.00 1 1 1.0517 -4.091" rawlist = line.split("'") print rawlist # test number = rawlist.pop(0).strip() name = rawlist.pop(0).strip() numbers = rawlist.pop(0).strip() mylist = [number, name] for n in numbers.split(): mylist.append(n) print mylist [/code] | |
Re: You can test this sort of thing with module timeit ... [code]import timeit stmt1 = "x = '0' + 'ff12'" print( "%s took %0.3f micro-seconds" % (stmt1, timeit.Timer(stmt1).timeit()) ) stmt2 = "x = ['ff12'].insert(0, '0')" print( "%s took %0.3f micro-seconds" % (stmt2, timeit.Timer(stmt2).timeit()) ) """my result --> x = '0' … | |
Re: What have you tried so far? Hint, you can read the file in one line at a time using a for loop. Each line will be a string that can be processed using your criteria. | |
Re: You got to let Python know where you want to create the Tkinter widgets. By default it's the MainWindow root. Change your code like this ... [code]from Tkinter import * class TopLevel3: def __init__(self): self.root2 = Toplevel() # lift root2 over MainWindow root1 self.root2.lift(aboveThis=mw.root1) self.canvas3 = Canvas(self.root2, width=400, height=200) self.canvas3.pack() … | |
Re: With some luck your department will publish a list of school holidays and then you can transfer it easily to a list of (month, day) tuples for the year, or the dictionary Gribouillis suggested. | |
Re: Something like this will work ... [code=python]import Tkinter def win1(): # this is the main/root window root = Tkinter.Tk() root.title("Window 1") startButton = Tkinter.Button(root, text="Start", command=win2) startButton.grid(row=9, column=7) leaveButton = Tkinter.Button(root, text="Quit", command=root.destroy) leaveButton.grid(row=1, column=1, sticky='nw') b1Var = Tkinter.StringVar() b2Var = Tkinter.StringVar() b1Var.set('b1') b2Var.set('b2') box1Label = Tkinter.Label(root,textvariable=b1Var,width=12) box1Label.grid(row=3, column=2) box2Label … | |
Re: If PHD stands for Piled High and Deep, the PHP stands for ... | |
Re: It's best to write yourself a little function ... [code]# working with deque (double ended que) # delete an item from a deque at given index from collections import deque def dq_delete(dq, del_ix): """delete a deque item at index del_ix""" dq2 = deque() for ix, item in enumerate(dq): if ix … | |
Re: This little code might give you a hint ... [code]# print out the third Fridays of each month in a given year import calendar year = 2010 print( "The third Friday of each month in %d:" % year ) for month in range(1, 13): k = 0 for day in … | |
Re: I don't have BOA, but I quickly created a sample program using the wxGlade designer and the SPE editor. It shows you how to set up a tree ... [code]#!/usr/bin/env python # -*- coding: iso-8859-15 -*- # generated by wxGlade 0.6.2 on Fri Feb 19 05:43:46 2010 import wx # … | |
Re: I thought that looked familiar. Looks like [B]def img_zoom(self, image1):[/B] also receives an event from the menu click, so try [B]def img_zoom(self, image1, event):[/B] where event is simply a dummy. | |
Re: You can run this Python file after proper option modifications to package a wxPython program with py2exe ... [code]""" file = wx2exeZ.py Py2Exe (version 6.6 and higher) setup file for wxPython GUI programs. Creates an exe file and a library.zip file. It's easiest to save this wx2exeZ.py file into the … | |
Re: Text files use mode "r" and the contents are usually read until they reach the EOF marker (end of file). Non ASCII files can contain an EOF marker anywhere in the file. | |
Re: Just for the fun of Python ... [code]# using the Python local dictionary vars() # you can dump/save and load mystr_dict with module pickle def mystrings(): s1 = 'I ' s2 = 'like ' s3 = 'Python' # in this case vars() is local to this function return vars() mystr_dict … | |
Re: You save your entire data with module pickle. Here is an example ... [code]# use module pickle to save/dump and load a dictionary object # or just about any other intact object # use binary file modes "wb" and "rb" to make it work with # Python2 and Python3 import … | |
Re: I don't think you want to create a new label widget every time you click on the menu item. That would eventually tax your computers memory. I corrected your code to replace the text in the same label ... [code]import wx class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, … | |
Re: So you want to go through [B]a op b op c[/B] until the result matches your target. Where a, b, c are integers and op are the various operators. Right? | |
Re: Some goofy indentations in there. You are mixing tabs and spaces, a recipe for disaster! I recommend to stick with spaces! | |
Re: In line 127 [B]self.stilltext = StillText(DEDITOR(self), -1, "")[/B] creates a new instance of class DEDITOR, you want to use the instance created in __main__ | |
Re: You also need to install the win32 extension module, free from: [url]http://sourceforge.net/projects/pywin32/files/[/url] | |
Re: Look at the module time The two time methods strptime() and strftime() are your friends. | |
Re: In the Python manual look under module ctypes. | |
Re: If you use an absolute layout, you can respond to a button click by moving the desired widgets to a new position. | |
Re: Like BearofNH pointed out in your other thread, the problem is in lines 18 and 19 [B]self.rank = str(self.rank) self.value = self.rank[/B] You are turning self.rank into a string and then assign it self.value. The solution would be to simple reverse the two lines ... [B]self.value = self.rank self.rank = … | |
Re: If you put the image on a canvas, you can delete it with something like canvas.delete(image) | |
Re: Wealth created by speculation can evaporate quickly. The US government owns a huge amount of land and resources that it can use as a collateral. | |
Re: There are quite a number of errors in your code. Check the remarks ending with '!!!!!!!!!!!' in the corrected code ... [code]import random class Card: def __init__(self, suit, rank, value): self.rank = rank self.suit = suit self.value= value if self.rank == 1: self.rank = "Ace" self.value = 11 elif self.rank … | |
Re: [B]def continueof(rotator):[/B] is a function, not a class. You can't set it up like a class and use it like a class. | |
Re: After line [B]data = s.recv(1024)[/B] put in a test print [B]print data[/B] What do you get? | |
Re: Your code is a mess! The all important indentations are mixed up and you are still using tabs. My program editor cannot handle this. For instance tabs expand to 8 spaces in DaniWeb's code field and after a few of those gigantic indents I can't even stomach the looks of … | |
Re: [B]sneekula:[/B] I know Snee is a science grad student. He likes the Cs, that is the C language, Computers, Church, Chemistry, Cooking and Cars. He seems to be light hearted, easy going, and on occasion will leave the Geek's Lounge to make a contribution to the Python forum. | |
Re: I don't think PIL can do this. The XPixelMap format is a text based C array and you could probably take bitmap information and create this array and save it. Presumably there are C utilities around that create XPM files, you should be able to run those from within Python. … | |
Re: Or you can simply use move to move the widgets around. | |
Re: In the mean time changing [B]saldo = f.readline()[/B] to [B]saldo = int(f.readline())[/B] will work | |
Re: You can test Gribouillis' clever code with something like this ... [code]# delete lines 0-51, 53-153, 155-255, 257-357 and so on in_list = list(range(1000)) out_list = [] save_line = 52 for ix, line in enumerate(in_list): if ix == save_line: out_list.append(line) save_line += 102 print(out_list) # [52, 154, 256, 358, 460, … | |
Re: Python checks in the working directory first, and if you save one of your own files with a module name, you don't get the proper module. | |
Re: You may have to give us more detail about JSON and the json module. |
The End.