Re: [Tutor] python time
spir wrote: Hello, How does python get the time in microseconds? (In other words, how would I get it if python (like some other languages) would provide time in whole seconds only?) Thank you, Denis la vita e estrany http://spir.wikidot.com/ You need to supply more information about your environment, and maybe the reason for asking. Since you don't, I'll make some guesses. If you're trying to do extremely fine delta-time measurements, there is a Pentium instruction to fetch the number of clock cycles. You'd get this in assembler language, or with _asm in C code. If you're on Windows, there is a NtQuerySystemTime() function exported by ntdll.dll. It fetches a large integer specifying the number of 100-ns intervals since some epoch time in 1601. It's been deprecated, however, in favor of GetSystemTimeAsFileTime(), available in Win2k and later, and exported from kernel32.dll There are others, but I can't find them at the moment. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] UnicodeEncodeError
OK, thanks a lot Spir and Kent for your replies. I converted element.text to str because some of the element.text were integers and these caused TypeErrors later on in the program. I don't have the program here (it's in the office) so I can't tell you the exact details. It's a search-and-replace program where users can enter a search text (or regex pattern) and a replace text. The source file is an xml file. Currently, strings with non-ascii letters still need to be inputted in unicode format, eg. u'enqu\xeate' instead of "enquête". Kinda ugly. I'll try to fix that later. Thanks again! Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~ --- On Wed, 11/25/09, Kent Johnson wrote: From: Kent Johnson Subject: Re: [Tutor] UnicodeEncodeError To: "Albert-Jan Roskam" Cc: "tutor@python.org tutor@python.org tutor@python.org" Date: Wednesday, November 25, 2009, 5:55 PM On Wed, Nov 25, 2009 at 8:44 AM, Albert-Jan Roskam wrote: Hi, I'm parsing an xml file using elementtree, but it seems to get stuck on certain non-ascii characters (for example: "ê"). I'm using Python 2.4. Here's the relevant code fragment: # CODE: for element in doc.getiterator(): try: m = re.match(search_text, str(element.text)) except UnicodeEncodeError: raise # I want to get rid of this exception. # PRINTBACK: m = re.match(search_text, str(element.text)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xea' in position 4: ordinal not in range(128) You can't convert element.text to a str because it contains non-ascii characters. Why are you converting it? re.match() will accept a unicode string as its argument. How can I get rid of this unicode encode error. I tried: s = str(element.text) s.encode("utf-8") (and then feeding it into the regex) This fails because it is the str() that won't work. To get UTF-8 use s = element.text.encode('utf-8') but I don't think this is the correct solution. The xml file is in UTF-8. Somehow I need to tell the program not to use ascii but utf-8, right? No, just pass Unicode to re.match(). Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] quick question
i am a first year student taking a python developers course. i wanted to know if from time to time in the future, is there somebody there i can speak to for support? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] quick question
Hi Travis, Welcome to the python mailing list. You have come to the right place for support and advice pertaining to python; it is what this list is about. On Thu, Nov 26, 2009 at 12:49 PM, Travis Murphy wrote: > i am a first year student taking a python developers course. i wanted to > know if from time to time in the future, is there somebody there i can speak > to for support? > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Regards, Lloyd ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] quick question
By the way, when asking a question or answering, you only ever need to send the message to tutor@python.org :) On Thu, Nov 26, 2009 at 3:29 PM, OkaMthembo wrote: > Hi Travis, > > Welcome to the python mailing list. You have come to the right place for > support and advice pertaining to python; it is what this list is about. > > > On Thu, Nov 26, 2009 at 12:49 PM, Travis Murphy wrote: > >> i am a first year student taking a python developers course. i wanted to >> know if from time to time in the future, is there somebody there i can speak >> to for support? >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> > > > -- > Regards, > Lloyd > -- Regards, Lloyd ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python time
On Wed, Nov 25, 2009 at 11:11 AM, spir wrote: > Hello, > > How does python get the time in microseconds? (In other words, how would I > get it if python (like some other languages) would provide time in whole > seconds only?) Use the source...in particular, see floattime() in timemodule.c: http://svn.python.org/view/python/branches/release31-maint/Modules/timemodule.c?view=markup Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] unicode mapping doesn't work
Hi, I want to substitute some letters with accents with theire non-accented equivalents. It should be easy, but it doesn't work. What am I doing wrong? trans = {} funnychars = u"éèêëóòôöáàâäÉÈÊËÓÒÔÖÁÀÂÄ" asciichars = "" for f, a in zip(funnychars, asciichars): trans.update({f: a}) print funnychars.translate(trans) # why doesn't this return the letters without accents? Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unicode mapping doesn't work
Albert-Jan Roskam wrote: Hi, I want to substitute some letters with accents with theire non-accented equivalents. It should be easy, but it doesn't work. What am I doing wrong? trans = {} funnychars = u"éèêëóòôöáàâäÉÈÊËÓÒÔÖÁÀÂÄ" asciichars = "" for f, a in zip(funnychars, asciichars): trans.update({f: a}) print funnychars.translate(trans) # why doesn't this return the letters without accents? Perhaps the doc should be more obvious and perhaps unicode.translate is badly designed, but: translate(...) S.translate(table) -> unicode Return a copy of the string S, where all characters have been mapped through the given translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None. Unmapped characters are left untouched. Characters mapped to None are deleted. it says "mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None" which reads as a mapping of (int) to (int, unicode, or None). your translation table is a mapping of (unicode) to (str). this works: for f, a in zip(funnychars, asciichars): trans.update({ord(f): unicode(a)}) this as well: for f, a in zip(funnychars, asciichars): trans.update({ord(f): ord(a)}) btw, you're updating the dict and creates a new dict for each character then immediately disposing it. Why not just: for f, a in zip(funnychars, asciichars): trans[ord(f)] = ord(a) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] quick question
"Travis Murphy" wrote i am a first year student taking a python developers course. i wanted to know if from time to time in the future, is there somebody there i can speak to for support? Yes, a whole mailinglist of people. The only caveat is that, as a matter of policy, we do not do homework for you. So if you are stuck on a homework problem show us what you have done, your expected approach and tell us what doesn't work or where you are stuck. We will then supply hints, pointers or corrections as appropriate. In general always tell us: - Which OS you are on - Which Python version and - Include short sample code to illustrate the problem - Include full error text Finally always use REPLY ALL in your mail tool to include the list as well as the individual to which you are replying. Otherwise enjoy the tutor mailing list. :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unicode mapping doesn't work
Thank you! Quite frankly, I didn't know about ordinals *blushes*. Also, I thought that d.update({k: v}) was equivalent to d[k] = v, but apparently it's not. So thank you twice! Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~ --- On Thu, 11/26/09, Lie Ryan wrote: From: Lie Ryan Subject: Re: [Tutor] unicode mapping doesn't work To: tutor@python.org Date: Thursday, November 26, 2009, 5:33 PM Albert-Jan Roskam wrote: > Hi, > > I want to substitute some letters with accents with theire non-accented > equivalents. It should be easy, but it doesn't work. What am I doing wrong? > > trans = {} > funnychars = u"éèêëóòôöáàâäÉÈÊËÓÒÔÖÁÀÂÄ" > asciichars = "" > for f, a in zip(funnychars, asciichars): > trans.update({f: a}) > print funnychars.translate(trans) # why doesn't this return the letters > without accents? > Perhaps the doc should be more obvious and perhaps unicode.translate is badly designed, but: translate(...) S.translate(table) -> unicode Return a copy of the string S, where all characters have been mapped through the given translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None. Unmapped characters are left untouched. Characters mapped to None are deleted. it says "mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None" which reads as a mapping of (int) to (int, unicode, or None). your translation table is a mapping of (unicode) to (str). this works: for f, a in zip(funnychars, asciichars): trans.update({ord(f): unicode(a)}) this as well: for f, a in zip(funnychars, asciichars): trans.update({ord(f): ord(a)}) btw, you're updating the dict and creates a new dict for each character then immediately disposing it. Why not just: for f, a in zip(funnychars, asciichars): trans[ord(f)] = ord(a) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unicode mapping doesn't work
On 11/27/2009 10:43 AM, The Music Guy wrote: > Next thing is, I can't see logically how the path of the discussion of > the proposal lead to the proposal being rejected. It looked like a lot > of people really liked the idea--including Guido himself--and several > examples were given about how it could be useful. The final verdict on > the matter just doesn't make logical sense in the context of the > discussions. Guido withdraws his support for the proposal due to many people declaiming that setattr, getattr, and hasattr are too rarely used to justify a new syntax (especially since nobody can agree to a syntax that looks pythonic). Many other followed Guido's lead to formally turn their "not vote"'s, +0s, and +1s to -1s for the reason. """ Guido wrote: > This seems to be the overwhelming feedback at this point, so I'm > withdrawing my support for the proposal. I hope that Ben can write up > a PEP and mark it rejected, to summarize the discussion; it's been a > useful lesson. Occasinoally, negative results are worth publishing! > > On 2/13/07, Barry Warsaw wrote: >> On Feb 13, 2007, at 7:24 PM, Greg Ewing wrote: >> > I'm still -1 on the basic idea, though, on the grounds of >> > YAGNIOE (You Aren't Going to Need It Often Enough). >> >> I can't really add much more than what's already be stated, but I >> echo Greg's sentiment. """ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] unicode mapping doesn't work
Huh?! Was this to the right place? It doesn't seem to be related to the previous posts in the thread? Confused Alan G. "Lie Ryan" wrote in message news:hen7am$4r...@ger.gmane.org... On 11/27/2009 10:43 AM, The Music Guy wrote: > Next thing is, I can't see logically how the path of the discussion of > the proposal lead to the proposal being rejected. It looked like a lot > of people really liked the idea--including Guido himself--and several > examples were given about how it could be useful. The final verdict on > the matter just doesn't make logical sense in the context of the > discussions. Guido withdraws his support for the proposal due to many people declaiming that setattr, getattr, and hasattr are too rarely used to justify a new syntax (especially since nobody can agree to a syntax that looks pythonic). Many other followed Guido's lead to formally turn their "not vote"'s, +0s, and +1s to -1s for the reason. """ Guido wrote: > This seems to be the overwhelming feedback at this point, so I'm > withdrawing my support for the proposal. I hope that Ben can write up > a PEP and mark it rejected, to summarize the discussion; it's been a > useful lesson. Occasinoally, negative results are worth publishing! > > On 2/13/07, Barry Warsaw wrote: >> On Feb 13, 2007, at 7:24 PM, Greg Ewing wrote: >> > I'm still -1 on the basic idea, though, on the grounds of >> > YAGNIOE (You Aren't Going to Need It Often Enough). >> >> I can't really add much more than what's already be stated, but I >> echo Greg's sentiment. """ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python time
Doesn't time.time return a float? >>> import time >>> help(time.time) Help on built-in function time in module time: time(...) time() -> floating point number Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them. >>> time.time() 1259288538.576565 Right? -Modulok- On 11/26/09, Kent Johnson wrote: > On Wed, Nov 25, 2009 at 11:11 AM, spir wrote: >> Hello, >> >> How does python get the time in microseconds? (In other words, how would I >> get it if python (like some other languages) would provide time in whole >> seconds only?) > > Use the source...in particular, see floattime() in timemodule.c: > http://svn.python.org/view/python/branches/release31-maint/Modules/timemodule.c?view=markup > > Kent > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python time
On Thu, Nov 26, 2009 at 9:28 PM, Modulok wrote: > Doesn't time.time return a float? time.time() > 1259288538.576565 > > Right? Yes. I'm not at all sure I understand the original question, but one plausible interpretation is, "How does python get the time to high accuracy? I want to do that in my programs." That is the question I was answering. Kent > -Modulok- > > On 11/26/09, Kent Johnson wrote: >> On Wed, Nov 25, 2009 at 11:11 AM, spir wrote: >>> Hello, >>> >>> How does python get the time in microseconds? (In other words, how would I >>> get it if python (like some other languages) would provide time in whole >>> seconds only?) >> >> Use the source...in particular, see floattime() in timemodule.c: >> http://svn.python.org/view/python/branches/release31-maint/Modules/timemodule.c?view=markup >> >> Kent >> ___ >> Tutor maillist - tu...@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] socket timeout
Hi guys, Maybe someone can point me in the right direction, since i'm not sure why i cant get the timeout to work. Admittedly i don't know much about socket programming. Im using the below code... s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #s.setdefaulttimeout(1) s.connect((proxy,port)) As the code is above, it works (with the timeout commented out), when i leave the uncomment the setdefaulttimeout, the code doesnt even seem to connect. I've played with various values (1, 5, 500 etc) The problem essentially occurs when i connect to a server where a firewall drops the packet. It seems to wait really long before moving on, i would like the timeout to kick in after 10secs or so to continue. Im also not sure if this is a good way to check if a ip,port is available. Thanks in advance stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor