« first day (1221 days earlier)      last day (3728 days later) » 

4:00 PM
Link?
 
> Quora is your best source for knowledge
I call BS.
 
Hi! I'm about to use JSON instead of XML for saving my app's config
 
I hate that site
Why do you have to log in to see more than one answer?
 
Is there a simple/usual way to encode the JSON file in order that it's not readable so easily ?
what are standard methods for storing JSON files ? gziping them ? hashing them ?
 
4:07 PM
JSON is meant to be human-readable
 
^
 
there are plenty of serialization formats that you can choose that aren't :-)
 
@roippi which one for example ?
 
def bigram_corr(line):
    words = line.split()
    for word1, word2 in zip(words[:-1], words[1:]):
        for i,j in fdist:
            if (word2==j) and (jf.levenshtein_distance(word1,i) < 4):
                word1=i
                break
                return word1
 
pickle, shelve, and friends spring to mind
 
4:09 PM
why the error word1 referenced before assignment?
 
@ThiefMaster @Ahmad Why so?
 
@Sword Where is fdist defined?
 
outside the function
 
return after break? o_O
 
Because Quora is a shitty site.
- Realnames
- No full read access for guests
- Obnoxious overlays for guests
 
4:11 PM
quora is good for opinionated stuffs
 
actually i applied this function on a dataframe object. but i was getting "NONE" in all fields. thought that it wasnt returning anything
 
Maybe in terms of content. But the site is still crap
 
except that no guest access thing
 
What ThiefMaster said @thefourtheye
 
yeah
 
4:12 PM
if you break before returning, then yes, it won't return anything
 
and without return, will it modify word1?
 
In any case, I see no reason why you would get "referenced before assignment"
I don't see anything in this code that modifies word1, so I guess not.
 
In Indian prime time, questions on SO will be very less compared to our night times. Quore is the only other site which is interesting
 
me too, i dint expect that
 
Unless levenshtein_distance modifies it. I have no way of knowing.
 
4:13 PM
levenshtein returns an int
 
@Sword may we have the traceback?
 
Basically, all I can say is "looks good to me" unless you can provide code I can copy/paste/run
 
1,2,3,4 and so on
yeah sure
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-164-0dc9d9ccd431> in <module>()
----> 1 BLR_data['bigram'] = BLR_data['no_punc'].apply(bigram_corr)
      2 BLR_data.head()

C:\Anaconda\lib\site-packages\pandas\core\series.pyc in apply(self, func, convert_dtype, args, **kwds)
   2021             values = lib.map_infer(values, lib.Timestamp)
   2022
-> 2023         mapped = lib.map_infer(values, f, convert=convert_dtype)
   2024         if len(mapped) and isinstance(mapped[0], Series):
 
The indentation in your error looks a lot different than in the code you posted
 
oi, your return is outside for loops
 
4:15 PM
without return statement it works without any error,but doesnt perform at all . i get NONE
 
Does return word1 have the same indentation as break? Or something different?
 
oh wait, i guess its working..
 
