« first day (1320 days earlier)      last day (3633 days later) » 

3:09 PM
@Crow jsonify() argument after ** must be a mapping, not instance
How can I serialize an instance? :'(
 
3:24 PM
@DrewR JSON isn't capable of representing Python objects. You serialize the data, not the instance.
 
Hey kids.
 
jsonify(someobj.__dict__) might do what you want (your object may vary).
 
@Wooble I was on the point to give this advice but that is usually bad style
 
indeed. It's much better to give the actual attributes you want to serialize.
 
@GamesBrainiac Hey, how's it going?
 
3:31 PM
@Kevin yo! Its all right, too much work, but i don't care, i just want to procrastinate :P
 
I know that feeling.
 
@Kevin I strive to become more like you everyday. But I can't get myself to love tk :P
 
I wouldn't prescribe anyone to use tk anyway. I just use it because I can't be bothered to try the alternatives.
Not much of a shining example, there
 
Yea, no argument there.
 
haha
 
DSM
3:34 PM
Not sure there really are many people who love tk, only people who find it sufficient..
 
Just talked to a django core dev a few days back. He was talking about how cool django was a year ago, now he's trying to fix whats broke, and having a hard time :P
 
args unpacking dupe anyone? stackoverflow.com/questions/23916135/…
Ah I've marked it as a dupe but I'm not convinced now :/
 
@Wooble So that sucks
 
As my dupe talks specifically about tuples rather than strings.
 
@Wooble I can't serialize my model directly...
I have to start pulling out properties etc.
that has kind of put me off the whole thing
in .NET i can just annotate properties I dont want serializing, all public properties will be included when serializing the object directly
in Node it just works
I think ive found the solution to my ORM woes, now I have serialization woes to replace them
fml :'(
 
3:49 PM
Does it have to be serialised to a JSON?
In Python there is a module called pickle which you can use to pickle objects (save them as a file) and then you unpickle them and get your object back.
 
pickle is trash.
 
This is for a Web API
 
Ah ok
 
@DrewR my_class.__dict__ perchance
 
Reckon that will work for SQLAlchemy results?
 
3:52 PM
probably, I think it's an ORM, right?
then everything should be an object and I think they usually have the __dict__ method to convert into dictionary
 
@DrewR best is to have a method called __json__ on serializable...
 
DSM
@Crow:__dict__ isn't a method which turns anything into a dictionary, it's a dictionary where the locals are stored.
 
@DrewR something like that jsonify(**{k,myobject.__dict__[k] for k in ["name","age"]}) ?
 
its put me off
 
4:05 PM
@DrewR you want to look into the pyramid approach, there are renderers for views...
including json renderer
 
thirty minutes and ten browser tabs' worth of Wikipedia articles later, I think I shouldn't try to fact-check Physics.SE answers.
 
DSM
@Kevin: ooh, what was the question?
 
4
Q: Why is absolute zero considered to be asymptotical? Wouldn't regions such as massive gaps between galaxy clusters have temperatures of absolute zero?

user47408Why is absolute zero considered to be asymptotical? Wouldn't regions such as massive gaps between galaxy clusters have temperatures of absolute zero? I just do not see why our model must work the way that it does. I mean there have to be regions with no thermal energy out there, the universe is ...

 
@DSM yeah... but I use it a lot
 
4:13 PM
I am now uncertain about the meaning of: space, temperature, energy, radiation, particles, matter...
Physics.SE is the only site where I know less then I did before I read it
 
really? I feel like that after every class
 
Basically I took issue with the answer saying "we can't suck heat out of a system". I hate to use folksy anecdotes, but my kitchen fridge sucks heat from its interior constantly.
 
output = io.BytesIO()
writer = csv.DictWriter(output, gen[0].keys(), quoting=csv.QUOTE_MINIMAL)
writer.writeheader()
writer.writerows(gen)
response = make_response(output)
response.headers.add('Content-Length', len(csv_string))
response.headers.add('Content-Type', 'text/csv')
response.headers.add('Content-Disposition', '''attachment; filename="{0}"'''.format(filename))
return response
how do I SEND the data, though? I don't get it
 
