« first day (1379 days earlier)      last day (3574 days later) » 

12:09 AM
cbg all
Hey @PeterVaro, I seem to remember you have some experience with cython. Is there a way to use it on Windows 8? Cause VS 2008 is long gone and Mingw32 gives me Errors...
 
cbg
 
or if anyone knows a magic trick... :-)
 
12:28 AM
ok, need a function that does this more efficiently: def f(g): return lambda a, b: cmp(g(a), g(b))
That function is the best solution I was able to come up with for a brain-teaser type problem at work. It's not good enough. Neither is mapping g to a and b. Please enlighten me, Python geniuses.
 
 
3 hours later…
 
3 hours later…
6:22 AM
@AaronHall calculate g(x) for all x first
use key for sort
 
6:45 AM
hey, im new to python and having some trouble on this codeademy exercise (no login needed) - codecademy.com/courses/python-beginner-en-IZ9Ra/1/…
bpaste.net/show/503396 thats what i tried, i dont understand how to get the key name when printing
could someone try to solve that one exercise and send me a paste, ill read through and ask if i have questions
 
6:57 AM
for key in prices
not for price in prices
 
but does that really make a difference/ its just a var name
...
 
yes
bc then you understand
btw see that problem there^
almost like your question :P
 
hmmm, could you send me solution in a paste?
pastebin, bpaste whatever
to the CA exercise, i dont think my code
accurately represents the issue
 
you asked how to print the key
i said if you do for key in prices
then you know what is the key
it is the key
then you print it
 
7:08 AM
how to import a file and modify it's content through python?
just trying to answer this question. I donno this basic question.
@Avinash_Raj Thank you! But this does not seem to import input.txt and then save the output like as in output.txt. How should it be edited for that purpose? — user3123767 14 mins ago
 
@tejas-manohar use format:
print "price: {}".format(prices[key])
 
Why a seperate output.txt file?
 
@AvinashRaj as per OP
 
so i need to add
with open('input.txt') as inf:
    with open('output.txt', 'w') as outf:
and then?
 
you need to read and write
 
8:23 AM
0
A: Imports in __init__.py and `import as` statement

Antti HaapalaPEP 0221 claims that the following 2 are "effectively" the same: import foo.bar.bazaar as baz from foo.bar import bazaar as baz The statement is of course false. The first one requires that the module bar is injected in foo namespace, in addition to being in sys.modules, whereas the second for...

my answer is the right one, pls upvotes :D
 
8:48 AM
cbg all
 