oo, neck-and-neck for 3rd place in the primaries (I know that doesn't mean anything)
 
@Basj Here's my lazy attempt at making a string unreadable:
def simple_obfuscate(message):
    return "".join(chr(ord(c) ^ 0xFF) for c in message)

print simple_obfuscate("Hello, world!")
#call a second time to reverse obfuscation
print simple_obfuscate(simple_obfuscate("Hello, world!"))
Result:
╖ÜôôÉ╙▀êÉìô¢▐
Hello, world!
 
still getting NONE :(
 
4:17 PM
Don't forget a call to .encode('rot13') :-)
 
Disclaimer: probably doesn't work well with Unicode
 
  word1=i
                break
                return word1
whats the problem with this part? without return i still get none
 
I think you may misunderstand what break does. Any code appearing after break on the same indentation level, will never execute
If you delete return word1 entirely, the program will behave identically. You may as well write return "this will never happen"
 
so how do i exit to for word1, word2 in zip(words[:-1], words[1:]): after finding the first match that satisfies levenshtein and equality?
 
I believe deleting break will do that.
 
4:23 PM
so it will automatically quit for i,j in fdist: ???
 
Yep. Once the function encounters return, it immediately stops executing. The for loop won't continue or anything.
 
because the data that appears in fdist first , is more probable to be correct. so i wouldnt want later values to override the best assignment..
 
We can observe that behavior in action in this example:
def frob():
    for i in range(10):
        print i,
        if i == 5: return

frob()
 
thank you Kevin, I may try something like this
 
Even though the loop appears to go to 10, the actual output is 0 1 2 3 4 5
This demonstrates how return can terminate a for loop early
 
4:26 PM
yes but the problem is that now i'm getting 1 word per sentence
 
I never thought websites would be this complicated...
 
Do you know what's the shortest to delete a key/value from a dict D whose value is "Hello" ?
 
del d['hello']
 
@roippi No, I want to delete d['key'] such that d['key'] == 'hello'
 
I don't know the shortest way, but here is a way: d = {key:value for key,value in d.iteritems() if value != "Hello"}
 
4:28 PM
@Kevin doesn't this recreate a copy of the dict ?
 
yes.
 
ah
if you absolutely have to do it in place
 
If you're worried about memory leaks, the garbage collector shouldn't have any problems cleaning up the original dict
 
hey martijn could u tell me what the problem is??
 
4:30 PM
for key in D:
            if D[key] == 'hello': del D[key]
Is this correct ?
 
def bigram_corr(line):
    words = line.split()
    for word1, word2 in zip(words[:-1], words[1:]):
        for i,j in fdist:
            if (word2==j) and (jf.levenshtein_distance(word1,i) < 3):
                word1=i
                return word1
 
@Basj I think modifying a dict while you iterate over it can lead to unexpected behavior.
Or is that just for lists? I forget.
 
for each sentence i only get word1 . example "cant railway station" is replaced by cant
 
@Kevin that's right for list, I already had this bug. For dict, I don't know
 
that should be fine actually
 
4:31 PM
To be completely safe, better to do it in two passes. First, generate a list of keys you wish to delete. Then, iterate through that list and delete them.
badKeys = [key for key, value in d.iteritems() if value == "Hello"]
for key in badKeys: del d[key]
 
what's your feeling @MartijnPieters ?
 
@Kevin it leads to an explicit exception.
altering a dictionary while iterating over it raises an exception. You'd have to loop over dict.keys() instead, which in Python 2 returns a list object.
 
@MartijnPieters what is the most pythonic way to delete the keys/values from a dict such that value == 'hello' ?
 
Then modifying the dictionary works.
Not use a dictionary? Use a bi-directional dictionary? Rethink your data structure?
 
@MartijnPieters ,please have a look. its a minute error.
 
4:34 PM
@MartijnPieters why not using a dictionary ? why is it bad to want to remove all items from a dict such that value ='hello' ?
 
generally d = {some comprehension that filters out things from d} is fine
if you're hyper concerned about performance you should be using a relational database anyway
 
@Sword This problem may be worthy of a full StackOverflow post. I suggest including a SSCCE, and English explanation of what "bigram corr" is, the input you're giving to the program, and expected output & actual output.
 
ohk , i'll ask a question on stackoverflow . please do check it out .
 
@roippi that's right, I think performance is not important at this stage, I'll use that
or
as suggested by @MartijnPieters,
for key in D.keys():
        if D[key] == 'hello': del D[key]
 
i guess , keys dont have duplicates..so there shouldnt be a need for a for loop. keys are unique.
 
4:38 PM
keys are unique, but values are not. You might have ten keys with a value of "hello"
 
yes
 
Hey guys quick questions about working wish JSON. I'm not entirely sure how to store data is a list would this work okay?
 
ohh sorry , i thought it was the key
 
cabbage
 
@jack I suspect those WHITE elements will need to be in quotes. Hard to say without knowing more about what you want to do.
 
4:42 PM
@jack that's not valid JSON, as github helpfully tries to tell you. You need quotes around the WHITEs
 
@MartijnPieters any recommandation for bi-directional dict ? (may be useful sometimes)
 
Ah Right I see thanks guys
 
when in doubt run it through json.dumps and/or json.loads and see if the json module knows what to do with it
 
@Basj I never used one in anger, so no.
 
The first Google result for "python bidict" looks serviceable.
 
4:46 PM
@Basj or rebuild the dictionary: {k: v for k, v in D.iteritems() if v != 'hello'}
 
@Kevin yes I read it, but I wanted to know if someone has experience with one of the proposed ways to do it
 
I think most bidicts will enforce unique values (since each value is also a key) so this whole "removing duplicate values" thing would be moot
I've never used one though so
grain o' salt
 
@roippi The bidict package supports multiple keys per value.
 
that confuses and scares me, but okay
 
@PeterVaro, this guy's question reminds me of your visual programming project.
 
4:53 PM
stackoverflow.com/questions/21860251/… heres the link to my question
 
LOL
1
A: Is there a way to create a complex polygon shape from any image in CSS for use in regions property?

markcialYou can use a image for box masking, details in this article and a sample in this link (webkit sample only) <style type="text/css"> .wrap { height:400px; width:800px; -webkit-mask-box-image:url('silhouette.png'); } </style> <div class="wrap">Large lipsum here...</div> Result : ** EDI...

edgy techs!
 
@Kevin I answered that ;)
thanks.
 
@markcial now that's what I call duck-typing
 
Sigh.
* Your question is largely opinion-based, so off-topic.
Answer: That largely comes down to opinion.
Such wonderful debating skills there.
 
it's, like, your opinion that people have opinions, man
 
5:00 PM
@roippi jajajaja pun intended :P
 
@markcial :)
 
