« first day (1585 days earlier)      last day (3355 days later) » 

12:12 AM
cbg
 
12:54 AM
I edited that question, does it make sense for you now ?
 
Sorry @Walle, I voted to reject that edit. The reason it's unclear is that OP clearly believes they have a tuple and even refers to their immutability, although what they have is a dict. Your edit may or may not conflict with what OP wants, because their question just doesn't make sense.
 
perhaps it is a good idea to comment the question with a link to types in Pyhton
 
The existing comments are plenty IMO - OP can clarify the question if they want; they have enough info to do so.
 
what does cv-plse mean ?
 
"Close Vote Please" - it's an invitation to people with enough rep to review the question, and vote to put it on hold if they agree. There's a browser plugin to assist with that.
 
1:42 AM
 
 
4 hours later…
5:33 AM
It's too late, I'm getting punchy... stackoverflow.com/questions/28555170/…
 
6:01 AM
cbg
 
 
1 hour later…
7:14 AM
hmhmhm
 
7:26 AM
@MattDMo Oh, I had a python like on the upper left corner. P. molurus bivitattus is the name, if I recall.
 
cbg
 
@AnttiHaapala fibonacci(10**19) is rather large ~= 2.20412332360153435830640E+2089876402499787337
 
@PM2Ring :P
I guess OP does not have enough harddisk to store the whole number... :P
 
Probably not. :)
 
7:29 AM
hmmm actually...
surprisingly it would fit in 64-bit address space?
it has only 2^61 decimal digits...
 
Cbg
 
cbg
@PM2Ring and btw that's no exact, show the exact value :D
@PM2Ring reminds me of the prime guy
 
0
A: I want to display software name and there versions in Ubuntu using python

Avinash RajYou need to import subprocess module. >>> import subprocess >>> subprocess.call('dpkg --get-selections', shell=True)

 
@AnttiHaapala Ah, no. The log to base 2 of fibonacci(10**19) is ~= 6942419136306173016.2. That's a lot of bits.
 
Good luck. 18446744073709551615 is 2^64 bits, to store the sieve you need 2^60 bytes, which incidentally is 1048576 TiB. With current hard disk prices it will cost about 35 million dollars to store this data. — Antti Haapala Feb 12 at 7:57
 
7:36 AM
@AnttiHaapala Oh, yeah. I remember that question.
 
@PM2Ring less than 63 bits of address space
still memmappable in the userspace of the theoretical maximum of x86-64 ISA :D
 
Sure, 64 bit address space is big enough to store the number of digits in fibonacci(10**19), but not the number itself.
 
now I think you're confusing address space with register width
I mean, it does not even cost more than that ^100 million dollars to store the number
and theoretically you could memmap it on a 64-bit computer then
it is all about choices: if you have 100 million, would you buy a tropical island, or calculate the 10^19th Fibonacci exactly
 
Maybe I am confusing address space with register width. :)
I calculate that it would take ~= 2**57 64-bit words to hold the binary value of fibonacci(10**19). Does that sound right?
 
yes
I thought it this way: if you sum the numbers in binary,
then maximum for each addition you will have 1 carry bit = 1
thus the absolute maximum for 10^19 additions is 10^19 bits if you start from 1 bit
 
7:55 AM
That works. To get a little more accuracy you can do:
>>> from math import log;phi=(1+5**.5)/2;1E19*log(phi)/log(2)
6.9424191363061729e+18
I did my earlier calculation using Binet's formula and mpmath
 
hmmm
yeah
maybe I should comment the prime guy, that if he wants to factor 2^64
then one needs only 2^32 sieve. and that is very doable
ah but you had said it yourself there already :d
 
Sure. I mentioned in one of my comments on that question that I have a database here of all primes up to 3000000000. FWIW, I computed that database using C code I wrote on the Amiga 20 years ago. The database I built on the Amiga was quite a bit smaller; back in those days a 128MB hard drive was considered large. :)
 
Whee, caught someone revenge downvoting me.
Heh, and they failed to read my answer, so they repeated the mistake the OP made in their 'look, I edited mine to correct the mistake you told me about' edit.
 
My database is generated using a modified sieve, similar to this Python code. In fact, that Python script is so fast that it compares very well to the database extraction code. Even though the database stuff is written in C it's still time-consuming unpacking the prime data from the individual bits.
@MartijnPieters Tee hee. :) Link, please.
 