cbg
^
nowadays if I find a new feature in python, it is mostly a bug
as above
:(
 
 
2 hours later…
10:31 AM
Hi,
I am trying to install Orange package. I got an error stating that I need to upgrade Distrubute. So I ran `easy_install -U distribute` which runs fine but even after that Orange installation gives the same error. I can't figure out what to do?
 
Are you using two versions of Python on your computer?
Make sure you're being consistent with your installations.
 
Aah! There is some issue with setuptools version. I guess I has not been upgraded
I updated Setuptools also and it has started to work.
Thanks
 
11:25 AM
cabbage everybody
 
cbg
 
12:00 PM
cbg
 
@AnttiHaapala I have no hint if it's a correct answer
I'm not enough good
 
well, it is :D
 
12:36 PM
cabbage
 
cbg
 
cbg
why am i getting the repository "Clean_data" when i have specified "Cl_data" just above??
 
Windows. That's why.
Everything is windows fault.
 
how do i fix it?
 
You switch to a unix based OS.
 
12:48 PM
we can make windows say sorry ,right?
 
You'd have to phone Bill Gates to do that
 
its my desktop , i can't
 
He'll send you an official I'm-sorry-we-suck apology letter
 
no kidding , i'm serious right now..
i know you are too
any workaround?
 
No, but really the command line in windows looks so weird
just a min, let me look into it
what happens if you do git remote -v
 
12:51 PM
@Swordy ofc you can switch your desktop to linux
@Swordy better now than tomorrow
 
@Ahmad fetch and push of the same link.. clean_data.git
 
@AnttiHaapala : i'd switch to linux when i get a laptop , im ok with windows here as of now..
 
cant see
 
i have deleted it
 
12:53 PM
ah :D
understood
fatal error origin already exist
 
the new link is Cl_data
 
you need to remove the origin remote
 
yeah
with?
 
git remote -v
see the list
 
yes
 
12:54 PM
git remote remove origin
 
its the same link coming twice
and i need to push 2 files from my local repository
so it goes like :
git add README.md
git add CodeBook.md
right?
 
yes
and then commit
 
git commit -m "2 files coming"
git push -u origin master
 
git push
 
why?
 
12:57 PM
should use by default the default remote, and update all matching branches
 
master is the default branch
 
if your current branch is master, then shouldnt need to specify master
 
yes it is
and what about origin?
ohhh damn , there are other files in the folder too
 
Is there a more efficient way to manufacture such a function?: def f(g): return lambda a, b: cmp(g(a), g(b))
 
1:13 PM
can't think of really
@AaronHall but which is the case here
the sort, sorted use key= function just because it is more efficient to call the key n times and not nlogn times
 
1:27 PM
my 3 files were even less than 1MB . why is the "writing objects" process writing 20mbs (till now) ? where did so much data come from?
 
the history
 
27mbs now.. so much of history :(
 
FYI, not more efficient, but similar: def f(g): return lambda a, b: cmp(*map(g (a, b)))
 
less efficient yes
 
1:53 PM
usage: cmp4pow = f(lambda i: pow(i, 4))
cmp4pow(-1.4121, (1+1j))
There's gotta be an optimal way, perhaps tuned to old Python.
 
So, if you do import logging, you can't access logging.handlers - you have to import it explicitly. How do they do that? I'm reading logging.__init__ and can't figure it out.
 
@AaronHall you never answered: why :D
 
2:26 PM
The reason why is it's like a job interview question, but in a program. So I have no idea why.
 
:D
If I had a job interview question like that, I'd say "hire someone else"
 
Ok, it's just in a program.
Forget "job interview"
I've google composing functions, nothing
 
2:42 PM
we call them Python koans, but they're not related to the Edgecase Ruby koans or the Python spinoff, I believe.
 
3:01 PM
Hiya
 
3:16 PM
Cbg
 
3:45 PM
codementor is silly :|
 
4:05 PM
cbg all
 
4:37 PM
cbg
 
@Raoul cbg
 
5:15 PM
cbg
Summer holidays, the weekend question stream and voting is anaemic.
 
5:32 PM
huh?
 
6:10 PM
Nothing, just grumbling.
 
user559633
i'm using a lambda and my print function is returning the reference to the lambda instead of executing it. will someone please take a look?

def getattr(self, path, fh=None):
Console.console("Calling os.lstat on %s %s" % (path, lambda fh: fh if fh is not None else 'Filehandle not specified'))

#Calling os.lstat on /Contents <function <lambda> at 0x10bffd500>
 
Why do you even have the lambda here? Why don't you simply leave the conditional expression there?
 
user559633
just 'fh if fh not none'?
 
user559633
fair enough. still curious why it's returning the ref instead of executing it
 
6:22 PM
Yup
You are just creating the function object, right? How are you invoking it?
Also, prefer format method over % based string formatting.
 
user559633
i use format in other places, this is just a crappy prototype and i like the forced type of %s
 
user559633
oh. yeah. i'm never actually calling it. i'd have to play with syntax
 
user559633
thanks @thefourtheye
 
user559633
have a good day
 
If you really want to execute the lambda function, try something like this
print (lambda: None)()
(lambda: None) creates a function object and you are invoking immediately. This is similar to JavaScript's Immediately Invoked Function Expression.
 
6:28 PM
cbg
@MartijnPieters so upvote me pls :D
 
@AnttiHaapala You upvote me first! :-P
 
done, for your open with +
 
from foo.bar imports foo.bar if not yet imported, actually.
 
@MartijnPieters it is not the case here
 
from urllib.request import urlopen as uo works just fine, even though urllib does not import urllib.request.
 
6:33 PM
if you read the op, the question is not whether it is imported or not
 
right; I was avoiding that whole question, btw.
 
so clearly I still need to rephrase
 
@MartijnPieters , is there a legacy use-case for this, and was there a more optimized approach?: def f(g): return lambda a, b: cmp(g(a), g(b))
 
to be clear, the equivalent real-world test would be from urllib import request as r vs. import urllib.request as r as this only applies to importing modules, not objects defined by modules.
@AaronHall A function that returns a wrapper for cmp?
 
Yes.
 
6:37 PM
Ah, plus a wrapper function.
just a sec
 
I love upvoting Martijn. I know it does absolutely nothing for his rep. It's like, plus one, sucker, ha! :)
Should I ask that on the main site?
 
@MartijnPieters ah indeed :P but that is the funny thing...
 
I haven't actually hit the cap yet today. :-)
 
you have legendary
 
Oh, today already qualifies for the badge, but that happens the moment you hit 200 even with accepts.
 
6:40 PM
yes
anw
 
right, back to focus here again.
 
nope, the specific case is not "from urllib import request as r"
yuo need to have 2 packages and then a module
 
@Aaron: So you want to pass in an extra function to apply to both a and b and then apply the results to cmp.
That's not something the stdlib can help you with.
I'd be wary of anything using cmp however.
@AnttiHaapala Yes, I realised that, I'll dig up a better test.
 
i'd be too, bc i'd be doing python 2 then :P
@MartijnPieters anw, have you used import foo.bar.bazaar as baz
 
Maybe the interpreter is running slow and I already have the answer.
They must be timing the solution.
 
6:44 PM
anw I do not want to lose the bounty bc of someone who says "this is my theory" and then complete baloney
 
After being up for a while, a two star answer seems to become a one-star answer
What would be the legacy use-case for that? Sorts without the key arg?
 
@Aaron: btw, apologies for not having responded to your LinkedIn req so far.
 
no worries, I have like 200+ I won't accept. :)
 
I may have to remove the link from my SO About Me section; too many spammy requests.
NYC is not in the books this year, too busy.
 
I got accepted!
anyways, I should be working on that right now anyways, and not stupid brain-teasers.
 
6:47 PM
>>> import xml
>>> xml.etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
>>> import xml.etree.ElementTree as ET
then exit interpreter, run again
from xml.etree import ElementTree as ET
works fine too.
xml.etree is a package, ElementTree is a module.
 
yes
where did I say it does not work? :D
 
> PEP 0221 claims that the following 2 are "effectively" the same:
 
Scipy does that too IIRC
 
> The statement is of course false
 
@MartijnPieters so you still ignored my answer and the question
 
6:49 PM
I stumbled over that part first, as what you say is not true.
 
:d
then I fixed it
added ... as evidenced by the corner case you hit
well it is effectively almost the same :P
 
Right, the OP has an import chain, so there are no entries in sys.modules yet.
 
ah there are entries in sys modules
importing does emit them right away afaik
the case here is that from xml.etree import ElementTree does search xml.etree in sys.modules
 
Yes, the objects are added to sys.modules as you import.
 
whereas import xml.etree.ElementTree searches 'xml'
foo = sys.modules['xml']
 
6:53 PM
Right, and the normal setattr('foo', 'bar', sys.modules['foo.bar']) is only executed after importing is completed.
 
then does ~ getattr(getattr(foo, 'etree'), 'ElementTree')
 
Hrm, that's actually not the case.
 
>>> import xml.etree.ElementTree
>>> from xml.etree import ElementTree
>>> import xml.etree.ElementTree as foo
>>> del xml.etree
>>> from xml.etree import ElementTree as foo
>>> import xml.etree.ElementTree as foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
 
Sure, but the etree attribute is set when the xml.etree entry in sys.modules is created.
 
6:56 PM
so by the time the ElementTree/__init__.py file is being imported the attribute is set.
 
sys.modules attr is done when the importing starts for the empty module
 
I just tested this.
 
hmm
which python?
 
2.7.8
I'll test some more, adding in some sys.modules tests in the __init__.py intervening packages.
 
nope you are wrong
 
7:00 PM
Ah, in the __init__.py files it is not.
 
pkg.subpkg.__init__.py
print sys.modules, have in sys modules
 
I used a foo/bar/baz.py file structure, with __init__.py files at the foo and bar levels.
 
but if I import pkg, and print pkg.subpkg, then the attr is not
 
Plus a top-level script doing import foo.bar.baz.
 
from pkg.subpkg import One
hmhm
i wonder if this also matters
 
7:01 PM
I added tests for 'bar' in dir(sys.modules['foo']) in those files.
 
nope it does not
 
but so too in foo/bar/__init__.py, until it has finished importing.
 
False
^ print output for 'subpkg' in dir(sys.modules['pkg']
 
however, in baz.py it is true.
 
but the really important question is
why if they are 'effectively' the same, they would differ that way...
that why there are actually 2 pieces of code doing the "effectively same"
 
7:04 PM
I get
In foo/ False
In foo/bar/ False
In foo/bar/baz.py True
Pfftw
Migrated from SF.
 
@MartijnPieters why's it troll?
bc troll asking?
 
Because that user (username) is a well-known troll.
They posted earlier today as anon, changed their name, were nuked.
It's the troll user that issued death threats.
 
he will come through the intertubes to my home and make me laugh to death.
 
Voting to close for now (unclear), then we'll just delete the post.
@AnttiHaapala Yeah, except the threats were a little more creepy than that.
 
pretty sure he wouldn't come to kill me first :P
ah
rbrb
 
7:39 PM
cbg
 
@Jon BRIIIIIIIAN!
 
@Ffisegydd STEWIE!!!!!!!!!!!!!!!!!!!!
 
Started watching Breaking Bad finally.
I decided to get a Netflix account, sharing it with Ruth so works quite nicely. I might find out how to use sopython as a proxy if possible @Jon.
 
No worries - there's also Hola as an app that does the trick as well
 
Ah ok
 
7:45 PM
Did you go with the 5.99/6.99 account?
 
The one with 2 screens but not HD if I remember rightly.
 
oh dude - it's pointless without HD
 
Not really. I don't have very good internet and I never watch TV directly, I always have it on in the background
So half the time I'm not even looking at the screen or only barely.
 
Fair enough then... just if you're playing it through a large widescreen SmartTV or something - it looks a bit naff without HD
 
Playing it through my xbox at the moment but it's not a HD TV anyway
 
7:47 PM
pointless having an HD sub then I guess
Anyway, if hola doesn't work, then I'll provide you an account on a US server so you can create a SOCKS proxy over SSH - just let us know
 
Ah ta. I'll try Hola anyway (didn't know about it)
Cheers puppy.
 
Hola's slightly more efficient as I believe it only changes the IP for the initial connections to over-ride the geoip blocking
Then it switches back to a direct connection, rather than proxying the entire content through the tunnel
 
Ah that's good.
 
Has tradeoffs though... I've got one server configured such that it buffers the data (and it's on a 100gbs pipe) so if netflix decides to bugger about a bit, it's still buffered server side anyway, so it's a slightly bit more reliable. But, at the same time, it's counted as gigs of traffic in and out for the data usage on the account. So - trade offs :)
 
rbrb all
dinner (pizza and film)
 
8:01 PM
@Martijn rbrb
rbrb - saturday night = fish and chips
 
Awwww man I want fish and chips now.
Don't know of any chippies round here though
 
8:17 PM
If you hurry over to mine, it might still be warm :) (can't guarantee it won't have already been eaten)
 
