« first day (1639 days earlier)      last day (3308 days later) » 

2:02 AM
guys
Why do I get an error when I try to import a module from other module within a same package?
I have a package called "articles" and I have forms and views modules in it
I am trying to import some class of forms module from views like

from forms import ArticleForm
but it does not recognise forms module
 
@EnglishMaster impossible to tell without seeing your package structure. Make a question and list it all out there.
 
Ok, I'll just take a screenshot and show u
give me a sec
 
Probably better to write it out as text in a question
 
wait lol
 
C:.
└───battleship
    │   board.py
    │   ships.py
    │   __init__.py
    │
    └───tests
            test_board.py
            test_ships.py
an example of one of my packages
 
2:13 AM
yeah
let's say I want to import a class in test_board from test_ships
How would you declare an import in test_ships.py?
 
@EnglishMaster: don't you know by now that if you are going to ask questions here, you need to provide proper context?
 
from test_board import crap?
 
@AdamSmith: don't let EnglishMaster make you his answer slave, by the way.
 
hey, why are you so mean to me, mate
 
@EnglishMaster from battleship.tests.test_board import foo
or from .test_board import foo if you're using relative imports (yuck)
although if you have to do that, you should probably re-evaluate how you're laying out your classes.
 
2:17 AM
from .test_board import foo works
thx mate
@MartijnPieters You mad brah?
 
Meh it'll work until you modify your structure, or call it from a different place, or take it out of the package, or....
Relative imports are nasty.
 
@AdamSmith I think it will always work
 
@EnglishMaster Don't brah me please. You've been told about help vampirism before and asked to stop.
 
I'm working on a Django project and those modules are inside of an app
so no matter where I move it, it is going to work
 
I'm leaving it up to Adam here, but don't you start playing 'funny'.
 
2:22 AM
k mate
 
The only reason I answered is because he seemed to have a straightforward question and was able to utilize my example formatting
Although every time I do tree on my Windows box it reminds me how much I prefer tree on *nix
 
@AdamSmith there have been episodes of continued pestering with questions without prior research and effort.
 
Don't be too concerned about Martjin, I'll calm him down
 
@MartijnPieters ah. I don't know this guy so I didn't know
@EnglishMaster I do know Martijn, so...
 
2:23 AM
Together with highly inappropriate behaviour towards other room members, means he's on warning.
@EnglishMaster roight, good luck with that.
 
How goes the campaign, @MartijnPieters?
 
@AdamSmith I'm not sure there is much campaining.
So far so good.
 
What, no babies to kiss? No palms to grease? I thought this was politics.
 
@AdamSmith I've offered to show pictures of me kissing babies, but was told my own kids don't count.
 
"And a loving father! Such an important quality in a moderator. Give the man a hand -- and a diamond!"
 
2:39 AM
I feel like I've been stuck in a rut lately. Never felt anything like "writer's block" while programming, but creatively I'm just sapped. Hate this feeling =/
Normally I go learn something new to bump myself out of it, but nothing's really standing out to me right now.
 
Two dupes of my top-voted answer within 40 minutes.
 
3:39 AM
What is this weird picture that keeps getting flagged as inappropriate? Like a kind of funhouse picture of a man's face. Is this some kind of veiled goetse and I'm too dim (or lucky) to figure it out?
 
4:20 AM
cbg
 
4:39 AM
I see what you're saying; but is there official docs on this behavior? I've always wonders why I see (x,); and this seems to definitely have something to do with it. — josten 13 mins ago
 
cbg
 
postimg.org/image/yw3nnnh51 hey guys, for a function like this, where both frequency and length matters, would you store the strings in a dictionary
btw what's cbg? aha
 
@Roger Check out sopython.com/salad
For the defn of cbg
 
:O
lol cool
 
@Roger looks like you need the Levenshtein difference
there's lots of google-able material on that.
 
4:51 AM
@Adam beat me to it
:)
 
oh wait
I'm wrong
 
It is that
 
because this question is irrespective of order
nearagram('apple', 'ppale') == 0
 
Huh?
 
that sounds a little complicated as I'm doing a beginners tutorial
levenshtein difference
 
4:52 AM
@AdamSmith Where does it mention that?
 
"note that the ordering of the letters in the respective words doesn't matter"
 
Levenshtein difference is how many mutations it takes from string a -> string b
 
@Roger 't would have been better if you had posted text instead of image
 
