« first day (1497 days earlier)      last day (3437 days later) » 

3:40 AM
Guys, why is the output of the following code snippet
>>> flist = []
>>> for i in range(3):
... flist.append(lambda: i)
...
>>> [f() for f in flist]
[2, 2, 2]?
Any links would be appreciated :)
 
4:10 AM
10
Q: Python Lambda Problems

Dan LorencWhat's going on here? I'm trying to create a list of functions: def f(a,b): return a*b funcs = [] for i in range(0,10): funcs.append(lambda x:f(i,x)) This isn't doing what I expect. I would expect the list to act like this: funcs[3](3) = 9 funcs[0](5) = 0 But all the functions i...

 
4:55 AM
@thefourtheye Thanks :)
 
lol
yam
 
5:34 AM
Morning Every One
 
6:03 AM
Cbg
@poke @kevin sorry for the very late reply :) Yes, () is always the function call syntax, but it's not the function...reference (?) syntax, so you could go either way. I guess you could even go the whole hog and make parentheses completely optional for function defs even with parameters: def fun something, **kwargs: pass
@poke @kevin then that might make the syntax more regular: never use parens except when calling a function
 
6:35 AM
@poke @kevin or when defining a list. Or make it so putting a list after a function name is the only way TO CALL IT. mind blown
 
cbggggggg
 
@poke @kevin then we just move the function name into the list, as the first parameter. And then we're finally at lisp :)
 
lisp <3
wish python would have proper anonymous functions :(
 
@AnttiHaapala does it only have them inside comprehensions?
 
I mean,
python is a bit stupid in that it says: ~"an expression no matter how complex can be on 1 line, but a statement is a single line too"...
but many things that are statements in python are expressions in lisp
 
6:45 AM
Showing even more ignorance here, but what's the difference between a statement and an expression?
Ooh, SO to the rescue
 
in python an expression cannot contain statements
76
Q: what is the difference between an Expression and a Statement in Python?

WassiManIn Python: what is the difference between Expressions and Statements? Thanks.

 
Yep, that's where I'm reading :)
Ok, I see what you're saying I think
Lisp doesn't special-case statements so much, so you can do more things with expression-level operations
Because more things can be expressions
 
Yeah, I hadn't thought of it like that, but it makes sense
 
it is pretty artificial to say that "these if, def, while need to be the special case"
 
6:48 AM
Yeah, in fact even though those are special forms by implementation in lisp, they're treated the same as anything else in most ways
I agree
 
more so in scheme...
bc much of scheme is purely syntactic sugaring for lambda functions
 
That's a nice way to do things
Yeah I don't like Python's general method of special-casing lots of stuff, but I suppose it's partly because I've seen Clojure, which is cool, and I'm so familiar with Java that I don't even notice it
 
it is very thought-provoking to read this: "In 1998 Sussman and Steele remarked that the minimalism of Scheme was not a conscious design goal, but rather the unintended outcome of the design process.
"We were actually trying to build something complicated and discovered, serendipitously, that we had accidentally designed something that met all our goals but was much simpler than we had intended....we realized that the lambda calculus—a small, simple formalism—could serve as the core of a powerful and expressive programming language."[7]"
 
Yeah, that's awesome.
 
bc many times when ppl start reading on scheme, me included, they read it as if the language was designed to be as minimal as possible...
when it was not...
many things I like about python, the forced indentation is one of them, cleanliness of code, lots of useful datatypes, good libraries etc, but never fond of the "no anonymous functions"
 
6:55 AM
Cbg
 
cbgggg
 
@AnttiHaapala yeah I'm the same
I don't even really like the magic comprehension syntax
It's as though they couldn't be bothered to do proper anonymous stuff, so they just hacked up something that covered the use cases they could think of at the time
 
