No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
15 Posted Topics
Re: [CODE=python] fn = 'c:\\file.txt' p = os.popen('attrib +h ' + fn) t = p.read() p.close() [/CODE] | |
Re: [CODE=python] >>> import re >>> data = '115Z2113-3-777-55789ABC7777' >>> ds = data.split('-') >>> out = '-'.join(ds[0:-1] + [re.split('[A-Z]', ds[-1])[0]]) >>> out '115Z2113-3-777-55789' [/CODE] HTH | |
Re: Maybe this will get you started: [URL="http://diveintopython.org/performance_tuning/index.html"]http://diveintopython.org/performance_tuning/index.html[/URL] HTH | |
Re: Maybe you need to do a line by line match in a loop and then line/line number shouldn't be a problem. I'm not sure how much slower it may be compared to what you're doing now but you can e.g. download a big plain-text e-book and do some tests. HTH | |
Re: If you want to be portable across *nix and windows, try something like: [CODE=python] import os ps = '/tmp/my/path'.split(os.sep) [/CODE] This will split the path into separate elements without you having to specify '/' or '\' as separator. HTH | |
Re: Without using lists: [CODE=python] #!/usr/bin/python fh = open('nd.txt', 'r') (page, nd) = fh.readline().split(',') (last, lastnd) = (page, page) print page, for i in fh: (page, nd) = i.strip().split(',') if nd == 'ND': print last if lastnd != last else "" lastnd = page print page, last = page print last … | |
Re: Nothing radical - basically worked on your original code: [CODE=python] def getChoice(bottom=False, cap=False): while True: try: choice = int(raw_input("Please enter your choice: ")) if ((bottom != False) and (choice <= bottom)): print "Choice should be greater than", bottom continue if ((cap != False) and (choice >= cap)): print "Choice should … | |
Re: You should indeed use existing/available python modules as you have many built-in functions available for exactly what you need instead of having to sift through output to do something specific. Using python modules instead of calling os-specific commands keeps your programs portable and they perform better. However, just in case … | |
Re: [CODE] April 1st, 2008 April 2nd, 2008 April 3rd, 2008 01: April 4th, 2008 02: April 5th, 2008 03: April 6th, 2008 04: April 7th, 2008 05: April 8th, 2008 06: April 9th, 2008 07: April 10th, 2008 08: April 11th, 2008 09: April 12th, 2008 10: April 13th, 2008 … | |
Re: [CODE] >>> a = input("Number: ") Number: 10 >>> b = 2 + a >>> b 12 >>> outfile = open(str(b), 'w') >>> outfile.write("Test line") >>> outfile.close() >>> quit() C:\Python>type 12 Test line [/CODE] | |
Re: Reading this it seem the requirement is to only use GUI to prompt for the password and use sudo functinality. Have you thought of calling gksu instead of sudo - gksu is a gtk frontend to sudo? i.e.: [CODE] # example # ... from os import system # ... system("gksu … | |
Re: You're expectations are incorrect. You are doing this: [CODE] test = [] mylist = [[1,2,3],[4,5,6],[7,8,9]] test.append(SuperList(mylist)) [/CODE] And are expecting this: [CODE] [[1,2,3],[4,5,6],[7,8,9]] # I want to get this, but I only get [] [/CODE] Shouldn't you be expecting: [CODE] [COLOR="Red"][[/COLOR][[1,2,3],[4,5,6],[7,8,9]][COLOR="Red"]][/COLOR] [/CODE] You are appending to an empty list, another … | |
Re: Here you go: [CODE] print reduce( lambda x,y: x+y, [int(i) for i in list(raw_input("Enter integer:"))] ) [/CODE] | |
Re: Sorry, I know awk/sed was requested, but a python solution was so easy, couldn't help to post it: [CODE] #!python (a, b) = ([], []) (i,j)=(1,1) diffchar=['.',':'] for line in open("sq.txt"): line=line.strip() if i == 1: a = list(line) elif i == 2: b = list(line) elif i == 3: … |
The End.