How do I look at the code for a python built in function e.g. min()?
Thanks
I am running 2.7.8 on OSX
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Are you asking for the source code? For the CPython implementation, PyPy,
IronPython, Jhyton?
For the CPython implementation you can go to the repository:
http://hg.python.org/cpython/branches
Builtin implementations in C (for 2.7 version) are in the file:
http://hg.python.org/cpython/file/81898
Thanks Raúl,
T'was the latter two.
-u
-Original Message-
From: Raúl Cumplido
To: uga...@talktalk.net
CC: tutor
Sent: Thu, 31 Jul 2014 10:36
Subject: Re: [Tutor] accessing code for built in min()
Are you asking for the source code? For the CPython implementation, PyPy,
Iron
I am on OSX, which needs to escape spaces in filenames with a backslash.
There are multiple files within one directory that all have the same
structure, one or more characters with zero or more spaces in the
filename, like this:
3 Song Title XYZ.flac.
I want to use Python to call ffmpeg to convert
On 7/31/2014 12:53 PM, C Smith wrote:
I am on OSX, which needs to escape spaces in filenames with a backslash.
There are multiple files within one directory that all have the same
structure, one or more characters with zero or more spaces in the
filename, like this:
3 Song Title XYZ.flac.
I want
>Change:
>subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
>to:
>subprocess.call(['ffmpeg', '-i', '"%s"' % filename, str(track)+'.mp3'])
I still get the same errors, the filenames are passed to the shell
without escaping the spaces.
>Why not using ffmpeg without jumping into Pyt
Even when I am using:
re.sub('/s', '\\/s', filename)
I am still getting the same output, even trying to assign the above to
a new variable doesn't work (as I wasn't sure if re.sub returned a new
value or changed filename in place, I tried both with)
Does the Python interpreter strip off backslashes
Okay I messed up with slash instead of backslash, so the re.sub()
works, but I am still curious about the previous question.
On Thu, Jul 31, 2014 at 6:14 PM, C Smith wrote:
> Even when I am using:
> re.sub('/s', '\\/s', filename)
> I am still getting the same output, even trying to assign the abo
Actually, I can get re.sub() to print the filenames where they look
like they would be in the correct format for the shell, like this:
10\ track \number \ten.flac
but the shell still says that no such file exists, and I am sure I am
operating on them in the right place because I can modify them. So
You may have already have solved your problem, unfortunately my
emails are coming in slowly and out of order, but I have a suggestion:
On Thu, Jul 31, 2014 at 03:53:48PM -0400, C Smith wrote:
> I am on OSX, which needs to escape spaces in filenames with a backslash.
Same as any other Unix, or Li
Oops, a silly bug:
On Fri, Aug 01, 2014 at 08:35:34AM +1000, Steven D'Aprano wrote:
> directory = '/path/to/the/directory'
> for track, filename in enumerate(os.listdir(directory), 1):
> pathname = os.path.join(directory, filename)
> subprocess.call(['ffmpeg', '-i', filename, str(track)+'
>for track, filename in enumerate(os.listdir(directory), 1):
It seems kinda counter-intuitive to have track then filename as
variables, but enumerate looks like it gets passed the filename then
track number. Is that correct and just the way enumerate works, a
typo, or am I missing something else he
woops, I see it pathname != filename
On Thu, Jul 31, 2014 at 6:55 PM, C Smith wrote:
>>for track, filename in enumerate(os.listdir(directory), 1):
> It seems kinda counter-intuitive to have track then filename as
> variables, but enumerate looks like it gets passed the filename then
> track numbe
Works now, thanks!
On Thu, Jul 31, 2014 at 6:57 PM, C Smith wrote:
> woops, I see it pathname != filename
>
> On Thu, Jul 31, 2014 at 6:55 PM, C Smith wrote:
>>>for track, filename in enumerate(os.listdir(directory), 1):
>> It seems kinda counter-intuitive to have track then filename as
>> varia
Huh, that is quite an annoyance about changing the order though. Any
ideas about that? I will look into it further in the meantime...
On Thu, Jul 31, 2014 at 6:57 PM, C Smith wrote:
> Works now, thanks!
>
> On Thu, Jul 31, 2014 at 6:57 PM, C Smith wrote:
>> woops, I see it pathname != filename
>
thanks, got it
import os, subprocess, re
directory = 'abs/path'
for track, filename in enumerate(os.listdir(directory), 1):
pathname = os.path.join(directory, filename)
subprocess.call(['ffmpeg', '-i', pathname, filename+str(track)+'.mp3'])
On Thu, Jul 31, 2014 at 7:02 PM, C Smith wrote:
or more accurately
import os, subprocess, re
directory = '/abs/path'
for track, filename in enumerate(os.listdir(directory), 1):
pathname = os.path.join(directory, filename)
subprocess.call(['ffmpeg', '-i', pathname, filename[:-5]+'.mp3'])
On Thu, Jul 31, 2014 at 7:13 PM, C Smith wrote:
>
C Smith wrote:
I'd throw in a check to verify that filename is indeed a flac:
> or more accurately
> import os, subprocess, re
> directory = '/abs/path'
> for track, filename in enumerate(os.listdir(directory), 1):
> pathname = os.path.join(directory, filename)
if filename.endswith(".fl
Nice, these are useful tools. I have been building something with just
basic stuff and avoiding learning any libraries. If I wanted to get
some insight on a larger program that is about 1000 lines, would that
be doable here?
On Thu, Jul 31, 2014 at 7:37 PM, Peter Otten <__pete...@web.de> wrote:
>
I would like to see if someone can help me with a python script. I'm trying to
export a file geodatabase feature class to csv file. This is what I have so
far:
import arcpy
import os
import csv
import domainvalues
def export_to_csv(dataset, output, dialect):
"""Output the data to a CSV f
On 01Aug2014 08:35, Steven D'Aprano wrote:
[...]
I want to use Python to call ffmpeg to convert each file to an .mp3.
So far this is what I was trying to use:
import os, subprocess
track = 1
for filename in os.listdir('myDir'):
subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
What is the difference between dict.get() and dict.get as shown in the
code below:
counts = dict()
for line in input_file:
words = line.split()
if len(words) == 0:
continue
else:
if words[0] != 'From:':
continue
else:
counts[words[1]]
memilanuk writes:
> What is the difference between dict.get() and dict.get
The ‘foo()’ syntax calls ‘foo’.
‘dict.get’ is the function (an attribute of the ‘dict’ type), and you
can call that function by specifying parameters in parens ‘()’.
> counts[words[1]] = counts.get(words[1],
On Thu, Jul 31, 2014 at 07:56:23PM -0700, memilanuk wrote:
> What is the difference between dict.get() and dict.get as shown in the
> code below:
Depending on how you look at it, the difference is either "nothing at
all", or "the round brackets ()". And I'm not trying to be funny.
Experimenting
On 07/31/2014 08:22 PM, Ben Finney wrote:
memilanuk writes:
>> So... the similarity between dict.get() and dict.get as used here is
>> kinda confusing me.
>
> I hope that helps. They are the same function; but the former is
> *calling* the function object, and optionally using the return value;
On 01/08/14 06:12, memilanuk wrote:
counts = {'a':1, 'b':22, 'c':100}
then counts.get('b') should return 22. I got that much.
And counts.get is just an uncalled version of that:
foo = counts.get
foo('b')
should return 22 as well. Think I got that as well.
Well done, thats the crux of it.
memilanuk writes:
> On 07/31/2014 08:22 PM, Ben Finney wrote:
> >> max_key = max(counts, key=counts.get)
> >
> > This specifies ‘counts.get’, without calling it. The expression
> > ‘counts.get’ evaluates to that function object.
> >
> > That value is then used as the value for the ‘key’ parameter
27 matches
Mail list logo