yes
and what is worse with the genexps and so is that they are very hard to read...
if you want to do a pipeline you need to split it in vars...
bc no one can read (i.foo() for i in (j.bar for j in (k for k in l if l) if j if i )
I started writing a lib that would wokr like java streams, so you could write that as
stream(k).filter().map(lambda i: i.bar).filter().map(I.foo)
or something...
or maybe better
 
That's so weird, I was thinking of writing something like that
But not around streams particularly, more around lazy syntax
Like take(), that sort of thing
 
ah just call it stream, but ofc it will be a generator...
 
7:07 AM
But yeah, chaining stuff together like that
Yeah
What I don't get with comprehensions is Python already has a decent for syntax
And this may be my ignorance, but I don't get why you can't just have for key, value in list where key != 'Bob':
print(value)
And maybe just have a tiny special case where it can fit on one line if you put it in parentheses
Sorry, key, value and list don't really make sense together
 
ofc it does
sequence unpacking
 
I think it would've been cooler to extend for with a where clause than add a whole new syntax
 
ofc there you have just minimal advantage of having the where for if, but
it is still a statement...
the thing with comprehensions is that they are expressions.
 
Sorry, what I meant with wrapping it in parentheses was also it could become an expression (through magic)
Although now I'm at the point where I'm just saying stuff, and I don't know the implications of what I'm suggesting
 
7:47 AM
You could even do
for key, value in list where key != 'Bob':
yield from something(value)
And for expressiony coroutineness: (for key, value in list where key != 'Bob': yield from something(value))
 
8:15 AM
Been confusing me for a while, as my github keys wouldn't work
 
Ah yeah. I normally use https because of proxy stuff
 
I've switched to using the git now, so much easier than typing bloody ffisegydd and ffisegydd1 as username and password for every push
 
And here's me thinking you changed it to 10. Sneaky.
 
I told everyone I had so they'd keep on iterating to infinity.
When really I'll be behind them.
 
On their 6, nice
Anyway, I want to email the python-ideas list with my idea for cool for loops and stuff. Someone shoot me down!
 
8:35 AM
Pew pew
 
Cbg :)
 
@IanClark cbg
 
@RobertGrant potato?
 
@IanClark Banana melon. Potato?
 
@Robert, tired! :)
 
8:43 AM
Cabbage
 
9:03 AM
Colleague deployed code that overrides the user input for testing...into production
Now no-one is getting any tickets logged to do work
 
9:21 AM
@RobertGrant Carrot
 
9:35 AM
@Pureferret is that about for loops or colleague code deployment? :)
 
@RobertGrant Blocking tickets!
 
Ah yes :)
 
10:03 AM
cbg
 
hrm, my serial downvoter from yesterday has proven malicious.
Yesterday's 4 votes have been reversed, so this morning only 2 downvotes were given (on a subset of the posts targeted yesterday).
a) as if that'd affect my reputation (the cap will easily wipe out the rep loss) and b) now that a pattern has been established the serial voting script will pick these two up too.
And reversed or not, I'll flag it for moderator attention because we can't have people going round trying to see how the serial voting script can be circumvented.
 
10:19 AM
It's been a while so I thought I might post this up:
0
Q: How can I use lettuce in my Django project, within Eclipse?

PureferretI'm following the Django Tutorial for Django v1.6, and running it inside eclipse with PyDev. I got to the page on testing and I thought I'd mix it up (read: Run before I can walk) and learn Lettuce as well. From what I've read online lettuce should be bundled with PyDev by default. which makes s...

As I'm pretty stumped
 
@Pureferret I saw you put a bounty on it.
sorry I can't help there.
 
Have an upvote, alas I can't help either.
 
How do I convert a numpy array of timestamp to float ?
array of float
 
Morning folks
 
cbg @Intrepid
@user994572 do you have some example data?
 
10:32 AM
sure....let me paste it
 
If it's long, paste it at pastebin.com
 
ok
pastebin.com/1UA1mRx5
 
Okay, what's the best way to handle this? Stumbled across an old, 0 vote question via Google. I'm pretty sure I know the guy is suffering from ye olde "not disposing of an image before loading a new one" issue - making it a dupe
 
This contains the data: nda[:,0] gives an array of timestamps, from this I need to get a float so I can use the float values to get unique dates like here: stackoverflow.com/questions/9673988/…
 
Should I just flag it as a potential dupe, or should I answer with a link to the question that I think solves his problem. If it solves the problem, then flag it as a dupe?
 
10:42 AM
@Pureferret commented
 
@IntrepidBrit are you talking about my question ?
 
@user994572 no, he's not
 
I am not sure if what I am trying to do is complicated. I'm dealing with all things pandas, but am having to get into numpy to do what the above link is doing:remove whitespace in the chart.
 
@user994572 you can get it in nanoseconds since the epoch with the following
In [65]: a = pd.date_range(start='2014-11-12 08:00:00', end='2014-11-20 00:00:00', freq='1D')

In [66]: b = a.values