How would I convert a string like "Thu, 21 Feb 2013 16:35:56 +0000" to mm/dd/yyy format? I tried convert = time.strptime(d, "%m %d %Y") but that gave me this error: ValueError: time data u'Wed, 24 Oct 2012 18:23:49 +0000' does not match format '%m %d %Y'
Not too sure where to go from there
 
DSM
I like the folksy anecdotes, not least because I think I can understand them. (Officemate and I got into a long conversation the other day about C++'s inheritance model, which came down to my insisting that a cat was an animal.)
 
4:23 PM
@RUJordan you do strptime to make it into a datetime object to begin with, you're giving it the improper format. 21 Feb 2013 is not 2/21/2013. After you've handed the proper format to strptime, you can use strftime to format it as you'd like
you probably need something like datetime.strptime(my_date, '%a, %d %b %Y %H:%M:%S').strftime('%m/%d/%Y')
 
@Crow any advice for the +0000? It's now throwing: ValueError: unconverted data remains: +0000
 
Rather than contextless inane questions did @Crow just answer a question? The end is nigh Gentlemen, say farewell to your loved ones for the apocalypse is come.
 
I know I'm surprised too
@RUJordan not quite sure... but I usually refer to this one for datetime formatting docs.python.org/2/library/…
 
@Crow now you have to answer a JavaScript question and I'll really be impressed lol ;)
 
that's easy, I can just say "you should use jquery it does all of the things!"
 
4:30 PM
If the +0000 is always there then add it into your format string
But beware that it probably signifies time zone so it may be necessary to handle it
 
@Ffisegydd precision isn't too important here thankfully
 
In that case try '%a, %d %b %Y %H:%M:%S +0000'
Can't test it as I'm on my phone
Or use dateutil.parser.parse (Google it as can't provide more explanation (phoooooone))
 
strptime makes me cry
datetime makes me cry
 
@AnttiHaapala well I'm a JavaScript guy -- relatively new to python. Any suggestions for better alternatives without using a library?
 
nope, that is the problem. Python datehandling is screwed in stdlib
and no one wants to do anything about it :d
 
4:36 PM
datetime is very similar to moment.js if that helps... dateutil is good as well
 
My boss told me to just substring the timezone variance off. So I used d[:-6] to substring and it works nicely.
 
@Crow without using a library?
@RUJordan yeah, just pray you do not need the actual timezones for anything :D
anw, keeping dates in date/dtatetime is still better than keeping them in strings :D
 
I don't, don't worry. It's being used to import data into Salesforce, so we just need a "general" date of transaction to include in the name. The specific date is done elsewhere and by a more experienced developer (python developer) than me
Anywhoodles, thanks guys
Appreciate the tips
 
the problem ofc is the lack of lax parsing
or even that of iso 8601
 
time is an illusion anyway.
 
4:39 PM
We're all an illusion
 
Lunch time doubly so.
 
I just ate lunch. I don't think it was illusory.
 
How active is this chat anyways?
 
@AnttiHaapala: That question title was almost word for word a dupe.
 
Like, people in here talking 24/7 or maybe a few hours of low time a day?
 
4:41 PM
Question you answered: Why does searching for > 100 different regular expressions slow my python script to a crawl?
I closed it as a dupe of Python re module becomes 20 times slower when looping on more than 100 different regex.
 
Lowish time during early morning gmt
 
@RUJordan The room info page has a nice activity chart.
 
Not that your answer was much one of one, I must say.
 
But otherwise fairly active
 
There is a definite nighttime period of low activity
 
4:43 PM
@Kevin I figured as much. It's the same in the JS room.
 
@AnttiHaapala: a little better, but doesn't explain why the OP observed the behaviour.
 
Though we have a lot more room owners than this room does
Not that that's good or bad
Or even relevant I guess
 
@MartijnPieters I'd... expect it to be 100x slower.
 
@Wooble: the post I closed achieved about 60x
 
@MartijnPieters I do not know the details about the cache :P
 
4:45 PM
(I didn't actually read the question before making that assumption from the title :) )
 
I didn't read the question either. I assume it means "looping on 101 regexes is 20 times slower than looping on 100 regexes"
 
@MartijnPieters writing
 
For that, I would blame "cache shenanigans"
 
looping on 100 regexes being 20 times slower than looping on just 1, as I read it, would be impressive.
 
Some kind of bulk discount, surely
Buy 20, get 80 free
 
4:50 PM
I am mostly quite surprised that the other post didn't show up when the OP put in their tags and their question title while posting their question.
The tags match exactly, the title is a close enough match.
 
darkside = "darkside"
print "Something something %s" % darkside
print "Something something "+darkside
Is there a difference between these or are the basically aliases?
Performance, security, etc?
 
If darkside is not always a string, the second version will fail.
 
@MartijnPieters done
@MartijnPieters the cache is worse than I thought
after re._MAXCACHE items are hit, the cache is cleared
 
@MartijnPieters meaning you can't concatenate non-strings to strings?
 
@RUJordan exactly.
@AnttiHaapala You do realise this is all already covered in the dupe, right? :-P
 
4:52 PM
Ahhh, I'm totally used to dynamic typing. This is going to be confusing for a bit
@MartijnPieters thanks
 
@MartijnPieters which dupe :P
 
DSM
Python is dynamically typed. But it's strongly typed, with few automatic coercions.
 
I suspect plain concatenation is faster than percent-style formatting, although I haven't tested it
 
@MartijnPieters hate you :D
 
oh god shell scripting... I dislike it so much...
 
4:54 PM
@DSM not going to lie, not sure what an automatic coercion is.
 
@Kevin which concat?
 
@AnttiHaapala You are welcome! :-P
 
+ + + is always slower
;(
 
@RUJordan This is nothing to do with dynamic typing.
 
trying to get my 200 but never succeed bc of those ppl who post dupes and I just try to answer fast
 
4:54 PM
@AnttiHaapala Specifically, the code RUJordan posted a page up
 
Automatic conversion is weak typing (Python is quite strongly typed)
 
DSM
@RUJordan: switching from one type to another automatically to make an operation possible. For example, if you do 1 + 2.0, you get a float out of it. But if you try to add a string to an integer, Python isn't going to guess what you mean.
 
@RUJordan you always want to use format now ;)
 
Seconding format.
 
thus:
 
4:55 PM
format is the new hotness. % is old and busted.
 
print("Something something {}".format(darkside))
 
@AnttiHaapala As for the cache, the Python devs did try to improve that but the attempt.. failed.
Yup, use str.format(), more powerful, more flexible, less prone to getting the syntax wrong.
 
weird question. Why would a package not show up in my virtualenv build after I install it using pip install?
 
@MartijnPieters it does not do so anymore
 
@AnttiHaapala Nope, that post I linked you to states that already. :-P
 
4:57 PM
@AnttiHaapala are those brackets literal? (not an example placeholder)
 
@Crow running the wrong pip?
 
I said the attempt failed. It was backed out again.
 
@MartijnPieters I hate you :D
is there anything martijn does not know
 
@AnttiHaapala Love you too, Antti. :-D
 
@RUJordan nope, placeholder
@RUJordan the reason to use 'asdfasdfasdf %s' % x
 
4:58 PM
@AnttiHaapala he doesn't know what number I'm thinking of right now!
 
instead of 'asdfasdfasdf ' + x is that
42
 
Hmm, dis is no help to me in determining whether a % b beats a + b. Their byte code is the same except one is BINARY_MODULO and the other is BINARY_ADD.
 
>>> x = None
>>> 'asdasdasd ' + x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'NoneType' object to str implicitly
>>> 'asasdasd %s' % x
'asasdasd None'
 
@Wooble nah, went into the directory and ran it. But it says the requirement is met by something completely different
 
@Kevin i mean multiformat case :P
 
4:59 PM
I think I agree with you, in that case
 
Oh I just googled it. format uses a sort of PDO style injection (or vice versa?) {1}{2}{3} etc
Got it
 
@RUJordan that above. but also % format makes it a bit easier to do mistakes
 
Iunno if this room has a bot, but it's time for lunch.
!!afk lunch time :D
 
>>> x = (1, 2, 3)
>>> 'asasdasd %s' % x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
@RUJordan ^
those are the main reasons why str.format() -> more robust code, easier to DWIM
 
I lied it's not lunch time yet :(
 
5:02 PM
We haven't got a bot, although the room owners have discussed it as a possibility
 
DSM
We do have a puppy.
 
Cabbage all. Anyone know of any standard video manipulation libs?
 
CapricaSix came in one day for a demo run, though.
 
@AnttiHaapala so why does format error out on that too?
>>> x = 1
>>> "derp {1}".format(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
 
laziness tip: skip numbering your brackets. "derp {}".format(x) also works
 
5:03 PM
@RUJordan 0-based indexing
 
Oh duhh... wow
 
>>> 'asasdasd {0}'.format(x)
'asasdasd (1, 2, 3)'
>>> 'asasdasd {1}'.format(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> 'asasdasd {}'.format(x)
'asasdasd (1, 2, 3)'
 
@AnttiHaapala I thought about mentioning that, but I coulda' been completely wrong, with my inexperience with formatting.
 
@AnttiHaapala I got it now. Much appreciated!
 
@Iplodman Nope. depends on what you mean by "standard" and "video" I suppose.
 
5:05 PM
>>> 'asasdasd {x}'.format(x=(1,2,3))
'asasdasd (1, 2, 3)'
this works too
 
(although even if you are more specific ex. "cutting the first thirty seconds from an mpeg", I'm still too uninformed on the subject to give a recommendation)
 
@Iplodman I did use gstreamer from python, it was hell :P
 
@Kevin Well, let's change that to 'comes with Python' and 'Images'.
 
@Iplodman standard is to use commandline apps, much easier
 
@AnttiHaapala And, as always, I'm lost.
 
5:07 PM
@Iplodman for image manipulation, I use PIL.
 
@Iplodman videos
 
Around now Ffise chimes in and says that PIL is in development limbo and you should use Pillow instead.
 
@Kevin s/PIL/Pillow/
 
@Kevin Ah. Does Pillow have 3.4 support, do you know?
 
@Kevin wrong again ;)
 
5:07 PM
I'm not sure. I only use it in 2.7.
 
I'll look it up.
 
@Iplodman I've used it in 3
I think...
 
Yup, Pillow has 3.4 support.
 
the reason for kill the PIL is that
it is pretty much impossible to install from source or so
even on 2
 
Time to install 3.4 (Again, did a factory reset) :D
 
5:10 PM
I'm curious, how many of y'all have an opinion on/use javascript frequently?
 
I use it occasionally for work.
 
Javascript - Looks like a bitch to learn, so I won't.
 
@RUJordan I like crockfordian javascript
 
Well, I want to learn JS, but I lack the reasons/time/dedication to at the moment.
 
@Iplodman youtube and watch videos by crockford
 
5:11 PM
Tutorials?
 
lectures
by the bearded guy who knows enough
 
@AnttiHaapala I like your style.
 
I like defining functions anywhere an expression could go. I don't like the class system (or lack thereof?). I don't like the not entirely clear scoping rules. I don't like the built-in array object.
 
Crockford style JS is good practice
 
5:12 PM
I think there is an error in your sentence
 
Rails sucks
 
@Kevin are you talking about the prototype methods? Array.prototype.slice.call([1,2,3,4,5]);?
 
also @RUJordan I use it everyday along side my python development. I see it as firstclass citizen language.
 
@Kevin python and javascript scoping rules are essentially the same
except ofc the "function definition jumps to the beginning of the scope"
 
Well you could hoist the scope, no?
 
5:16 PM
@RUJordan exactly like in python, in javascript the scope is the function
 
@RUJordan I don't use the prototyping system, so I think I'm not talking about it. (I suspect this comment will reveal my lack of mastery of the language)
 
@Kevin the .prototype. style sucks :P
 
@AnttiHaapala why?
 
that is why I like the crockford power constructors
it is so confusing
 
When I talk about scoping, I mean that occasionally this or self or whatever it's called will rebind occasionally to the window object in certain circumstances. I'm certain we've had this conversation before.
 
5:17 PM
no one can use it right
@Kevin we did
 
I'm still getting used to the prototype methods, but they are easily overidden
@Kevin no worries, I'm nowhere near a JS master (I'd say good at the minimum lol) but my python is merely a week old so just a py noob on this end.
 
the this is not about scoping at all
this is a special operator that refers to the "bindee" of the current function
 
And sometimes the bindee becomes window, much to my surprise.
 
as if python had implicit self declared as def method(self=window, foo, bar, baz):
it is fixable in strict mode :)
 
And sometimes for each (element in myArray) will iterate over the array's length attribute, much to my surprise
 
5:22 PM
bc it is for (propertyName in object)
 
yeah, but that's because for each in JS loops over all enumerable properties
or rather, for in loop, the forEach is different :P
 
yes it sucks, and that is why I seldom use that
 
Yeah, me neither, I stick to the normal for loop :)
 
blech javascript
 
there are bad structures like: with, eval, etc...
what you can expect if you are told to make a programming language in 2 weeks, it turned out very well
 
5:25 PM
So there's three ways to define a class, and two ways to do a for each... Every time I return to Python, I'm thankful for "There should be one-- and preferably only one --obvious way to do it."
 
lerdorf baked php for ages, and it still is worse after 5 rewrites than the original js :P
 
but we have eval in other languages as well :) cough cough
 
@limelights eval is fixed in python too :P
cant spit out variables into func scope
... anymore
 
*exec that is
not much wrong with eval
and ofc python too has strange scoping rules
[ i for i in range(5) ]
{ j for j in range(5) }
print i, j
python 2, where do we get error? :P
 
5:27 PM
Is there a way in Python to run "eval", but only in so far as to safely turn a string like '["this", "should", "be", "a", "list"]' into an actual list?
 
Any time I look at javascript I'm very grateful for not working with web front end stuff.
 
@Soviero I want to say, asp.literal_eval
 
@Soviero sort of: ast.literal_eval
ast
 
oops, wrong module :-)
 
