« first day (977 days earlier)      last day (4196 days later) » 

03:16
Hi does anyone know which file contains the built-in function filter(function, iterable), source code for python?
Which version of python? Also why?
2.7.5
I want to understand why when getting the intersection of 2 dicts
that the following code is so efficient
def dictintersect():
... return filter(evens.has_key, to500.keys())
yes
awesome thanks
You're welcome :)
Is it considerably faster than a dict comprehension?
03:21
It is faster
than any of the solutions in this question
3
Q: Python (2.7): Why is there a performance difference between the following 2 code snippets that implement the intersection of two dictionaries

pponeThe following 2 code snippets (A & B) both return the intersection of 2 dictionaries. Both of following 2 code snippets should run in O(n) and output the same results. However code snippet B which is pythonic, seems to run faster. These code snippets come from the Python Cookbook. Code Snipp...

Like way faster, but only for Python 2.7. Python 3 has different facilities for comparison
For python 3, this seems to be the fastest
def reallyfastdictintersection():
... return to500.keys() & evens.keys()
that code won't work on Python 2
Is this an actual bottleneck in your application or are you just curious?
curious
was reading Python Cookbook
very nice book
Yeah, the speed of this sort of thing seems implementation independent. Usually when you do intersections you use sets anyway. I think that sets are implemented internally by dictionaries (at least that's how they are in other programming language I know) which means python has to optimize at least one way to find the intersection.
Ok
Chances are that if you go to the set source code and find out what it uses for intersection - that's the fastest way.
03:26
Yea let me do that.
def reallyreallyfastintersect():
... return set(to500).intersection(set(evens)) is slower than
def reallyfastdictintersection():
... return to500.keys() & evens.keys()
If you use control+K you won't need the ... :)
the code is different for set intersection
vs builtin filter
lol
Yeah, I saw :)
cpython is pretty slow anyway isn't it?
03:41
I guess so :)
Python Cookbook is a good book.
Looking forward to reading more of it.
Also why does the cpython source code has GOTO
Isn't that suppose to be bad coding styel
Yes, yes it is.
thanks for the help. I am off to bed, goodnight!
 
2 hours later…
05:58
hi Good morning
morning
06:48
Cabbage, Banana Morning Folks!
cabbage
potato?
07:09
half a bean, you?
07:21
Half a bean? Fascinating...
07:32
hello room
how r u all
I'm fine, dunno about the room.
great
I am gina
from italy
@InbarRose where are u from
I am new to python
need some help
could you pls help
What seems to be the problem?
cabbage
zup mp
07:40
not much
Your gravatar changed ?
I have a project on SVN and I want to get the source files from a mentioned revision to a folder on my machine, How to do it using python. i have no clue could you pls help me to start
Well. How would you do it without using Python?
i would clone to my local machine
@InbarRose oh yeah i wanted to change it but forgot
07:43
now i want to get the files automatically when i run the script
Python is not magic
It can be used to automate the process that you would do yourself
So you just need to run Python and call subprocess to perform the same commands you would.
So if YOU know how to do it without Python, all you need to do is learn how to make Python run do what you already know how to do.
i dont know
how would i do it
If YOU don't know how to do it without Python, how can you do it with Python?
@cavallo Do you have access to the svn sources folder? as in do you know what is the full path to the folder you want to retrieve?
no i know how to do it manually, create a folder and clone the files to that folder. Now i want to create a folder using python and then get the source files to that folder using python
yes i do @MaxPower
07:48
Do you know how to do what you want to do using the command line?
Learn that.
I am new to this
Once you know, then using Python is simple.
@MaxPower could u please help me
07:49
The way to use Python for this is to have Python do all the command line calls for you, this is faster than typing - and can be mobilized with options, arguments, and etc etc...
how would i start?
what is the script to create a folder ?
So YOU need to read the command line documentation for whatever SVN application you are using.
hnnnnng
i am stuck
dont know how to start with
create a folder on a machine?
Do you know how to do it in any programming language?
08:02
@cavallo look for how to read / write files. Then poissbly how to copy files. Then how to play with file paths... For loops... Combine these all together...
directory = 'E:\_WorkArea\somewhere'
if not os.path.exists(directory):
os.makedirs(directory)
i created a folder on my machine
It's a process... You can't expect anyone to provide you with like easy steps on how to do it... It's subjective to your environment and needs, etc...
well that's a start
yeah
@MaxPower thanks
08:04
itertools.combinations(iterable, r) <-- is there builtin function that returns all possible combinations without requiring r
@cavallo If along the way you encounter things that you don't quite understand, you can ask about them specifically and people will probably be able to help
thanks @MaxPower that sounds good
i will start with coping files now
@InbarRose I'm thinking that Python is probably not the best choice to do what i am trying to do (with the avi file length). Do you agree?
That depends - what are you trying to do?
08:27
ok, in your opinion: gist.github.com/anonymous/4671f2117b76e6feacb3 <-- is this combination finding code very ugly?
I would do something like, c = [list(itertools.combinations(subs, x)) for x in range(len(l), 0, -1)]
Yeah, for some superstitious thinking I dislike while loops. For sounds so much more confident :)
I'm pretty sure while is always slower since you are dealing with variable increment/decrement completely in Python whereas for lets C do much of the work.
But obviously sometimes you need it.
The speed difference between While and For loops are entirely dependent on what they are doing. And each type of loop is for a different type of action/method... So there is no use comparing them - you will either use one or the other, and never have a need to choose.
08:44
@user2144553 dont use getters. it's python we're all consenting adults here.
you're not a java programmer are you!?
ARE YOU!?
@limelights, this is edx course. Think of it like training brain muscles
first month you do 20 push ups, the following month 50
and now, already during the first month, you can do 35!
@limelights, what the pythonic way to write def getName(self):?
the pythonic way would be not to.
as i said, we're all consenting adults here, we dont put locks on our doors.
Using a @property probably
08:48
but if you wanted to do a "get/set" use @property
@Jared, perhaps a simple code example?
`@property
def name(self):
return self.name`
09:07
@InbarRose sorry for the delay :P All i'm trying to do is print back all of the avi files' lengths
09:32
if you have a bunch of lists within a list like this [class, class, class], then how to add those lists to dictionary?
d = {'lotsoflists': []}
Hi Folks
sorry for interruption......... is there any one have experienced in djangg framework.
i really need help. please if any
yeah, what's the problem?
Thanks @limelight:
Here is the model

