« first day (2002 days earlier)      last day (2963 days later) » 
00:00 - 23:0023:00 - 00:00

12:00 AM
Here's what you get if you try to make a dict literal mapping a Hebrew string to the int 1: {"א": 1}
 
ok
i just pasted the dictionary in that answer
in to PyCharm. and everything went to shit
vals = {'א': 1,
        'ב': 2,
        'ג': 3}

print(vals.get('א'))
ok
see in PyCharm the characters are on the left and they keep jumping around on my screen when the cursor goes over it
and yeah I'm getting those funky quotes when pasting back in to chat
I gotta run. Enjoy the unicode battle.
 
See you.
I wonder if Programmers has enough users with native RTL languages that I could ask them how they put up with this.
Even if they pick variable names in LTR scripts and shove all the RTL text out of their source code and into other files, those other files are going to look crazy whenever LTR and RTL scripts have to mix.
 
12:47 AM
Someone created a namedtuple to help shorten my code and I'm trying to use one to make a list of monsters that have stats instead of a list of classes with stats. I'm not entirely sure how. This would be simple enough in js with an object constructor but I'm not sure how in python, haven't found anything useful about namedtuples either. ideone.com/kzy9ha
 
1:12 AM
@Shniper you don't need to use a new namedtuple for the same stats, you can just do e.g. 'fly': Stats(hp=10, attack=2, defense=3)
the namedtuple constructor is namedtuple("name_goes_here", "list of attributes here"); you only need a new namedtuple class for storing new types of records
and you would access your monsters dictionary as MONSTERS_STATS['fly'] for example
you could also create a Monster class instead that had different subtypes, which is a little more advanced since you need to learn about class inheritance but it'll probably help out in the long run
 
Is the collections module in C or in python?
 
1:33 AM
Interesting I just learned Python doesn't have " do while"
 
monsters = ('fly', 'mouse', 'rat', 'serpent', 'goblin', 'gnome')

MONSTERS_STATS = {
'fly': Stats(hp=10, attack=2, defense=1),
'mouse': Stats(hp=20, attack=4, defense=1),
'rat': Stats(hp=25, attack=6, defense=3),
'serpent': Stats(hp=40, attack=7, defense=3),
'goblin': Stats(hp=55, attack=8, defense=4),
'gnome': Stats(hp=55, attack=8, defense=8),
}

print(MONSTERS_STATS['fly'])

this will not return any errors but it prints nothing
 
NameError: name 'Stats' is not defined
 
Stats is defined earlier in my code, which is linked above.
 
sorry) i see
 
not a problem, I was mainly posting for tzaman because he's been helping me out for a while on this
 
1:43 AM
works fine for me
I see Stats(hp=10, attack=2, defense=1)
 
oh strange, it worked the second time i ran it
the way it is now is it possible to target the specific stats for each monster? eg. hp, attack, defense?
 
what do you mean by target?
you can say MONSTERS_STATS['fly'].hp to get its hp, if that's what you mean
 
@user3561871 Anything you can do with a do while loop can be done with a while loop, the former just makes certain things better looking.
 
okay thanks i did MONSTERS_STATS['fly'.hp] oops
 
2:04 AM
@Byte: collections is partly C, partly Python.
In 2.7, the C parts are deque and defaultdict.
 
@user2357112 Can you explain a bit about how built-in procedures written in C get executed without parsing to the bytecode first? Does it simply get parsed into some sort of C source and so doesn't need to run through the interpreter?
 
They're compiled to machine language, just like the C code that makes up the interpreter itself.
 
user559633
all python goes through bytecode first.
 
user559633
absolutely nothing in python gets written as machine code and all of it goes through the python vm first
 
When python source is parsed to bytecode, the resulting control-flow is stack-based where each opcode is executed in a giant switch statement; whereas parsing to C code doesn't need to conform to a possibly un-optimized order unlike the bytecode flow; Am I right about this or am I understanding incorrectly?
 
user559633
2:13 AM
all python goes to bytecode first. the "when" there is redundant
 
user559633
this song is pretty cool
 
user559633
probably worth noting too that c is a cpython implementation detail. python is just a recipe and you can implement it in many languages
 
