| |
| |
| |
|
Comments:
<0> hi. i need to convert a file consisting of floats to a file consisting of bytes. <0> i'm experienced in c++, but i'd really like to use python for this <1> well a file of floats already is a file of bytes ... <0> basically, at the moment i can open and close files in python, and pickle stuff from/to files <0> xihr, i need to convert the files into corresponding bytes (via some linear transformation) <0> the floats, even <1> "corresponding bytes"? <1> you'll have to define the problem more clearly <1> are they floats in text format and you want to write them out as IEEE binary floats or something? <0> oh, sorry, i was unspecific <0> the floats are standard 4-byte IEEE floats <0> the input file is just a dump of those
<1> if you're asking how to read files in binary, then use the struct module <0> yeah, at the moment i'm using temp = struct.unpack('f', file.read(4)); v = temp[0] <0> it's rather inelegant but it works <0> writing the bytes is a harder problem, though <1> how is it harder <1> you're not specifying what it is you're trying to do <2> How about an example input and output <0> it's rather hard to give examples of binary data <1> if you're dealing with homogeneous data, you could also use the array module <0> i just need to convert from 4-byte floats to 1-byte ints <0> that's all <1> so what problem are you having doing that? <1> you already know about reading and writing files and the struct module ... <0> no, i only about reading files with the struct module =) <0> writing files, i don't know of <1> aFile.write(aString) <0> hmm, or perhaps file.write( struct.pack('b', v), 1 ) might work <1> without the 1 <0> hmm... ah yes, it's automatic of course <0> well, thanks for straightening my thoughts... i'll hack the thing for a while <0> yay, it's pretty much working <0> only that struct.pack('b', v) expects -128 <= v < 127 <0> -128 <= v <= 127 even <0> whereas i have 0 <= v <= 255, i.e unsigned <1> are you looking at the library documentation? http://www.python.org/doc/current/lib/module-struct.html <1> use 'B', not 'b' <0> millions of thanks... sorry, i'm just thinking aloud =) <0> well, that's enough python for one night. still, thousands of thanks to you guys, you were exceptionally helpful for ircers =) <3> I'm offended now <3> what's wrong with ircers? <1> well most IRC "help" channels are not very helpful <1> but still that wasn't a great way to sign off :-) <1> "thanks for your help, you guys didn't **** as hard as I expected" <4> lol <5> heh, gotta love when you accidently take down the wrong vlan and dont realize the office phones dropped :) <5> woops, my bad ;) <1> call it a drill <5> hehe <5> Yea <6> Hello! <7> Hello <7> is any of you familiar with the Komodo IDE? <8> I have a [] full of values. How can I get the last 4 of them? <8> I should know this, I really should. <8> arrray[-4::] is the answer <9> array[-4:] is enough <10> mornin' chaps
<8> good morning. <11> hello <1> hey <11> i switched to asynchat for my client after all <11> it was much simpler than twisted :) <1> :-) <11> although now i want to add a server to make a relay, and an example i saw used threading, is that necessary? <1> unless you already know it well, the philosophy fits well, and it supports a protocol you plan on using, Twisted is not necessarily a good solution <1> my understanding is that even a lot of the "supported" protocols are very sketchy, though I don't know that for a fact <1> nah, just use asynchronous I/O, no need for threading <11> ah, good <11> although the example there isn't very good <1> which example was this? <11> on the docs, of the http server <1> well there are non-threaded varieties too <11> well, the one on asynchat is just a simple server. i found a test_asynchat.py which showed how to use asynchat for an outgoing connection (the docs weren't clear on this), but that's the one that used threading <1> I think if you look there the threading is not really crucial to its operation, it's just so that they can fire up a thread AND test it <1> in an actual server the thread would be totally unnecessary <11> i thought so, but i don't know how to do it in a single thread <1> there's a better example in the library documentation, hold <11> ok <1> there are better examples here: http://www.nightmare.com/medusa/ <1> basically the only reason a thread is used there is that they can start the server, do one test, and then quit <11> ah, i see <11> the docs look good, thanks :) <11> by the way, how can i catch the exception when the host is unreachable? trying the self.connect doesn't work :/ <1> if you want to see a simple proxy, I wrote one I can show you <11> that'd be great, thanks <1> http://www.alcyone.com/tmp/proxy.py <1> well self.connect is definitely where the exception will come from <11> that's what i needed, thanks a lot :) <1> or are you asking how to catch exceptions? <11> no, i am trying the block, but it just spams me with "unhandled exception" <11> it doesn't run the except: block <1> you probably need the try clause at a lower level, it gets swallowed by .loop <11> ah, hmm <11> how do i do it? <1> you'd have to show me your code, not sure where the problem is <1> typically you'd do it when you create the server, so you'd catch it there before you enter the event loop <11> ok, let me paste the block <1> use a pastebin <11> yes :) <1> :-) <11> http://rafb.net/paste/results/A27vZK92.html <1> what's the exception that's being spammed? <11> "warning: unhandled exception" <1> my guess is that MUDConnection is now broken when that gets caught, so the exceptions are caused by other problems since the socket didn't connect <1> yeah but it says what the exception was <11> nope <1> scroll back up through the spamming and see what the FIRST one was <11> it just spams that until i ctrl+c <1> huh <11> hmm, let me redirect it, it's fast <11> nothing, they're all the same <11> let me print some debugging info <1> hmm
Return to
#python or Go to some related
logs:
the average american eats 84,775 #nhl nfs: command not found #goal #csharp #politics #nhl #windowsxp #stocks #beginner
|
|