« first day (962 days earlier)      last day (3976 days later) » 

12:11 AM
bed time - laters
 
Zac
12:54 AM
If I have a server socket connected to a client and the client closes how do I gracefully handle it on the server side ?
currently my python server socket just breaks with a socket.error: [Errno 10053] An established connection was aborted by the software in your host machine
 
user1786283
1:35 AM
@Zac Just taking a guess, you can send a signal back to the server to close the connection. But it might not be that efficient.
 
5:24 AM
Hello! I want to make an array of images. Currently I'm doing this:
`for a in range(0,BlockMax):`
`wholeimage[a] = Image.new("RGB",[128,128])`
However, python is saying that wholeimage is undefined. How do I initialise wholeimage to be an array? Is there a better way of doing this?
 
5:34 AM
wholeimage = [Image.new("RGB", [128, 128]) for _ in range(BlockMax)]
List comprehensions are better than explicit loops if they're that simple.
 
Otherwise you'd have to do wholeimage = [] outside of your loop and wholeimage.append(Image.new("RGB", [128, 128])) inside. Lists don't automatically resize when you assign to an index that doesn't exist yet.
Hello.
 
Hi @Cairnarvon, I tried using wholeimage = [] and appending a copy of one blank image that I'd made Blockmax times in a loop, would that work? It seems like all of the images are the same, but I don't know if that's from this or something else in my code
 
Yes, though it will be slower than the list comprehension.
And be aware that if they're all the same reference, changing one will change everything in your list.
 
@Cairnarvon, I thought that making a copy would fix that?
 
5:42 AM
Well, yes, if you're really making a copy.
 
I had wholeimage.append(copy.copy(blankimage));
is that really making a copy, or are all my list elements still going to be pointing to the same thing?
 
I don't know that copy.copy can handle PIL images.
 
ah, you are correct. blankimage.copy() worked
 
Look at the repr representation in the shell. It should look something like <PIL.Image.Image image mode=RGB size=128x128 at 0x7F8D342C5248>. If that last number is different for all of them, you're good.
 
@Cairnarvon, thanks.
So when I create a for loop and am appending the same image multiple times, python is actually just repeatedly appending a pointer to that image instead of creating multiple instances
 
5:48 AM
Yes. Python (sort of) passes everything by reference rather than by value.
 
that explains a lot
 
 
1 hour later…
6:52 AM
cabbage
 
7:14 AM
Cabbage Morning Folks.
 
cabbage all
 
7:32 AM
would it be wise to place several functions in different files then have another file call them all in a specific order?
 
What would be the reason for this?
 
My inability to merge several functiones under one class
 
Then resolve this problem instead of looking for other solutions.
Where are you having the trouble?
You can use pastebin to post a large chunk of code.
 
hmm alright hold up
each of the functions on their own work
 
Feels as if this class could be called fileutils.py or something
instead of "final".
 
7:38 AM
I forgot to update that it's supposed to be "Main"
 
okay, well, my statement still stands :)
 
as in, the class should share the file's name?
 
call it fileutils.py - but be careful, calling stuff "util" always implies more stuff than it might do. (or that's what I've come to realize though).
Also line 30 in compare you're using eval(), you're aware of why that's bad right?
 
Iv'e heard people saying it's bad but i can't figure out why exactly. I can't find some link explaining why it is so
 
7:44 AM
Well these reasons do not really concern me at the moment
There is almost always a better way to do it
Very dangerous and insecure
Makes debugging difficult
Slow
But thanks for the links i'll read more into them later
 
yeah, no worries.
 
First thing is first.
All class methods/functions need to have self as the first argument
and you never pass it, since it is implied.
I told you to read about how classes work in Python - it seems you did not.
 
i'm sorry i only had les than a day and i'm already knee deep into this code! i promise you that i will very soon though ;)
how do you call a function from within a class using the shell though?
 
Hi anyone here
 
Yup and no - just going out
 
7:59 AM
cabbage
 