In [67]: [np.int64(i) for i in b]
Out[67]:
[1415779200000000000,
 1415865600000000000,
 1415952000000000000,
 1416038400000000000,
 1416124800000000000,
 1416211200000000000,
 1416297600000000000,
 1416384000000000000,
 1416470400000000000]
You'll need to multiply each of the values by 10**9 to get it into seconds.
a is just a pandas object I created for the example, and b is just a numpy array created from it. The magic is in [np.int64(i) for i in b]
O_o I love dealing with time...
 
@Ffisegydd 'Love' is one way to describe that, yes.
 
10:59 AM
ok....let me see how I can fit this in my logic. Thanks.
Final roadblock: Can you tell me what this particular line does ?
data2 = np.hstack([np.arange(data[:,0].size)[:, np.newaxis], data[:,1:]])
This is from the same link above: stackoverflow.com/questions/9673988/…
 
Umm. It is stacking two arrays, one array appears to be the numbers 0,1,2,3,...size_of_array.
The other is the data.
It's also stacking "horizontally"
 
@RobertGrant Thanks
 
The comment says this: # creation of new data by replacing the time array with equally spaced values. # this will allow to remove the gap between the days, when plotting the data
How does it work ? If the days are 13, 14, 17, 18, 19. How does the above code
create equally spaced values ?
Two dates 15 and 16 are missing.
 
I'm sorry, I don't have time to debug all the code right now.
 
no worries.
 
hah, indeed..
 
What a question...
 
Closed and nuked.
My work here is done!
 
hi
 
cbg
 
11:23 AM
any one can explain about python code paste.ofcode.org/YTZjpbcQVrjrMGg59yChMD i am new on Python i am Android developer but web service which user in android is written in Python please explain
 
@Edge what do you need explaining?
 
sherjilozair.pythonanywhere.com/log this hosted here No database is used, i.e. the incoming data is appended to flat files. The data is sent to the server via GET requests. i just want to know how use get i mean appending
in android code this api calling like this private void sendLocation(Location location) {
String url = Uri.parse("http://sherjilozair.pythonanywhere.com/log")
.buildUpon()
.appendQueryParameter("location", location.toString())
.appendQueryParameter("imei", IMEI)
.build().toString();
//url = "http://sherjilozair.pythonanywhere.com/log";
Log.d("URL", url);
(new DownloadWebPageTask()).execute(url);
}
location ,imei when i will send what response will come
HttpGet httpGet = new HttpGet(url); like this am posting
@Ffisegydd
 
@Edge take a lookie here :) sopython.com/pages/chatroom
 
11:42 AM
ok @Pureferret thanx
 
if plain_index == 0 or plain_index == -1: or
if plain_index in (0,-1):
 
Second.
 
why
 
Cos I said so Looks neater
 
11:53 AM
what about performance ?
 
Plus it's easier to extend, i.e. if you needed (-1, 1, 2, 3, 3.14159)
Don't micro-optimise prematurely.
 
@WalleCyril Python 3: if plain_index in {0, -1}:
 
Ah good shout.
 
Python 2: if plain_index in (0, -1):.
 
@Martijn why don't you still use a set in 2.x?
 
11:54 AM
Python 3 recognizes a set literal as something it can turn into a constant, so a frozenset() is stored in the code constants array.
 
I need to support python 2 and 3
 
In Python 2 that's not the case, so for a short sequence the fact that no object is being created for the tuple then testing against that is going to beat creating a set object each time.
For just 2 elements, the difference is so minimal as to be non-existent.
So stick with the tuple.
Another option, which I didn't time, would be to use if -1 <= plain_index <= 0:
Use timeit to measure such things.
But unless this is on a critical path and executed many, many, many times I'd not bother.
 
I ll use the tuple way then
how should I indent/whitespace rawdata[self.i : self.i+2]
if x:
    if y:
        doa()
    else:
        dob()
or
if x and y:
    doa()
elif x and not y:
    dob()
 
First
 
12:17 PM
@Intrepid wanna pick your brain on the nidaba stuff. We're going to have a set of functions which work on Question objects, for example, right? These functions will extract a feature from the Question objects, but they may do this using lower level functions which just work on, for example, a string.
So 1. Should we have unittests that test the higher level, the lower level, or both?
2. At the moment we have a package nidaba.features and I was going to store the higher level functions in these package, can you think of a good place to store the lower level functions? Something like nidaba.features._raw but _raw sounds wrong.
 
