Search Results

Search found 13693 results on 548 pages for 'python metaprogramming'.

Page 168/548 | < Previous Page | 164 165 166 167 168 169 170 171 172 173 174 175  | Next Page >

  • Python Tkinter after loop not working fast enough

    - by user2658538
    I am making a simple metronome where it plays a tick sound every few milliseconds depending on the bpm and plays the sound using the winsound module. I use tkinter because there will be a gui component later but for now the metronome code is working, it plays the sound at a constant rate, but even though I set the after loop to play the sound every few milliseconds, it waits longer and the beat is slower than it should be. Is it a problem with the code or a problem with the way I calculate the time? Thanks. Here is my code. from Tkinter import * import winsound,time,threading root=Tk() c=Canvas(root) c.pack() class metronome(): def __init__(self,root,canvas,tempo=100): self.root=root self.root.bind("<1>",self.stop) self.c=canvas self.thread=threading.Thread(target=self.play) self.thread.daemon=True self.pause=False self.tempo=tempo/60.0 self.tempo=1.0/self.tempo self.tempo*=1000 def play(self): winsound.PlaySound("tick.wav",winsound.SND_FILENAME) self.sound=self.c.after(int(self.tempo),self.play) def stop(self,e): self.c.after_cancel(self.sound) beat=metronome(root,c,120) beat.thread.start() root.mainloop()

    Read the article

  • Python - Removing duplicates from a string

    - by Daniel
    def remove_duplicates(strng): """ Returns a string which is the same as the argument except only the first occurrence of each letter is present. Upper and lower case letters are treated as different. Only duplicate letters are removed, other characters such as spaces or numbers are not changed. >>> remove_duplicates('apple') 'aple' >>> remove_duplicates('Mississippi') 'Misp' >>> remove_duplicates('The quick brown fox jumps over the lazy dog') 'The quick brown fx jmps v t lazy dg' >>> remove_duplicates('121 balloons 2 u') '121 balons 2 u' """ s = strng.split() return strng.replace(s[0],"") Writing a function to get rid of duplicate letters but so far have been playing around for an hour and can't get anything. Help would be appreciated, thanks.

    Read the article

  • python multiprocessing.Process.Manager not producing consistent results?

    - by COpython
    I've written the following code to illustrate the problem I'm seeing. I'm trying to use a Process.Manager.list() to keep track of a list and increment random indices of that list. Each time there are 100 processes spawned, and each process increments a random index of the list by 1. Therefore, one would expect the SUM of the resulting list to be the same each time, correct? I get something between 203 and 205. from multiprocessing import Process, Manager import random class MyProc(Process): def __init__(self, A): Process.__init__(self) self.A = A def run(self): i = random.randint(0, len(self.A)-1) self.A[i] = self.A[i] + 1 if __name__ == '__main__': procs = [] M = Manager() a = M.list(range(15)) print('A: {0}'.format(a)) print('sum(A) = {0}'.format(sum(a))) for i in range(100): procs.append(MyProc(a)) map(lambda x: x.start(), procs) map(lambda x: x.join(), procs) print('A: {0}'.format(a)) print('sum(A) = {0}'.format(sum(a)))

    Read the article

  • Simple python mvc framework

    - by Overdose
    Is there any lightweight mvc webframework which is not necessary to install to the server? I need something simple, that i could just copy to the shared hosting. And it must handle urls other that localhost/test.py, something like this localhost/Blog/test

    Read the article

  • Http.Request and cookies Python

    - by Kyle
    I am trying to retrieve source code from a webpage with an already issued cookie and write the source code to a txt file. If I remove the cookies=cookie portion I can retrieve the source code but I need to somehow send the cookie with the http.request. output = open('Filler.txt', 'w+') http = urllib3.PoolManager() cookie =('users' , '1597413515') r = http.request('http://google.com' , 'GET' , cookies=cookie) output.write(r.data) output.close() I get a KeyError: None

    Read the article

  • Python script to delete old SVN files lacks permission

    - by Rosarch
    I'm trying to delete old SVN files from directory tree. shutil.rmtree and os.unlink raise WindowsErrors, because the script doesn't have permissions to delete them. How can I get around that? Here is the script: # Delete all files of a certain type from a direcotry import os import shutil dir = "c:\\" verbosity = 0; def printCleanMsg(dir_path): if verbosity: print "Cleaning %s\n" % dir_path def cleandir(dir_path): printCleanMsg(dir_path) toDelete = [] dirwalk = os.walk(dir_path) for root, dirs, files in dirwalk: printCleanMsg(root) toDelete.extend([root + os.sep + dir for dir in dirs if '.svn' == dir]) toDelete.extend([root + os.sep + file for file in files if 'svn' in file]) print "Items to be deleted:" for candidate in toDelete: print candidate print "Delete all %d items? [y|n]" % len(toDelete) choice = raw_input() if choice == 'y': deleted = 0 for filedir in toDelete: if os.path.exists(filedir): # could have been deleted already by rmtree try: if os.path.isdir(filedir): shutil.rmtree(filedir) else: os.unlink(filedir) deleted += 1 except WindowsError: print "WindowsError: Couldn't delete '%s'" % filedir print "\nDeleted %d/%d files." % (deleted, len(toDelete)) exit() if __name__ == "__main__": cleandir(dir) Not a single file is able to be deleted. What am I doing wrong?

    Read the article

  • python send/receive hex data via TCP socket

    - by Mike
    I have a ethenet access control device that is said to be able to communicate via TCP. How can i send a pachet by entering the HEX data, since this is what i have from their manual (a standard format for the communication packets sent and received after each command)

    Read the article

  • python regular expressions, how to extract longest of overlapping groups

    - by xulochavez
    Hi How can I extract the longest of groups which start the same way For example, from a given string, I want to extract the longest match to either CS or CSI. I tried this "(CS|CSI).*" and it it will return CS rather than CSI even if CSI is available. If I do "(CSI|CS).*" then I do get CSI if it's a match, so I gues the solution is to always place the shorter of the overlaping groups after the longer one. Is there a clearer way to express this with re's? somehow it feels confusing that the result depends on the order you link the groups.

    Read the article

  • Checking if a string's characters are ascending alphabetically and its ascent is evenly spaced python

    - by FRU5TR8EDD
    So need to check if a string's characters are ascending alphabetically and if that ascent is evenly spaced. a = "abc" b = "ceg" So a is alphabetically ascending and it's spacing is 1 (if you convert to the ordinal values they are 97,98,99). And b is also alphabetically ascending and it's spacing is 2 (99,101,103). And I am sticking with the following code: a = 'jubjub' words1 = [] ords = [ord(letter) for letter in a] diff = ords[1] - ords[0] for ord_val in range(1, len(ords)-1): if diff > 0: if ords[ord_val + 1] - ords[ord_val] == diff: if a not in words1: words1.append((a, diff)) print words1 How come 'jubjub' works, 'ace' works, but 'catcat' doesn't?

    Read the article

  • Python Frequently Asked Questions

    - by Casebash
    After seeing this suggestion for creating tag homepages/FAQs, I thought it'd be best to go on ahead and start collecting links to frequently asked questions to demonstrate how this would work. Object Oriented Metaclasses Missing features Enums Tools Available IDEs?

    Read the article

  • Python regular expression

    - by user3692739
    I have this HTTP Request and I want to display only the Authorization section (base64 Value) : any help ? This Request is stored on a variable called hreq I have tried this : reg = re.search(r"Authorization:\sBasic\s(.*)\r", hreq) print reg.group() but doesn't work Here is the request : HTTP Request: Path: /dynaform/custom.js Http-Version: HTTP/1.1 Host: 192.168.1.254 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://domain.com/userRpm/StatusRpm.htm Authorization: Basic YWhtEWa6MDfGcmVlc3R6bGH I want to display the value YWhtEWa6MDfGcmVlc3R6bGH Please I need your help thanks in advance experts

    Read the article

  • Error when feeding a mysql db with a python-parsed data

    - by Barnabe
    I use this bit of code to feed some data i have parsed from a web page to a mysql database c=db.cursor() c.executemany( """INSERT INTO data (SID, Time, Value1, Level1, Value2, Level2, Value3, Level3, Value4, Level4, Value5, Level5, ObsDate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", clean_data ) The parsed data looks like this (there are several hundred such lines) clean_data = [(161,00:00:00,8.19,1,4.46,4,7.87,4,6.54,null,4.45,6,2010-04-12),(162,00:00:00,7.55,1,9.52,1,1.90,1,4.76,null,0.14,1,2010-04-12),(164,00:00:00,8.01,1,8.09,1,0,null,8.49,null,0.20,2,2010-04-12),(166,00:00:00,8.30,1,4.77,4,10.99,5,9.11,null,0.36,2,2010-04-12)] if i hard code the data as above mySQL accepts my request (except for some quibbles about formatting) but if the variable clean_data is instead defined as the result of the parsing code, like this: cleaner = [(""" $!!'""", ')]'),(' $!!', ') etc etc] def processThis(str,lst): for find, replace in lst: str = str.replace(find, replace) return str clean_data = processThis(data,cleaner) then i get the dreaded "TypeError: not enough arguments for format string" After playing with formatting options for a few hours (I am very new to this) I am confused... what is the difference between the hard coded data and the result of the processThis function as fas as mySQL is concerned? Any idea greatly appreciated...

    Read the article

  • Python Terminated Thread Cannot Restart

    - by Mel Kaye
    Hello, I have a thread that gets executed when some action occurs. Given the logic of the program, the thread cannot possibly be started while another instance of it is still running. Yet when I call it a second time, I get a "RuntimeError: thread already started" error. I added a check to see if it is actually alive using the Thread.is_alive() function, and it is actually dead. What am I doing wrong? I can provide more details as are needed.

    Read the article

  • How to stop attributes from being pickled in Python

    - by Ries
    I am using gnosis.xml.pickle to convert an object of my own class to xml. The object is initialized so that: self.logger = MyLogger() But when I do dump the object to a string I get an exception stating that the pickler encountered an unpickleable type . Is there a way to 'tag' the logger attribute so that pickler will know not to try and pickle that attribute?

    Read the article

  • Assistance with regular expressions in Python

    - by da5id
    I am still learning REGEX, and I've run into an issue ... I am trying to separate a string that is composed of a mixture of letters and numbers that are in decimal format: AB0.500CD1.05EF2.29 Into something like this: list1 = AB,CD,EF list2 = 0.500,1.05,2.29 A complication to all this is that I also have strings that look like this: AB1CD2EF3 Which I'd also like to separate into this: list1 = AB,CD,EF list2 = 1,2,3 A previous inquiry yielded the following snippet, import re pattern = re.compile(r'([a-zA-Z]+)([0-9]+)') for (letters, numbers) in re.findall(pattern,cmpnd): print numbers print letters This example works fine for strings of the 2nd kind, but only "finds" the leading digit in the numbers that contain decimal places in the strings of the first kind. I've attempted an approach using the following line: pattern = re.compile(r'([a-zA-Z]+)([0-9]+(\.[0-9]))') But this results in an error: "ValueError: too many values to unpack" Thanks for any and all assistance!

    Read the article

  • python intercepting communication

    - by nabizan
    lets say you run third party program on your computer whitch create a process named example.exe how do i determinate if this process is running and how many windows does he open? How do i intercept network communication between this windows and server? my goal is to create an app whitch will be monitoring network trafic between example.exe and its home server in order to analyze data and save to database, and finally simulate user interaction to get more relevant data

    Read the article

  • [Python] Different work of the script in Windows and in FreeBSD

    - by www.yegorov-p.ru
    Hello. I'm writing some script, that works with web-servers. So, I have the following code: client = suds.client.Client(WSDLfile) client.service.Login('mylogin', 'mypass') print client.options.transport.cookiejar ####### sessnum = str(client.options.transport.cookiejar).split(' ')[1] client = suds.client.Client( WSDLfile, headers= { 'Set-Cookie' : sessnum } ) When running in FreeBSD, it returns <cookielib.CookieJar[<Cookie sessnum=9WAXQ25D37XY535F6SZ3GXKSCTZG8CVJ for .IP.IP.IP.IP/>]> but in Windows it returns <cookielib.CookieJar[]> How can I fix it?

    Read the article

  • Python code, extracting extensions

    - by user1434001
    import os path = '/Users/Marjan/Documents/Nothing/Costco' print path names = os.listdir(path) print len(names) for name in names: print name Here is the code I've been using, it lists all the names in this category in terminal. There are a few filenames in this file (Costco) that don't have .html and _files. I need to pick them out, the only issue is that it has over 2,500 filenames. Need help on a code that will search through this path and pick out all the filenames that don't end with .html or _files. Thanks guys

    Read the article

  • Python List length as a string

    - by mvid
    Is there a preferred (not ugly) way of outputting a list length as a string? Currently I am nesting function calls like so: print "Length: %s" % str(len(self.listOfThings)) This seems like a hack solution, is there a more graceful way of achieving the same result?

    Read the article

  • Perfom python unit tests via a web interface

    - by 47
    Is it possible to perform unittest tests via a web interface...and if so how? EDIT: For now I want the results...for the tests I want them to be automated...possibly every time I make a change to the code. Sorry I forgot to make this more clear

    Read the article

< Previous Page | 164 165 166 167 168 169 170 171 172 173 174 175  | Next Page >