Quickly
-1
A: Remove brackets from list in Python

HaidroIf you're dealing with small lists: >>> sum([['a'],['b'],['c']], []) ['a', 'b', 'c'] But as the list gets larger, the performance time gets slower. So take this into consideration :)

Why was this downvoted?
 
@MaxPower I am rewriting your class. Because I am awesome and bored.
 
@Haidro I can only guess that it's because it's somewhat an abuse of sum
 
Worst reason ever....
It's correct though...
 
@InbarRose ;)
 
8:01 AM
Test
Oh well. I'm sad now :'(. C ya everyone
Ooh, thanks for the +1 whoever :)
 
8:29 AM
 
Wow
Alright i need some time to evaluate :P
 
Thank you!
 
You are welcome. I hope it is what you wanted - I have not tested it at all, and I just copied your logic assuming it was right.
Though I tweaked it to be faster/smoother/nicer :)
 
:D
it left a good opportunity to refactor as well! Great work Inbar! :)
 
8:32 AM
One noticeable change - I do append '.txt' to each file. Since it is convention that when you pass a file_path as an argument, it usually includes the full path to the file and it is not clear that you should do it without extensions.
@limelights Yes - I made it very clean :)
@MaxPower what do you say?
 
It's hard for me to grasp all of this code that fast
 
I see...
 
I need to understand the workflow so i can provide just two files and an output folder at the start... Where the output folder could also be named as the two initial files combined
It will take me time
 
I don't understand anything of what you just said.
 
I need to understand the workflow
 
8:45 AM
Okay - see, the terminology that you are using confuses me.
The workflow is still the same.
It is your workflow
I just modified the code.
Everything should still function exactly the same.
 
earlier i would type "load('x','y')"
I assume it's different now but i'm not sure why you assign "None" to file_in/out
 
@Haidro Using sum for non-numbers is not Pythonic, and it's allowed more-or-less only because it's hard to forbid
(like sum() rejects strings)
 
@InbarRose how do i assign what file_in / file_out would be? in the compare function i can manualy edit the output_file='my_file_compare_results.txt' for an example
 
what do you mean "manually edit"
 
9:00 AM
as in, editing the code itself
 
this is a Python module, you run it and assing a variable to the class. then you call that variable.
You don't need to manually edit anything
You simply call the class with the arguments you want.
Look, lets say you want to run the compare?
So first you create a class instance.
c = my_file_utils()
then, you do the compare
c.compare(first_file='', second_file='')
Or
if you already have f1 and f2 set.
c.compare()
And if you want to modify the output location....
c.compare('OUTPUT')
if you want your own output, and new files...
c.compare('OUTPUT', first_file='', second_file='')
or even without key-word-arguments:
c.compare('OUTPUT', 'f1', 'f2')
 
Alright, thanks.
 
cabbage
 
cabbage
 
Cabbage.
rbrb
 
9:18 AM
would this be the right usage? c.compare(first_file='180.txt', second_file='181.txt')
or this: c.compare('180.txt','181.txt')
c.compare('final', first_file='180.txt', second_file='181.txt')
returns no first_file specified, and none pre-set
 
@MaxPower: I missed the context, but what does your code try to do exactly?
can you summarize it?
 
I dont see why this would'nt work either c.load(file_in='hw1.txt', file_out='out.txt')
oh it's something Inbar helped me with
I'm trying to instantiate a class and then call a function
 