class DiscountUsagePerUser(models.Model):
discount = models.OneToOneField(Discount, primary_key=True)
userAllowedUses = models.IntegerField(max_length=3, default=0, verbose_name='Allowed uses for user')

class DiscountUsageRecord(models.Model):
email = models.EmailField(max_length=255, verbose_name='User Email')
discount = models.ForeignKey(Discount)
additionalUses = models.IntegerField(max_length=3, default=0, verbose_name='Additional usage')
order = models.ManyToManyField(Order)
you can see the "order" as m2m relation
this order need to displayed in tabular format inline
i have spend an hour but did found the correct format
this the admin module for the order that need to be displayed inline

class OrderPerUserInline(admin.TabularInline):
model = DiscountUsageRecord.order.through
exclude = ('order', )
can_delete = False
extra = -1
def ID(self, instance):
if instance.order_id:
order_id = instance.order_id
return mark_safe(u'<a href="/admin/shop/order/%s/" target="_blank">%s</a>' % (order_id, order_id))
else:
return mark_safe(u'<a href="#">View</a>')
def Name(self, instance):
if instance.order_id:
name = instance.order.contact
please post it as a question if you have this much code :) or at least make a gist :)
09:42
ok sure..
but just wanted to knwo
will it be possible to know the template associated for admin module
Please let me know if it does make sense
i am a kind of noob for django and wanted to know the html file associated to an admin in the admin module itself
you want to know where to find it?
would be great to know in the admin class itself
you can probably set it with template = "templatelocation/sometemplate.html"
i see now you're using a tabularinline, i'm not sure that you can override that template from within django
yes you are right.... overriding template and wanted to know that template location
i tried but unable to find the template location.
09:55
what?
I wanted to override the template but unable to find its location
@MaNKuR you can find the template within your django installation
@user2144553 what do you mean? you've probably not updated the code.
okay
xz is never changed to t_value
you loop over xz and append to t_value
@limelights, if I run it in ipython notebook, then xz list is changed
before:

[[(<__main__.Subject object at 0x3440a50>, <__main__.Subject object at 0x3440a10>, <__main__.Subject object at 0x3440a90>, <__main__.Subject object at 0x3440ad0>)]


after:

[[(<__main__.Subject object at 0x3440a50>, <__main__.Subject object at 0x3440a10>, <__main__.Subject object at 0x3440a90>, <__main__.Subject object at 0x3440ad0>), 37, 24, 0]
completely stumped, is it enumerate's fault?
10:07
there is something else happening
the lists are of equal length
the lists are the exact same length and the thing that changes are the stuff that is within the list
where you add the totals
you're actually messing with the list t_value[v].append()
where v is the same object in both t_value and xz
v is a number? t_value[v] == e.g. t_value[1]
10:27
yeah, v is a number (the list indice) but it refers to a Subject object that you append to t_value at line 68
how do I avoid this
so when you do t_value[v].append you're appending to the object that is at the v index of the list t_value
well, you can either not do lines 69, 70, 71
lol, I am staring into abyss
and rethink your entire design
10:57
cabbage
cabbage
I have a non python. yet python related question
are there any languages like visual basic that work well with python. Mostly for gui programming on a linux OS
why not use wx / tkiner or the likes? or are these for windows only? i never checked tbh
Is there a better faster way then mine?
0
A: How to format string padding both sides to center it around particular point

Peter VaroFirst: store your informations in an ordered dictionary, to preserve its order, and also get the data organized into key-value pairs: import collections d = collections.OrderedDict([ ('SERiES', 'Game of Thrones'), ('SiZE', '47,196,930,048 bytes'), ('AUDiO FORMATS', 'English: DTS-HD ...

I like your answer, it makes the most sense to me
11:02
@Inhale.Py thanks
no questions im able to answer today =(
@PeterVaro answer looks good - aren't you just missing the |'s though ?
yepp I'm writing it right now
@JonClements for GUI design in linux, is there anything like visual basic? Or is using something like python with tkinter a better a option?
@Peter also the longest key is more easily done as max(map(len, pairs))
@Inhale.Py there's Wx, Qt Glade and others - depending how "nice"/complex/cross-compatible you want it to be
11:17
@JonClements in your opinion which one has the "nicest" looking interface, and which is the easiest to use.
68
@Inhale.Py can't say I've used all of them
or delved that much into what's good/bad - never had to really do GUIs - so...
Please can you help to convert time_stamp
2013-06-17 08:26:29.130761 to 17th Jun 2013 08:26
=( I'll figure it out eventually, my goal is to develop software for Linux, Software with beautiful GUI's that have clean and easy to use interfaces.
@MaNKuR have a look at strptime
@PeterVaro ignore my previous comment - I was looking at the other answer - d0h! More tea needed!
11:21
Although having said that, I do prefer map in that case, but others will disagree ;)
no, i love map
although, thinking about it, i suck at python so i dont qualify to belong to the category of others.
@limelights your opinion is the same as mine - so therefore you count? :)
Besides, if you don't belong in the category of others, and only I can belong in the category of "me" - where the hell do we fit you in? :)
the rest that suck at python? :)
i being selfcritical though
you don't suck at Python - sheesh man ;)
thanks :P
i still sometimes program python as i program java
11:26
With trepidation, fear and loathing?
yes
i fruiting hate java
@JonClements done! I've added the paragraph decorator function
@limelights ahhh, we have "yamming" for that purpose apparently ;)
yes, i saw but yamming doesn't really convey the sweetness of my yamming towards it
@PeterVaro cool - nice use of OrderedDict - just going to have a quick go at doing that myself.... might be able to make it more compact
11:29
haha:)
I'm sure you will
@limelights we need a mega-yam or something? :)
my goal was here
to create separatly useable functions
so they are universal, and can be used elsewhere too
good job ;) I see Python has wrapped itself around you and refusing to let go then ;)
absolutely:)
@PeterVaro you are aware of textwrap.wrap right ?
11:34
yepp
but that is freakin slow
I created two snippets for myself a few weeks ago, char_wrap and word_wrap
they are faster and more customizable than the "builtin" ones
okie dokies
@JonClements here they are:
    def char_wrap(string, width=80):
        output = list()
        for i in xrange(0, len(string), width):
            try:
                line = string[i:i + width]
            except IndexError:
                line = string[i:]
            output.append(line)
        return output


    def word_wrap(string, width=80, indent=4, tab=True):
        output = list()
        for ln in string.replace('\t', ' ' * indent).split('\n'):
            line = list()
            for wd in ln.split(' '):
Okay thanks - although it's not incorrect most people will go for [] instead of list() (and if you're concerned about speed - it's likely to be faster)
really?
[] is easier to parse as an empty list literal
11:42
yeah, normally creating inline literals is more lightweight and easier to parse than creating the object
wow.. did not know that.. thanks guys
plus, someone can't bugger it up by doing list = set somewhere in your code
oh.. that is also a fair point although I always warn everyone, not to use builtin names as variables
:)
    import timeit

    print timeit.timeit("""
    l = []
    l.append(1)
    """)
    # 0.31409406662
    print timeit.timeit("""
    l = list()
    l.append(1)
    """)
    # 0.426775932312