8:12 AM
@PM2Ring the opposing answer is now deleted. Not that the vote on my post was removed.
0
Q: FOR loop on File Management using Python

Anand SurampudiI am working on a small exercise. There is a text file which has 3 columns: EmployeeID, First Name and Last Name. Write a program to create dictionary whose keys() are the EmployeeIDs in the text file and the values() are the first and last names combined. I tried first without loop....

 
Thanks, Martijn. It's kind of surprising to me how common that error is:
for line in f:
        line = f.readline()
 
The question also received a downvote, which was surprising given that the OP did clearly their best, provided all info asked for and linked to their research.
@PM2Ring the competing answer told the OP to use the file as a context manager (use with keyword, it makes the file IO safe:) and removed the loop altogether.
So I downvoted and left a comment. I got a downvote in return and found the other author had just lost 3 points from the rep they had when posting. Tsk tsk.
They then edited their answer to add the loop from the question, complete with the f.readline() still there.
 
8:29 AM
lol
 
8:40 AM
Noob python question, I need to call a subclass's method in a base class and it's not getting to the subclass's module.
Basically I have a base class that implements foo and each subclass implements __foo - when I do self.__foo from the base class it calls the base class's __foo rather than the subclass's
 
hai friends
 
re-cbg
 
cbg
I guess there is no way to do this sort of IoC in Python then.
 
9:05 AM
@Benjamin that's correct. AFAIK a parent class knows nothing about any subclasses derived from it.
 
hey, does anyone know the API to turn off transactions in sqlalchemy ? reading through docs + SO cant seem to find the right solution here
 
9:28 AM
cbg
 
@Ffisegydd meh
 
Alas, unless someone wants to jump in with some black magic, them's the facts :P
 
@KurtSpindler, which backend?
 
9:50 AM
@BenjaminGruenbaum Maybe I don't understand the question., but you can easily call a subclass's methods in the base class if you pass a subclass instance to the base class. But using the double-underscore prefix interferes with that, due to name mangling. Eg, try this:
class BaseClass(object):
    def foo(self):
        return 'Base foo'

    def show_other(self, other):
        return self.foo(), other.foo()

class SubClass(BaseClass):
    def foo(self):
        return 'Sub foo'

t = (BaseClass(), BaseClass(), SubClass())
for slf in t:
    for other in t:
        print slf.show_other(other)
output:
('Base foo', 'Base foo')
('Base foo', 'Base foo')
('Base foo', 'Sub foo')
('Base foo', 'Base foo')
('Base foo', 'Base foo')
('Base foo', 'Sub foo')
('Sub foo', 'Base foo')
('Sub foo', 'Base foo')
('Sub foo', 'Sub foo')
 
tsk, non-function-print
 
That's just to let people know I'm still using Python 2. :)
 
there's always __future__
 
grmp grmp grmp bike chain broke grmp grmp grmp 30 pounds lighter grmp grmp grmp
 
10:09 AM
Cabbage!
 
cbg
 
@MartijnPieters huh? You had to walk?
 
@poke I managed to limp the bike to near a bike shop. Walked the last bit.
Now waiting for a new chain to be put on.
Can't be bothered spending an hour doing it myself when they can do it for me in 15.
 
10:28 AM
Since there are no real django rooms I will ask here :D When I set blank=True in a model field and use a model form, do I have to say that it is not required once again?
 
you probably want null=True as well
depending on the field type
 
yes I did that too
 
it should default to required=False iirc
if both null & blank are True
 
okay :) so the default of every field is required=True when I didn't blank=true?
 
In addition, each generated form field has attributes set as follows:

If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True.
 
thanks Mark R. :)
 
sure
 
Spam gone.
 
I like how SE just randomly dishes out rep for associated accounts
 
Hmmm, should I bother going all the way down to London for Postmodern Jukebox?
 
10:36 AM
in this weather I wouldn't go down to London for anything
 
Also: cabbage(all, tone=warm)
 
@Intrepid nah. Come down to Bath and we can drink scrumpy.
 
except maybe a pint with Hammond from Top Gear
 
Well, Scottish weather is currently malfunctioning. It's raining, clear blue skies and I can't see any clouds
Where the hell is the rain coming from?!
@Ffisegydd I do like a good proper scrumpy
 
Went to the Bath cider festival on Friday just gone. Was good. Over 100 different ciders on offer, plus a Wurzels tribute band.
 
10:39 AM
Jealous. Most Scottish cider should relabelled to "tooth rot"
 