abstract syntax tree
 
5:28 PM
working with both languages is really rewarding, just saying, as a fullstack developer you kinda need to :P
 
@Soviero I also made an extension on that... with more fullblown support, IIRC I did post it somewhere in SO or so...
 
@AnttiHaapala "This can be used for safely evaluating strings containing Python expressions from untrusted sources without the need to parse the values oneself." That's perfect! Why did you say "sort of"?
 
@Soviero limited support
 
@limelights Sure. My javascript projects tend to have much more interesting results than my Python projects. When they work, that is ;-)
 
@AnttiHaapala It supports strings, numbers, tuples, lists, dicts, booleans, and None. What else could you want?
 
5:29 PM
@limelights I've just never had any interest in the front end edge of things.
 
@Soviero sets :P
 
@Kevin im guessing you're not used to writing tests for your js? :)
 
and datetimes :P
 
@AnttiHaapala Why couldn't you just use list, and then run set() on it?
 
@limelights Excellent guess.
 
5:30 PM
@AnttiHaapala Ok, ya, that would be useful. Does datetime have a way to parse like the Linux date command does?
 
@Soviero dont ask too difficult questions
@Soviero no :P
datetime is teh suk
:(
 
there's strptime, but you have to supply a nice format string
 
finally, summer is over in this wonderful land
under 40 degrees outside
 
I don't know of any "just guess what the format probably is" function
 
Dealing with dates and times in general just sucks.
 
5:31 PM
@Kevin :) Once you get on that bandwagon, javascript becomes like any other language
 
