os.walk and os.listdir problems python 3.0+
I've run into a bit of an issue iterating through files in python 3.0 and 3.1rc2. When it comes to a files with '\u200b' in the file name it gives the error... Traceback (most recent call last): File "ListFiles.py", line 19, in f.write("file:{0}\n".format(i)) File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 30: character maps to Code is as follows... import os f = open("dirlist.txt", 'w') for root, dirs, files in os.walk("C:\\Users\\Filter\\"): f.write("root:{0}\n".format(root)) f.write("dirs:\n") for i in dirs: f.write("dir:{0}\n".format(i)) f.write("files:\n") for i in files: f.write("file:{0}\n".format(i)) f.close() input("done") The file it's choking on happens to be a link that internet explorer created. There are two files that appear in explorer to have the same name but one actually has a zero width space ('\u200b') just before the .url extension. In playing around with this I've found several files with the same character throughout my file system. OS: Vista SP2, Language: US English. Am I doing something wrong or did I find a bug? It's worth noting that Python 2.6 just displays this character as a ? just as it appears if you type dir at the windows command prompt. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.walk and os.listdir problems python 3.0+
Thank you. That works very well when writing to a text file but what is the equivalent when writing the information to stdout using print? Sorry when I originally replied I sent it directly and it didn't go to the list. On Thu, Jun 25, 2009 at 12:57 AM, Mark Tolonen > wrote: > > "Amos Anderson" wrote in message > news:a073a9cf0906242007k5067314dn8e9d7b1c6da62...@mail.gmail.com... > > I've run into a bit of an issue iterating through files in python 3.0 and >> 3.1rc2. When it comes to a files with '\u200b' in the file name it gives >> the >> error... >> >> Traceback (most recent call last): >> File "ListFiles.py", line 19, in >> f.write("file:{0}\n".format(i)) >> File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode >> return codecs.charmap_encode(input,self.errors,encoding_table)[0] >> UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in >> position >> 30: character maps to >> >> Code is as follows... >> import os >> f = open("dirlist.txt", 'w') >> >> for root, dirs, files in os.walk("C:\\Users\\Filter\\"): >> f.write("root:{0}\n".format(root)) >> f.write("dirs:\n") >> for i in dirs: >> f.write("dir:{0}\n".format(i)) >> f.write("files:\n") >> for i in files: >> f.write("file:{0}\n".format(i)) >> f.close() >> input("done") >> >> The file it's choking on happens to be a link that internet explorer >> created. There are two files that appear in explorer to have the same name >> but one actually has a zero width space ('\u200b') just before the .url >> extension. In playing around with this I've found several files with the >> same character throughout my file system. OS: Vista SP2, Language: US >> English. >> >> Am I doing something wrong or did I find a bug? It's worth noting that >> Python 2.6 just displays this character as a ? just as it appears if you >> type dir at the windows command prompt. >> > > In Python 3.x strings default to Unicode. Unless you choose an encoding, > Python will use the default system encoding to encode the Unicode strings > into a file. On Windows, the filesystem uses Unicode and supports the full > character set, but cp1252 (on your system) is the default text file > encoding, which doesn't support zero-width space. Specify an encoding for > the output file such as UTF-8: > > f=open('blah.txt','w',encoding='utf8') >>>> f.write('\u200b') >>>> >>> 1 > >> f.close() >>>> >>> > -Mark > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: 3.2*2 is 9.6 ... or maybe it isn't?
I think what your experiencing is addressed on this page... http://docs.python.org/tutorial/floatingpoint.html ... it has to do with the binary representation of the numbers. On Thu, Jun 25, 2009 at 1:04 PM, Bojan Sudarevic wrote: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > > >>> 3.2*3 > 9.6014 > > So I became curious... > > >>> 3.21*3 > 9.629 > >>> (3.2*3)*2 > 19.203 > ... and so on ... > > After that I tried Windows version (3.1rc2), and... > > >>> 3.2*3 > 9.601 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. > > Cheers, > Bojan > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginning with Python; the right choice?
In learning most programming languages, in my experience anyway, it's easy to get overwhelmed and want to give up. Python is easy enough that you should be able to pick it to a point that it will be useful to you while still learning the more advanced features. Python generally teaches good programming practices and I can see easily moving from Python to a more advanced language. BASIC is so far removed from modern languages that, IMO, it would make it difficult to transition to a modern language like C, C++ or Java. Python.org has a tutorial that should get you going. It seems to assume some programming knowledge but I think it's clear enough that even an absolute beginner could learn from it. http://docs.python.org/tutorial/index.html I learned C++ coming from Applesoft BASIC and Tandy Coco3 BASIC. I got a Sam's Teach Yourself book to do it. I really don't recommend that approach to anybody. It was very hard for me to understand the concepts necessary to make good use of C++. If I had only known about Python. On Fri, Jun 26, 2009 at 9:22 PM, sato.ph...@gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list