There was a Scottish presence there actually, had 10 or so ciders on offer.
Cider festivals are good in theory, but you can get some proper awful ciders sometimes.
 
I'm guessing Thistly Cross would have been there?
 
The name sounds familiar, so possibly.
 
Yeah. Tooth rot ;)
 
Had a proper bad one, was basically a toffee apple cider.
It was just vile.
 
10:44 AM
Urgh
 
Seemed like a good idea at the time.
 
They always do
Like banana bread beer. Top tip - don't do it
I'm trying a new local Edinburgh brew called "Blind Pig" on Friday. It's apparently quite promising
 
hello
 
That was slightly sinister. I could mentally imagine you spinning around in your chair, stroking a white cat like some kind of Bond villain...
 
@Ffisegydd One of my nephews makes a good scrumpy. But I bet it's not as good as Discworld scumble. :)
I wonder what this guy is really trying to do.. and if he'll succeed without bricking his system. :)
 
10:58 AM
Could be just trying to ensure his MBR hasn't been modified?
But he could always be on the other side of the fence
 
That's my triage done for the day
 
11:20 AM
I strongly suspect this is a troll post. The comment is raising my troll alerts.
So are the choices of variable names and the account name.
@PM2Ring: that post is not worthy of an answer, really.
Hrm, account has been around for 2 months, troll alert level lowered.
and the site went to read-only mode so I cannot vote to delete.
 
Possible-Troll can't comment/troll though, so at least there's that.
 
Should I delete this answer? It was so simple I couldn't help myself. :)
I understand why the question was closed, but at least the kid posted his code and a full traceback...
 
Site's back btw.
 
And back.
 
read-only-mode
 
11:30 AM
Fluctuating, some fail-over failing somewhere?
 
oh, now it's gone..
 
@Ffisegydd Which site? I can't post comments yet if you're referring to SO.
 
It was back for a bit Roman.
 
We are looking into network issues now, stand by.
 
@Ffisegydd I must have blinked. :)
 
11:36 AM
cbg
 
It was brief. I'm just sat here constantly refreshing, crying onto my keyboard.
 
15 utc
17 EET
 
3.5 hours?
hmm
 
@Antti yeah 3.5 hours time.
 
11:37 AM
yesterday I only got 154 rep :(
but I managed to get the 15k in the morning
from the itmestamps I infer that the site was rw 7 minutes ago...
everyone must be writing their answers :D
 
please notify me once the site get back to normal.
 
Ideal time to write an app that calls you as soon as SO is back online.
 
Huh. Some Beeb reporters were almost hit by artillery fire. Some peacefire...
 
hmm
python standard library needs peekable iterators
online
 
11:55 AM
@PM2Ring, thanks for proofreading my strptime
 
No worries, Mark. If you've fixed your answer I'll delete my comment, once the site's back up.
 
@PM2Ring, yep, edited + added closing paren to the strptime call
 
And one-boxing tweets isn't working either..
 
and down
there was 1 answer submitted 22 seconds ago
and I copypasted my answer to another q and
failed
 
11:59 AM
sad
what am I supposed to do in the office, actually work?
pff
 
@MarkR. Work? Who is that?
 
:)
 
@MarkR. Ah, I didn't notice that missing paren. :) Maybe you should also chuck in a link to the docs for time.strftime so the OP can see the table of format directives.
 
@PM2Ring, if the site decides to work, I will
added
 
Sometimes I edit minor typos in answers myself, but I generally prefer to just drop a comment when the answer's still fresh, as it can be very annoying to have someone else edit your post when you're in the middle of fixing it.
 
12:10 PM
it's back. SO returned to normal mode..
 
Yep
 
12:23 PM
stackoverflow.com/questions/28560813/… 3 answers and the 2 others are just my answer again
 
anoyne come up with another
and cbg
 
12:42 PM
1
Q: list of list concept in python

dangerousI solved the below problem using nested while loops. Is there a way to solve the problem in a simple, Pythonic way? Question: Define a procedure that takes in a string of numbers from 1-9 and outputs a list with the following parameters: Every number in the string should be inserted...

hate these kinds of questions "I have a problem that I cannot formulate in words, and I have some really complicated code for it and actually I do not know myself what it should do, but how to do it in a pythonic way"
 
@Martijn appears you can get an easy upvote/two from answering typo questions though :)
 
@JonClements I dislike that about SO.
 