@tristan: Stuff like PyDict_GetItem doesn't go through bytecode.
 
That was my assumption too.
 
user559633
2:17 AM
Yessir it does. How do you think your python script gets to PyDict_GetItem ?
 
user559633
I promise you it goes to bytecode first, even if it's a quick jump in cpython to the c-api
 
user559633
maybe it's relevant, but my knowledge on this is 2.6-3.6 only
 
Oh! There's the misunderstanding.
 
PyInitialize_Ex, perhaps.
 
user559633
in any case, it all goes through the python VM to get to anything C.
 
2:19 AM
I know that everything in python must be initiated through a bytecode op, but I am wondering how things written in the c-api avoid the bytecode
 
user559633
maybe pre 2.6 there was some direct "don't lex or eval, just go right to the open C"
 
I think that was where I explained incorrectly
 
user559633
oh, things that go back to the C-api are no longer visible by bytecode/the interpreter
 
And the interpreter is limited to stack-based operations that may possibly not be as fast as an optimized C operation right?
 
user559633
it's basically like [my script]->[call to c-api]->[handoff of args]->[GIL holds]->[shit happens below the visibility of the interpreter]->[pyobject comes back to interpreter]->[back to bytecode]
 
2:22 AM
There's plenty of setup in C before the bytecode evaluation loop is entered.
 
user559633
well, sure.
 
user559633
but we're not really talking about that
 
user559633
standard disclaimer that i'm probably the dumbest person in here applies
 
I'd have to disagree as I am the one asking these questions and you are able to provide answers.
 
user559633
it's impossible to know the entirety or even the majority of how a complex system works in 2016.
 
user559633
2:24 AM
if it helps, consider that when you pass something off to the gil, unless you specify otherwise, it's a blocking operation in python
 
user559633
if you're looking using the dis module, things handed off to the C-api are often (always?) explained as built-in
 
"when you pass something off to the gil" - huh? The GIL is just a lock. Did you mean to use a different noun there?
 
user559633
err, yeah. sorry, tired and had a handful of beers.
 
user559633
when you pass something off to the layer beneath the interpreter
 
user559633
and the GIL is also an implementation detail, so we're pretty deep into "when using cpython" territory
 
2:27 AM
def add(a, b, c): return a + b + c gets translated to some bytecode that takes 3 objects, and adds, etc... But if add was a built-in function written in C, how would it operate differently than whatever the bytecode instructions would dictate? (* I think I distilled my question better this time ;))
 
user559633
where add is implemented already and known by the interpreter to be a function and signature provided by its underlying layer?
 
It'd consist of several calls to PyNumber_Add and some explicit handling for exceptions and refcounts.
 
user559633
if so, the types of a,b,c would be checked to make sure they match some signature (e.g. *args are all int), then it would be dispatched to the relevant function
 
user559633
if it was in bytecode, it would come down to how (type) (operator) (type) behaves
 
Alright, I think I understand it now, with the exception of (type) (operator) (type).
 
user559633
2:31 AM
yeah ignore that, it's a whole can of poopy worms
 
user559633
the tl;dr is that if it's bytecode, python will use its existing logic to try to figure out. if it's implemented in C (careful by saying built-in unless you compiled it in), python just sort of shoves all the parts across the table and says "let me know when you're done"
 
Alright, thank you both.
 
user559633
:) cheers dude/dudette
 
user559633
i could also be totally wrong though, so check my work, and if i am, please come back and throw it in my face
 
I doubt you're incorrect, after a lot of reading I came to the same sort of conclusion but didn't understand what it really meant. Much like when you write a working, creative piece of code but then don't understand why it's working.
Anyways I doubt I'll truly understand it unless I write a basic python interpreter in C.
HL3 or Portal 3 is more likely to happen though, haha
 
user559633
2:40 AM
lol have at it. playing with the c-api or dis should help though
 
user559633
alright, i'm off. have a good one :)
 
You too, have a good night.
 
3:01 AM
I don't know if I've been working on my code so long that I can't spot the simple bug or i'm just dumb.
 
 
1 hour later…
4:41 AM
^ was edited
 
 
2 hours later…
6:30 AM
Django I created a new settings folder for my dev and production settings file but now I am getting template doesn't exist error
Please help out I am new to django
 
 
1 hour later…
7:38 AM
Word.
 