it is levenstein distance not difference :D, belongs to the category of algorithms called edit distances
 
4:53 AM
pfft
shush Antti :)
 
There are a few extensions of Levensteins <whateva> that consider order
I had answered a question on that
 
But it sounds interesting to solve, lemme try it
 
this question stackoverflow.com/questions/29585910/… was actually more interesting than it looked - the exception in this particular case is really unhelpful and I do not understand why does it happen
 
I feel like we're being nerd sniped into doing his homework :)
 
4:55 AM
nah it's not homework
grok tutorial
 
but he's just askin tips and not code
So not bein tricked :)
 
yea, a few tips would be awesome
 
def nearagram(a, b):
    c_a, c_b = map(lambda s: collections.Counter(set(s)), (a,b))
    return sum(abs(c_a.get(ch, 0)-c_b.get(ch, 0)) for ch in set(c_a.keys()).union(set(c_b.keys())))
maybe?
untested and probably have missing parens or something
 
@Roger You've gotta clarify the level of a beginners tutorial
 
lol :D
beginner in python maybe not programming?
 
4:58 AM
Can we suggest usin libraries?
 
Never heard of that library stuff
 
a certain Levenshtein library comes to mind, even though the maintainer is a prick
 
hmm no mine doesn't work. Not sure why yet.
oh because I'm dumb
that's why.
 
5:02 AM
sets!
Not the way
 
I was trying with dictionaries
 
there we go
def nearagram(a, b):
    c_a, c_b = map(collections.Counter, (a,b))
    return sum(abs(c_a.get(ch, 0)-c_b.get(ch, 0)) for ch in set(c_a.keys()).union(set(c_b.keys())))
 
lists are the best. I think I cracked it
Oh! Adam's on it
Adam's alwayz the first
Even on earth
 
passes all the test cases in the assignment :P
now Bhargav can explain it ;)
 
what is that collection.counter stuff
 
5:04 AM
magic!
 
I'm not sure if I'm supposed to use them
 
collections.Counter
 
if you don't use collections.Counter you can build one yourself.
 
you can always roll your own...
but it'd be just stupid :D
 
def counter(iterable):
    d = {}
    for el in iterable:
        d.setdefault(el, 0) += 1
    return d
 
5:04 AM
collections.Counter is not an algorithm,
 
Hey Adam, have ya typed the test cases? Just post it here, damn lazy to type them out
 
it is just a shorthand behaviour on top of a dictionary
 
test_cases = [('apple','papal',2), ('apple','app', 2), ('apple', 'aaa', 6), ('a', 'apple', 4)]
demonstrating collections.Counter:
In [23]: from collections import Counter

In [24]: some_string = "abccdef"

In [25]: c = Counter(some_string)

In [26]: c
Out[26]: Counter({'c': 2, 'a': 1, 'e': 1, 'd': 1, 'f': 1, 'b': 1})
works on any iterable
you get a dict that looks like {el: iterable.count(el) for el in iterable}
 
I'm such a newbie, I really don't understand most of this stuff
 
That's okay -- we don't bite. Where'd you get lost?
 
5:09 AM
.setdefault(el, 0)
 
oh sorry
dict.setdefault is a method that does two things
the first being d[first_arg]
the second being if first_arg not in d: d[first_arg] = second_arg; return first_arg
 
oh
 
d = {'a':1, 'b':1}
d.setdefault('a', 0) # returns 1
d.setdefault('c', 0) # returns 0, and sets d['c'] = 0
d == {'a':1, 'b':1, 'c':0} # True
 