can get equally easily some downvotes :D
 
Though not typo, I got 11upv on Sunday for a very simple answer
 
12:52 PM
RTFM answers on the C# tag also gain lots of upvotes…
 
yeah, maybe we should do the meta about "lacks minimal understanding"
someone who answers haskell mostly might be oblivious to these :D
 
The sad thing is that the C# community almost never closes questions.
It’s incredibly hard to get questions closed there.
 
we should do a system that would see if a question is posted with SyntaxError in it
 
@AnttiHaapala For some posts... "should give up, and pursue another career" would be a great OT reason :p
 
that it should be cv-plsd
@JonClements "not much luck in programming, maybe you should try knitting.stackexchange.net"
 
12:54 PM
@AnttiHaapala that's a good idea for nidaba... there's even a syntax-error tag I believe
 
RTFEM
 
can be even blind cv-pls, and ppl can evaluate if it is good
bc there are patterns in questions, about some ppl who are just noobs but can become good programmers, and others who will stay clueless forever...
 
re-cbg
 
Explanation vs. code-only answer. Guess who gets accepted?
Happens all the time, and shows very well who can become a good programmer and who simply doesn’t care enough.
 
always choose the "code only answer"
or the "code only answer that you feel most comfortable with"
that is "not those generators or list comprehensions but plain old while"
also I do not undrestand the question
 
@BhargavRao see, I knew that that was a troll account.
 
Yep.
That's called Ninja vision
 
@AnttiHaapala: that account is just trolling now. Flagged for ICBM treatment.
 
I know
re-edited tags there
 
ICBM?
 
1:05 PM
inter-continental ballistic missile
aka nuke
 
Seems appropriate
 
nucular therapy
 
@Vader Surprised you don't know that considering how many Russia has :p
 
International Conference on Business and Management
 
@Jon you're confusing Vader and Vaultah I think (senility from your recent birthday maybe? Old age setting in?)
 
1:10 PM
Oh well... I'm sure the Death Star had some form of ICBM cough cough
 
Why do I not get a typeError when running the second line?
In[7]: 'b'.capitalize()
Out[7]: 'B'
In[8]: 3.capitalize()
  File "<ipython-input-8-3f6be13b10d2>", line 1
    3.capitalize()
               ^
SyntaxError: invalid syntax
 
Because it reads it as 3. and then capitalize()
So it's a float (3.0) followed by capitalize()
Which is syntactically incorrect.
 
it is because the tokenizer is greedy
>>> 3.
3.0
 
In [38]: (3).capitalize()
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "c:\python34\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-38-595c77ec7a2e>", line 1, in <module>
    (3).capitalize()
AttributeError: 'int' object has no attribute 'capitalize'
 
1:22 PM
Software user question, nothing to do with programming.
 
My ipython install is messed up :/
 
I see, makes sense now
 
@Vader
>>> tokenize.tokenize(iter(['''3.capitalize()''']).next)
1,0-1,2:        NUMBER  '3.'
1,2-1,12:       NAME    'capitalize'
1,12-1,13:      OP      '('
1,13-1,14:      OP      ')'
2,0-2,0:        ENDMARKER       ''
 
Unclear, no expected output given even after asking.
 
1:23 PM
@Ffisegydd I could never get that working properly. I like the way SAGE handles this. Install virtual box, have fun.
 
@AnttiHaapala what is this telling me?
 
exactly how python parses the input
 
It parses it as a number (3.) then a name (capitalize) then two ops (())
 
the parser deals with these tokens
since there is no rule for "number followed by name" then it says "syntax error"
c.f.
>>> tokenize.tokenize(iter(['''(3).capitalize()''']).next)
1,0-1,1:        OP      '('
1,1-1,2:        NUMBER  '3'
1,2-1,3:        OP      ')'
1,3-1,4:        OP      '.'
1,4-1,14:       NAME    'capitalize'
1,14-1,15:      OP      '('
1,15-1,16:      OP      ')'
2,0-2,0:        ENDMARKER       ''
... and on the related note, the tokenize function has the most idiotic interface of all
remnant of the time gone by when there were no generators
 
ahh, now I see what it's doing
 
1:28 PM
better yet:
lines = code.splitlines(true)
tokenize.tokenize(iter(lines).next)
 
This is another weird thing I don't understand
In[12]: 'test\nline2'
Out[12]: 'test\nline2'
In[13]: print('test\nline2')
test
line2
 