you are all right.. yes
sometimes it is twice as fast (like Apple:))
it's the same for all literals
just fyi, if you were curious
11:48
@limelights i absolutely am! so i have to change that everywhere in my codes :(:( because I always used the verbosed versions..
:)
it depends though
if you're using list([1,2,3,4]) it makes a copy of the list [1,2,3,4]
a "shallow copy"
yeah, thanks @JonClements
12:06
oh i know that
i almost only use list() for declare
an empty list
rbrb
~
root = Tk()
#create a function for appending to clipboard and make it take an argument
def clipboard_append(inches_to_mm, plus_or_minus, js_tol):
    root.clipboard_clear()
    root.clipboard_append(inches_to_mm, plus_or_minus, js_tol)
#create a function that converts user input and sends an argument to clipboard_append
def js_tolerance():
    mm_to_inches = 25.4
    user_input = input("Enter number here > ")
    user_input = float(user_input)
    inches_to_mm = user_input / mm_to_inches
    if user_input <= 3.0:
syntax error: line 6
clipboard_append takes 2 arguments
4 were given
wtf?
anyone got an idea?
12:21
root.clipboard_append(inches_to_mm, plus_or_minus, js_tol)
You gave it three things, it expected one.
(well technically you gave it four things and it expected two. Some magic is performed when you call an object's method, taking root and putting it in as the first argument)
Well i fixed my problem by changing up the code a bit
from tkinter import *
root = Tk()
#create a function for appending to clipboard and make it take an argument
def copy_to_clip(output):
    root.clipboard_clear()
    root.clipboard_append(output)
#create a function that converts user input and sends an argument to clipboard_append
def js_tolerance():
    mm_to_inches = 25.4
    user_input = input("Enter number here > ")
    user_input = float(user_input)
    inches_to_mm = user_input / mm_to_inches
    if user_input <= 3.0:
	    js_tol = (20 / 100) /25.4
thats what I got
And does it copy the right data to the clipboard?
si senior
entering .3 copys these results
We determined a month ago that clipboard_append occasionally breaks when you pass it a tuple instead of a string, which is what you're doing here.
0.012 ± 0.008
12:25
So, if it starts acting wonky, that's the first place to look.
It's working
for now at least
if user_input > 3 and < 6:
why do I get a syntax error on that line? Is that not allowed
That's not allowed. There's two ways to do it.
if user_input > 3 and user_input < 6
or
or .... 3 < user_input < 6
^^^ Yeah
thank you
works like a charm, and I learned something
12:30
Most people learn that the hard way. They'll do something like, if x == 0 or 100, which produces no syntax errors, but does not act the way they expect
yeah I ran into this problem once before and just gave up
x = 50
if x == 0 or 100:
    print "x equals zero or one hundred"
else:
    print "x does not equal zero or one hundred"
Expected output: "x does not equal zero or one hundred". Actual output: "x equals zero or one hundred"
@JonClements any luck on making the dictionary formatting more compact?
@Kevin They might even put brackets around 0 or 100: x == (0 or 100).
thats gonna make today so much easier for me
=D
12:35
God forbid they do if x == (1 or 100), and only test it half way. It will appear to work for most cases, but pick the wrong branch when x == 100
@PeterVaro no - work distracted me
that's ok
What do you write here: gist.github.com/anonymous/f44a934b6d5105040dab Can def __init__(self): be empty?
Not empty as such. You ought to put a pass statement in at least.
@Kevin or be really cruel and just put a docstring ;)
12:46
i believe docstring to be better, then at least you tried documenting that you were thinking
Does the docstring thing actually work if you run with -OO?
class Widget:
    def __init__(self):
        """This space intentionally left blank."""
It does work with -OO (I tried it)
Same
wow - that tongue in cheek remark got a few more sentences than I expected ;)
12:50
It's something that I had wondered about previously.
Never expect a joke to go un-dissected in a room full of computer folk.
Humor is a lot like a cat. When you take it apart to see how it works, it stops working.
--Somebody famous, I dunno. George Carlin?
mm_to_inches = 25.4
    user_input = c.get()
    user_input = float(user_input)
    inches_to_mm = user_input / mm_to_inches
my bad
mm_to_inches = 25.4
user_input = c.get()
user_input = float(user_input)
inches_to_mm = user_input / mm_to_inches
cant convert string to float error, before you get a chance to enter
anything
What's this c thing?
an entry box
c = Entry(root, width = 10)
c.bind('<Return>', js_tolerance)
c.grid(row=0, column=0)
v = StringVar()
Label(textvariable = v, width = 10).grid(row=0, column=1)
12:54
Well, the entry box is initially empty, so when you do c.get(), it returns an empty string.
@Kevin come on - surely you know of c being the traditional shorthand for an Entry Box
And that can't be turned into a float.
Say, didn't you have this problem a month ago? I'm having some terrific deja vu.
not this exact problem, and the thing that confuses me is I am copying and pasting code from my other project
got it

« first day (977 days earlier)      last day (4196 days later) »