well, before that
what's the actual goal?
you don't necessarily need a class
(it doesn't look like you do)
 
Well its mainly load, compare, finalize
 
i've seen the code, but can you summarize it to a sentence?
 
9:28 AM
load: load up a file -> manipulate content -> write to a new file
 
define "manipulate content"
 
MaxPower it's supposed to be c.compare("180.txt", "181.txt")
 
Is your actual goal the manipulation, or learning more about file I/O, or what?
 
@limelights it still gives me the error
 
wat does it say? no output?
 
9:30 AM
ValueError: no first_file specified, and none pre-set
i appreciate the help guys but i have to get going for lunch
i'll continue later ;)
 
yeah, you missed this step probably utils = my_file_utils(file1, file2)
then after that step you can do utils.load(180, 181)
there is some refactoring to be done with your newer file i think
as inbar said, it had not been tested
 
9:44 AM
Yeah sorry, Small mistake, I forgot a small condition in the value checks. I will make the change and put it back up.
 
10:04 AM
I am bored. And hungry.
:(
I am at work running the most boring tests imaginable .... god, make it stop :P
 
Zac
morning
question time
0
Q: Python sockets how to handle the client closing unexpectedly

ZacMy python socket server listens and then connects to a client that will then send a indeterminate number of strings from a user. The client may then close or lose connection to the server. This causes an error. [Errno 10053] An established connection was aborted by the software in your host mac...

 
Morning.
 
Zac
Once you've done that one, I need to work out how to make the listening part non blocking
I've tried using threads but it is killing my simple little brain
 
"you've"..?
 
10:08 AM
@Zac Basically - anytime the connection is not working, it should be caught by an exception handler, and then you just run the connect method and try the action again.
 
Can I ask you a stupid question?
 
Zac
I've done exception handling in java before but not python
 
@O0oO0oOO0ooO If you must.
 
yeah
 
Zac, mostly the same principle
 
Zac
10:09 AM
... @O0oO0oOO0ooO maybe you already have
 
I have 8 bit data like 1000 0001
and it is 129 in bytes
I am working on a crap language that I cannot figure out how to stream bytes over socket
but it already has API to stream String
I need to convert 129 into UTF-8 format string but how?
Which encoding is suitable for this?
 
@Zac: you'll probably want to look at Twisted
@O0oO0oOO0ooO What language?
 
It's hard to explain but a language derived from Ocaml (built on top of it)
 
and what does the receiver expect?
 
value 129
 
10:13 AM
it's no use sending UTF-8 to an that expects a 129 octet
to a receiver, even
 
one more question! python string format precision: what is the number after the decimal? like: %(threadName)-12.12s
 
@Raskol just the number of digits to include after the decimal in the formatted string
 
@PietDelport In Java
Receiver successfully accepts result from following code
 
Zac
Twisted ?
 
@Raskol check pydoc FORMATTING
 
10:14 AM
frame[0] = (bytes) 129;
 
kk thank you sir. @PietDelport
 
println(frame[0]); //-127
 
@O0oO0oOO0ooO You'll need to figure out how to send raw bytes from the sending language
 
output.write(frame); //accepts
dang
it
 
10:16 AM
sending UTF-8 isn't the same thing
 
damn
 
UTF-8 lets you encode and decode 129 as a Unicode codepoint, but over the wire, it will be encoded as two bytes.
 
yeah
because 128 is the maximum value
titty balls
 
any language that lets you use sockets should give you a way to send bytes
 
I wonder how Java sends that byte value then
@PietDelport yo
Can I ask you a question?
 
10:21 AM
@O0oO0oOO0ooO same way it receives it, pretty much
 
So 1000 0001 is what I originally have
 
@O0oO0oOO0ooO 128 is not the maximum value of one byte.
A bytes 'value' goes from 0-255, it has 256 possible states.
 
Yeah, sorry
I mean 0-255. But the problem is
 
@O0oO0oOO0ooO don't ask to ask, just ask :)
 
if I want to send a string version of that byte value, which encoding do I need to use for it
 
10:24 AM
You are complicating things needlessly
 
@O0oO0oOO0ooO You don't use text encodings for binary data.
 
I know
 
@O0oO0oOO0ooO Encodings are just how you translate from logical text (Unicode, generally) and binary data
 
>>> chr(127)
'\x7f'
>>> ord('\x7f')
127
 
It would be easier if I could send integers at least
 
10:27 AM
You can....
 
so I can just stream binary
 
I think you need to stop asking questions, and start reading documentation.
 
it would help a lot if you would tell us what language you're trying to do this in :P
 
in that case, I need to implement them in compiler
problem is my teacher seems to hate me configuring his compiler
=D
 
Zac
I added a try: except: around my server conn.sendall(message) to try to capture the error when the client was unexpectidly closed but it didn't work
I still get Errno 10054 an exsisting connection was forcibly closed by the remote host
 
10:30 AM
well, you should do:
except Exception as exc:
    print exc # or something.
That will help you understand the error.
Then when you know what error it is that you get when the connection is down.. lets say "ConnectionError" for arguments sake.. then you change your except to this:

except ConnectionErro as con_err:
reconnect()
resend() # or something like this?
 
damn
 
That is a very informative message.
 
I was so happy because my prototype code in Java worked well
but I cannot simply translate that in to this stupid language (Ocaml variation)
 
@O0oO0oOO0ooO the language must have an API for it
 
Hmm, right
BTW, I do not understand the people who are so sensitive about hearing movie spoilers
I mean, why do they get all-upset and over react to spoilers?
 
10:37 AM
@InbarRose Oh i see
 
I told my friend Stark's family gets murdered in episode 9 and he become so mad at me.
 
lol
 
cuz spoilers... spoil your experience
;)
But damn i was really surprised by episode 9
 
me 2
 
I have read the books, years ago, so for the it is just silly.
 
10:40 AM
Do you know who is going to be the next lord of Winterfell?
 
It is like someone telling you that Darth Vader is Lukes father and you not knowing...
I do not spoil things for others.
If you want to know, read the books.
Or wait.
 
Not really in this case. It's like
when a king dies, his son or brother becomes the King
so it is not really a spoiler
 
I do have to say though - that the scene of the Red Wedding (that is what it is going to be called) Was done very well, albeit not like the books at all.
 
I think I know what you are talking about
 
In that case, at this stage in the TV show - the oldest living Stark heir is Brandon (Bran)
Please do not swear.
 
10:43 AM
@O0oO0oOO0ooO no spoilers please
 
1 message moved to Trash can
1 message moved to Trash can
Stop swearing./
 
As you have noticed from MaxPower, people are so sensitive about spoilers.
 
So stop offending them.
 
Why would people not be sensitive about spoilers?
If a person is immersed in a plot of some book / movie or whatever... He will be sensitive about it being spoiled
The need to ruin it for others is selfish and childish
 
If you can pause the whole world (except you and resources to survive) so everyone is completely concreted then what would you do?
 
10:53 AM
@O0oO0oOO0ooO I think you are losing the point here.
 
I don't get that analogy
 
This is not a philosophical discussion, it is quite clear what the issue is. And it is quite obvious that you are just going to find some clever and obnoxious way to avoid "being in the wrong" But no one is accusing you of that. Just don't give out spoilers, that is the bottom line.
 
yeah, it's really that simple :D
 
You have two choices @O0oO0oOO0ooO . Either say "Okay, I will not give out spoilers" and mean it. Or leave the chat room one way or another.
 
Okay, I will not give out spoilers. In addition to that, I won't swear
 
10:56 AM
Wonderful, thank you for your compliance :)
Don't have to exaggerate, it only serves to make yourself out as sarcastic.
Or worse, apathetic.
 