Let me bring some more opinion to it then:
32 mins ago, by Martijn Pieters
http://stackoverflow.com/questions/21859223/custom-json-string-format-could-this‌​-be-written-better-improved?noredirect=1#comment33092498_21859223
 
opinion rendered
 
that json could be improved removing all whitespaces, it is all unnecessary bytes that doesnt need to be transfered
 
who doesn't love a good javascript uglify
 
5:11 PM
what does placing bounty on a question do? put the question at the top at the cost of rep points?
 
the ol' times of the function(p,a,c,k,e,d){} xDD
 
@Sword It gets placed on the "featured" list
Most likely attracting more attention, since answerers will get a bigger reward
 
wow awarded with badge revival!
sweeet
 
that means my rep gets transferred to others ,right?
 
@Kevin it looks like he doesn't know exactly what he really wants :)
 
5:17 PM
its night here.. my work is done. thanx kevin :)
 
work is hard ._.
 
Omg
has anyone seen the new house of cards season
 
@PeterVaro I think he wants exactly what your tkinter code did
 
now I know that, that's why I showed him my version
 
Is it open source? A link to it would probably be quite useful to him.
 
5:31 PM
unfortunately it's not, because I never finished the tkinter version, I moved to Pyglet and then pure OpenGL
the only downsides implementing this in tkinter (not to mention the lack of antialiasing and gradient, and difficult image loading) is it is really hard to separate the Model from the View and the Controller
 
Yeah, I have had some MVC frustrations with it, myself.
Oh well. I think that guy can get along fine just using Blender.
 
probably -- but I don't know how you can seperate the node editor from blender
ofc you create your own unified window arrengement:
But a full blender is still running at the background..
 
I guess that's what his comment about "too much overhead" means
 
6:14 PM
Is it a good idea ?
After weeks of annoying XML tests, now I want to go to JSON <-> dict
 