Thinking of writing a very beginner stuff, but can't think of a way without using collections
Phew
So dependent on collections
:(
 
The first two libraries any beginner should learn is collections and itertools
Oh the time I could have saved had I spent more time digging into itertools earlier....
 
5:14 AM
sorry internet disconnected
 
cbg
 
Phew finally a way
def nearagram(a,b):
    la = list(a)
    lb = list(b)
    for i in a:
    	if i in lb: lb.remove(i)
    for i in b:
    	if i in la: la.remove(i)
    return len(la+lb)
The timing would suck
 
No I don't think that will work
 
what I'm trying to do is store the letters as keys and the frequencies as values in dictionaries, and for when the keys are the same a +=1 and if the frequencies of the keys are not the same a = a + 1 + abs(value of frequency1 - value of frequency2) but I can't seem to construct that
 
Works for these cases
Used assert on your list
:D
 
5:18 AM
hmm maybe I'm wrong
just LOOKS ugly haha :D
 
Srsly!
Used all my brains not to use libraries :(
 
@Roger that's basically what my function does.
 
lol it's too advanced for my understanding
I'll check yours out@BhargavRao
 
so break it down into pieces and understand it :D
 
@Roger But note that Adam's is the way to do it actually
 
5:21 AM
He's way too good at python :p
How many years of experience do you guys have?
 
I've been hacking away at Python since before Py3, so...
lots?
Professionally about 4 years
 
@Roger 6 months
7 projects in Python
That's all in my CV
:)
 
nice @ both of you
Only been 2 weeks for me, and never done programming before that
so yea I'm the newbiest of newbies
 
anyone compiled python 3.5 in ubuntu
any hints?
 
def counter(iterable):
    d = {}
    for el in iterable:
        if el in d:
            d[el] += 1
        else:
            d[el] = 1
    return d

def nearagram(a, b):
    c_a = counter(a)
    c_b = counter(b)
    c_a_keys = set(c_a.keys())
    c_b_keys = set(c_b.keys())
    both_keys = c_a_keys.union(c_b_keys)

    accumulator = 0

    for key in both_keys:
        diff = c_a.get(key, 0) - c_b.get(key, 0)
        accumulator += abs(diff)

    return accumulator
@Roger
is that better?
 
5:27 AM
def nearagram(a,b):
    la = list(a)
    lb = list(b)
    for i in a:
    	if i in lb: lb.remove(i)
    for i in b:
    	if i in la: la.remove(i)
    return len(la+lb)
 
ohhhh yep! that makes so much more sense @AdamSmith
 
hmm? isn't that the same as the set symmetric difference?
 
thanks a lot guys
 
@AnttiHaapala except in Python sets can't contain duplicates
 
ah just noticerd that it removes from lb not from la
 
5:28 AM
so set('aaaa') - set('a') == set() instead of set('aaa') :)
yeah that's what I screwed up at first, too
 
@AdamSmith there is a saying that you shouldn't teach your mom to...
 
Make cookies?
Yeah my mom's great at that.
 
What the hell? A guy books ticket to Canada yesterday at Rs 69k, today I call it's 77k. (USD 145 increase in 1 day)
What do these airline companies do?
 
lose money, mostly.
You know the old joke
"How do you become a millionaire?" "Easy! Start out as a billionaire and buy an airline."
5
 
I srsly wanna get the code that increases and decreases these prices
I wait 1 day and lose 145$
Daf....
rbrb guys,
 
5:43 AM
rbrb as well
 
gotta go and book tickets
@AdamSmith Mutual Rbrb
:D
 
hehe :D
 
Leavin @Antti alone in the room
 
all the Asians goin' to pycon
and look what I'm doing
or I guess not ... but going to canada :D
 
adam, your code helped me out a lot. I didn't know you could connect 2 functions in that manner
saves so much time
 
5:44 AM
Adam's left
 
connect 2 functions?
 
he made a function to store dictionaries and used it on both a and b, rather then storing them separately. And then went on to calculate the differences between the words
Didn't know you could do that
 
hm? Kind of here
Oh yeah. Functions are tools. If you can't solve the problem -- build the tool that will solve it for you
Note that my extended code is LITERALLY just an unrolling of the two-liner I put earlier
 
0
Q: Searching for user input variable (string) in SQLite using python

LloydyPoydyI am trying to search for a username in a table and subsequently find that users password and check it against input so far I have... def check(): username = logEntry.get() password = passEntry.get() curs.execute("SELECT * FROM logins WHERE username = VALU...

WOOT :D:D
how to log in as any user
 
lol wait
wait a second
doesn't that authenticate if username is in the table anywhere
and if password belongs to any user in the table?
 
5:50 AM
yes
 
I'm FAIRLY certain that's not how to do it ;)
 
Antti, I like your antics
:D
 
I'm considering switching full-time to ubuntu
Right now I'm running a windows box and virtualizing ubuntu
 
DO IT ASAP
 
but the more time I spend in my VM the more I miss it when I go back to my host machine
I do a lot of gaming, though. Steam's linux support is catching up but I don't think it's all the way there yet =/
 
5:54 AM
Wine
Use Wine
 
does the sqlite even work with () single argument placeholder
@BhargavRao well milder a bit
 
@AnttiHaapala Huh? Wrt?
 
nvm :D
 
