- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 15
- Posts with Upvotes
- 12
- Upvoting Members
- 11
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
88 Posted Topics
I have a wx.DatePickerCtrl with the dropdown popup window that allows the user to pick a date from the calendar. What I would l like to have my program do is process an event when the user has clicked on a day in the dropdown calendar. Unfortunately the only native … | |
Re: look into time.strftime (string format time) [CODE=python] import time time.strftime("%a %m/%d/%y @ %H:%M:%S", time.localtime())[/CODE] returns 'Mon 01/23/12 @ 17:38:22' if you only wanted the time portion just do [CODE=python] time.strftime("%H:%M:%S", time.localtime())[/CODE] here is a reference for the meaning of each letter [URL="http://strftime.org/"]http://strftime.org/[/URL] | |
I stumbled on upon this anomaly in one of my programs and can't figure out why this is happening. I made a small test function that exhibits the same behavoir. It's like the local variables of my function are being saved after the function exits. The exclude_ids variable keeps growing. … | |
I'm soliciting advice for performace improvements for creating a weak checksum for file segments (used in the rSync algorithm) Here's what I have so far: def blockchecksums(instream, blocksize=4096): from hashlib import md5 weakhashes = [] stronghashes = [] for chunk in iter(lambda: instream.read(blocksize),""): a = b = 0 l = … | |
Re: Do you have a file named DailyExpenses.py in the same folder. It is case sensitive. | |
Re: Maybe I'm missing something, but how are you keeping time? You set clock_start, but I don't see the math to determine how much time has elapsed. I would expect something like clock_start = time.clock() time_elapsed = time.clock() - clock_start if time_elapsed > 2: ....(and so on) | |
I came across this project that could be really helpful.. if I was c++ literate. I know enough c++ to be dangerous and thats about it. Thanks in advance for anyone who wants to take a crack at it. ps credit to: http://www.codeproject.com/Articles/13839/How-to-Prepare-a-USB-Drive-for-Safe-Removal | |
Re: if you want to drop everything after the last "." you would add this after line 39 file_name = ".".join(file_name.split(".")[:-1]) Here is a breakdown of that code file_name = "test.file.txt" file_name.split(".") <<< ["test", "file", "txt"] take a slice of that minus the last item in the list ["test", "file", "txt"][:-1] … | |
Re: if you google "monitor changes to folder python" the first link that comes up is http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html Pretty useful article | |
Re: Here's something that I use for similar purposes. (Note: I cannot take credit for the longest_common_sequence function and am too lazy to look up who actually created it, sorry.) Usage: >>> find_likeness(what='ardvark', where=['aardvark', 'apple', 'acrobat'], threshold=80.0, case_sensitive=True, return_seq=True, bestonly=False) [(93.33, 'aardvark', 0, 'ardvark')] ardvark is a 93.33% match with aardvark, … | |
I'm trying to create a wx.ListCtrl with a searchable header. I've been looking through the listctrl mixins, but I really don't have the wx expertise needed. I'm thinking I need to paint a textctrl using a dc object, but other than that I'm lost. Any ideas? | |
I'm doing some research to determine the most efficient way to copy files. I've got 3 candidate functions: #1 [CODE=python] # uses generator to load segments to memory def copy(src, dst, iteration=1000): for x in xrange(iteration): def _write(filesrc, filedst): filegen = iter(lambda: filesrc.read(16384),"") try: while True: filedst.write(filegen.next()) except StopIteration: pass … | |
Re: try raw_input instead of input | |
Re: To tell if a thread has finished it's assigned processing use [CODE] thread1 = ProcessThread(xyz) # # Then either from the main thread or from inside your second # thread run thread.isAlive() to check if the thread is still # running. The same principle as passing the arguments to the … | |
Re: The code perfect for me. windows 7, python 2.7.2, wxpython 2.9.3.1 You can try updating wx or use the wx.CallAfter method which calls whatever you pass to it after the current event has finished processing. Maybe something like [CODE=python] def HideFrame(self, evt): self.Hide() wx.CallAfter(self.Wait) def Wait(self): time.sleep(1) self.Show() [/CODE] | |
Re: You question isn't very clear. Are you wondering about the print function? That is [URL="http://docs.python.org/release/2.5.2/lib/typesseq-strings.html"]string formatting[/URL]. | |
Re: I just dealt with this, asked for help in a post here but didn't get much help. It has to do with nat traversal which can be done from your computer. Hours of googling led me to uPnP. You have to forward public requests to your local (private) ip address. … | |
Re: So you have to create a unique file name with incremental values starting at 1. First thing you gotta do it separate the file from the folder. os.path is going to be your friend for this one [CODE=python] from os import path # get the absolute path file_path = path.abspath(file_path) … | |
Re: Hard to check your syntax unless you put your code in code blocks because we can't see the indents. Change 'random.randit' to 'random.randint' x 2. Change 'myrole = (diceroll + diceroll2)' to 'myrole = (diceroll[I][B]1[/B][/I] + diceroll2)' As written this will not play until the pot is empty. Consider adding … | |
Re: I think you'll find that most people hate using globals. I would probaly add an argument to the __init__ method to accept the args: [CODE=python] def __init__(self, args): self.args = args[/CODE] and then simply pass those saved arguments in your 'run' method. [CODE=python] def run(self): os.system(self.args)[/CODE] Just pass the args … | |
Re: To get you started [CODE] pw = '' while len(pw) < 6: pw = raw_input('Please enter a password at least 6 characters long\n') if len(pw) < 6: print('The password needs to be 6 characters long, not (%s)'%len(pw)) raw_input('Good Job!!!!!')[/CODE] | |
Re: [url]http://docs.python.org/tutorial/[/url] basically there are 2 ways to run a python file. Via command line interface or via python's built in IDLE. Python will be installed at c:\python27. At c:\python27\lib you will find python's standard library, a bunch of .py files that give the user python's famed functionality. If you right … | |
Re: it would probably look something like this [CODE=python] # untested x = 1000 with open(path, 'rb') as fileobj: data = [x.strip().split(' ') for x in fileobj.readlines()] total_rows = len(data) for n in xrange(1, total_rows): first = int(data[n-1][0].strip()) second = int(data[n][0].strip()) print (second-first)/x [/CODE] | |
Re: What are you using the 'user' variable for? You should use raw_input to set the 'text' variable and if you want it to be called more than once you have to put it inside the while loop.. something like this: [CODE=python] total = 0 text = '' while text != … | |
Re: tested on python 2.7.2 [CODE=python] import random def guessing(): start = int(raw_input('enter the starting number\n')) stop = int(raw_input('enter the ending number\n')) while start < stop: guess = random.randint(start, stop) answer = '' while answer not in ('higher', 'lower', 'equal'): answer = raw_input('Is it higher, lower, or equal to %s\n'%guess) if … | |
Re: strip removes those characters from the left and right sides of the string. If the character occurs in the middle of the string it will have no effect on it. This is what I use to remove duplicate characters from a string [CODE=python] def Unduplicate(string, chars): for char in chars: … | |
Re: It would have been more helpful if you copied the actual traceback, but it looks like in your code: [CODE=python]def updateprimepage(): try: import urllib cobdate = string.replace(sys.argv[1], '-', '') f = urllib.urlopen('http://xxx.xx.xx.xxx:18080/optionupload/OptionReportOndemandServlet?dirpath=%%2Fexport%%2Fdata%%2Fgpfs%%2Freports%%2FSAReport&cobdate=%s&submit=submit&operation=submit' %cobdate) print f.read() except IOError: print 'Cannot open URL %s for reading' % f[/CODE] If an IOError is … | |
Re: string formatting [CODE=python] path = 'c:\\aPath' arg1 = 'an argument' arg2 = 6 '%s "%s" %s' % (path, arg1, arg2) # returns 'c:\\aPath "an argument" 6[/CODE] %s tells python you want to insert something into the string It replaces every occurrence of %s with what you supply it with in … | |
Just wanted to point out for anyone using py2exe that it apparently doesn't always (or maybe ever) raise AssertionErrors. It's been a while since they've updated the program so it's probably just easier to implement a workaround for those of us who use this compiler. I've noticed it not raising … | |
Re: to get you started... *untested [CODE] import os for name in os.listdir(aDirectory): if not name.lower().endswith('.html'): continue with open(os.path.join(aDirectory, name), 'rb') as fileobj: output = [line.replace("Paragraph", "Absatz") for line in fileobj.readlines() if not "embed_music" in line] with open(os.path.join(aDirectory, name), 'wb') as fileobj: fileobj.write(''.join(output)) [/CODE] You may want to create a backup … | |
![]() | Re: *untested [CODE=python] dic = {ric:24, ric1:46, ric2:23, mike:1, mike1:47} values = [v for k, v in dic.items() if 'ric' in k or 'mike' in k] [/CODE] |
Re: You just have to describe the format to python. You are looking for 3 items separated by a comma. The third item is a digit and the second item is a 3 letter month. *Note: Code is untested [CODE] print "You chose to add a new birthday" with open('birthdays.txt', 'r') … | |
Re: if you end up using threads make sure the threads exit. I've ran into that error a few times only to find an extra instance of python.exe running in the background because a thread never exited. | |
Re: your post needs clarification. Exactly what do you want to accomplish? | |
Re: This is what I've used in the past [CODE=python] import os os.system('start "" "%s" False' % path) [/CODE] start executes the file "" is the name of the console window %s is the path to the fie and False was an argument passed to the exe | |
Re: I would look into SendKeys [URL="http://www.networkautomation.com/automate/urc/resources/help/instructions/Sbe6_000SendKeys_Instruction.htm"]Here[/URL] or [URL="http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm"]Here[/URL] The code is pretty straightforward [CODE=python] from win32com.client import Dispatch SendKeys = Dispatch("WScript.Shell").SendKeys # then to actually send a key SendKeys('a') [/CODE] Here is an answer related to getting the title of currently opened windows: [URL="http://mail.python.org/pipermail/python-win32/2008-December/008510.html"]here[/URL] | |
I've been working with python's SocketServer.ThreadingTCPServer a bit and I'm having some difficulty making a publicly available server. Everything works fine when I set the server address as 'localhost' [CODE=python]self.server = SocketServer.ThreadingTCPServer(('localhost', constants.cmdport), Handler)[/CODE] As long as the both the server and client are on the same computer and both … | |
Re: [CODE=python]def isprime(num): for x in range(2, num): if num % x == 0: return False return True[/CODE] | |
Re: delete everything above "import random" in the picture you posted. also use code tags when posting here it helps people run your code when they're testing it (press the code button and put [CODE=python] on the first code block. Instead of input() I would use [CODE=python]answer = raw_input('ask a question … | |
Re: I don't understand completely what you're trying to do so this might not be helpful at all, but I feel bad cuz no one's tried to give you an answer. you would need to make another class to save the attribute 'contents' [CODE=python] class container(object): pass class CustomError(Exception): def __init__(self): … | |
Re: Simple way to do this is to put the program or a shortcut to it here C:\\Users\\*USERNAME*\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup where *USERNAME* is your username | |
I made a simple ThreadManager class that receives tasks and spawns threads to complete the tasks. Currently it keeps all the threads alive until I explicitly set threadmgr.waiting=False and all of the tasks are complete. I'm trying to eliminate the need for the former. What I would prefer is that … | |
Currently running python 2.7 on windows 7. I have an app created with wx python and compiled with py2exe. This app has an update utility that polls an update server at startup. If an update is found it downloads the new executable file (approx. 7mb) and makes the switch. It … | |
how do I catch changes to a mutable object ie: [CODE=python] class test(object): def __init__(self): self.x = [] def __getattr__(self, atr): print 'retrieving atr %s' % atr return self.__dict__[atr] def __setattr__(self, atr, val): print 'setting atr %s to value % s' % (atr, val) self.__dict__[atr] = val [/CODE] >>> instance … | |
Anyone work with UltimateListCtrl's before? I'm looking for a way to dynamically change the column headers background color. | |
I'm having a hard time getting my website to email the contents of form. It will send an email with the field labels but no values.. ie name: phone number: email: from: () the only thing I can get it to return is the ip Here is the relevant html … | |
How do you keep a wx frame from not responding while the code is running in the background? ie a search or other demanding function. | |
Re: you can try os.startfile to start any sound file or if you're making a gui app you can try wx.Sound or wx.SoundFromData to play a .wav file | |
why does this fail to call any event? [CODE=python] def StartTimer(self, timer = 1): timer_data = { 1: (self.TimeKeeper, False, 50), 2: (self.InterimSearch, True, 200), 3: (self.InterimCurSearch, True, 200), 4: (self.SetOpaque, False, 50), 5: (self.DisplayPhoto, True, 200) } function, singlefire, time = timer_data[timer] timer = str(timer) # class of constants … |
The End.