Try it out and see if you like it :-)
 
@Kevin would you use JSON ? if you need to serialize dict ?
 
Nah, I'd use pickle
Although that's a possible attack vector for hackers, so I only use it for personal projects
I'd probably use json otherwise
 
@Kevin What would be a pickle output of {'a' : 'blah', 'b' : {'myint' : 17} } ?
 
"(dp0\nS'a'\np1\nS'blah'\np2\nsS'b'\np3\n(dp4\nS'myint'\np5\nI17\nss."
 
6:20 PM
Can something that is pickled be restored into a dict, with the good types (int and str in my example) ?
or are the datatypes lost when pickle and then re-load ? @Kevin
 
It wouldn't be a very good module if it could only store objects, and not restore them!
>>> pickle.loads(pickle.dumps({'a' : 'blah', 'b' : {'myint' : 17} }))
{'a': 'blah', 'b': {'myint': 17}}
 
ok so the datatypes are always restored ? (int, str, are other common datatypes) ?
 
Yes, even user-created classes.
 
@Kevin which one is a possible attack vector : pickled files or JSON files ?
 
@Basj pickled files are. They can be made to run python code upon loading.
 
6:25 PM
@Ffisegydd What kind of ?
 
@Basj well...any kind...
 
(wayback machine link. The actual url just redirects to the author's linkedin)
 
with JSON, can I also dump / restore dicts with datatypes ?
 
The article demonstrates how it can run the command ls, but it could just as easily run rm -rf / and blank your hard drive
json wouldn't be a very good module if it could only store objects, and not restore them!
 
6:28 PM
@Kevin :) ok so JSON can also restore int, str, tuples of ints, etc. ?
 
You can find out as easily as me. All of these questions, I just look up the answer in the documentation
 
ow okay, I thought you know it already
ok I'll look there
 
I know surprisingly little ;-)
 
@Kevin :) To do a local config file for your app, would you use json ? pickle ? xml ? yaml ?
 
It's thanks to Python's thorough documentation, that I can create the illusion that I know what I'm talking about :-D
 
6:33 PM
I have difficulties to make decisions :)
:)
 
json if I want the data to be modifiable by the user, pickle if I don't.
 
ok thanks !
 
Actually, last time I did configuration, I didn't use any modules. I just kept all configurable options in a file config.py, which I then imported as necessary elsewhere
 
ok
 
The benefit being, it's easy for the user to modify. The drawback being, it's impossible to modify from within the program
 
6:58 PM
Hey mates, I have short question. I have ten variables, "item1" throught "item10", and I have a loop which has to assign values to those variables. I have never accessed variables by referencing a portion of its name plus some number or other thing, so how is that done in python?
 
The typical solution is to use a list
Ex.
items = []
for i in range(10):
    items.append(i)

print items
 
That would do it, but those values that are not touched, like item2-item10, in case only first one has value, have to be "none", but still there. If I do it that way, those ones wouldnt be "created"
 
items now contains ten elements - the numbers zero through nine. You can access individual elements with items[index]
Not quite sure what you mean. In any case, lists are allowed to contain None. Ex. items = [4, None, 8, 15, None, 16]
 
Oh, that would do it, I will reference those item1 = list[0], and so on
And populate that list with 10 items regardles of number of actual items, and "fill" the remaining number up to 10 with None, so that will solve this
Thanks Kevin! :)
Upvotes for you!
 
well, the idea is to always use lists instead of a series of variables with numbers at the end
But, uh, whatever works for you I guess! Good luck with your project
 
7:04 PM
I tend to do that, but this is a model in the db which I need to commit, so I can't really change that now (too cumbersome), so this trick shall do it. I tend to rely on lists and, my favorite, dictionaries a lot :)
But, just out of curiosity, is there a way to iterate through those variables that have number at the end? Or reference them via combination of a constant portion + the changeable part (number)?
 