Nah I'm good :P
 
@Ffisegydd how long a trip is it for you to get to London?
 
2 hours by train maybe.
1-2 hours
To Paddington anyway
 
Ummm.... we should arrange a London meet up for the UK members at some point
sopycon UK or something :p
 
Lol yeah maybe. I'm sure Peter could wander over from Hungary too :P
I remember him either visiting or planning to visit London anyway
 
8:22 PM
hi
 
cbg @ChirdeepTomar
 
cbg @Chirdeep
 
what does cbg mean? first time in this chat
sorry lol
 
any django users here?
 
8:25 PM
@Chirdeep please see sopython.com/pages/chatroom
If you have a question then just ask it
Anyone who can help you, will do so.
 
okay thanks a lot, will read
 
8:48 PM
I am using order_by on a django queryset to order by name but its returns the results in the following order: Taylormade Adidas, Adidas, Arrow....I have no idea why its putting Taylormade Adidas on top.
 
What's the exact query you're using ?
 
9:04 PM
queryset = SearchQuerySet()\
.facet('style')\
.facet('city')\
.facet('location')\
.facet('category')\
.facet('type')\
.order_by('brand')
this is a django-haystack queryset
 
Weighting perhaps?
 
hmmm not sure if thats the right solution
 
haven't dealed with haystack
 