1) The "unit" tests should be done on the lowest level blocs (ie, feature extraction from strings). Because the higher level stuff (ie, the Question stuff) requires the string feature extraction to be working
Ergo, it's a different type of test.
But depends on how purist one wants to be about the whole thing. One could run the lowest tests to ensure that they're all working okay, then run "integration" tests (if you will), whilst still using the unit test framework.
Not sure on the best way to do that kind of testing in Python, as most of my stuff doesn't get too hierarchical past unit testing.
2) What about extraction? I think it reads pretty clear in English (nidaba.features.extraction); could be mistaken for pulling the features from the server though
 
Yeah I assumed we'd always test the lowest level, but thought it would make sense to also test the higher level to ensure it's using the lower level correctly.
I also thought about util?
So nidaba.features.util
Or tools
I'm gonna go with util as it's shortest and I'm lazy.
 
util and tools could both work, but we might end up creating tools/utilities for feature extraction
Especially if we want to keep things DRY
 
I'll call it _util and we can always save tools for such things.
 
Sure. If it gets too confusing we can always change it
Going back to 1) Unit test the feature extraction; integration test the rest
 
12:34 PM
Ok. I don't know the difference, but ok :P
 
I think with PyTest, there isn't a difference
 
You're lucky we've got tests at all.
 
(currently perusing the docs)
 
Yeah I've been reading them over
I've created some fixtures to get question and answer data
Which can then be used by testing functions
 
In my news - my Linux distro is mangled. I decided it would be a great idea to install my proprietary nvidia drivers - and no longer have access to the GUI. Might have to stop wasting about with it, and just do ye olde Python/vim combo
Love me a bit 'o' vim
 
12:38 PM
:D
 
Cabbage!
 
cab @poke
 
@RobertGrant There isn’t really a “more regular”. Either it’s regular, or it’s not. Nevertheless, all these things are decisions that were made. Sure, there are arguments for other ways, but it’s just how it is.
 
@poke okay :)
Not sure I agree with the purely semantic thing about regularity, e.g. "@poke's bowel movements are becoming more regular" sounds like a legitimate thing to say, but I totally agree with you that the way things are at the moment is how it is :)
 
Well, I’m talking in the sense of a regular language.
 
12:48 PM
I just meant more consistent
 
A parser gains literally nothing from the fact that at some point in the grammar, the language is “more regular” than it was before.
Oh, I see.
 
The idea was that you could write Python in a style so you only put parens after a function name when you want to call it, without disturbing backwards compatibility
 
Okay, sort of rhubarbing - an RMA has come in
 
You could also just use Ruby :P
 
@poke if that's the only difference...:)
But given the def ... : syntax, it feels as though parens are overkill, unless I'm missing something
 
12:55 PM
Do you mean because you don’t need parameters, or because you could put the parameters just behind it?
def foo bar, baz, bla:
    pass
looks super odd
 
That's subjective, but okay :) I quite like it for its slightly more lisposity
 
Also, with annotations:
def foo bar:str, baz:int, bla:bool -> string:
    pass
ugh
A benefit from including the parentheses is also that you can just copy the whole definition line (minus the def and the colon) and have a valid call of it.
 
And minus the self
Assuming there is one
And minus the annotations :)
 
:P
It will probably look even more complicated, when you have longer function and parameter names, possibly with underscores, that makes it difficult to see where the function name ends.
 
I've just seen a few times on here already that (new) people get confused about what a function is doing with/without parens
And that feels as though it makes more sense: you have parens when you call it, otherwise you're referring to it
Possibly an alignment that only makes sense in my head, I dunno
 
1:01 PM
But you are neither calling nor referring to it when you define it.
 
Awesome, got unittest fixtures set up and it seems to be working in PyCharm
 
Well as I say, it may only make sense in my head :) But it feels like defining is much closer to referring to it than to calling it
 
What if you are calling the special thing def instead? :P
 
Basically I want to be able to do this:
def leppard:
    pass
 
I know that when using TDD you're meant to write tests and then write a function that passes the test, but I really think it makes sense to do it the other way round here. After all, to get the features out of the data I'm going to have to write Python code to do it! I can't define my tests without know what the features should be, so I need to write some code to work it out.
 
1:04 PM
@poke then you're crazy
eek
I misread. Ahem.
 