I am not pathetic, AUGH!
 
I never said pathetic, I said apathetic. It is a different word completely.
 
http://www.thefreedictionary.com/apathetic
1. Feeling or showing a lack of interest or concern; indifferent.
2. Feeling or showing little or no emotion; unresponsive.
 
Sorry, I did not see the 'a' there
Nice, anyway. I do not want to fix my teacher's compiler any-more.
I am sick of it, He should have build his compiler with Python then students would not suffer so much
I figured there are 3 types of VIM and Vi users
1 is people who want a quick access and make some change to a source file
2 is people who really enjoys vim features and they are good at it
3 is people who use vim and vi during classes (to show off) while they do not even know how to install syntax highlighting plugin
 
11:08 AM
@InbarRose the load function outputs line in this format "{106,:['16,', '28],', '3,', '[32,']}" which seems kinda odd. Is it intentional?
This was the original output format of the initial load function "{16:[3, [-7, 87, 20, 32], 3, [-7, 87, 20, 32]]}"
you took away this line "frame_rects[frame].append(rect)"
Oh wait scratch that
sorry my bad
 
That is okay.
 
But it still does not handle the ID's i had in the original code i posted
which are needed to determine the "final" function's output which are the files called after each ID
 
what?
You never used the id's except to hold the dictionary together, and you don't need that dictionary anymore.
 