I think the problem is due to multiple words but dont know why would that be a problem
 
Is it perhaps thinking that it's a 'FirstName LastName' idea and it's sorting by the LastName
 
9:11 PM
exactly
 
Modify one of your other variables and add a name in
Then test where it comes
You should be able to predict it.
 
Taylormade Adidas
 
Yes I know
But add a name like "Bob" to one of the other names
 
oh yeah that work
i mean that is already working
it does sort but in cases like Taylormade Adidas it shows that on top
 
Yes because Adidas is the top of the list
 
9:14 PM
I reckon if you put in "Bob Robert William Something Something Adidas" - that's also come out on top
as it's indexing words
 
Exactly.
 
Taylormade Adidas
Adidas
Armani Jeans
Arrow
U.S. Polo Assn.
United Colors of Benetton
Blackberrys
Blacksoul
Boggi
CK Jeans
so thats what I am getting
 
Yup - so it's in order of the least lexographically ordered word
"Adidas, Adidas, Armani, Arrow, Assn., Benetton, Blackberrys, Blacksoul, Boggi, CK"
 
yes
is there a way to rectify this?
 
Resort the result set?
 
9:32 PM
i guess I have slug field, i can sort on that...that would work
 
10:52 PM
cbg
 
11:02 PM
cbg Antti
 
rbrb :D
 

« first day (1379 days earlier)      last day (3574 days later) »