The issue is that it's not like the normal "stories" like "User should be able to return their sweater" or whatever. The story is "Given this several thousand character string, what's the ratio of upper case to lower case?"
 
@Ffisegydd The idea is a bit different though. TDD is not ultimately about having tests. It’s more about designing your interface before you complete the implementation.
 
Or "What percentage of it is Python code?"
 
So you are using someApi.someMethod() before that method actually exists, so you know before how you use it. And you then implement your methods to fit how you are using it.
@RobertGrant How often do you define functions without any parameters?
OMFG
I just corrected Jon Skeet!
 
@poke dunno, why? I wasn't just talking about functions with no parameters
 
1:12 PM
Because of your example
 
Oh, that was a joke. Def Leppard is a band
But yeah, because of the weird self thing, almost never I'd imagine
I guess I think some of the Ruby syntax looks quite cool, but perhaps I'm in a minority in this room :)
I guess it was more of a Ruby/Lisp hybrid
 
Well, I think their arr.sort and arr.sort! stuff is fun
 
Yeah that's also quite cool
 
Hooray! It's not a software problem. Time for an IntrepidLunchtime
@Ffisegydd I know what you mean, but if we're looking for "how many sentences are there in this string, and what's the character/word/sentence ratio?" that can very much be written test first :)
 
1:28 PM
I hate this so much.
Someone is asking a question to understand something, and then there are answers that try to move completely away from the issue without explaining what was going on originally but just to ignore whatever that was.
 
@Intrepid, yeah, I'm kinda tempted to cheat though :P anyway I'm about to commit our first test (testing the capitalisation of a title :O)
Done. We has unittests. Think it's time for the pub now.
 
Was it:
def TestIfPubTime(isitpubtimeyet):
     self.assertTrue(True)
 
If you have a second, have a look at the unittests and see if I'm being sensible github.com/sopython/nidaba/tree/master/nidaba/features
I've never actually done testing properly before.
When I did testing for my data analysis procedures I knew all the answers, and knew I'd enver have to share the code, so I could just make it "for myself"
 
1:46 PM
I would actually say that using fixtures for that is (a) not necessary and (b) probably harmful. You could/should just use some static strings instead and avoid having regressions from fixture changes.
And for better coverage you should definitely have a test case that returns false the capitalization test too.
 
I see what you're saying, but I didn't know how to save such data effectively. Or should I put them into the functions directly?
 
E.g.:
 
Yeah good call.
 
def test_title_capitalisation():
    assert question.capitalised_title('Why is reading lines from stdin much slower in C++ than Python?')
    assert question.capitalised_title('how make pysmp oids respone readable for human')
 
The titles and such wouldn't be too bad if they were in the functions directly, but if you look at the json github.com/sopython/nidaba/blob/master/nidaba/features/test/… you'll see the body is pretty extreme.
 
1:48 PM
And yeah, it’s absolutely fine to have the values you are testing against directly in the tests. That way, they are self-contained and independent.
 
Ok, I see what you mean. When I've done unittests previously I've had my data in files as it was easier than putting it directly into the tests. But as I said, those tests were pretty much just written for me.
 
And usually, unless you are actually changing the data, using fixtures shouldn’t be necessary.
fixtures are more helpful when you have a test that requires data in the database and then goes like (1) load question from db (2) evaluate question (3) save question evaluation (4) verify saved evaluation in the database
At least that’s how I have been using fixtures so far.
 
Wot he said
 
Hmm ok. I saw that pandas use pickle objects for their testing so assuming that saving the data to a file would be ok. I'll have to put the body string in a file though, can't really have that craziness in a Python function :P
 
Since you are not changing it, you could also have it as a constant in the test module
 
1:54 PM
Having it as a constant was kind of what I intended the fixtures to be.
But I understand if they're meant to be more dynamic
 
Fixtures are more meant to reenact an established system state for a test.
 
Yeah I see, the pytest tutorials use it to connect using smtplib
I'll refactor it later to use it as constants.
 
@Ffisegydd i agree with @poke previously, i had problems with fixtures when data models are changed
 
At least for things like the body which are so insanely long.
And I'll refactor the title to be independent.
 
good :)
 
1:59 PM
Okay guys.
So, they way GitHub wants to work is for me to fork the repo, and perform pull requests yeah?
 

« first day (1497 days earlier)      last day (3437 days later) »