IRC Networks
Irc Logs Stats
Start date: 2007-09-27 02:48:27
Last update: 2008-10-24 20:19:38
Channels: 41
Logged Lines: 6230436
Size: 1822.67 MB
Powered by
Channel Info
Network: freenodeChannel: #python |
Search in www.irclog.org
Log from #python at freenode 2006-05-20
[23:13]<lxus>+what's repr() again ?
[23:14]<zjzdd>+"Return the canonical string representation of the object." (from help(repr))
[23:14]<ajn_c>+repr(o) returns o.__repr__() which is usually supposed to be something you can paste back into the interpreter and reproduce the object
[23:14]<lxus>+ok way too advance for me :-)
[23:14]<lxus>+i dont use any of those .__func__ stuff yet
[23:16]<c2zjjcs>+phus: its not too advanced
[23:19]<ajn_c>+phus: it lets you change how objects are printed (their "representation"). i.e. see the difference between how m and m2 are presented in http://rafb.net/paste/results/uqz2HA34.html
[23:20]<vgzrajg_>+What's the simplest way of converting from dec to bin in Python?
[23:21]<ajn_c>+you want a string of 1's and 0's or what?
[23:21]<vgzrajg_>+Yeah
[23:22]<dyrcrnf__>+successive divisions ?
[23:22]<dtd>+I just finished a data structures class in java and I'm trying to aquaint myself with python. If you have a moment, what's wrong with this small Stack class? http://pastebin.com/728720
[23:22]<ajn_c>+''.join([2**i & s and '1' or '0' for i in range(7)])
[23:22]<ajn_c>+where s is an int
[23:22]<ajn_c>+(up to 127 ;) )
[23:23]<vgzrajg_>+Thanks
[23:23]<yxrws>+m5m: you forgot about the difference between instances and classes.
[23:23]<dtd>+I realize stack is available as a module most likely, I'm just trying to practice & learn
[23:23]<ajn_c>+you could change the range argument to use log2(s)+1
[23:23]<yxrws>+m5m: Stack is a class, but any functions you define in it will be instance methods, so they have to take 'self' as first argument.
[23:23]<ajn_c>+where log2 = math.log(s)/math.log(2)
[23:23]<yxrws>+m5m: and you need an instance of Stack to work with. But if you store data the way you do (in a class variable), all the instances will share the data.
[23:23]<vgzrajg_>+Then how would I convert back? :P
[23:23]<dtd>+Yhg1s: hmm I tried putting self in there, and still it errors on line #8
[23:24]<zjzdd>+int('101111',2) #=> 47
[23:24]<yxrws>+m5m: yes. you need to use 'self.mylist' (but see what I said about using a class variable.)
[23:24]<vgzrajg_>+Thanks
[23:24]<yxrws>+m5m: the class/instance scope isn't implicit.
[23:24]<dtd>+ok Yhg1s, thanks
[23:25]<yxrws>+joe_k: log2 is math.log(s, 2)
[23:25]<ajn_c>+ahh, didnt know that. THanks
[23:26]<vgzrajg_>+>>> int(''.join([2**i & 15 and '1' or '0' for i in range(7)]), 2) => 120
[23:26]<vgzrajg_>+:/
[23:26]<ajn_c>+probably an endianness issue ;)
[23:26]<vgzrajg_>+You lost me :P
[23:27]<ajn_c>+the string of 1's and 0's is in least-significant-bit-first order,
[23:27]<zjzdd>+'0' and '1' are the wrong way around, i think
[23:27]<yxrws>+veracon_: joe_k's algorithm prints the binary representation of th enumber with the least significant bit first.
[23:27]<dtd>+Yhg1s: I'd rather keep the variables in the instances, not the class, does that mean I need to move them to a constructor def __init__() ?
[23:27]<c2zjjcs>+brb
[23:27]<ajn_c>+int(x,2) wants most-significant-bit-first
[23:27]<zjzdd>+oh
[23:27]<zjzdd>+oopth
[23:28]<zjzdd>+111 is 7, not 15
[23:28]<yxrws>+m5m: __init__ is actually an initializer, but yes.
[23:28]<yxrws>+veracon_: not that most-significant-bit-first is an unreasonable assumption, the decimal, octal and hexadecimal representations in Python are also most-significant-bit-first ;)
[23:29]<ajn_c>+dectobin = lambda s: ''.join([2**i & s and '1' or '0' for i in reversed(range(math.log(s,2)+1))])
[23:29]<lrrrgygy>+I would like to learn to write python scripts for XCHAT. Does anyone know of a good tutorial for that?
[23:29]<lrrrgygy>+ACTION is having trouble finding anything but the python API reference
[23:29]<lrrrgygy>+errr, XCHAT API reference
[23:29]<vgzrajg_>+I think I understand that, thanks
[23:30]<yxrws>+veracon_: or ''.join([2**i & s and '1' or '0' for i in range(math.log(s, 2), -1, -1)])
[23:31]<vgzrajg_>+I found another function too, dunno if it's more efficient
[23:31]<vgzrajg_>+But it's not lambda-able
[23:31]<yxrws>+quite possibly.
[23:31]<yxrws>+so make it a real function.
[23:31]<vgzrajg_>+Doesn't use any external libraries (i.e. math)
[23:31]<yxrws>+math is builtin.
[23:32]<vgzrajg_>+Right
[23:32]<vgzrajg_>+But no importing
[23:32]<ajn_c>+another good way is to shift bits out repeatedly until the number is zero
[23:32]<ajn_c>+with >>
[23:32]<yxrws>+if you're saving on imports, you're saving on the wrong thing :)
[23:32]<vgzrajg_>+That's what the other function does
[23:33]<2fzac2|zm>+What's faster: dict.get() and handling None or if foo in dict.keys: … ?
[23:33]<vgzrajg_>+http://deadbeefbabe.org/paste/521
[23:33]<ajn_c>+veracon_: http://rafb.net/paste/results/v5upJS81.html
[23:33]<vgzrajg_>+or if dict.has_key(foo)
[23:34]<vgzrajg_>+Hehe
[23:34]<vgzrajg_>+joe_k: that one looks pretty short (efficient?)
[23:35]<ajn_c>+what do you mean by efficient?
[23:35]<vgzrajg_>+Fast, really
[23:35]<ajn_c>+for tiny tight loop algorithms on numbers i wouldn't really use python
[23:36]<ajn_c>+and for format conversions i.e. when translating a file the IO speed will dominate
[23:36]<ajn_c>+so it doesn't matter
[23:36]<ajn_c>+use the easiest to understand code
[23:37]<gyacwqt>+what do you all suggest for outputing PDFs in pythno>
[23:37]<gyacwqt>+*python
[23:37]<ajn_c>+and if you are using a really big int, (really big), i think both those pieces of code suck because they append() a list and do str = str + str in a loop
[23:37]<c2zjjcs>+nick125: hmm, reportlab
[23:37]<ajn_c>+the list comprehension from before would be faster on those because it doesnt have to walk the linked list on every new bit
[23:38]<ajn_c>+or build a new string
[23:38]<2fzac2|zm>+nick125: I only know of reportlab
[23:38]<vgzrajg_>+Thanks, I think I've got what I need :P
[23:38]<c2zjjcs>+nick125: i havent tried it, but it seems to be good from what people say
[23:38]<gyacwqt>+I've got three weeks to build a control panel for xen, and, some form of invoicing would be needed...mmm
[23:39]<ajn_c>+geez spit it out as a csv
[23:39]<ajn_c>+import into quickbooks ;)
[23:39]<gyacwqt>+lol
[23:39]<ajn_c>+produce HTML and get firefox to print it
[23:39]<ajn_c>+(reportlab is nice though and probably does what you want)
[23:40]<gyacwqt>+first thing on the todo list: get a HTML layout done..
[23:41]<gyacwqt>+this should take a good half week or so..lol
[23:41]<c2zjjcs>+lol nick125
[23:41]<gyacwqt>+of course, since I fired the web designer, I gotta do it myself..
[23:48]<gyacwqt>+brb
[23:54]<gyacwqt>+mmm..