No i actually did use the id's. Each file in the final output was named after the unique id
 
11:17 AM
Which you still have...
 
let me double check
 
@InbarRose Shh. I upvoted
 
Oh, welcome back :P
What is un-pythonic about it?
 
lambdas screams
Nah, it's just the fact that a more simple solution could have been achieved :p
Actually, I knida take that back
It looks sexy
 
@InbarRose yes you are obviously right again, sorry for the confusion. Though the contents of each file is not accurate. The first value is not the minimum frame but a different value from the original input which i don't need
 
11:21 AM
Thanks. And how about now?
 
LOL brilliant
 
@MaxPower It uses your logic, so that is your problem to fix. Not mine :)
 
@InbarRose i'm aware of that but you did change a couple of things relating to how you iterate over the lines. That's where i'm trying to find the difference
 
@Haidro takes a bow
    with open(file_in) as fin:
        lines = (line.split() for line in fin)
        for k, g in groupby(lines, itemgetter(0)):
            fst = next(g)
            lst = next(iter(deque(g, 1)), fst)

            with open(dir_out + '/final_{}.txt'.format(k), 'w') as fout:
                fout.write('{} {}'.format(fst[1], lst[2]))
I am not sure exactly what your logic there is.
So I just copied it.
But I am 100% certain there is a nicer way to do that.
 
At least you used with :P
 
11:24 AM
Especially since you are advancing the iterator from within the loop.
 
what does signed and unsigned value mean? what are the usecases in python? (I just read those somewhere related to python, and I don't understand these terms..)
 
signed has negative values, but can only go to half the range on either side, whie unsigned is only positive, but can go much higher than signed
eg 8-bit signed would be from -128 to 127
whereas unsigned would be from 0 to 255
 
Hai @Volatility
 
Cabbage
 
@InbarRose How is it possible that it returns "no second_file specified, and none pre-set" when i type"c.compare('hw1.txt', 'hw2.txt')"
 
11:43 AM
@Volatility thanks, now I got it!
I mean melon.
And does the interpreter choose which one to use, or I have to?
 
Not sure how it works, but you don't choose
 
Arg, anyone have a link to that pastebin
 
from inbar'+
 
pastebin.com/z7zQqzCw
 
Thanks @MaxPower
 
11:48 AM
@Haidro np, not sure why it didnt count as a hyperlink
 
OMG YOU'RE NOT YOUR
 
@Volatility OK, loud and clear. Melon.
 
@MaxPower Probably needed the http://
 
Hey, did it get unpinned?
 
11:49 AM
Looks like it
I don't think I starred it, so I will
 
starred what?
Yesterday I posted a link to that pastebin to shamelessly get closer to an Outspoken badge (see right)
 
The pastebin link of fruit
 
Although, maybe my link isn't as easy to recognize since it doesn't have the telling z7zQqzCw in it.
 
11:56 AM
matty :)
 
how is the question off topic?
 
I was refeerring to my comment
 
@Haidro -- You might want to edit the comment clarifying it.
 
I thought you were saying the question was off topic as well.
 
11:57 AM
Oh, sorry guys
@akkatracker It's Terry :)
 
no problem, Black Eyed Peas like that happen sometimes
 
There's a teacher at my school called Terry ;)
 
What a great name
 

« first day (962 days earlier)      last day (3976 days later) »