8:29 AM
Cbg
Anyone know a (old) programming language that has no scoping rules? Ie it's all just global state?
 
Even FORTRAN had scoping :P
 
Yeah exactly :) I'm trying to insult one of the tools we use because it basically has no scoping rules
My backup is "The only place where no scoping is good is in call of duty"
 
Top bants.
 
It's a mailing list that gets seen by relatively senior product people, but, yeah. Bants above all.
 
8:46 AM
Okay I already regret the bants. But that's just part of the rush.
 
@AnttiHaapala Yes that was exactly the issue. Thanks
 
@RobertGrant Never regret the bants.
Stand up for your bants.
 
9:33 AM
:)
 
 
2 hours later…
12:01 PM
saturday cbg
 
heheh what brought you to that question
 
wish there was a way to oppose undelete
@idjaw 10k tools, that answer had some delv on it
 
ah ok
 
I added another, since, well it is not an answer
 
1:39 PM
The Animaniacs are on Netflix now. Time to be a kid again.
3
 
DSM
2:17 PM
If by "kid" you mean university student and then graduate student..
 
I loved the Animaniacs
 
DSM
Morning cabbage anyhow, everyone!
 
morning cabbage!
and morning rbrb. Time to take the kids to the gym
kiddie gyms are awesome. It's all obstacle courses
I want obstacle courses
 
DSM
They're fun! But I admit the people who go the obstacle-course places here in TO tend to be a little more.. intense.. about their sporting activities than I am about mine. :-)
Have fun at the gym!
 
2:44 PM
cbg
I guess this one is unclear, and the OP's grasp of English, Python, and how programming works is so poor they won't be able to fix it: stackoverflow.com/questions/36518252/…
 
 
1 hour later…
3:47 PM
Well, nobody's attempted to answer that. And although I like to post clarification request comments, I really don't know what to say to that OP. So I guess it's time for...
 
4:30 PM
Quick question guys, how is something like this done in python Board[] pmoves=new Board[6];
Board is a class
 
DSM
Does that syntax create six separate instances of Board?
 