epoch time is all you need
 
Your users must love you. :P
 
I was talking with some ppl about
having at least iso-8601 timestamp parsing in python core
 
@Crow All of our applications log using epoch time as the "datetime" field. Makes it so much easier to parse later
 
without speccing the formats
and they were like "why do we need to include all sort of crap in python stdlib, will have date formats changing every second day"
 
5:33 PM
@RUJordan you need %z for the +0000 thing
super late response on that one
 
@Crow it does not work like 86 % of time.. .:(
 
@AnttiHaapala but it's easily transferrable which makes it nice for web applications, I usually add a JSONEncoder which will turn all my datetimes into epoch times, making it easy for moment to parse it without knowing a specific format
 
@Crow i mean %z does not work
@Crow there is a format for dates, called ISO8601
it is an international standard, and everyone else recognize it but not python :P
 
@AnttiHaapala are you on Windows?
 
python doesn't recognize it? Isn't there a datetime from iso timestamp thingy?
 
5:36 PM
@Crow no, there is no, you can use strptime
but there is no formats for the timezone
so you need to parse it by hand
 
(IIRC their underlying C library is stupid and treats %z wrong)
 
"bc we do not want to support everything in standard library"
>>> datetime.datetime.now().isoformat()
'2014-05-28T20:36:37.392427'
@Wooble I am never on windows.
that much support in python :P
the other way it does not work
even with strptime you need to know if there is "T" or " "
@Crow ah forgot: impossible to parse that timestamp since the 6 digit fraction :D
 
@AnttiHaapala you know you can just do str(datetime.datetime.now())? It will give you the same result
 
@frostnational it does not, T missing :P
 
@AnttiHaapala, well, docs say they are equivalent
 
5:46 PM
no they are not
or then i ran 2 python versions
 
>>> str(datetime.now())
'2014-05-28 20:47:31.798417'
>>> datetime.utcnow().isoformat()
'2014-05-28T17:47:34.518414'
@frostnational kewl, fixed that
>>> str(datetime.datetime.utcnow())
'2014-05-28 17:48:20.622966'
>>> str(datetime.datetime.utcnow().isoformat())
'2014-05-28T17:48:31.887301'
 
I get different results too. That's strange..
 
no they lie
docs should say
equivalent to
@frostnational ah you linked the "date" docs :P
For a datetime instance d, str(d) is equivalent to d.isoformat(' ').
 
Right, found it
I feel stupid now :(
 
5:52 PM
>>> datetime.datetime.now(tz=tz)
>>> str(y)
'2014-05-29 05:52:06.564311+12:00'
hmm that works at least that way
 
And I've linked these wrong docs in one of my answers D:
 
but there is absolutely no way to parse that :D
@frostnational quickly go and delete it :P
if you have 3 upvotes, get even a badge ;)
 
2 upvotes ;) I fixed that, instead of deleting
 
I cannot see where this problem is coming from...
 
Gah, I never understand why a post that shows a traceback that doesn't match the code gets upvoted..
 
5:56 PM
runs off to Meta to demand required comments when upvoting
 
@Wooble I'd upvote that but then I'd have to comment.
 
I reflexively upvote any question with code that looks complete and a stack trace that looks like it could come from the code. Ain't nobody got time to actually verify the results!
 
The question is, in it's entirety: For some reason I am having trouble getting past the very basics of Flask with this app.. Thanks in advance for your help! with a minimal code example to create a Flask server without routes.
Plus a traceback, that doesn't match anything in the code sample. The code sample runs without problems.
 
Ah, a decoy traceback.
 
5:59 PM
A decoy traceback.
 
Like the cuckoo bird whose egg resembles a rival species', so it can infiltrate its children into their nest.
 
@AnttiHaapala: what do you mean by 'still wrong code'?
 
does not match traceback
 

« first day (1320 days earlier)      last day (3633 days later) »