The usual way is, instead of having item0, item1, item2... You instead have a single items list, and access it with items[0], items[1], items[2], etc. This way, you can also access items dynamically, ex. items[valueThatIsDeterminedAtRuntime]
There is also the evil, terrible, no good, very bad way, which is to compose the variable name using strings, ex name = "item" + str(number), and then access it from the locals function.
>>> item0 = "bluh"
>>> digit = 0
>>> locals()["item" + str(digit)]
'bluh'
 
It sure is evil :D But I'm glad this exists as well, just in case!
I will stick to the lists!
Thanks once again!
 
Good luck!
This question has a peculiar error message.
Seems like the OP is somehow entering two statements on one line of the interactive interpreter, while still having a newline between them
In his code sample, his second line doesn't have the usual >>> signifier
No idea how that's possible.
The simplest explanation is, the OP isn't pressing enter between the two statements, and is being "helpful" by altering his code sample to look like he is
 
7:32 PM
And.... Champions League is back.
 
The football thing? It's odd to me that the US is so disinterested in the sport.
Maybe there's something in the national attitude that makes us abhor ties :-D
 
My Texan mates reckoned it was because of the lack of scoring
 
It's funny, because from my point of view, American football (aka "hand-egg") is 70% commercials/commentary/shots of players standing around, and 30% gameplay
 
It's even worse when you're in the stadium - you can't wander off and make a cuppa or anything
 
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\]]]]]]
 
7:42 PM
bless you @AshwiniChaudhary
 
No, but if you drink enough beer, you'll forget that you want a cuppa :-)
 
Well, they called it beer...
 
If you drink enough beer*, you'll forget that it's not actually beer :-)
 
(Mind you, some of the Bocks were rather quite good). I was gutted that I left before the microbreweries really kicked off
@Kevin It was the general tactic
@Kevin Weren't loads of Americans annoyed at the S. African world cup? With the dodgy referee decisions?
 
Not that I heard of. But that only means, if there was an uproar, it wasn't loud enough to make the evening news or the front page of reddit
 
7:51 PM
@Kevin Which unfortunately doesn't mean squat in today's mass media - dailymail.co.uk/tvshowbiz/article-2560118/…
 
Yep, over here we get coverage of teen pop idols egging people's houses
Instead of violent unrest in Syria, or what have you
 
8:10 PM
This guy is getting a litany of name related criticism
If you try to do processing on ambiguously formatted name data, you're gonna have a bad time
insert meme image here
Seems like the OP just wants to do a one-time operation on his names list, and by manual investigation he can see that they all look "normal". So I guess it's possible to do. I just hope no one named 田中太郎 becomes one of his customers in the future :-)
 
9:13 PM
cbg all
 
cbg @JVarhol
 
Is it me, or is there alot of new peeps in the chat today
 
It's just you.
 
Wheres Jon @Ffisegydd
 
9:25 PM
Hmm new people?
 
@Ahmad I think so, but @Ffisegydd says otherwise
 
jack, Sword, and wont_compile were all new to me. The rest are familiar.
I guess three new users is fairly exceptional.
 
what about Lattyware
 
Nah, I see his peculiar lobster avatar idling in here every day
 
With JSON, is it impossible to use a tuple as key ?
import json
di = {(1,2,3): 'blah'}
print di
print json.dumps(di)
=> TypeError: keys must be a string
 
10:29 PM
Why is editing 20MB files so hard…
 
A 20MB text file?
 
yeah
 
lol what are you working on?
That's quite large for a text file
 
It’s a log
 
Ah I see
 
haha
 
I’m removing some lines from the file so I can process it with Python, and I have to wait like 10 seconds before the action I entered happened..
Oh.
And apparently Sublime Text has a problem with displaying column #18138682…
 
11:40 PM
why not limit the length of each log file, no need for one huge file
 

« first day (1221 days earlier)      last day (3728 days later) »