:D I understand your nevermind
:)
 
@AdamSmith stop gaming
all those games that do not work with wine aren't worth playing :D
 
5:59 AM
curs is short for cursor?
That's sounds bad
cur would have been better
 
but does the "cursor execute" work with a single string correctly?
 
I have no idea. Build a sample database and test it :D
 
I have no idea about sqlite api really, I never use it
 
Well I fell for your edit :D
and for his comment too
:)
 
@AdamSmith can't find a "hash your passwords" for windows :d
 
6:03 AM
huh?
 
crypt.crypt is unix only
I mean woudl link it there
 
hashlib
from hashlib import sha256
or etc
 
no
it is not a password hash
 
no, but he's currently doing NOTHING.
And you're right, there's no bcrypt analogy that's standard on Windows.
 
he is also writing a tkinter app
with passwords in sqlite :d
 
6:05 AM
Meh nothing wrong with SQLite. It's production ready for small databases
 
Just noticed that I've got 15 points in Java ... Closer to generalist by 1.
Have to answer in 18 more tags now
:)
 
I'm 180 points from my Python hammer
 
I've now been damn busy, thanks to end of semester
Will have to start answering again
Perhaps in 1 month
 
@AnttiHaapala maybe recommend pypi.python.org/pypi/passlib ?
 
Lol I remember I was here once with 20 rep and then someone down-voted one of my questions... Got kicked out. So cruel!
 
6:11 AM
That's so sad and not so cruel
 
@BhargavRao yeah I was repcapped like 8 rep away or something?
 
Yeah
I was repcapped 15 away on my 10k day
I then got an accept
 
:o
 
Cbg
 
cbg vaultah
 
6:14 AM
cbg vaultah
rbrb rest
2nd time I'm tellin
:D
 
6:33 AM
What flavor *nix should I install?
I've only used Ubuntu
 
7:04 AM
A few people in this room are happy users of Arch Linux
 
I've heard Arch is pretty far from user friendly, though
I'm not exactly a wiz on linux
so I'm concerned I'll paint myself into a corner
 
Feb 15 at 15:17, by Peter Varo
and I'm using Arch for 10-14 hours a day for the last 5 months
 
Well if Peter Varo can do it...!
;)
 
Jul 19 '14 at 3:26, by davidism
Nice, I'm an arch user too :)
:p
 
Well if our glorious &quot;Web Dev&quot; can do it...
 
7:23 AM
does google use python frameworks or they wrote everything from base using cgi scripts
 
7:46 AM
cbg
 
cbg
 
@AnttiHaapala Scary! My SQL is very rusty, in all dialects. Is that thing safe from SQL injection?
 
@PM2Ring Usually when you see those kinds of constructs (not a Python string format but something done by the module somehow) it's safe from SQL injection
 
Cool. Just checking.
 
@PM2Ring But it's doing if username in passworddict.keys() and password in passworddict.values(): login() (essentially)
 
7:50 AM
cbg
 
re-cbg, @BhargavRao
 
ty
Does Pythonic mean that faster code or using more of python's principles.
 
Yeah, I understand the main error that Antti addressed in his answer.
 
"Pythonic" means "Looks like good Python code"
 
7:52 AM
I wonder why this 91k user with dozens of gold badges is asking this fairly basic question: stackoverflow.com/questions/29586698/… . Maybe he has a scathingly brilliant answer of his own that he intends to post...
Hee hee. There's a bit of synchronicity going on here.
 
Aha PM you here?
Is my answer bad?
 
@BhargavRao I think it's ok. It's fairly comprehensive, and it shows non-regex ways to do it as well as the regex solution. And I guess use of a regex is justified here since standard str methods don't let you search for the index of something that doesn't match a pattern.
 
I'm a fan of the takewhile answer.
 
Another answer mentions takewhile but does not tell from where he got that function
 
I noticed that
Although, contrary to @PM2Ring -- I'd consider the two answers he pointed out at particularly Pythonic as the least "Pythonic" answers there
 
7:59 AM
That's my doubt
They are fast but not pythonic
 
I think BhargavRao's regex solution is a little better that Avinash's 1st regex, since that one has to build a new string using sub.
 
yeah his regex is better than the one I'd use too
 
Avinash's answer was same as mine but he changed it later to make amends. So that the answer want conflict
 
len(re.findall(r"^\s+", text))
 

« first day (1639 days earlier)      last day (3308 days later) »