Rather than asking us to translate some language that we may not understand, you should probably explain what you actually want in English.
It looks like Java (which I'm sure @DSM will just love that I knew)
 
re-cbg gents
 
Alright, so for my last class in school, we are being taught python. We had to create an entire game in Java and then convert it into python so we can understand the difference in syntax. No idea why we are being taught this way, but that's how the teacher teaches the class apparently.
 
ok so let's put forward some thinking strategies
 
4:37 PM
So in Java I did a variable called Board[] pmoves = new Board[6] creating 6 seperate instances of Board.
 
what does this do in java
Board[] pmoves=new Board[6];
does that create an array of Board instances?
 
DSM
A line-by-line translation of Java into Python will make for some very ugly Python code. I can understand the merits of seeing the same thing implemented natively in different languages, but I doubt how useful assigning the translation is to students pedagogically.. but then again I don't regularly teach programming.
 
If you try to translate line for line then you'll fail. It declares a typed array (of length 6) but not actual Board instances, you can't really create typed arrays in Python.
 
instead of line by line translation, you should mimic the behaviour and do it in Python.
based on however you designed it. If you created a bunch of classes. Those classes must have a responsibility
 
That's what your lecturer will be wanting, for you to understand the concepts and be able to apply them in a different language.
 
4:40 PM
translate that responsibility in to python
I actually had do this once upon a job from perl to python. I instead read the documentation on it and designed the app based on that. I looked at the code. But only to make sure that there weren't any extra implementations that were not documented
 
DSM
Makes sense. Last time I did a port it was from C# to C++, so there wasn't as much of a jump. Some routines I really only did change the syntax of, because there was no new pattern to take advantage of.
 
that's an interesting port
what was the reason for going from C# to C++
 
DSM
Performance. This was a number crunching library, which was originally done in C# and I needed to call it from some other C++ code. We switched to a single C++ lib and then swigged it for calling from Python, C#, and (shudder) Java.
 
yeah that totally makes sense.
 
Afternoon cabbage.
 
4:55 PM
@DSM I was meaning to ask you. With all your number crunching, do you hit limits with Python where you resort to just straight up C?
@Morgan'Venti'Thrappuccino whaddup
 
@idjaw Watching TV and sippin whisky. You?
 
@Morgan'Venti'Thrappuccino Just got back from taking my daughter to her gym class. Now sippin' on some coffee (had a 6 AM wake up today....kids love waking up early on weekends)
 
DSM
Short version: yes. Not every problem can be vectorized, and if it depends on doing a lot of different things quickly all over the place, approaches like cython or numba are impractical.
 
@idjaw Ooof. 6AM is too early for anything.
 
@DSM I'm intrigued by some of the problems you come across sometimes. It's something I've never delved in to.
@Morgan'Venti'Thrappuccino it's ridiculous. They sleep in on the weekdays and wake up early on the weekends. It's like they have this collective agreement to make us exhausted 7 days a week
:P
 
5:00 PM
@idjaw Sounds like fun. :P
 
The trick is to not have kids.
 
Yeah, that's my plan.
 
my wife is currently talking to me about how she saw a 9 month old baby today and she missed that
....
:D
 
Get her a cat.
 
that's actually a really good idea.
 
5:02 PM
Again, that's my plan. :D The GF and I are getting a kitten soon.
 
The kids would like it too
 
It's always a good idea to get a cat.
 
Much like getting a bottle of gin.
 
DSM
That makes me want to pour myself a bottle glass (oops.. too honest?) of Scotch, but not having had breakfast yet I think I'll have cereal instead.
 
You could do both. Replace the milk with scotch?
 
5:05 PM
I wonder how cheerios would taste with some Aberlour
 
Scotchie-o's!
(I can't decide if it looks better with or without the apostrophe)
 
scotcheeos
the double e gives it a friendlier look. Fun for the whole family.
 
Mmmmm, I'd eat them.
Malty and peaty cereal.
 
DSM
I do have some Alpha-Bits, I think. They're alphabetically delicious!
 
I've seen than 27% of my proposal followers are from stack overflow with top tags being python. so I thought maybe it's ok to put an ad here
 
5:09 PM
No.
Well, ad for what?
 
@Ffisegydd ad for the proposal to inform other interested people about that
 
I think you've linked it enough now.
 
@Ffisegydd yes thanks for your attention
 
Anyone else watch Bob's Burgers?
 
I've seen a couple of episodes. Never fully invested. But enjoyed the episodes I saw
 
DSM
5:22 PM
Jul 31 '15 at 16:01, by DSM
I love Bob's Burgers so much storywise that I wished I liked the animation more.
 
It's a wonderful show. The best part is that every episode they have a new pun related burger. The most recent one from the ep I'm watching currently is "To Thine Own Self Be Bleu".
Which is amazing.
 
DSM
My favourite new-every-episode gags are the neighbouring store and the exterminator truck name..
 
The ones from this episode is "Weapons of Mouse Distruction" and "I Think Therefor I Jam: The Philosophical Preservatives Store"
 
I'm really enjoying Rick and Morty
that show is freakin' hilarious
 
Also an amazing show.
 
DSM
5:27 PM
There are advertisements for it in subway stations here, which surprised me.
 
Never watched Bob's Burgers. Big fan of Archer.
 
@Ffisegydd It's like Archer, but with more word play and slightly less obscure references.
 
Same people make it IIRC.
Or maybe I made that up.
 
Honestly, Bob's Burgers has surpassed Archer for me. Especially after season 4.
Nope, just H Jon Benjamin.
 
I've heard that Archer has really gone back to the good old stuff with the latest season.
 
5:29 PM
Archer is Adam Reed (Ray) and Bob's Burger's is Loren Bouchard.
Yeah, I haven't watched this season yet, but once I finish this episode I'm starting it.
 
Finally gotten around to setting up a decent CentOS VM so I can do some data work at home.
 
5:42 PM
I've brought up the pythondotorg site locally. Trying to run the tests but failing to do so. I must be something that is of type stupid.
 
Managed to build Hadoop.
 
ha doop doop woop shoop da woop
 
DSM
♫ mmmbop ♫ ba duba dop ♫
What do people think about this? It's well-intentioned, but I think it would have been closed as too broad if the OP hadn't self-answered.
 
@DSM Well, now that's stuck in my head the rest of the day...
 
@DSM ha! I was just looking at that and telling myself "Is this dude seriously asking for this?"
and saw that someone answered and had an "are you kidding me" moment. Then noticed it was a self-answer
 
5:49 PM
Space Engineers is on special on Steam!
 
So, verdict is, yes. This season of Archer is definitely back to basics.
 
is django supposed to be disliked as quickly as I started disliking it?
Because I'm really not liking it
it's been a while since I played around with django....but getting back in to it is not bringing up any good feelings
 
DSM
I made it most of the way through one of the tutorials once before I got bored. That's the limit of my Django experience.
 
pythondotorg is django....it's so....massive
ok nope. I'm done. I'm gonna find something more interesting to have fun with.
this is bringing me too far back to my all-in-one PHP days
 
6:06 PM
Do you need to talk to your sponsor? I know PHP is a hard one to shake.
 
@RobertGrant Got it. I should play it.
 
@Morgan'Venti'Thrappuccino I'm one year sober. Wait, does it count if you read through PHP code to find an answer?
 
DSM
(shakes head sadly)
 
awww :(
 
@idjaw There there, it's going to be okay.
 
6:08 PM
resets timer to 3 days
 
No it's not.
"This has been a PHP free zone for 2 0 days"
 
For penance, say four hail Guidos.
6
 
Considered writing a "Hail Guido" prayer but then thought a) it'd be sacrilegious, and more importantly b) I'm lazy.
 
@davidism it was a self answer
 
6:12 PM
it's a terrible question, literally "I have a decent idea of how my program works, how do I write an app that does the same?"
 
it's very broad, yes.
 
@Ffisegydd sacrilegious as in you might not write a prayer worthy of Guido?
Because I totally get that
 
Yeah exactly.
I did my Neo4j certification the other day. They've decided to send me a free t-shirt and stickers O_o
"Please wear out t-shirt that says "Certified Neo4j Professional"! Please! We want free advertising!"
 
6:30 PM
Sweeeet
 
cbg all
I have the "Pinky and the Brain" theme song stuck in my head and its awesome
 
"Fizzy and the Bobby, Bobby, Bobby, Bobby..."
 
@JGreenwell Narf! Zort!
Can't remember the rest...
 
6:57 PM
my kids are loving it, star wars, Dr. Who,....I have geeky kids and I couldn't be prouder :)
 
Is there any canonical reference for how to "open" a file in the sense of what you get if you browse to it in your GUI file manager, right-click on it, and pick "Open"?
 
wouldn't that type of canonical answer make more sense on SuperUser?
 
When you click "open", it opens with some program that can display it correctly.
 
DSM
@user2357112: not that I know of in a platform-independent way.
 
@JGreenwell: I don't mean a canonical reference for how to browse to a file in your file manager, right-click on it, and pick "Open". I mean doing the equivalent in Python, or [programming language here].
 
7:10 PM
Oh, open(*filepath here*)
 
DSM
AFAIK you have to look at where you are and call xdg-open/open/start as appropriate.
 
@Byte: No, that's the other sense of "opening" a file, the one I don't want.
 
@user2357112 Oh alright, sorry I couldn't help.
 
DSM
Hmm. JFS seems to think that opening the file via webbrowser might delegate appropriately.
 
This doesn't work?:
58
Q: Open document with default application in Python

Abdullah JibalyI need to be able to open a document using its default application in Windows and Mac OS. Basically, I want to do the same thing that happens when you double click on the document icon in Explorer or Finder. What is the best way to do this in Python?

 
7:13 PM
Sweet.
 
use the second answer down, the accepted one is incomplete
 
accepted answer in that is Windows & Mac but there is another answer that includes Linux
 
the windows solution is also lacking
 
DSM
I hate to repeat myself, but with the exception of os.startfile on windows, that's just basically just branching on your OS and calling (as I said) xdg-open, open, or start.
 
Yep, there's no cross platform solution. I was looking it up the other day, there's a bug report about it.
They came to the same conclusion, you'd have to branch. And the other issue is that startfile is an os level call, but the others would belong in subprocess or shutil.
 
7:19 PM
I've just read about Python3's typing hints. Does this improve the performance of python code by making the runtime not have to check the type?
 
DSM
No, it doesn't improve the performance. It doesn't even check the type.
 
What are the type annotations for then other than possibly improving readability?
 
static analysis tools could use them
they have no real use
 
Well, apart from static analysis :P
 
Alright, thanks
 
DSM
7:22 PM
In principle you could test them at runtime, but that's not included in stdlib ATM AFAIK.
 
DSM
7:32 PM
Rhubarb for all!
 
7:46 PM
cbg all
 
Hello
 
Cbg all
The python tutorial mentions "Python also offers much more error checking than
C"
I don't understand how since python is a interpreted language.
 
8:10 PM
If you do x = [1, 2]; x[4] in Python, Python catches that.
If you do int x[] = {1, 2}; x[4]; in C, that's undefined behavior.
Python has very little undefined behavior.
 
8:53 PM
Thanks @user2357112. Any reason why?
What does python do differently to achieve this?
 
Why what? Why Python has little undefined behavior? Because that's how it was written.
 
9:50 PM
python also has garbage collection, unlike C(++)
 
The C language's static typing only makes sure that whatever types you assign to variables or functions use/return whatever you specify. But in the example above, int x[] = {1, 2}; x[4]; C will execute that without raising an error because x[4] just shows what is in the memory address stored 4 integer sizes past the memory addr of x
 
it's hard to leak memory with python
 
hello guys, I have a python script that prints each elements in a for elem in file:
I would like to add a slash after the element but it prints / on the next line
How can I make it print the slash on the same line
 
print var will print the variable and print a newline; print var, will not print a newline
in python 2
print(var,end='') should work in python 3, I'll check
 
10:07 PM
fp = open('filepath', 'r')
    for elem in fp:
	    string = elem[:]
	    string = string.replace('\n', '/')
	    print(string)
fp.close()
This will work.
 
I think Bob needs the newlines, but the slashes are on the wrong side
something like print(line,end='\\\n') might be of use
 
@BobEbert a for loop iterating over a text file iterates over each line, and each line has a '\n' delimiter at the end. Are you trying to print the slash after each word or each line? If after each line, the code I wrote should be ok, maybe not the most efficient solution though.
 
10:35 PM
I'm sorry, I am back
@Byte It indeed really worked well! Better than my solution. I did elem.split("\n") then print ("/"+elem[0]+"/")
but it felt wrong
 
while we're at it: always use files in with open(...) as fp: to be safe
 
what do you mean
I did f = open ("path../")
 
@BobEbert something like this: stackoverflow.com/questions/1369526/…
second top answer shows what I meant
 
Yes I saw some people code this way but never knew why
to be safe you say...
 
if you see something like this, suspect a good reason:)
from the answer I linked:
> The advantage of using a with statement is that it is guaranteed to close the file no matter how the nested block exits. If an exception occurs before the end of the block, it will close the file before the exception is caught by an outer exception handler. If the nested block were to contain a return statement, or a continue or break statement, the with statement would automatically close the file in those cases, too.
go read those posts, they are useful
 
10:46 PM
I just read it haha
 
and if you see a pattern in many posts, investigate the source, it's good for you:)
 
basically it assures that the file will be closed?
 
yes
even if you get an error in your parsing block
and you don't have to close by hand if there are no errors
 
Ohh!
 
it's the right way of doing it
 
10:48 PM
it says that "with" works with "unmanaged resources"
Do you know what these are?
 
nope
there are a lot of sources on the web about the with statement (and python in general, of course)
this was just the quickest thing I could find on SO
 
Thanks for the tip!
 
anytime
 
@AndrasDeak There's a problem with it though, if I want to simultaneously open (lets say) 2 files, it wouldn't work correctly
 
why not?
 
10:52 PM
hum, let me see
 
python 2 or 3?
 
nvm you are right
 
00:00 - 23:0023:00 - 00:00

« first day (2002 days earlier)      last day (2963 days later) »