newbie q
how to get rid of 'for' operator in the code? import os, os.path def _test(): src = 'C:\\Documents and Settings\\Егор\\My Documents\\My Music\\' for i in [x for x in os.listdir(src) if os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']: os.remove(os.path.join(src, i)) if __name__ == '__main__': _test() -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie q
"Stephen Thorne" <[EMAIL PROTECTED]> ÑÐÐÐÑÐÐ/ÑÐÐÐÑÐÐÐ Ð ÑÐÐÐÑÑÑÐÐ: news:[EMAIL PROTECTED] On Thu, 13 Jan 2005 15:55:10 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: how to get rid of 'for' operator in the code? import os, os.path def _test(): src = 'C:\\Documents and Settings\\ÐÐÐÑ\\My Documents\\My Music\\' for i in [x for x in os.listdir(src) if os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']: os.remove(os.path.join(src, i)) if __name__ == '__main__': _test() import glob for x in glob.glob("*.m3u"): os.remove(x) i want to wipe out 'for x in []: f(x)' using map, lambda, reduce, filter and List Comprehensions [x for x in []] just don't get how to add string to all elements of list -- http://mail.python.org/mailman/listinfo/python-list
lambda
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the names of the files in a directory?
On Sat, 15 Jan 2005 15:16:02 GMT, .removethis. <"(.removethis.)kartic.krishnamurthy"@gmail.com> wrote: Sara Fwd said the following on 1/15/2005 8:10 AM: Can you guys also help me find a module that looks in a directory and print out the names of the files in there? You can use glob: >>> import glob >>> from os.path import isfile >>> print filter(isfile, glob.glob('/tmp/*')) # can use patterns (will print a list of all files in the given directory, matching the given pattern) If you want to traverse a directory tree recursively, please take a look at this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/200131 import os, os.path def get_all_files(path): if len(path) > 0: if path[-1] == ':': path = path + '\\' try: for i in os.listdir(path): j = os.path.join(path, i) if os.path.isdir(j): for ii in get_all_files(j): yield ii else: yield j except:pass for i in get_all_files('c:\\'): print i -- http://mail.python.org/mailman/listinfo/python-list
[PIL] import error
import image gives Traceback (most recent call last): File "image1.py", line 7, in ? import image ImportError: No module named image i've installed python 2.3.4 and PIL for python 2.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: [PIL] import error
On Thu, 02 Dec 2004 13:10:25 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: ho error is bad case. there must be import Image import image gives Traceback (most recent call last): File "image1.py", line 7, in ? import image ImportError: No module named image i've installed python 2.3.4 and PIL for python 2.3 -- http://mail.python.org/mailman/listinfo/python-list
os.listdir("\\\\delta\\public")
import os print os.listdir("delta\\public") outputs ['Bases', 'Docs', 'Drivers', 'Soft', '\xc7\xe0\xec\xe5\xed\xe0 \xd1\xe5\xf2\xe5\xe2\xee\xec\xf3 \xce\xea\xf0\xf3\xe6\xe5\xed\xe8\xfe', 'Games'] and import os print os.listdir("delta") outputs Traceback (most recent call last): File "C:\Documents and Settings\Егор\My Documents\Scripts\test.py", line 4, in ? print os.listdir("delta") WindowsError: [Errno 53] : 'delta/*.*' so how to get list of delta's shares? -- http://mail.python.org/mailman/listinfo/python-list
[pywin32] windows shares, was os.listdir("\\\\delta\\public")
Try grabbing the output of os.popen(r"net view \\delta") and parse it to get a list of the shares: c:\>net view \\monolith Shared resources at \\monolith Share name Type Used as Comment --- Printer Print Microsoft Office Document Image Writer Printer2Print hp psc 1310 series Printer3Print HP LaserJet 4 shared Disk I: SharedDocs Disk The command completed successfully. No doubt you can also do this much more easily with the pywin32 package, or via COM (using pywin32 or ctypes), but I'll leave that response to someone else. Or you could figure it out yourself if you are motivated enough. how to get list of shares using pywin32? -- http://mail.python.org/mailman/listinfo/python-list
os.path.islink()
hi all i want my program to ignore ntfs links, but os.path.islink() isnt work as i expect print os.path.islink('''C:\Documents and Settings\Егор\My Documents\Scripts\Antiloop\) outputs False far file manager said 'C:\Documents and Settings\Егор\My Documents\Scripts\Antiloop\' is link how to detect ntfs links? =program== import os, os.path def get_all_files(path): if len(path) > 0: if path[-1] == ':': path=path+'\\' try: for i in os.listdir(path): j = os.path.join(path, i) if os.path.isdir(j) and not os.path.islink(j): for ii in get_all_files(j): yield ii else: yield j except:pass for i in get_all_files('c:'): print i == -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.islink()
On Wed, 08 Dec 2004 10:23:13 +0100, Peter Maas <[EMAIL PROTECTED]> wrote: Egor Bolonev schrieb: far file manager said 'C:\Documents and Settings\Егор\My Documents\Scripts\Antiloop\' is link how to detect ntfs links? There are no ntfs links. What appears as a link on GUI level is nothing but a plain file with special content, so that os.path.islink() tells the truth. Windows "links" are a special Windows feature (shortcuts) and must be detected via Win32 api calls or by searching for content characteristics of shortcuts. gui folder link is a .lnk file -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.islink()
On Wed, 08 Dec 2004 20:29:27 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: gui folder link is a .lnk file i want to detect "'s" C:\Documents and Settings\Егор\My Documents>dir Том в устройстве C не имеет метки. Серийный номер тома: 386D-F630 Содержимое папки C:\Documents and Settings\Егор\My Documents 08.12.2004 20:39 . 08.12.2004 20:39 .. 08.12.2004 20:39 Antiloop 06.12.2004 20:47 My eBooks 02.12.2004 22:50 My Music 06.12.2004 23:34 My Pictures 06.12.2004 23:56 My Videos 08.12.2004 20:23 Scripts 04.12.2004 16:23 upload 16.11.2004 21:14 Virtual CD v6 16.11.2004 21:15 Virtual CDs 08.12.2004 20:36 [temp] 04.12.2004 20:11 Личное 06.12.2004 22:51 Новая папка 0 файлов 0 байт 14 папок 8 970 833 920 байт свободно -- http://mail.python.org/mailman/listinfo/python-list
threading problem
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders """ if len(path) > 0: if path[-1] == ':': path=path+'\\' try: for i in os.listdir(path): j = os.path.join(path, i) if os.path.isdir(j): for ii in get_all_files(j): yield ii if os.path.isfile(j): yield j except:pass # lock1 = threading.Lock() def run(path): for i in get_all_files(path): lock1.acquire() print i lock1.release() # for path in os.listdir('c:\\'): if os.path.isdir(os.path.join('c:\\', path)): threading.Thread(target = run, args = (os.path.join('c:\\', path))).start() else: lock1.acquire() print path lock1.release() =output= RESTART AUTOEXEC.BAT boot.iniException in thread Thread-1: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (10 given) Bootfont.bin BOOTLOG.PRV BOOTLOG.TXT BOOTSECT.DOS COMMAND.COM CONFIG.SYS DETLOG.TXT devicetable.log Exception in thread Thread-2: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (25 given) FRUNLOG.TXT Exception in thread Thread-3: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (9 given) hsf5442.sys Exception in thread Thread-4: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (10 given) IO.SYS LOGO.SYS MSDOS.--- MSDOS.SYS netldx.vxd NETLOG.TXT NHL2005.mdf NHL2005.mds ntdetect.com ntldr Exception in thread Thread-5: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (9 given) PAGEFILE.SYS Exception in thread Thread-6: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (16 given) Exception in thread Thread-7: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (11 given) Exception in thread Thread-8: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (11 given) Exception in thread Thread-9: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (11 given) rew.ini Exception in thread Thread-10: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (10 given) SETUPLOG.TXT SUHDLOG.DAT Exception in thread Thread-11: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) TypeError: run() takes exactly 1 argument (28 given) SYSTEM.1ST Exception in thread Thread-12: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in r
Re: threading problem
On Fri, 10 Dec 2004 00:12:16 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote: I think if you change the call to look like: threading.Thread(target=run, args=(os.path.join('c:\\', path),)).start() oh i see now. thanks s='sdgdfgdfg' s == (s) True s == (s,) False -- http://mail.python.org/mailman/listinfo/python-list
Re: newsgroups
On Sun, 12 Dec 2004 14:57:50 -0500, Francis Lavoie <[EMAIL PROTECTED]> wrote: Do we need a special account or something to use the newsgroup instead of the mailling list? why we use newsgroup instead of mailing list? -- http://mail.python.org/mailman/listinfo/python-list
[dictionary] how to get key by item
saluton al ciuj i know how to get item by key == dict = {10 : 50, 2 : 12, 4 : 43} print dict[2] 12 but i wonder how to get key by item print dict[12] 2 == is there a more fast way than that one (my dictionary is really big) == dict = {10 : 50, 2 : 12, 4 : 43} item = 12 for key in dict.keys(): if dict[key] == item: print key break == -- http://mail.python.org/mailman/listinfo/python-list
Re: list IndexError
On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote: l ['a', 'b', 'c', 'd', 'e'] for x in l[:]: if x == 'd': l.remove('d'); l ['a', 'b', 'c', 'e'] This code is so clean and looks very healthy. Python will live a long way because its a cute language. imho the code is very unhealthy, i would write l = ['a', 'b', 'c', 'd', 'e'] l.remove('d') print l btw what are you using ';' for -- http://mail.python.org/mailman/listinfo/python-list
[PIL] is there a downloadable docs for PIL
sometimes a have no internet access, but want to work :) -- http://mail.python.org/mailman/listinfo/python-list
Re: [PIL] is there a downloadable docs for PIL
On Fri, 24 Dec 2004 10:00:39 +0100, Michel Claveau - abstraction meta-galactique non triviale en fuite perpetuelle. <[EMAIL PROTECTED]> wrote: Is that ? http://www.pythonware.com/products/pil/pil-handbook.pdf yes. thanks -- http://mail.python.org/mailman/listinfo/python-list
FutureWarning
= C:\Documents and Settings\┼уюЁ\My Documents\Scripts\octopus_eye\1\oct_eye_db.py: 213: FutureWarning: hex()/oct() of negative int will return a signed string in P ython 2.4 and up if hex(binascii.crc32(data))[0] == '-': = hex() will return numbers like -0xa1? -- http://mail.python.org/mailman/listinfo/python-list