Search Results

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

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

  • Using Python, How to copy files in 'temporary internet files' folder in Windows

    - by pythBegin
    I am using this code to find files recursively in a folder , with size greater than 50000 bytes. def listall(parent): lis=[] for root, dirs, files in os.walk(parent): for name in files: if os.path.getsize(os.path.join(root,name))>500000: lis.append(os.path.join(root,name)) return lis This is working fine. But when I used this on 'temporary internet files' folder in windows, am getting this error. Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> listall(a) File "<pyshell#2>", line 5, in listall if os.path.getsize(os.path.join(root,name))>500000: File "C:\Python26\lib\genericpath.py", line 49, in getsize return os.stat(filename).st_size WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Documents and Settings\\khedarnatha\\Local Settings\\Temporary Internet Files\\Content.IE5\\EDS8C2V7\\??????+1[1].jpg' I think this is because windows gives names with special characters in this specific folder... Please help to sort out this issue.

    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

  • Python sort 2-D list by time string

    - by Mark Kennedy
    How do I sort a multi dimensional list like this based on a time string? The sublists can be of different sizes (i.e. 4 and 5, here) I want to sort by comparing the first time string in each sublist (sublist[-4]) x = (['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5]) The sorted result would be sortedX = (['0690', '07:25AM', '09:19AM', 1, 4], ['0201', '08:50AM', '10:50AM', 1, 4], ['1166', '04:35PM', '06:36PM', 1, 4], ['0845', '05:40PM', '07:44PM', 1, 4], ['1267', '07:05PM', '09:07PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1513', '08:19PM', '10:21PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['1290', '09:45PM', '11:43PM', 1, 4], ['8772', '0159', '12:33PM', '02:43PM', 1, 5], ['2086', '2231', '04:10PM', '06:20PM', 1, 5], ['0888', '0570', '09:42PM', '12:20AM', 1, 5]) I tried the following: sortedX = sorted(x, key=lambda k : k[-4]) #k[-4] is the first time string and it works but it doesn't respect the sublist size ordering

    Read the article

  • difference between 2 pieces Python code

    - by draw
    Hello, I'm doing an exercise as following: # B. front_x # Given a list of strings, return a list with the strings # in sorted order, except group all the strings that begin with 'x' first. # e.g. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] yields # ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'] # Hint: this can be done by making 2 lists and sorting each of them # before combining them. sample solution: def front_x(words): listX = [] listO = [] for w in words: if w.startswith('x'): listX.append(w) else: listO.append(w) listX.sort() listO.sort() return listX + listO my solution: def front_x(words): listX = [] for w in words: if w.startswith('x'): listX.append(w) words.remove(w) listX.sort() words.sort() return listX + words as I tested my solution, the result is a little weird. Here is the source code with my solution: http://dl.dropbox.com/u/559353/list1.py. You might want to try it out.

    Read the article

  • Accessing items from a dictionary using pickle efficiently in Python

    - by user248237
    I have a large dictionary mapping keys (which are strings) to objects. I pickled this large dictionary and at certain times I want to pull out only a handful of entries from it. The dictionary has usually thousands of entries total. When I load the dictionary using pickle, as follows: from cPickle import * # my dictionary from pickle, containing thousands of entries mydict = open(load('mypickle.pickle')) # accessing only handful of entries here for entry in relevant_entries: # find relevant entry value = mydict[entry] I notice that it can take up to 3-4 seconds to load the entire pickle, which I don't need, since I access only a tiny subset of the dictionary entries later on (shown above.) How can I make it so pickle only loads those entries that I have from the dictionary, to make this faster? Thanks.

    Read the article

  • convert the key in MIME encoded form in python

    - by jaysh
    this is the code : f = urllib.urlopen('http://pool.sks-keyservers.net:11371/pks/lookup?op=get&search= 0x58e9390daf8c5bf3') #Retrieve the public key from PKS data = f.read() decoded_bytes = base64.b64decode(data) print decoded_bytes i need to convert the key in MIME encoded form which is presently comes in (ascii armored) radix 64 format.for that i have to get this radix64 format in its binary form and also need to remove its header and checksum than coversion in MIME format but i didnt find any method which can do this conversion. i used the base64.b64decode method and its give me error: Traceback (most recent call last): File "RetEnc.py", line 12, in ? decoded_bytes = base64.b64decode(data) File "/usr/lib/python2.4/base64.py", line 76, in b64decode raise TypeError(msg) TypeError: Incorrect padding what to do i'didnt getting .can anybody suggest me something related to this...... thanks!!!!

    Read the article

  • Python: Regex outputs 12_34 - I need 1234

    - by Guy F-W
    So I have input coming in like: 12_34 5_6_8_2 4___3 1234 and the output I need from it is: 1234, 5682, 43, 1234 I'm currently working with r'[0-9]+[0-9_]*'.replace('_','') which (as far as I can tell) successfully rejects any input which is not a combination of numeric digits and under-scores, where the underscore cannot be the first character. However, replacing the _ with the empty string causes 12_34 to come out as 12 and 34. Is there a better method than 'replace' for this? Or could I adapt my regex to deal with this problem?

    Read the article

  • In python, what does len(list) do?

    - by nsharish
    My doubt is that if the len(list) calculates the length of the list everytime it is called or it returns the value of the builtin counter.I have a context where i need to check the length of list everytime in a loop, likelistData = [] for value in ioread(): if len(listData)=25: processlistdata() clearlistdata() listData.append(value) Should I check len(listData) every iteration, or can I have a counter for the length of the list.

    Read the article

  • printing the instance in Python

    - by kame
    Hello! With this code: class Complex: def __init__(self, realpart, imagpart): self.real = realpart self.imag = imagpart print self.real, self.imag class Circle: def __init__(self, radius): print "A circle wiht the radius", radius, "has the properties:" print "circumference =", 3.14*radius print "area =", 3.14*radius**2 I get this output: >>> Complex(3,2) 3 2 <__main__.Complex instance at 0x01412210> But why does he print the last line?

    Read the article

  • Python - open text file, but specify name when executing command

    - by Dunnolol
    I have a directory of text files that all end in the extension .txt My goal is to print the contents of the text file. I wish to be able use the wildcard *.txt to be able to specific the text file name I wish to open (I'm thinking along the lines of something like "F:\text*.txt" ?), split the lines of the text file, then print the output. Here is an example of what I want to do, but I want to be able to change "somefile" when executing my command. f = open('F:\text\somefile.txt', 'r') for line in f: print line,

    Read the article

  • Network Communication program in python

    - by lamnep
    Hi all, Basically what I'm trying to achieve is a program which allow users to connect to a each other over a network in, essentially, a chat room. What I'm currently struggling with is writing the code so that the users can connect to each other without knowing the IP-address of the computer that the other users are using or knowing the IP-address of a server. Does anyone know of a way in which I could simply have all of the users scan the IP range of my network in order to find any active 'room' and then give the user a chance to connect to it? Also, the hope is that there will be no need for a central server to run this from, rather every user will simply be connected to all other user, essentially being the server and client at the same time.

    Read the article

  • Python sort strings started with digits

    - by vlad
    I have the next list: a = ['1th Word', 'Another Word', '10th Word'] print a.sort() >>> ['10th Word', '1th Word', 'Another Word'] But I need: ['1th Word', '10th Word','Another Word'] Is there an easy way to do this? I tried: r = re.compile(r'(\d+)') def sort_by_number(s): m = r.match(s) return m.group(0) x.sort(key=sort_by_number) But some strings do not have numbers and this leads to an errors. Thanks.

    Read the article

  • More elegant way to initialize list of duplicated items in Python

    - by Claudiu
    If I want a list initialized to 5 zeroes, that's very nice and easy: [0] * 5 However if I change my code to put a more complicated data structure, like a list of zeroes: [[0]] * 5 will not work as intended, since it'll be 10 copies of the same list. I have to do: [[0] for i in xrange(5)] that feels bulky and uses a variable so sometimes I even do: [[0] for _ in " "] But then if i want a list of lists of zeros it gets uglier: [[[0] for _ in " "] for _ in " "] all this instead of what I want to do: [[[0]]*5]*5 Has anyone found an elegant way to deal with this "problem"?

    Read the article

  • Python Threading, loading one thread after another

    - by Michael
    Hi, I'm working on a media player and am able to load in a single .wav and play it. As seen in the code below. foo = wx.FileDialog(self, message="Open a .wav file...", defaultDir=os.getcwd(), defaultFile="", style=wx.FD_MULTIPLE) foo.ShowModal() queue = foo.GetPaths() self.playing_thread = threading.Thread(target=self.playFile, args=(queue[0], 'msg')) self.playing_thread.start() But the problem is, when I try to make the above code into a loop for multiple .wav files. Such that while playing_thread.isActive == True, create and .start() the thread. Then if .isActive == False, pop queue[0] and load the next .wav file. Problem is, my UI will lock up and I'll have to terminate the program. Any ideas would be appreciated.

    Read the article

  • Sending Data as Instances using Python Sockets

    - by Alice
    I'm working on the networking part of a 2 player game (similar to tetris), and I'm trying to pass the game grid from client to server and vice versa. However, when I tried using send(grid) I get a TypeError: send() argument 1 must be string or read-only buffer, not instance. Is there anyway to circumvent this, or do I have to convert my grid instance into a string and then interpret it from the other side? Thanks in advance!

    Read the article

  • replacing values in formated file with python

    - by froggy
    I have a string see attached file like that and i would like to modify it using a function Giving section name parameter name and value to set Also in case i want to modify several parameters for a same section how can i have position in file to avoid scanning x time for a same section and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question and other to pass my question an and other to pass my question d other to pass my question and other to pass my question and other to pass my question and other to pass my questionand other to pass my question and other to pass my question

    Read the article

  • Python Pandas operate on row

    - by wuha
    Hi my dataframe look like: Store,Dept,Date,Sales 1,1,2010-02-05,245 1,1,2010-02-12,449 1,1,2010-02-19,455 1,1,2010-02-26,154 1,1,2010-03-05,29 1,1,2010-03-12,239 1,1,2010-03-19,264 Simply, I need to add another column called '_id' as concatenation of Store, Dept, Date like "1_1_2010-02-05", I assume I can do it through df['id'] = df['Store'] +'' +df['Dept'] +'_'+df['Date'], but it turned out to be not. Similarly, i also need to add a new column as log of sales, I tried df['logSales'] = math.log(df['Sales']), again, it did not work.

    Read the article

  • Python references

    - by hekevintran
    Can someone explain why the example with integers results in different values for x and y and the example with the list results in x and y being the same object? x = 42 y = x x = x + 1 print x # 43 print y # 42 x = [ 1, 2, 3 ] y = x x[0] = 4 print x # [4, 2, 3] print y # [4, 2, 3] x is y # True

    Read the article

  • I need to make a multithreading program (python)

    - by Andreawu98
    import multiprocessing import time from itertools import product out_file = open("test.txt", 'w') P = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p','q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',] N = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] M = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] c = int(input("Insert the number of digits you want: ")) n = int(input("If you need number press 1: ")) m = int(input("If you need upper letters press 1: ")) i = [] if n == 1: P = P + N if m == 1: P = P + M then = time.time() def worker(): for i in product(P, repeat=c): #check every possibilities k = '' for z in range(0, c): # k = k + str(i[z]) # print each possibility in a txt without parentesis or comma out_file.write( k + '\n') # out_file.close() now = time.time() diff = str(now - then) # To see how long does it take print(diff) worker() time.sleep(10) # just to check console The code check every single possibility and print it out in a test.txt file. It works but I really can't understand how can I speed it up. I saw it use 1 core out of my quad core CPU so I thought Multi-threading might work even though I don't know how. Please help me. Sorry for my English, I am from Italy.

    Read the article

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