@PM2Ring, thanks again
@Vader, evaluating != printing, what's weird about it?
 
@MarkR. No worries. Better late than never. :) But it's surprising nobody else noticed that screw-up.
 
I am making a blackjack game, I need to print out all card sina a deck (not HW btw)
 
@Vader when you print something the escaped chars will get used (i.e. \n for newline)
 
1:32 PM
@Vader Do you understand the difference between str() and repr()?
 
__str__ not print?
but it must be
It still prints
lemme read the docs
 
print will use the __str__ method for the object. Whilst just typing whatever into your console will use the __repr__ method.
 
Yes but this isn't in the console. I am calling print
 
Ah I see what you mean.
 
Stack Exchange is currently offline, we'll be back shortly!
 
1:36 PM
:D
 
Dafa?
Am I the only one?
 
And the site is gone again.
Hard this time.
 
Unfortunately I don't have time to explain why that \n appears at the mo, need to do some work before the GM.
 
@PM2Ring, I tend to glaze over code, E.G., i.imgur.com/DkGfDwX.jpg
 
@MartijnPieters So I'm not the only one!
 
1:37 PM
@Ffisegydd no worries, I am sure the docs will tell me sooner or later
 
We are taking our sites briefly offline to fix the issues we have been troubleshooting this morning.
 
@Vader though if I were going to store strings in a list, I'd store them without the newlines included. Then if I needed to print with lines I'd use '\n'.join(my_list_of_strings).
 
Good! We can concentrate more on our General Meeting. :)
 
@Ffisegydd I already have a way of doing that as well return '\n'.join(str(lst).split(', ')[1:-1])
but it's a lot of unnecessary type casting just for a new line
 
Exactly. If you just had list of strings without any '\n' it'd be '\n'.join(lst)
 
1:39 PM
I'd do any(map(print, list))
 
always with the fancy stuff
 
wish there was 'consume_all` in itertools
 
This is what the list looks like raw ['2 of Spades', '3 of Spades']
@Ffisegydd this seems to do the exact same thing as my method, just better
How did I miss that
 
Easy to accidentally overcomplicate something when you're engrossed in it :)
It's only when you step back and look at it that you may spot things.
 
Thanks for the help, as always
 
1:48 PM
@Vader since you're using Python 3, use print(*your_list, sep='\n') instead if you don't have new lines...
 
also do not ever call the dunder methods directly, ever... unless of course :d
 
dunder methods?
 
ah: Card.__str__(card) -> str(card)
 
__str__ for e.g.
 
how else would I do it?
 
1:49 PM
the __dunder__s are called by python..
 
the Card class has the __str__ method I can use to print the individual cards
 
the first rule is: you never call dunder methods yourself
the second rule is: except...
 
@Vader you use str(object)....
 
@JonClements thanks, Looks good
 
when you have 335k rep like martijn and have programmed python for 20 yrs then you can call dunder methods directly :D
 
1:52 PM
what is dunder?
 
double under. Referring to the double underscores.
 
okay
I was googling it and found some liquid related stuff.
str(card) is different from Card.__str__(card)?
 
@AnttiHaapala oh come on... who doesn't write stuff like z = (2).__add__(5) ? :)
 
@JonClements actually I can't use print because it's I am defining the print statement __str__
 
@Vader yes, because Card.__str__(card) assumes that card is a Card, and why would you do that, just do str(card) and let it be what it wants to be
omg
also from your screenshot:
 
1:55 PM
@Vader okay... was under the impression you were building a list...
 
omg, okay, thanks
 
basically your whole method would be:
 
too bad you can't store the output of print in a variable
 
return '\n'.join(map(str, self.cards))
of course you can
 
@Vader Yes, because str() will fall back to other options if there is no __str__.
 
1:56 PM
but why would you
@MartijnPieters is there any case when there is no __str__
ah indeed
because it is not in the class
@Vader consider this:
>>> class Foo():
...     pass
...
>>> Foo.__str__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: class Foo has no attribute '__str__'
@Vader it is because the Foo class itself does not have the __str__ method at all
 
Hey guys, I tried to give class based views a shot but unfortunately I make really slow progress. Is it worth trying to keep learning and practicing it or should I go with the more low level functions?
 
@IbrahimApachi can we assume you're talking django?
 
@IbrahimApachi your question lacks context
 
yes django :D
 
somehow I assumed..
 

« first day (1585 days earlier)      last day (3355 days later) »